@kamino-finance/klend-sdk 5.10.34 → 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 +31 -25
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +604 -193
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +11 -2
- 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/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.map +1 -1
- package/dist/classes/vault.js +4 -4
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +6 -1
- 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/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 +770 -196
- package/src/classes/manager.ts +14 -1
- package/src/classes/reserve.ts +2 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +6 -7
- package/src/client.ts +7 -3
- package/src/client_kamino_manager.ts +8 -1
- 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/managerTypes.ts +1 -0
- package/src/utils/seeds.ts +13 -0
- package/src/utils/userMetadata.ts +21 -26
package/src/classes/action.ts
CHANGED
|
@@ -21,9 +21,12 @@ import BN from 'bn.js';
|
|
|
21
21
|
import Decimal from 'decimal.js';
|
|
22
22
|
import {
|
|
23
23
|
borrowObligationLiquidity,
|
|
24
|
+
borrowObligationLiquidityV2,
|
|
24
25
|
depositObligationCollateral,
|
|
26
|
+
depositObligationCollateralV2,
|
|
25
27
|
depositReserveLiquidity,
|
|
26
28
|
depositReserveLiquidityAndObligationCollateral,
|
|
29
|
+
depositReserveLiquidityAndObligationCollateralV2,
|
|
27
30
|
initObligation,
|
|
28
31
|
initObligationFarmsForReserve,
|
|
29
32
|
InitObligationFarmsForReserveAccounts,
|
|
@@ -31,6 +34,7 @@ import {
|
|
|
31
34
|
initReferrerTokenState,
|
|
32
35
|
initUserMetadata,
|
|
33
36
|
liquidateObligationAndRedeemReserveCollateral,
|
|
37
|
+
liquidateObligationAndRedeemReserveCollateralV2,
|
|
34
38
|
redeemReserveCollateral,
|
|
35
39
|
refreshObligation,
|
|
36
40
|
refreshObligationFarmsForReserve,
|
|
@@ -38,10 +42,12 @@ import {
|
|
|
38
42
|
RefreshObligationFarmsForReserveArgs,
|
|
39
43
|
refreshReserve,
|
|
40
44
|
repayObligationLiquidity,
|
|
45
|
+
repayObligationLiquidityV2,
|
|
41
46
|
requestElevationGroup,
|
|
42
47
|
RequestElevationGroupAccounts,
|
|
43
48
|
RequestElevationGroupArgs,
|
|
44
49
|
withdrawObligationCollateralAndRedeemReserveCollateral,
|
|
50
|
+
withdrawObligationCollateralAndRedeemReserveCollateralV2,
|
|
45
51
|
withdrawReferrerFees,
|
|
46
52
|
} from '../idl_codegen/instructions';
|
|
47
53
|
import {
|
|
@@ -54,11 +60,10 @@ import {
|
|
|
54
60
|
createLookupTableIx,
|
|
55
61
|
isNotNullPubkey,
|
|
56
62
|
PublicKeySet,
|
|
57
|
-
WRAPPED_SOL_MINT,
|
|
58
63
|
getAssociatedTokenAddress,
|
|
59
64
|
ScopeRefresh,
|
|
60
65
|
createAtasIdempotent,
|
|
61
|
-
|
|
66
|
+
obligationFarmStatePda,
|
|
62
67
|
} from '../utils';
|
|
63
68
|
import { KaminoMarket } from './market';
|
|
64
69
|
import { KaminoObligation } from './obligation';
|
|
@@ -322,10 +327,6 @@ export class KaminoAction {
|
|
|
322
327
|
...(action === 'depositAndBorrow' ? [outflowReserve!] : []),
|
|
323
328
|
]).toArray().length;
|
|
324
329
|
|
|
325
|
-
if (distinctReserveCount > POSITION_LIMIT) {
|
|
326
|
-
throw Error(`Obligation already has max number of positions: ${POSITION_LIMIT}`);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
330
|
return {
|
|
330
331
|
kaminoObligation,
|
|
331
332
|
depositReserves,
|
|
@@ -409,10 +410,12 @@ export class KaminoAction {
|
|
|
409
410
|
mint: PublicKey,
|
|
410
411
|
owner: PublicKey,
|
|
411
412
|
obligation: KaminoObligation | ObligationType,
|
|
413
|
+
useV2Ixs: boolean,
|
|
412
414
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
413
415
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
414
416
|
requestElevationGroup: boolean = false, // to be requested *before* the deposit
|
|
415
417
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
418
|
+
createLookupTable: boolean = true,
|
|
416
419
|
referrer: PublicKey = PublicKey.default,
|
|
417
420
|
currentSlot: number = 0,
|
|
418
421
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
@@ -450,10 +453,16 @@ export class KaminoAction {
|
|
|
450
453
|
requestElevationGroup,
|
|
451
454
|
includeUserMetadata,
|
|
452
455
|
addInitObligationForFarm,
|
|
456
|
+
useV2Ixs,
|
|
457
|
+
createLookupTable,
|
|
453
458
|
undefined,
|
|
454
459
|
overrideElevationGroupRequest
|
|
455
460
|
);
|
|
456
|
-
|
|
461
|
+
if (useV2Ixs) {
|
|
462
|
+
axn.addDepositIxV2();
|
|
463
|
+
} else {
|
|
464
|
+
axn.addDepositIx();
|
|
465
|
+
}
|
|
457
466
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
458
467
|
|
|
459
468
|
return axn;
|
|
@@ -503,10 +512,12 @@ export class KaminoAction {
|
|
|
503
512
|
mint: PublicKey,
|
|
504
513
|
owner: PublicKey,
|
|
505
514
|
obligation: KaminoObligation | ObligationType,
|
|
515
|
+
useV2Ixs: boolean,
|
|
506
516
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
507
517
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
508
518
|
requestElevationGroup: boolean = false,
|
|
509
519
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
520
|
+
createLookupTable: boolean = true,
|
|
510
521
|
referrer: PublicKey = PublicKey.default,
|
|
511
522
|
currentSlot: number = 0,
|
|
512
523
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
@@ -544,10 +555,16 @@ export class KaminoAction {
|
|
|
544
555
|
requestElevationGroup,
|
|
545
556
|
includeUserMetadata,
|
|
546
557
|
addInitObligationForFarm,
|
|
558
|
+
useV2Ixs,
|
|
559
|
+
createLookupTable,
|
|
547
560
|
undefined,
|
|
548
561
|
overrideElevationGroupRequest
|
|
549
562
|
);
|
|
550
|
-
|
|
563
|
+
if (useV2Ixs) {
|
|
564
|
+
axn.addBorrowIxV2();
|
|
565
|
+
} else {
|
|
566
|
+
axn.addBorrowIx();
|
|
567
|
+
}
|
|
551
568
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
552
569
|
|
|
553
570
|
return axn;
|
|
@@ -562,7 +579,6 @@ export class KaminoAction {
|
|
|
562
579
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
563
580
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
564
581
|
requestElevationGroup: boolean = false,
|
|
565
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
566
582
|
referrer: PublicKey = PublicKey.default,
|
|
567
583
|
currentSlot: number = 0,
|
|
568
584
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -598,8 +614,10 @@ export class KaminoAction {
|
|
|
598
614
|
'mint',
|
|
599
615
|
includeAtaIxns,
|
|
600
616
|
requestElevationGroup,
|
|
601
|
-
|
|
602
|
-
addInitObligationForFarm
|
|
617
|
+
false,
|
|
618
|
+
addInitObligationForFarm,
|
|
619
|
+
false,
|
|
620
|
+
false
|
|
603
621
|
);
|
|
604
622
|
axn.addDepositReserveLiquidityIx();
|
|
605
623
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
@@ -615,7 +633,6 @@ export class KaminoAction {
|
|
|
615
633
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
616
634
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
617
635
|
requestElevationGroup: boolean = false,
|
|
618
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
619
636
|
referrer: PublicKey = PublicKey.default,
|
|
620
637
|
currentSlot: number = 0,
|
|
621
638
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -651,8 +668,10 @@ export class KaminoAction {
|
|
|
651
668
|
'redeem',
|
|
652
669
|
includeAtaIxns,
|
|
653
670
|
requestElevationGroup,
|
|
654
|
-
|
|
655
|
-
addInitObligationForFarm
|
|
671
|
+
false,
|
|
672
|
+
addInitObligationForFarm,
|
|
673
|
+
false,
|
|
674
|
+
false
|
|
656
675
|
);
|
|
657
676
|
axn.addRedeemReserveCollateralIx();
|
|
658
677
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
@@ -665,10 +684,12 @@ export class KaminoAction {
|
|
|
665
684
|
mint: PublicKey,
|
|
666
685
|
owner: PublicKey,
|
|
667
686
|
obligation: KaminoObligation | ObligationType,
|
|
687
|
+
useV2Ixs: boolean,
|
|
668
688
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
669
689
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
670
690
|
requestElevationGroup: boolean = false,
|
|
671
691
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
692
|
+
createLookupTable: boolean = true,
|
|
672
693
|
referrer: PublicKey = PublicKey.default,
|
|
673
694
|
currentSlot: number = 0,
|
|
674
695
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -705,9 +726,15 @@ export class KaminoAction {
|
|
|
705
726
|
includeAtaIxns,
|
|
706
727
|
requestElevationGroup,
|
|
707
728
|
includeUserMetadata,
|
|
708
|
-
addInitObligationForFarm
|
|
729
|
+
addInitObligationForFarm,
|
|
730
|
+
useV2Ixs,
|
|
731
|
+
createLookupTable
|
|
709
732
|
);
|
|
710
|
-
|
|
733
|
+
if (useV2Ixs) {
|
|
734
|
+
axn.addDepositObligationCollateralIxV2();
|
|
735
|
+
} else {
|
|
736
|
+
axn.addDepositObligationCollateralIx();
|
|
737
|
+
}
|
|
711
738
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
712
739
|
return axn;
|
|
713
740
|
}
|
|
@@ -720,10 +747,12 @@ export class KaminoAction {
|
|
|
720
747
|
borrowMint: PublicKey,
|
|
721
748
|
payer: PublicKey,
|
|
722
749
|
obligation: KaminoObligation | ObligationType,
|
|
750
|
+
useV2Ixs: boolean,
|
|
723
751
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
724
752
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
725
753
|
requestElevationGroup: boolean = false,
|
|
726
754
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
755
|
+
createLookupTable: boolean = true,
|
|
727
756
|
referrer: PublicKey = PublicKey.default,
|
|
728
757
|
currentSlot: number = 0,
|
|
729
758
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -767,14 +796,22 @@ export class KaminoAction {
|
|
|
767
796
|
requestElevationGroup,
|
|
768
797
|
includeUserMetadata,
|
|
769
798
|
addInitObligationForFarmForDeposit,
|
|
799
|
+
useV2Ixs,
|
|
800
|
+
createLookupTable,
|
|
770
801
|
twoTokenAction
|
|
771
802
|
);
|
|
772
|
-
|
|
803
|
+
|
|
804
|
+
if (useV2Ixs) {
|
|
805
|
+
await axn.addDepositAndBorrowIxV2();
|
|
806
|
+
} else {
|
|
807
|
+
await axn.addDepositAndBorrowIx();
|
|
808
|
+
}
|
|
773
809
|
await axn.addInBetweenIxs(
|
|
774
810
|
'depositAndBorrow',
|
|
775
811
|
includeAtaIxns,
|
|
776
812
|
requestElevationGroup,
|
|
777
|
-
addInitObligationForFarmForBorrow
|
|
813
|
+
addInitObligationForFarmForBorrow,
|
|
814
|
+
useV2Ixs
|
|
778
815
|
);
|
|
779
816
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
780
817
|
return axn;
|
|
@@ -789,10 +826,12 @@ export class KaminoAction {
|
|
|
789
826
|
payer: PublicKey,
|
|
790
827
|
currentSlot: number,
|
|
791
828
|
obligation: KaminoObligation | ObligationType,
|
|
829
|
+
useV2Ixs: boolean,
|
|
792
830
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
793
831
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
794
832
|
requestElevationGroup: boolean = false,
|
|
795
833
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
834
|
+
createLookupTable: boolean = true,
|
|
796
835
|
referrer: PublicKey = PublicKey.default,
|
|
797
836
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
798
837
|
) {
|
|
@@ -834,17 +873,24 @@ export class KaminoAction {
|
|
|
834
873
|
requestElevationGroup,
|
|
835
874
|
includeUserMetadata,
|
|
836
875
|
addInitObligationForFarmForRepay,
|
|
876
|
+
useV2Ixs,
|
|
877
|
+
createLookupTable,
|
|
837
878
|
twoTokenAction
|
|
838
879
|
);
|
|
839
880
|
|
|
840
881
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
|
|
882
|
+
if (useV2Ixs) {
|
|
883
|
+
await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
|
|
884
|
+
} else {
|
|
885
|
+
await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
|
|
886
|
+
}
|
|
841
887
|
|
|
842
|
-
await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
|
|
843
888
|
await axn.addInBetweenIxs(
|
|
844
889
|
'repayAndWithdraw',
|
|
845
890
|
includeAtaIxns,
|
|
846
891
|
requestElevationGroup,
|
|
847
|
-
addInitObligationForFarmForWithdraw
|
|
892
|
+
addInitObligationForFarmForWithdraw,
|
|
893
|
+
useV2Ixs
|
|
848
894
|
);
|
|
849
895
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
850
896
|
return axn;
|
|
@@ -856,10 +902,12 @@ export class KaminoAction {
|
|
|
856
902
|
mint: PublicKey,
|
|
857
903
|
owner: PublicKey,
|
|
858
904
|
obligation: KaminoObligation | ObligationType,
|
|
905
|
+
useV2Ixs: boolean,
|
|
859
906
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
860
907
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
861
908
|
requestElevationGroup: boolean = false, // to be requested *after* the withdraw
|
|
862
909
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
910
|
+
createLookupTable: boolean = true,
|
|
863
911
|
referrer: PublicKey = PublicKey.default,
|
|
864
912
|
currentSlot: number = 0,
|
|
865
913
|
scopeRefresh: ScopeRefresh | undefined = undefined,
|
|
@@ -905,13 +953,19 @@ export class KaminoAction {
|
|
|
905
953
|
requestElevationGroup,
|
|
906
954
|
includeUserMetadata,
|
|
907
955
|
addInitObligationForFarm,
|
|
956
|
+
useV2Ixs,
|
|
957
|
+
createLookupTable,
|
|
908
958
|
false,
|
|
909
959
|
overrideElevationGroupRequest
|
|
910
960
|
);
|
|
911
961
|
|
|
912
962
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
963
|
+
if (useV2Ixs) {
|
|
964
|
+
await axn.addWithdrawIxV2(collateralAmount);
|
|
965
|
+
} else {
|
|
966
|
+
await axn.addWithdrawIx(collateralAmount);
|
|
967
|
+
}
|
|
913
968
|
|
|
914
|
-
await axn.addWithdrawIx(collateralAmount);
|
|
915
969
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
916
970
|
|
|
917
971
|
return axn;
|
|
@@ -938,12 +992,14 @@ export class KaminoAction {
|
|
|
938
992
|
mint: PublicKey,
|
|
939
993
|
owner: PublicKey,
|
|
940
994
|
obligation: KaminoObligation | ObligationType,
|
|
995
|
+
useV2Ixs: boolean,
|
|
941
996
|
currentSlot: number,
|
|
942
997
|
payer: PublicKey | undefined = undefined,
|
|
943
998
|
extraComputeBudget: number = 1_000_000,
|
|
944
999
|
includeAtaIxns: boolean = true,
|
|
945
1000
|
requestElevationGroup: boolean = false,
|
|
946
1001
|
includeUserMetadata: boolean = true,
|
|
1002
|
+
createLookupTable: boolean = true,
|
|
947
1003
|
referrer: PublicKey = PublicKey.default,
|
|
948
1004
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
949
1005
|
) {
|
|
@@ -980,9 +1036,15 @@ export class KaminoAction {
|
|
|
980
1036
|
includeAtaIxns,
|
|
981
1037
|
requestElevationGroup,
|
|
982
1038
|
includeUserMetadata,
|
|
983
|
-
addInitObligationForFarm
|
|
1039
|
+
addInitObligationForFarm,
|
|
1040
|
+
useV2Ixs,
|
|
1041
|
+
createLookupTable
|
|
984
1042
|
);
|
|
985
|
-
|
|
1043
|
+
if (useV2Ixs) {
|
|
1044
|
+
await axn.addRepayIxV2();
|
|
1045
|
+
} else {
|
|
1046
|
+
await axn.addRepayIx();
|
|
1047
|
+
}
|
|
986
1048
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
987
1049
|
|
|
988
1050
|
return axn;
|
|
@@ -997,10 +1059,12 @@ export class KaminoAction {
|
|
|
997
1059
|
liquidator: PublicKey,
|
|
998
1060
|
obligationOwner: PublicKey,
|
|
999
1061
|
obligation: KaminoObligation | ObligationType,
|
|
1062
|
+
useV2Ixs: boolean,
|
|
1000
1063
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
1001
1064
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
1002
1065
|
requestElevationGroup: boolean = false,
|
|
1003
1066
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
1067
|
+
createLookupTable: boolean = true,
|
|
1004
1068
|
referrer: PublicKey = PublicKey.default,
|
|
1005
1069
|
maxAllowedLtvOverridePercent: number = 0,
|
|
1006
1070
|
currentSlot: number = 0,
|
|
@@ -1042,9 +1106,15 @@ export class KaminoAction {
|
|
|
1042
1106
|
includeAtaIxns,
|
|
1043
1107
|
requestElevationGroup,
|
|
1044
1108
|
includeUserMetadata,
|
|
1045
|
-
addInitObligationForFarm
|
|
1109
|
+
addInitObligationForFarm,
|
|
1110
|
+
useV2Ixs,
|
|
1111
|
+
createLookupTable
|
|
1046
1112
|
);
|
|
1047
|
-
|
|
1113
|
+
if (useV2Ixs) {
|
|
1114
|
+
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
1115
|
+
} else {
|
|
1116
|
+
await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
|
|
1117
|
+
}
|
|
1048
1118
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
1049
1119
|
|
|
1050
1120
|
return axn;
|
|
@@ -1170,25 +1240,23 @@ export class KaminoAction {
|
|
|
1170
1240
|
return await sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
1171
1241
|
}
|
|
1172
1242
|
|
|
1173
|
-
|
|
1174
|
-
this.lendingIxsLabels.push(`
|
|
1243
|
+
addDepositReserveLiquidityIx() {
|
|
1244
|
+
this.lendingIxsLabels.push(`depositReserveLiquidity`);
|
|
1175
1245
|
this.lendingIxs.push(
|
|
1176
|
-
|
|
1246
|
+
depositReserveLiquidity(
|
|
1177
1247
|
{
|
|
1178
1248
|
liquidityAmount: this.amount,
|
|
1179
1249
|
},
|
|
1180
1250
|
{
|
|
1181
1251
|
owner: this.owner,
|
|
1182
|
-
obligation: this.getObligationPda(),
|
|
1183
1252
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1184
1253
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1185
1254
|
reserve: this.reserve.address,
|
|
1186
1255
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1187
1256
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1188
1257
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1189
|
-
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1190
1258
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1191
|
-
|
|
1259
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
1192
1260
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1193
1261
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1194
1262
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1198,12 +1266,12 @@ export class KaminoAction {
|
|
|
1198
1266
|
);
|
|
1199
1267
|
}
|
|
1200
1268
|
|
|
1201
|
-
|
|
1202
|
-
this.lendingIxsLabels.push(`
|
|
1269
|
+
addRedeemReserveCollateralIx() {
|
|
1270
|
+
this.lendingIxsLabels.push(`redeemReserveCollateral`);
|
|
1203
1271
|
this.lendingIxs.push(
|
|
1204
|
-
|
|
1272
|
+
redeemReserveCollateral(
|
|
1205
1273
|
{
|
|
1206
|
-
|
|
1274
|
+
collateralAmount: this.amount,
|
|
1207
1275
|
},
|
|
1208
1276
|
{
|
|
1209
1277
|
owner: this.owner,
|
|
@@ -1213,8 +1281,8 @@ export class KaminoAction {
|
|
|
1213
1281
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1214
1282
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1215
1283
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1216
|
-
|
|
1217
|
-
|
|
1284
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
1285
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1218
1286
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1219
1287
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1220
1288
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1224,23 +1292,26 @@ export class KaminoAction {
|
|
|
1224
1292
|
);
|
|
1225
1293
|
}
|
|
1226
1294
|
|
|
1227
|
-
|
|
1228
|
-
|
|
1295
|
+
// @deprecated -- use addDepositIxV2 instead
|
|
1296
|
+
addDepositIx() {
|
|
1297
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
1229
1298
|
this.lendingIxs.push(
|
|
1230
|
-
|
|
1299
|
+
depositReserveLiquidityAndObligationCollateral(
|
|
1231
1300
|
{
|
|
1232
|
-
|
|
1301
|
+
liquidityAmount: this.amount,
|
|
1233
1302
|
},
|
|
1234
1303
|
{
|
|
1235
1304
|
owner: this.owner,
|
|
1305
|
+
obligation: this.getObligationPda(),
|
|
1236
1306
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1237
1307
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1238
1308
|
reserve: this.reserve.address,
|
|
1239
1309
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1240
1310
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1241
1311
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1242
|
-
|
|
1243
|
-
|
|
1312
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1313
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1314
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1244
1315
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1245
1316
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1246
1317
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1250,6 +1321,52 @@ export class KaminoAction {
|
|
|
1250
1321
|
);
|
|
1251
1322
|
}
|
|
1252
1323
|
|
|
1324
|
+
addDepositIxV2() {
|
|
1325
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1326
|
+
? {
|
|
1327
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1328
|
+
reserveFarmState: PROGRAM_ID,
|
|
1329
|
+
}
|
|
1330
|
+
: {
|
|
1331
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1332
|
+
this.getObligationPda(),
|
|
1333
|
+
this.reserve.state.farmCollateral
|
|
1334
|
+
)[0],
|
|
1335
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
1339
|
+
this.lendingIxs.push(
|
|
1340
|
+
depositReserveLiquidityAndObligationCollateralV2(
|
|
1341
|
+
{
|
|
1342
|
+
liquidityAmount: this.amount,
|
|
1343
|
+
},
|
|
1344
|
+
{
|
|
1345
|
+
depositAccounts: {
|
|
1346
|
+
owner: this.owner,
|
|
1347
|
+
obligation: this.getObligationPda(),
|
|
1348
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1349
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1350
|
+
reserve: this.reserve.address,
|
|
1351
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1352
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1353
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1354
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1355
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1356
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1357
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1358
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1359
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1360
|
+
},
|
|
1361
|
+
farmsAccounts,
|
|
1362
|
+
farmsProgram: farmsId,
|
|
1363
|
+
},
|
|
1364
|
+
this.kaminoMarket.programId
|
|
1365
|
+
)
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
1253
1370
|
addDepositObligationCollateralIx() {
|
|
1254
1371
|
this.lendingIxsLabels.push(`depositObligationCollateral`);
|
|
1255
1372
|
this.lendingIxs.push(
|
|
@@ -1272,6 +1389,47 @@ export class KaminoAction {
|
|
|
1272
1389
|
);
|
|
1273
1390
|
}
|
|
1274
1391
|
|
|
1392
|
+
addDepositObligationCollateralIxV2() {
|
|
1393
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1394
|
+
? {
|
|
1395
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1396
|
+
reserveFarmState: PROGRAM_ID,
|
|
1397
|
+
}
|
|
1398
|
+
: {
|
|
1399
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1400
|
+
this.getObligationPda(),
|
|
1401
|
+
this.reserve.state.farmCollateral
|
|
1402
|
+
)[0],
|
|
1403
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1404
|
+
};
|
|
1405
|
+
|
|
1406
|
+
this.lendingIxsLabels.push(`depositObligationCollateralV2`);
|
|
1407
|
+
this.lendingIxs.push(
|
|
1408
|
+
depositObligationCollateralV2(
|
|
1409
|
+
{
|
|
1410
|
+
collateralAmount: this.amount,
|
|
1411
|
+
},
|
|
1412
|
+
{
|
|
1413
|
+
depositAccounts: {
|
|
1414
|
+
owner: this.owner,
|
|
1415
|
+
obligation: this.getObligationPda(),
|
|
1416
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1417
|
+
depositReserve: this.reserve.address,
|
|
1418
|
+
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
1419
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
1420
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1421
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1422
|
+
},
|
|
1423
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1424
|
+
farmsAccounts,
|
|
1425
|
+
farmsProgram: farmsId,
|
|
1426
|
+
},
|
|
1427
|
+
this.kaminoMarket.programId
|
|
1428
|
+
)
|
|
1429
|
+
);
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
1275
1433
|
addBorrowIx() {
|
|
1276
1434
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
1277
1435
|
|
|
@@ -1308,6 +1466,219 @@ export class KaminoAction {
|
|
|
1308
1466
|
this.lendingIxs.push(borrowIx);
|
|
1309
1467
|
}
|
|
1310
1468
|
|
|
1469
|
+
addBorrowIxV2() {
|
|
1470
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
1471
|
+
|
|
1472
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1473
|
+
|
|
1474
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1475
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1476
|
+
});
|
|
1477
|
+
|
|
1478
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1479
|
+
? {
|
|
1480
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1481
|
+
reserveFarmState: PROGRAM_ID,
|
|
1482
|
+
}
|
|
1483
|
+
: {
|
|
1484
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1485
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1486
|
+
};
|
|
1487
|
+
|
|
1488
|
+
const borrowIx = borrowObligationLiquidityV2(
|
|
1489
|
+
{
|
|
1490
|
+
liquidityAmount: this.amount,
|
|
1491
|
+
},
|
|
1492
|
+
{
|
|
1493
|
+
borrowAccounts: {
|
|
1494
|
+
owner: this.owner,
|
|
1495
|
+
obligation: this.getObligationPda(),
|
|
1496
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1497
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1498
|
+
borrowReserve: this.reserve.address,
|
|
1499
|
+
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1500
|
+
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1501
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1502
|
+
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
1503
|
+
referrerTokenState: referrerTokenStatePda(
|
|
1504
|
+
this.referrer,
|
|
1505
|
+
this.reserve.address,
|
|
1506
|
+
this.kaminoMarket.programId
|
|
1507
|
+
)[0],
|
|
1508
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1509
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1510
|
+
},
|
|
1511
|
+
farmsAccounts,
|
|
1512
|
+
farmsProgram: farmsId,
|
|
1513
|
+
},
|
|
1514
|
+
this.kaminoMarket.programId
|
|
1515
|
+
);
|
|
1516
|
+
borrowIx.keys =
|
|
1517
|
+
this.obligation!.state.elevationGroup > 0 || this.obligation!.refreshedStats.potentialElevationGroupUpdate > 0
|
|
1518
|
+
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
1519
|
+
: borrowIx.keys;
|
|
1520
|
+
this.lendingIxs.push(borrowIx);
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
/// @deprecated -- use addWithdrawIxV2 instead
|
|
1524
|
+
async addWithdrawIx(collateralAmount: BN) {
|
|
1525
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
1526
|
+
this.lendingIxs.push(
|
|
1527
|
+
withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
1528
|
+
{
|
|
1529
|
+
collateralAmount,
|
|
1530
|
+
},
|
|
1531
|
+
{
|
|
1532
|
+
owner: this.owner,
|
|
1533
|
+
obligation: this.getObligationPda(),
|
|
1534
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1535
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1536
|
+
withdrawReserve: this.reserve.address,
|
|
1537
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1538
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1539
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1540
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1541
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1542
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1543
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1544
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1545
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1546
|
+
},
|
|
1547
|
+
this.kaminoMarket.programId
|
|
1548
|
+
)
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
async addWithdrawIxV2(collateralAmount: BN) {
|
|
1553
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1554
|
+
? {
|
|
1555
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1556
|
+
reserveFarmState: PROGRAM_ID,
|
|
1557
|
+
}
|
|
1558
|
+
: {
|
|
1559
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1560
|
+
this.getObligationPda(),
|
|
1561
|
+
this.reserve.state.farmCollateral
|
|
1562
|
+
)[0],
|
|
1563
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
1567
|
+
this.lendingIxs.push(
|
|
1568
|
+
withdrawObligationCollateralAndRedeemReserveCollateralV2(
|
|
1569
|
+
{
|
|
1570
|
+
collateralAmount,
|
|
1571
|
+
},
|
|
1572
|
+
{
|
|
1573
|
+
withdrawAccounts: {
|
|
1574
|
+
owner: this.owner,
|
|
1575
|
+
obligation: this.getObligationPda(),
|
|
1576
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1577
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1578
|
+
withdrawReserve: this.reserve.address,
|
|
1579
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1580
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1581
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1582
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1583
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1584
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1585
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1586
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1587
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1588
|
+
},
|
|
1589
|
+
farmsAccounts: farmsAccounts,
|
|
1590
|
+
farmsProgram: farmsId,
|
|
1591
|
+
},
|
|
1592
|
+
this.kaminoMarket.programId
|
|
1593
|
+
)
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
/// @deprecated -- use addRepayIxV2 instead
|
|
1598
|
+
async addRepayIx() {
|
|
1599
|
+
this.lendingIxsLabels.push(
|
|
1600
|
+
`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
|
|
1601
|
+
);
|
|
1602
|
+
|
|
1603
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1604
|
+
|
|
1605
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1606
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
const repayIx = repayObligationLiquidity(
|
|
1610
|
+
{
|
|
1611
|
+
liquidityAmount: this.amount,
|
|
1612
|
+
},
|
|
1613
|
+
{
|
|
1614
|
+
owner: this.payer,
|
|
1615
|
+
obligation: this.getObligationPda(),
|
|
1616
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1617
|
+
repayReserve: this.reserve.address,
|
|
1618
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1619
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1620
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1621
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1622
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1623
|
+
},
|
|
1624
|
+
this.kaminoMarket.programId
|
|
1625
|
+
);
|
|
1626
|
+
|
|
1627
|
+
repayIx.keys =
|
|
1628
|
+
this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1629
|
+
|
|
1630
|
+
this.lendingIxs.push(repayIx);
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
async addRepayIxV2() {
|
|
1634
|
+
this.lendingIxsLabels.push(
|
|
1635
|
+
`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
|
|
1636
|
+
);
|
|
1637
|
+
|
|
1638
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1639
|
+
|
|
1640
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1641
|
+
? {
|
|
1642
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1643
|
+
reserveFarmState: PROGRAM_ID,
|
|
1644
|
+
}
|
|
1645
|
+
: {
|
|
1646
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1647
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1648
|
+
};
|
|
1649
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1650
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
const repayIx = repayObligationLiquidityV2(
|
|
1654
|
+
{
|
|
1655
|
+
liquidityAmount: this.amount,
|
|
1656
|
+
},
|
|
1657
|
+
{
|
|
1658
|
+
repayAccounts: {
|
|
1659
|
+
owner: this.payer,
|
|
1660
|
+
obligation: this.getObligationPda(),
|
|
1661
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1662
|
+
repayReserve: this.reserve.address,
|
|
1663
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1664
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1665
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1666
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1667
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1668
|
+
},
|
|
1669
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1670
|
+
farmsAccounts,
|
|
1671
|
+
farmsProgram: farmsId,
|
|
1672
|
+
},
|
|
1673
|
+
this.kaminoMarket.programId
|
|
1674
|
+
);
|
|
1675
|
+
|
|
1676
|
+
repayIx.keys =
|
|
1677
|
+
this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1678
|
+
|
|
1679
|
+
this.lendingIxs.push(repayIx);
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1311
1682
|
async addDepositAndBorrowIx() {
|
|
1312
1683
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
1313
1684
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
@@ -1386,6 +1757,118 @@ export class KaminoAction {
|
|
|
1386
1757
|
this.lendingIxs.push(borrowIx);
|
|
1387
1758
|
}
|
|
1388
1759
|
|
|
1760
|
+
async addDepositAndBorrowIxV2() {
|
|
1761
|
+
const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1762
|
+
? {
|
|
1763
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1764
|
+
reserveFarmState: PROGRAM_ID,
|
|
1765
|
+
}
|
|
1766
|
+
: {
|
|
1767
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1768
|
+
this.getObligationPda(),
|
|
1769
|
+
this.reserve.state.farmCollateral
|
|
1770
|
+
)[0],
|
|
1771
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1772
|
+
};
|
|
1773
|
+
|
|
1774
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
1775
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
1776
|
+
this.lendingIxs.push(
|
|
1777
|
+
depositReserveLiquidityAndObligationCollateralV2(
|
|
1778
|
+
{
|
|
1779
|
+
liquidityAmount: this.amount,
|
|
1780
|
+
},
|
|
1781
|
+
{
|
|
1782
|
+
depositAccounts: {
|
|
1783
|
+
owner: this.owner,
|
|
1784
|
+
obligation: this.getObligationPda(),
|
|
1785
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1786
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1787
|
+
reserve: this.reserve.address,
|
|
1788
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1789
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1790
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1791
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1792
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1793
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1794
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1795
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1796
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1797
|
+
},
|
|
1798
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
1799
|
+
farmsProgram: farmsId,
|
|
1800
|
+
},
|
|
1801
|
+
this.kaminoMarket.programId
|
|
1802
|
+
)
|
|
1803
|
+
);
|
|
1804
|
+
|
|
1805
|
+
if (!this.outflowReserve) {
|
|
1806
|
+
throw new Error(`outflowReserve not set`);
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1810
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
if (!this.outflowAmount) {
|
|
1814
|
+
throw new Error(`outflowAmount not set`);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1818
|
+
if (depositReservesList.length === 0) {
|
|
1819
|
+
depositReservesList.push(this.reserve.address);
|
|
1820
|
+
}
|
|
1821
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1822
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1823
|
+
});
|
|
1824
|
+
|
|
1825
|
+
const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(PublicKey.default)
|
|
1826
|
+
? {
|
|
1827
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1828
|
+
reserveFarmState: PROGRAM_ID,
|
|
1829
|
+
}
|
|
1830
|
+
: {
|
|
1831
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1832
|
+
this.getObligationPda(),
|
|
1833
|
+
this.outflowReserve.state.farmDebt!
|
|
1834
|
+
)[0],
|
|
1835
|
+
reserveFarmState: this.outflowReserve.state.farmDebt,
|
|
1836
|
+
};
|
|
1837
|
+
|
|
1838
|
+
const borrowIx = borrowObligationLiquidityV2(
|
|
1839
|
+
{
|
|
1840
|
+
liquidityAmount: this.outflowAmount,
|
|
1841
|
+
},
|
|
1842
|
+
{
|
|
1843
|
+
borrowAccounts: {
|
|
1844
|
+
owner: this.owner,
|
|
1845
|
+
obligation: this.getObligationPda(),
|
|
1846
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1847
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1848
|
+
borrowReserve: this.outflowReserve.address,
|
|
1849
|
+
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1850
|
+
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
1851
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1852
|
+
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1853
|
+
referrerTokenState: referrerTokenStatePda(
|
|
1854
|
+
this.referrer,
|
|
1855
|
+
this.outflowReserve.address,
|
|
1856
|
+
this.kaminoMarket.programId
|
|
1857
|
+
)[0],
|
|
1858
|
+
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1859
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1860
|
+
},
|
|
1861
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1862
|
+
farmsProgram: farmsId,
|
|
1863
|
+
},
|
|
1864
|
+
this.kaminoMarket.programId
|
|
1865
|
+
);
|
|
1866
|
+
|
|
1867
|
+
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
1868
|
+
|
|
1869
|
+
this.lendingIxs.push(borrowIx);
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1389
1872
|
async addRepayAndWithdrawIxs(withdrawCollateralAmount: BN) {
|
|
1390
1873
|
this.lendingIxsLabels.push(
|
|
1391
1874
|
`repayObligationLiquidity(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
|
|
@@ -1456,38 +1939,11 @@ export class KaminoAction {
|
|
|
1456
1939
|
);
|
|
1457
1940
|
}
|
|
1458
1941
|
|
|
1459
|
-
async
|
|
1460
|
-
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
1461
|
-
this.lendingIxs.push(
|
|
1462
|
-
withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
1463
|
-
{
|
|
1464
|
-
collateralAmount: withdrawCollateralAmount,
|
|
1465
|
-
},
|
|
1466
|
-
{
|
|
1467
|
-
owner: this.owner,
|
|
1468
|
-
obligation: this.getObligationPda(),
|
|
1469
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1470
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1471
|
-
withdrawReserve: this.reserve.address,
|
|
1472
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1473
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1474
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1475
|
-
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1476
|
-
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1477
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1478
|
-
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1479
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1480
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1481
|
-
},
|
|
1482
|
-
this.kaminoMarket.programId
|
|
1483
|
-
)
|
|
1484
|
-
);
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
async addRepayIx() {
|
|
1942
|
+
async addRepayAndWithdrawIxsV2(withdrawCollateralAmount: BN) {
|
|
1488
1943
|
this.lendingIxsLabels.push(
|
|
1489
|
-
`
|
|
1944
|
+
`repayObligationLiquidityV2(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
|
|
1490
1945
|
);
|
|
1946
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
1491
1947
|
|
|
1492
1948
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1493
1949
|
|
|
@@ -1495,28 +1951,95 @@ export class KaminoAction {
|
|
|
1495
1951
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1496
1952
|
});
|
|
1497
1953
|
|
|
1498
|
-
const
|
|
1954
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1955
|
+
? {
|
|
1956
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1957
|
+
reserveFarmState: PROGRAM_ID,
|
|
1958
|
+
}
|
|
1959
|
+
: {
|
|
1960
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1961
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1962
|
+
};
|
|
1963
|
+
|
|
1964
|
+
const repayIx = repayObligationLiquidityV2(
|
|
1499
1965
|
{
|
|
1500
1966
|
liquidityAmount: this.amount,
|
|
1501
1967
|
},
|
|
1502
1968
|
{
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1969
|
+
repayAccounts: {
|
|
1970
|
+
owner: this.owner,
|
|
1971
|
+
obligation: this.getObligationPda(),
|
|
1972
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1973
|
+
repayReserve: this.reserve!.address,
|
|
1974
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1975
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1976
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1977
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1978
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1979
|
+
},
|
|
1980
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1981
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1982
|
+
farmsProgram: farmsId,
|
|
1512
1983
|
},
|
|
1513
1984
|
this.kaminoMarket.programId
|
|
1514
1985
|
);
|
|
1515
1986
|
|
|
1516
|
-
repayIx.keys =
|
|
1517
|
-
this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1987
|
+
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
1518
1988
|
|
|
1519
1989
|
this.lendingIxs.push(repayIx);
|
|
1990
|
+
if (!this.outflowReserve) {
|
|
1991
|
+
throw new Error(`outflowReserve not set`);
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1995
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
if (!this.outflowAmount) {
|
|
1999
|
+
throw new Error(`outflowAmount not set`);
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
2003
|
+
? {
|
|
2004
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2005
|
+
reserveFarmState: PROGRAM_ID,
|
|
2006
|
+
}
|
|
2007
|
+
: {
|
|
2008
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
2009
|
+
this.getObligationPda(),
|
|
2010
|
+
this.outflowReserve.state.farmCollateral
|
|
2011
|
+
)[0],
|
|
2012
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2013
|
+
};
|
|
2014
|
+
|
|
2015
|
+
this.lendingIxs.push(
|
|
2016
|
+
withdrawObligationCollateralAndRedeemReserveCollateralV2(
|
|
2017
|
+
{
|
|
2018
|
+
collateralAmount: withdrawCollateralAmount,
|
|
2019
|
+
},
|
|
2020
|
+
{
|
|
2021
|
+
withdrawAccounts: {
|
|
2022
|
+
owner: this.owner,
|
|
2023
|
+
obligation: this.getObligationPda(),
|
|
2024
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
2025
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
2026
|
+
withdrawReserve: this.outflowReserve.address,
|
|
2027
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
2028
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
2029
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
2030
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
2031
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
2032
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
2033
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
2034
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
2035
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2036
|
+
},
|
|
2037
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
2038
|
+
farmsProgram: farmsId,
|
|
2039
|
+
},
|
|
2040
|
+
this.kaminoMarket.programId
|
|
2041
|
+
)
|
|
2042
|
+
);
|
|
1520
2043
|
}
|
|
1521
2044
|
|
|
1522
2045
|
async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
|
|
@@ -1571,15 +2094,97 @@ export class KaminoAction {
|
|
|
1571
2094
|
this.lendingIxs.push(liquidateIx);
|
|
1572
2095
|
}
|
|
1573
2096
|
|
|
2097
|
+
async addLiquidateIxV2(maxAllowedLtvOverridePercent: number = 0) {
|
|
2098
|
+
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateralV2`);
|
|
2099
|
+
if (!this.outflowReserve) {
|
|
2100
|
+
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
2101
|
+
}
|
|
2102
|
+
if (!this.additionalTokenAccountAddress) {
|
|
2103
|
+
throw Error(`Liquidating token account address is not defined`);
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
2107
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
2108
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
2109
|
+
});
|
|
2110
|
+
|
|
2111
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
2112
|
+
? {
|
|
2113
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2114
|
+
reserveFarmState: PROGRAM_ID,
|
|
2115
|
+
}
|
|
2116
|
+
: {
|
|
2117
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
2118
|
+
this.getObligationPda(),
|
|
2119
|
+
this.outflowReserve.state.farmCollateral
|
|
2120
|
+
)[0],
|
|
2121
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2122
|
+
};
|
|
2123
|
+
|
|
2124
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
2125
|
+
? {
|
|
2126
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2127
|
+
reserveFarmState: PROGRAM_ID,
|
|
2128
|
+
}
|
|
2129
|
+
: {
|
|
2130
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
2131
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
2132
|
+
};
|
|
2133
|
+
|
|
2134
|
+
const liquidateIx = liquidateObligationAndRedeemReserveCollateralV2(
|
|
2135
|
+
{
|
|
2136
|
+
liquidityAmount: this.amount,
|
|
2137
|
+
// TODO: Configure this when updating liquidator with new interface
|
|
2138
|
+
minAcceptableReceivedLiquidityAmount: this.outflowAmount || new BN(0),
|
|
2139
|
+
maxAllowedLtvOverridePercent: new BN(maxAllowedLtvOverridePercent),
|
|
2140
|
+
},
|
|
2141
|
+
{
|
|
2142
|
+
liquidationAccounts: {
|
|
2143
|
+
liquidator: this.owner,
|
|
2144
|
+
obligation: this.getObligationPda(),
|
|
2145
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
2146
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
2147
|
+
repayReserve: this.reserve.address,
|
|
2148
|
+
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
2149
|
+
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
2150
|
+
withdrawReserve: this.outflowReserve.address,
|
|
2151
|
+
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
2152
|
+
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
2153
|
+
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
2154
|
+
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
2155
|
+
userSourceLiquidity: this.additionalTokenAccountAddress,
|
|
2156
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
2157
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
2158
|
+
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
2159
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
2160
|
+
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
2161
|
+
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
2162
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2163
|
+
},
|
|
2164
|
+
debtFarmsAccounts,
|
|
2165
|
+
collateralFarmsAccounts,
|
|
2166
|
+
farmsProgram: farmsId,
|
|
2167
|
+
},
|
|
2168
|
+
this.kaminoMarket.programId
|
|
2169
|
+
);
|
|
2170
|
+
liquidateIx.keys =
|
|
2171
|
+
this.obligation!.state.elevationGroup > 0
|
|
2172
|
+
? liquidateIx.keys.concat([...depositReserveAccountMetas])
|
|
2173
|
+
: liquidateIx.keys;
|
|
2174
|
+
this.lendingIxs.push(liquidateIx);
|
|
2175
|
+
}
|
|
2176
|
+
|
|
1574
2177
|
async addInBetweenIxs(
|
|
1575
2178
|
action: ActionType,
|
|
1576
2179
|
includeAtaIxns: boolean,
|
|
1577
2180
|
requestElevationGroup: boolean,
|
|
1578
|
-
addInitObligationForFarm: boolean
|
|
2181
|
+
addInitObligationForFarm: boolean,
|
|
2182
|
+
useV2Ixs: boolean
|
|
1579
2183
|
) {
|
|
1580
2184
|
await this.addSupportIxsWithoutInitObligation(
|
|
1581
2185
|
action,
|
|
1582
2186
|
includeAtaIxns,
|
|
2187
|
+
useV2Ixs,
|
|
1583
2188
|
'inBetween',
|
|
1584
2189
|
requestElevationGroup,
|
|
1585
2190
|
addInitObligationForFarm
|
|
@@ -1612,6 +2217,7 @@ export class KaminoAction {
|
|
|
1612
2217
|
async addSupportIxsWithoutInitObligation(
|
|
1613
2218
|
action: ActionType,
|
|
1614
2219
|
includeAtaIxns: boolean,
|
|
2220
|
+
useV2Ixs: boolean,
|
|
1615
2221
|
addAsSupportIx: AuxiliaryIx = 'setup',
|
|
1616
2222
|
requestElevationGroup: boolean = false,
|
|
1617
2223
|
addInitObligationForFarm: boolean = false,
|
|
@@ -1840,46 +2446,48 @@ export class KaminoAction {
|
|
|
1840
2446
|
}
|
|
1841
2447
|
}
|
|
1842
2448
|
|
|
1843
|
-
if (
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
// If this is an inbetween, it means it's part of a two-token-action
|
|
1875
|
-
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1876
|
-
// add added to 'setup' ixns
|
|
1877
|
-
if (action === 'depositAndBorrow') {
|
|
1878
|
-
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
|
|
1879
|
-
} else if (action === 'repayAndWithdraw') {
|
|
1880
|
-
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2449
|
+
if (!useV2Ixs) {
|
|
2450
|
+
if (addAsSupportIx === 'setup') {
|
|
2451
|
+
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|
|
2452
|
+
// or the first of a two-token-action
|
|
2453
|
+
if (action === 'liquidate') {
|
|
2454
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2455
|
+
this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, ReserveFarmKind.Debt);
|
|
2456
|
+
} else if (
|
|
2457
|
+
action === 'depositAndBorrow' ||
|
|
2458
|
+
action === 'depositCollateral' ||
|
|
2459
|
+
action === 'withdraw' ||
|
|
2460
|
+
action === 'deposit'
|
|
2461
|
+
) {
|
|
2462
|
+
this.addRefreshFarmsForReserve(
|
|
2463
|
+
currentReserves,
|
|
2464
|
+
addAsSupportIx,
|
|
2465
|
+
ReserveFarmKind.Collateral,
|
|
2466
|
+
undefined,
|
|
2467
|
+
twoTokenAction
|
|
2468
|
+
);
|
|
2469
|
+
} else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
2470
|
+
this.addRefreshFarmsForReserve(
|
|
2471
|
+
currentReserves,
|
|
2472
|
+
addAsSupportIx,
|
|
2473
|
+
ReserveFarmKind.Debt,
|
|
2474
|
+
undefined,
|
|
2475
|
+
twoTokenAction
|
|
2476
|
+
);
|
|
2477
|
+
} else {
|
|
2478
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
2479
|
+
}
|
|
1881
2480
|
} else {
|
|
1882
|
-
|
|
2481
|
+
// If this is an inbetween, it means it's part of a two-token-action
|
|
2482
|
+
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
2483
|
+
// add added to 'setup' ixns
|
|
2484
|
+
if (action === 'depositAndBorrow') {
|
|
2485
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
|
|
2486
|
+
} else if (action === 'repayAndWithdraw') {
|
|
2487
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2488
|
+
} else {
|
|
2489
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
2490
|
+
}
|
|
1883
2491
|
}
|
|
1884
2492
|
}
|
|
1885
2493
|
}
|
|
@@ -1891,13 +2499,25 @@ export class KaminoAction {
|
|
|
1891
2499
|
requestElevationGroup: boolean,
|
|
1892
2500
|
includeUserMetadata: boolean,
|
|
1893
2501
|
addInitObligationForFarm: boolean,
|
|
2502
|
+
useV2Ixs: boolean,
|
|
2503
|
+
createLookupTable: boolean,
|
|
1894
2504
|
twoTokenAction: boolean = false,
|
|
1895
2505
|
overrideElevationGroupRequest?: number
|
|
1896
2506
|
) {
|
|
1897
2507
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1898
2508
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1899
2509
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
1900
|
-
|
|
2510
|
+
let lookupTable: PublicKey = PublicKey.default;
|
|
2511
|
+
if (createLookupTable) {
|
|
2512
|
+
const [createLutIx, lookupTableAddress] = await createLookupTableIx(
|
|
2513
|
+
this.kaminoMarket.getConnection(),
|
|
2514
|
+
this.owner
|
|
2515
|
+
);
|
|
2516
|
+
lookupTable = lookupTableAddress;
|
|
2517
|
+
this.setupIxs.push(createLutIx);
|
|
2518
|
+
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
2519
|
+
}
|
|
2520
|
+
this.addInitUserMetadataIxs(lookupTable);
|
|
1901
2521
|
}
|
|
1902
2522
|
|
|
1903
2523
|
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
@@ -1913,6 +2533,7 @@ export class KaminoAction {
|
|
|
1913
2533
|
await this.addSupportIxsWithoutInitObligation(
|
|
1914
2534
|
action,
|
|
1915
2535
|
includeAtaIxns,
|
|
2536
|
+
useV2Ixs,
|
|
1916
2537
|
'setup',
|
|
1917
2538
|
requestElevationGroup,
|
|
1918
2539
|
addInitObligationForFarm,
|
|
@@ -2126,13 +2747,6 @@ export class KaminoAction {
|
|
|
2126
2747
|
crank: PublicKey = this.payer,
|
|
2127
2748
|
twoTokenAction: boolean = false
|
|
2128
2749
|
) {
|
|
2129
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
2130
|
-
const getPda = (farm: PublicKey) =>
|
|
2131
|
-
PublicKey.findProgramAddressSync(
|
|
2132
|
-
[BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()],
|
|
2133
|
-
farmsId
|
|
2134
|
-
)[0];
|
|
2135
|
-
|
|
2136
2750
|
const farms: [
|
|
2137
2751
|
typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
|
|
2138
2752
|
PublicKey,
|
|
@@ -2145,7 +2759,7 @@ export class KaminoAction {
|
|
|
2145
2759
|
farms.push([
|
|
2146
2760
|
ReserveFarmKind.Collateral,
|
|
2147
2761
|
kaminoReserve.state.farmCollateral,
|
|
2148
|
-
|
|
2762
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
|
|
2149
2763
|
kaminoReserve,
|
|
2150
2764
|
]);
|
|
2151
2765
|
}
|
|
@@ -2153,7 +2767,7 @@ export class KaminoAction {
|
|
|
2153
2767
|
farms.push([
|
|
2154
2768
|
ReserveFarmKind.Debt,
|
|
2155
2769
|
kaminoReserve.state.farmDebt,
|
|
2156
|
-
|
|
2770
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
|
|
2157
2771
|
kaminoReserve,
|
|
2158
2772
|
]);
|
|
2159
2773
|
}
|
|
@@ -2234,28 +2848,21 @@ export class KaminoAction {
|
|
|
2234
2848
|
mode: typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
|
|
2235
2849
|
addAsSupportIx: AuxiliaryIx = 'setup'
|
|
2236
2850
|
): Promise<void> {
|
|
2237
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
2238
|
-
const getPda = (farm: PublicKey) =>
|
|
2239
|
-
PublicKey.findProgramAddressSync(
|
|
2240
|
-
[BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()],
|
|
2241
|
-
farmsId
|
|
2242
|
-
)[0];
|
|
2243
|
-
|
|
2244
2851
|
const farms: [number, PublicKey, PublicKey][] = [];
|
|
2245
2852
|
|
|
2246
2853
|
if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
|
|
2247
|
-
const
|
|
2248
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
2854
|
+
const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
|
|
2855
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
2249
2856
|
if (!account) {
|
|
2250
|
-
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral,
|
|
2857
|
+
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
|
|
2251
2858
|
}
|
|
2252
2859
|
}
|
|
2253
2860
|
|
|
2254
2861
|
if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
|
|
2255
|
-
const
|
|
2256
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
2862
|
+
const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
|
|
2863
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
2257
2864
|
if (!account) {
|
|
2258
|
-
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
2865
|
+
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
|
|
2259
2866
|
}
|
|
2260
2867
|
}
|
|
2261
2868
|
|
|
@@ -2318,10 +2925,7 @@ export class KaminoAction {
|
|
|
2318
2925
|
}
|
|
2319
2926
|
}
|
|
2320
2927
|
|
|
2321
|
-
private
|
|
2322
|
-
const [createLutIx, lookupTableAddress] = await createLookupTableIx(this.kaminoMarket.getConnection(), this.owner);
|
|
2323
|
-
this.setupIxs.push(createLutIx);
|
|
2324
|
-
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
2928
|
+
private addInitUserMetadataIxs(lookupTableAddress: PublicKey) {
|
|
2325
2929
|
const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
|
|
2326
2930
|
const referrerUserMetadataAddress = this.referrer.equals(PublicKey.default)
|
|
2327
2931
|
? this.kaminoMarket.programId
|
|
@@ -2401,11 +3005,11 @@ export class KaminoAction {
|
|
|
2401
3005
|
}
|
|
2402
3006
|
|
|
2403
3007
|
private async addAtaIxs(action: ActionType) {
|
|
2404
|
-
if (this.mint.equals(
|
|
3008
|
+
if (this.mint.equals(NATIVE_MINT) || this.secondaryMint?.equals(NATIVE_MINT)) {
|
|
2405
3009
|
await this.updateWSOLAccount(action);
|
|
2406
3010
|
}
|
|
2407
3011
|
|
|
2408
|
-
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(
|
|
3012
|
+
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(NATIVE_MINT)) {
|
|
2409
3013
|
const [, createUserTokenAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
2410
3014
|
this.owner,
|
|
2411
3015
|
this.reserve.getLiquidityMint(),
|
|
@@ -2414,13 +3018,8 @@ export class KaminoAction {
|
|
|
2414
3018
|
this.userTokenAccountAddress
|
|
2415
3019
|
);
|
|
2416
3020
|
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
2420
|
-
} else {
|
|
2421
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2422
|
-
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
2423
|
-
}
|
|
3021
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
3022
|
+
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
2424
3023
|
}
|
|
2425
3024
|
|
|
2426
3025
|
if (action === 'liquidate') {
|
|
@@ -2435,13 +3034,9 @@ export class KaminoAction {
|
|
|
2435
3034
|
this.outflowReserve.getLiquidityTokenProgram(),
|
|
2436
3035
|
this.userTokenAccountAddress
|
|
2437
3036
|
);
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
} else {
|
|
2442
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2443
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
2444
|
-
}
|
|
3037
|
+
|
|
3038
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
3039
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
2445
3040
|
|
|
2446
3041
|
const [, createUserCollateralAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
2447
3042
|
this.owner,
|
|
@@ -2451,23 +3046,15 @@ export class KaminoAction {
|
|
|
2451
3046
|
this.userCollateralAccountAddress
|
|
2452
3047
|
);
|
|
2453
3048
|
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2457
|
-
} else {
|
|
2458
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
2459
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2460
|
-
}
|
|
3049
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
3050
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2461
3051
|
|
|
2462
3052
|
if (!this.additionalTokenAccountAddress) {
|
|
2463
3053
|
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
2464
3054
|
}
|
|
2465
3055
|
}
|
|
2466
3056
|
|
|
2467
|
-
if (
|
|
2468
|
-
action === 'depositAndBorrow' ||
|
|
2469
|
-
(action === 'repayAndWithdraw' && !this.secondaryMint?.equals(WRAPPED_SOL_MINT))
|
|
2470
|
-
) {
|
|
3057
|
+
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(NATIVE_MINT))) {
|
|
2471
3058
|
if (!this.additionalTokenAccountAddress) {
|
|
2472
3059
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
2473
3060
|
}
|
|
@@ -2515,13 +3102,8 @@ export class KaminoAction {
|
|
|
2515
3102
|
this.userCollateralAccountAddress
|
|
2516
3103
|
);
|
|
2517
3104
|
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2521
|
-
} else {
|
|
2522
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
2523
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2524
|
-
}
|
|
3105
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
3106
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2525
3107
|
}
|
|
2526
3108
|
}
|
|
2527
3109
|
|
|
@@ -2564,7 +3146,7 @@ export class KaminoAction {
|
|
|
2564
3146
|
}
|
|
2565
3147
|
|
|
2566
3148
|
let userTokenAccountAddress = this.userTokenAccountAddress;
|
|
2567
|
-
if (this.secondaryMint?.equals(
|
|
3149
|
+
if (this.secondaryMint?.equals(NATIVE_MINT)) {
|
|
2568
3150
|
if (!this.additionalTokenAccountAddress) {
|
|
2569
3151
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
2570
3152
|
}
|
|
@@ -2580,7 +3162,7 @@ export class KaminoAction {
|
|
|
2580
3162
|
action === 'deposit' ||
|
|
2581
3163
|
action === 'repay' ||
|
|
2582
3164
|
action === 'mint' ||
|
|
2583
|
-
(action === 'liquidate' && this.secondaryMint?.equals(
|
|
3165
|
+
(action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
2584
3166
|
|
|
2585
3167
|
const transferLamportsIx = SystemProgram.transfer({
|
|
2586
3168
|
fromPubkey: this.owner,
|
|
@@ -2623,14 +3205,6 @@ export class KaminoAction {
|
|
|
2623
3205
|
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
2624
3206
|
}
|
|
2625
3207
|
|
|
2626
|
-
// TODO: Consider for liquidations and other types of actions if we have to split up some ixs in 2-3 txs
|
|
2627
|
-
// if (this.positions && this.positions >= POSITION_LIMIT) {
|
|
2628
|
-
// this.preTxnIxs.push(...preIxs);
|
|
2629
|
-
// this.preTxnIxsLabels.push(...preIxsLabels);
|
|
2630
|
-
// this.postTxnIxs.push(...postIxs);
|
|
2631
|
-
// this.postTxnIxsLabels.push(...postIxsLabels);
|
|
2632
|
-
// } else {
|
|
2633
|
-
// }
|
|
2634
3208
|
this.setupIxs.unshift(...preIxs);
|
|
2635
3209
|
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
2636
3210
|
this.cleanupIxs.push(...postIxs);
|