@kamino-finance/klend-sdk 5.10.28-beta.1 → 5.11.0-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 +22 -14
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +585 -132
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +0 -3
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +0 -3
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.js +1 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -6
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +2 -4
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/types.d.ts +1 -13
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/idl.json +71 -5
- 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 +35 -3
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +61 -5
- package/dist/idl_codegen/errors/custom.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 +22 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +2 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +6 -1
- 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 +4 -2
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +10 -12
- package/dist/leverage/calcs.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 +27 -24
- 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/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 +6 -9
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +4 -4
- package/src/classes/action.ts +749 -146
- package/src/classes/index.ts +0 -3
- package/src/classes/manager.ts +1 -1
- package/src/classes/obligation.ts +4 -8
- package/src/classes/types.ts +1 -17
- package/src/client.ts +7 -3
- package/src/idl.json +71 -5
- package/src/idl_codegen/accounts/Obligation.ts +12 -1
- package/src/idl_codegen/errors/custom.ts +66 -4
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +31 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +1 -1
- package/src/idl_codegen/zero_padding/ObligationZP.ts +6 -1
- package/src/lending_operations/repay_with_collateral_operations.ts +11 -3
- package/src/lending_operations/swap_collateral_operations.ts +11 -0
- package/src/leverage/calcs.ts +13 -16
- package/src/leverage/operations.ts +38 -11
- package/src/leverage/types.ts +4 -1
- package/src/utils/seeds.ts +13 -0
- package/src/utils/userMetadata.ts +19 -24
- package/dist/classes/stakePool.d.ts +0 -8
- package/dist/classes/stakePool.d.ts.map +0 -1
- package/dist/classes/stakePool.js +0 -18
- package/dist/classes/stakePool.js.map +0 -1
- package/dist/classes/standardStakePool.d.ts +0 -174
- package/dist/classes/standardStakePool.d.ts.map +0 -1
- package/dist/classes/standardStakePool.js +0 -275
- package/dist/classes/standardStakePool.js.map +0 -1
- package/dist/classes/unstakingPool.d.ts +0 -117
- package/dist/classes/unstakingPool.d.ts.map +0 -1
- package/dist/classes/unstakingPool.js +0 -448
- package/dist/classes/unstakingPool.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.d.ts +0 -50
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.js +0 -156
- package/dist/idl_codegen_unstaking_pool/accounts/PoolState.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/index.d.ts +0 -3
- package/dist/idl_codegen_unstaking_pool/accounts/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/accounts/index.js +0 -6
- package/dist/idl_codegen_unstaking_pool/accounts/index.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/anchor.d.ts +0 -435
- package/dist/idl_codegen_unstaking_pool/errors/anchor.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/anchor.js +0 -767
- package/dist/idl_codegen_unstaking_pool/errors/anchor.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/custom.d.ts +0 -163
- package/dist/idl_codegen_unstaking_pool/errors/custom.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/custom.js +0 -290
- package/dist/idl_codegen_unstaking_pool/errors/custom.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/index.d.ts +0 -6
- package/dist/idl_codegen_unstaking_pool/errors/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/errors/index.js +0 -75
- package/dist/idl_codegen_unstaking_pool/errors/index.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/burn.d.ts +0 -21
- package/dist/idl_codegen_unstaking_pool/instructions/burn.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/burn.js +0 -73
- package/dist/idl_codegen_unstaking_pool/instructions/burn.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/collect.d.ts +0 -16
- package/dist/idl_codegen_unstaking_pool/instructions/collect.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/collect.js +0 -29
- package/dist/idl_codegen_unstaking_pool/instructions/collect.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/index.d.ts +0 -11
- package/dist/idl_codegen_unstaking_pool/instructions/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/index.js +0 -14
- package/dist/idl_codegen_unstaking_pool/instructions/index.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.d.ts +0 -15
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.js +0 -28
- package/dist/idl_codegen_unstaking_pool/instructions/initializePool.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/mint.d.ts +0 -21
- package/dist/idl_codegen_unstaking_pool/instructions/mint.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/mint.js +0 -77
- package/dist/idl_codegen_unstaking_pool/instructions/mint.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.d.ts +0 -13
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.js +0 -58
- package/dist/idl_codegen_unstaking_pool/instructions/updatePoolConfig.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/programId.d.ts +0 -4
- package/dist/idl_codegen_unstaking_pool/programId.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/programId.js +0 -9
- package/dist/idl_codegen_unstaking_pool/programId.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.d.ts +0 -32
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.js +0 -105
- package/dist/idl_codegen_unstaking_pool/types/PoolConfigField.js.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/index.d.ts +0 -5
- package/dist/idl_codegen_unstaking_pool/types/index.d.ts.map +0 -1
- package/dist/idl_codegen_unstaking_pool/types/index.js +0 -39
- package/dist/idl_codegen_unstaking_pool/types/index.js.map +0 -1
- package/src/classes/stakePool.ts +0 -21
- package/src/classes/standardStakePool.ts +0 -358
- package/src/classes/unstakingPool.ts +0 -577
- package/src/idl_codegen_unstaking_pool/accounts/PoolState.ts +0 -163
- package/src/idl_codegen_unstaking_pool/accounts/index.ts +0 -2
- package/src/idl_codegen_unstaking_pool/errors/anchor.ts +0 -764
- package/src/idl_codegen_unstaking_pool/errors/custom.ts +0 -288
- package/src/idl_codegen_unstaking_pool/errors/index.ts +0 -49
- package/src/idl_codegen_unstaking_pool/instructions/burn.ts +0 -60
- package/src/idl_codegen_unstaking_pool/instructions/collect.ts +0 -43
- package/src/idl_codegen_unstaking_pool/instructions/index.ts +0 -10
- package/src/idl_codegen_unstaking_pool/instructions/initializePool.ts +0 -41
- package/src/idl_codegen_unstaking_pool/instructions/mint.ts +0 -64
- package/src/idl_codegen_unstaking_pool/instructions/updatePoolConfig.ts +0 -40
- package/src/idl_codegen_unstaking_pool/programId.ts +0 -7
- package/src/idl_codegen_unstaking_pool/types/PoolConfigField.ts +0 -85
- package/src/idl_codegen_unstaking_pool/types/index.ts +0 -6
- package/src/idl_unstaking_pool.json +0 -456
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 {
|
|
@@ -59,6 +65,7 @@ import {
|
|
|
59
65
|
ScopeRefresh,
|
|
60
66
|
createAtasIdempotent,
|
|
61
67
|
POSITION_LIMIT,
|
|
68
|
+
obligationFarmStatePda,
|
|
62
69
|
} from '../utils';
|
|
63
70
|
import { KaminoMarket } from './market';
|
|
64
71
|
import { KaminoObligation } from './obligation';
|
|
@@ -409,6 +416,7 @@ export class KaminoAction {
|
|
|
409
416
|
mint: PublicKey,
|
|
410
417
|
owner: PublicKey,
|
|
411
418
|
obligation: KaminoObligation | ObligationType,
|
|
419
|
+
useV2Ixs: boolean,
|
|
412
420
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
413
421
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
414
422
|
requestElevationGroup: boolean = false, // to be requested *before* the deposit
|
|
@@ -450,10 +458,15 @@ export class KaminoAction {
|
|
|
450
458
|
requestElevationGroup,
|
|
451
459
|
includeUserMetadata,
|
|
452
460
|
addInitObligationForFarm,
|
|
461
|
+
useV2Ixs,
|
|
453
462
|
undefined,
|
|
454
463
|
overrideElevationGroupRequest
|
|
455
464
|
);
|
|
456
|
-
|
|
465
|
+
if (useV2Ixs) {
|
|
466
|
+
axn.addDepositIxV2();
|
|
467
|
+
} else {
|
|
468
|
+
axn.addDepositIx();
|
|
469
|
+
}
|
|
457
470
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
458
471
|
|
|
459
472
|
return axn;
|
|
@@ -503,6 +516,7 @@ export class KaminoAction {
|
|
|
503
516
|
mint: PublicKey,
|
|
504
517
|
owner: PublicKey,
|
|
505
518
|
obligation: KaminoObligation | ObligationType,
|
|
519
|
+
useV2Ixs: boolean,
|
|
506
520
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
507
521
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
508
522
|
requestElevationGroup: boolean = false,
|
|
@@ -544,10 +558,15 @@ export class KaminoAction {
|
|
|
544
558
|
requestElevationGroup,
|
|
545
559
|
includeUserMetadata,
|
|
546
560
|
addInitObligationForFarm,
|
|
561
|
+
useV2Ixs,
|
|
547
562
|
undefined,
|
|
548
563
|
overrideElevationGroupRequest
|
|
549
564
|
);
|
|
550
|
-
|
|
565
|
+
if (useV2Ixs) {
|
|
566
|
+
axn.addBorrowIxV2();
|
|
567
|
+
} else {
|
|
568
|
+
axn.addBorrowIx();
|
|
569
|
+
}
|
|
551
570
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
552
571
|
|
|
553
572
|
return axn;
|
|
@@ -599,7 +618,8 @@ export class KaminoAction {
|
|
|
599
618
|
includeAtaIxns,
|
|
600
619
|
requestElevationGroup,
|
|
601
620
|
includeUserMetadata,
|
|
602
|
-
addInitObligationForFarm
|
|
621
|
+
addInitObligationForFarm,
|
|
622
|
+
false
|
|
603
623
|
);
|
|
604
624
|
axn.addDepositReserveLiquidityIx();
|
|
605
625
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
@@ -652,7 +672,8 @@ export class KaminoAction {
|
|
|
652
672
|
includeAtaIxns,
|
|
653
673
|
requestElevationGroup,
|
|
654
674
|
includeUserMetadata,
|
|
655
|
-
addInitObligationForFarm
|
|
675
|
+
addInitObligationForFarm,
|
|
676
|
+
false
|
|
656
677
|
);
|
|
657
678
|
axn.addRedeemReserveCollateralIx();
|
|
658
679
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
@@ -665,6 +686,7 @@ export class KaminoAction {
|
|
|
665
686
|
mint: PublicKey,
|
|
666
687
|
owner: PublicKey,
|
|
667
688
|
obligation: KaminoObligation | ObligationType,
|
|
689
|
+
useV2Ixs: boolean,
|
|
668
690
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
669
691
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
670
692
|
requestElevationGroup: boolean = false,
|
|
@@ -705,9 +727,14 @@ export class KaminoAction {
|
|
|
705
727
|
includeAtaIxns,
|
|
706
728
|
requestElevationGroup,
|
|
707
729
|
includeUserMetadata,
|
|
708
|
-
addInitObligationForFarm
|
|
730
|
+
addInitObligationForFarm,
|
|
731
|
+
useV2Ixs
|
|
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,6 +747,7 @@ 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,
|
|
@@ -767,14 +795,21 @@ export class KaminoAction {
|
|
|
767
795
|
requestElevationGroup,
|
|
768
796
|
includeUserMetadata,
|
|
769
797
|
addInitObligationForFarmForDeposit,
|
|
798
|
+
useV2Ixs,
|
|
770
799
|
twoTokenAction
|
|
771
800
|
);
|
|
772
|
-
|
|
801
|
+
|
|
802
|
+
if (useV2Ixs) {
|
|
803
|
+
await axn.addDepositAndBorrowIxV2();
|
|
804
|
+
} else {
|
|
805
|
+
await axn.addDepositAndBorrowIx();
|
|
806
|
+
}
|
|
773
807
|
await axn.addInBetweenIxs(
|
|
774
808
|
'depositAndBorrow',
|
|
775
809
|
includeAtaIxns,
|
|
776
810
|
requestElevationGroup,
|
|
777
|
-
addInitObligationForFarmForBorrow
|
|
811
|
+
addInitObligationForFarmForBorrow,
|
|
812
|
+
useV2Ixs
|
|
778
813
|
);
|
|
779
814
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
780
815
|
return axn;
|
|
@@ -789,6 +824,7 @@ export class KaminoAction {
|
|
|
789
824
|
payer: PublicKey,
|
|
790
825
|
currentSlot: number,
|
|
791
826
|
obligation: KaminoObligation | ObligationType,
|
|
827
|
+
useV2Ixs: boolean,
|
|
792
828
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
793
829
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
794
830
|
requestElevationGroup: boolean = false,
|
|
@@ -834,14 +870,20 @@ export class KaminoAction {
|
|
|
834
870
|
requestElevationGroup,
|
|
835
871
|
includeUserMetadata,
|
|
836
872
|
addInitObligationForFarmForRepay,
|
|
873
|
+
useV2Ixs,
|
|
837
874
|
twoTokenAction
|
|
838
875
|
);
|
|
839
|
-
|
|
876
|
+
if (useV2Ixs) {
|
|
877
|
+
await axn.addRepayAndWithdrawIxsV2();
|
|
878
|
+
} else {
|
|
879
|
+
await axn.addRepayAndWithdrawIxs();
|
|
880
|
+
}
|
|
840
881
|
await axn.addInBetweenIxs(
|
|
841
882
|
'repayAndWithdraw',
|
|
842
883
|
includeAtaIxns,
|
|
843
884
|
requestElevationGroup,
|
|
844
|
-
addInitObligationForFarmForWithdraw
|
|
885
|
+
addInitObligationForFarmForWithdraw,
|
|
886
|
+
useV2Ixs
|
|
845
887
|
);
|
|
846
888
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
847
889
|
return axn;
|
|
@@ -853,6 +895,7 @@ export class KaminoAction {
|
|
|
853
895
|
mint: PublicKey,
|
|
854
896
|
owner: PublicKey,
|
|
855
897
|
obligation: KaminoObligation | ObligationType,
|
|
898
|
+
useV2Ixs: boolean,
|
|
856
899
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
857
900
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
858
901
|
requestElevationGroup: boolean = false, // to be requested *after* the withdraw
|
|
@@ -902,10 +945,15 @@ export class KaminoAction {
|
|
|
902
945
|
requestElevationGroup,
|
|
903
946
|
includeUserMetadata,
|
|
904
947
|
addInitObligationForFarm,
|
|
948
|
+
useV2Ixs,
|
|
905
949
|
false,
|
|
906
950
|
overrideElevationGroupRequest
|
|
907
951
|
);
|
|
908
|
-
|
|
952
|
+
if (useV2Ixs) {
|
|
953
|
+
await axn.addWithdrawIxV2();
|
|
954
|
+
} else {
|
|
955
|
+
await axn.addWithdrawIx();
|
|
956
|
+
}
|
|
909
957
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
910
958
|
|
|
911
959
|
return axn;
|
|
@@ -932,6 +980,7 @@ export class KaminoAction {
|
|
|
932
980
|
mint: PublicKey,
|
|
933
981
|
owner: PublicKey,
|
|
934
982
|
obligation: KaminoObligation | ObligationType,
|
|
983
|
+
useV2Ixs: boolean,
|
|
935
984
|
currentSlot: number,
|
|
936
985
|
payer: PublicKey | undefined = undefined,
|
|
937
986
|
extraComputeBudget: number = 1_000_000,
|
|
@@ -974,9 +1023,14 @@ export class KaminoAction {
|
|
|
974
1023
|
includeAtaIxns,
|
|
975
1024
|
requestElevationGroup,
|
|
976
1025
|
includeUserMetadata,
|
|
977
|
-
addInitObligationForFarm
|
|
1026
|
+
addInitObligationForFarm,
|
|
1027
|
+
useV2Ixs
|
|
978
1028
|
);
|
|
979
|
-
|
|
1029
|
+
if (useV2Ixs) {
|
|
1030
|
+
await axn.addRepayIxV2();
|
|
1031
|
+
} else {
|
|
1032
|
+
await axn.addRepayIx();
|
|
1033
|
+
}
|
|
980
1034
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
981
1035
|
|
|
982
1036
|
return axn;
|
|
@@ -991,6 +1045,7 @@ export class KaminoAction {
|
|
|
991
1045
|
liquidator: PublicKey,
|
|
992
1046
|
obligationOwner: PublicKey,
|
|
993
1047
|
obligation: KaminoObligation | ObligationType,
|
|
1048
|
+
useV2Ixs: boolean,
|
|
994
1049
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
995
1050
|
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
|
|
996
1051
|
requestElevationGroup: boolean = false,
|
|
@@ -1036,9 +1091,14 @@ export class KaminoAction {
|
|
|
1036
1091
|
includeAtaIxns,
|
|
1037
1092
|
requestElevationGroup,
|
|
1038
1093
|
includeUserMetadata,
|
|
1039
|
-
addInitObligationForFarm
|
|
1094
|
+
addInitObligationForFarm,
|
|
1095
|
+
useV2Ixs
|
|
1040
1096
|
);
|
|
1041
|
-
|
|
1097
|
+
if (useV2Ixs) {
|
|
1098
|
+
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
1099
|
+
} else {
|
|
1100
|
+
await axn.addLiquidateIx(maxAllowedLtvOverridePercent);
|
|
1101
|
+
}
|
|
1042
1102
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
1043
1103
|
|
|
1044
1104
|
return axn;
|
|
@@ -1164,25 +1224,23 @@ export class KaminoAction {
|
|
|
1164
1224
|
return await sendTransaction(txn, this.kaminoMarket.getConnection());
|
|
1165
1225
|
}
|
|
1166
1226
|
|
|
1167
|
-
|
|
1168
|
-
this.lendingIxsLabels.push(`
|
|
1227
|
+
addDepositReserveLiquidityIx() {
|
|
1228
|
+
this.lendingIxsLabels.push(`depositReserveLiquidity`);
|
|
1169
1229
|
this.lendingIxs.push(
|
|
1170
|
-
|
|
1230
|
+
depositReserveLiquidity(
|
|
1171
1231
|
{
|
|
1172
1232
|
liquidityAmount: this.amount,
|
|
1173
1233
|
},
|
|
1174
1234
|
{
|
|
1175
1235
|
owner: this.owner,
|
|
1176
|
-
obligation: this.getObligationPda(),
|
|
1177
1236
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1178
1237
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1179
1238
|
reserve: this.reserve.address,
|
|
1180
1239
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1181
1240
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1182
1241
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1183
|
-
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1184
1242
|
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1185
|
-
|
|
1243
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
1186
1244
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1187
1245
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1188
1246
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1192,12 +1250,12 @@ export class KaminoAction {
|
|
|
1192
1250
|
);
|
|
1193
1251
|
}
|
|
1194
1252
|
|
|
1195
|
-
|
|
1196
|
-
this.lendingIxsLabels.push(`
|
|
1253
|
+
addRedeemReserveCollateralIx() {
|
|
1254
|
+
this.lendingIxsLabels.push(`redeemReserveCollateral`);
|
|
1197
1255
|
this.lendingIxs.push(
|
|
1198
|
-
|
|
1256
|
+
redeemReserveCollateral(
|
|
1199
1257
|
{
|
|
1200
|
-
|
|
1258
|
+
collateralAmount: this.amount,
|
|
1201
1259
|
},
|
|
1202
1260
|
{
|
|
1203
1261
|
owner: this.owner,
|
|
@@ -1207,8 +1265,8 @@ export class KaminoAction {
|
|
|
1207
1265
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1208
1266
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1209
1267
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1210
|
-
|
|
1211
|
-
|
|
1268
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
1269
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1212
1270
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1213
1271
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1214
1272
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1218,23 +1276,26 @@ export class KaminoAction {
|
|
|
1218
1276
|
);
|
|
1219
1277
|
}
|
|
1220
1278
|
|
|
1221
|
-
|
|
1222
|
-
|
|
1279
|
+
// @deprecated -- use addDepositIxV2 instead
|
|
1280
|
+
addDepositIx() {
|
|
1281
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
1223
1282
|
this.lendingIxs.push(
|
|
1224
|
-
|
|
1283
|
+
depositReserveLiquidityAndObligationCollateral(
|
|
1225
1284
|
{
|
|
1226
|
-
|
|
1285
|
+
liquidityAmount: this.amount,
|
|
1227
1286
|
},
|
|
1228
1287
|
{
|
|
1229
1288
|
owner: this.owner,
|
|
1289
|
+
obligation: this.getObligationPda(),
|
|
1230
1290
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1231
1291
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1232
1292
|
reserve: this.reserve.address,
|
|
1233
1293
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1234
1294
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1235
1295
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1236
|
-
|
|
1237
|
-
|
|
1296
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1297
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1298
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1238
1299
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1239
1300
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1240
1301
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1244,6 +1305,52 @@ export class KaminoAction {
|
|
|
1244
1305
|
);
|
|
1245
1306
|
}
|
|
1246
1307
|
|
|
1308
|
+
addDepositIxV2() {
|
|
1309
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1310
|
+
? {
|
|
1311
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1312
|
+
reserveFarmState: PROGRAM_ID,
|
|
1313
|
+
}
|
|
1314
|
+
: {
|
|
1315
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1316
|
+
this.getObligationPda(),
|
|
1317
|
+
this.reserve.state.farmCollateral
|
|
1318
|
+
)[0],
|
|
1319
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1322
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
1323
|
+
this.lendingIxs.push(
|
|
1324
|
+
depositReserveLiquidityAndObligationCollateralV2(
|
|
1325
|
+
{
|
|
1326
|
+
liquidityAmount: this.amount,
|
|
1327
|
+
},
|
|
1328
|
+
{
|
|
1329
|
+
depositAccounts: {
|
|
1330
|
+
owner: this.owner,
|
|
1331
|
+
obligation: this.getObligationPda(),
|
|
1332
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1333
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1334
|
+
reserve: this.reserve.address,
|
|
1335
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1336
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1337
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1338
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1339
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1340
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1341
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1342
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1343
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1344
|
+
},
|
|
1345
|
+
farmsAccounts,
|
|
1346
|
+
farmsProgram: farmsId,
|
|
1347
|
+
},
|
|
1348
|
+
this.kaminoMarket.programId
|
|
1349
|
+
)
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
1247
1354
|
addDepositObligationCollateralIx() {
|
|
1248
1355
|
this.lendingIxsLabels.push(`depositObligationCollateral`);
|
|
1249
1356
|
this.lendingIxs.push(
|
|
@@ -1266,6 +1373,47 @@ export class KaminoAction {
|
|
|
1266
1373
|
);
|
|
1267
1374
|
}
|
|
1268
1375
|
|
|
1376
|
+
addDepositObligationCollateralIxV2() {
|
|
1377
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1378
|
+
? {
|
|
1379
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1380
|
+
reserveFarmState: PROGRAM_ID,
|
|
1381
|
+
}
|
|
1382
|
+
: {
|
|
1383
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1384
|
+
this.getObligationPda(),
|
|
1385
|
+
this.reserve.state.farmCollateral
|
|
1386
|
+
)[0],
|
|
1387
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
this.lendingIxsLabels.push(`depositObligationCollateralV2`);
|
|
1391
|
+
this.lendingIxs.push(
|
|
1392
|
+
depositObligationCollateralV2(
|
|
1393
|
+
{
|
|
1394
|
+
collateralAmount: this.amount,
|
|
1395
|
+
},
|
|
1396
|
+
{
|
|
1397
|
+
depositAccounts: {
|
|
1398
|
+
owner: this.owner,
|
|
1399
|
+
obligation: this.getObligationPda(),
|
|
1400
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1401
|
+
depositReserve: this.reserve.address,
|
|
1402
|
+
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
1403
|
+
userSourceCollateral: this.userCollateralAccountAddress,
|
|
1404
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1405
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1406
|
+
},
|
|
1407
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1408
|
+
farmsAccounts,
|
|
1409
|
+
farmsProgram: farmsId,
|
|
1410
|
+
},
|
|
1411
|
+
this.kaminoMarket.programId
|
|
1412
|
+
)
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
1269
1417
|
addBorrowIx() {
|
|
1270
1418
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
1271
1419
|
|
|
@@ -1302,6 +1450,238 @@ export class KaminoAction {
|
|
|
1302
1450
|
this.lendingIxs.push(borrowIx);
|
|
1303
1451
|
}
|
|
1304
1452
|
|
|
1453
|
+
addBorrowIxV2() {
|
|
1454
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
1455
|
+
|
|
1456
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1457
|
+
|
|
1458
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1459
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1463
|
+
? {
|
|
1464
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1465
|
+
reserveFarmState: PROGRAM_ID,
|
|
1466
|
+
}
|
|
1467
|
+
: {
|
|
1468
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1469
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
const borrowIx = borrowObligationLiquidityV2(
|
|
1473
|
+
{
|
|
1474
|
+
liquidityAmount: this.amount,
|
|
1475
|
+
},
|
|
1476
|
+
{
|
|
1477
|
+
borrowAccounts: {
|
|
1478
|
+
owner: this.owner,
|
|
1479
|
+
obligation: this.getObligationPda(),
|
|
1480
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1481
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1482
|
+
borrowReserve: this.reserve.address,
|
|
1483
|
+
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1484
|
+
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1485
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1486
|
+
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
1487
|
+
referrerTokenState: referrerTokenStatePda(
|
|
1488
|
+
this.referrer,
|
|
1489
|
+
this.reserve.address,
|
|
1490
|
+
this.kaminoMarket.programId
|
|
1491
|
+
)[0],
|
|
1492
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1493
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1494
|
+
},
|
|
1495
|
+
farmsAccounts,
|
|
1496
|
+
farmsProgram: farmsId,
|
|
1497
|
+
},
|
|
1498
|
+
this.kaminoMarket.programId
|
|
1499
|
+
);
|
|
1500
|
+
borrowIx.keys =
|
|
1501
|
+
this.obligation!.state.elevationGroup > 0 || this.obligation!.refreshedStats.potentialElevationGroupUpdate > 0
|
|
1502
|
+
? borrowIx.keys.concat([...depositReserveAccountMetas])
|
|
1503
|
+
: borrowIx.keys;
|
|
1504
|
+
this.lendingIxs.push(borrowIx);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
/// @deprecated -- use addWithdrawIxV2 instead
|
|
1508
|
+
async addWithdrawIx() {
|
|
1509
|
+
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
|
|
1510
|
+
this.currentSlot,
|
|
1511
|
+
this.kaminoMarket.state.referralFeeBps
|
|
1512
|
+
);
|
|
1513
|
+
|
|
1514
|
+
const collateralAmount = this.amount.eq(new BN(U64_MAX))
|
|
1515
|
+
? this.amount
|
|
1516
|
+
: new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
1517
|
+
|
|
1518
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
1519
|
+
this.lendingIxs.push(
|
|
1520
|
+
withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
1521
|
+
{
|
|
1522
|
+
collateralAmount,
|
|
1523
|
+
},
|
|
1524
|
+
{
|
|
1525
|
+
owner: this.owner,
|
|
1526
|
+
obligation: this.getObligationPda(),
|
|
1527
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1528
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1529
|
+
withdrawReserve: this.reserve.address,
|
|
1530
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1531
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1532
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1533
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1534
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1535
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1536
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1537
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1538
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1539
|
+
},
|
|
1540
|
+
this.kaminoMarket.programId
|
|
1541
|
+
)
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
async addWithdrawIxV2() {
|
|
1546
|
+
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
|
|
1547
|
+
this.currentSlot,
|
|
1548
|
+
this.kaminoMarket.state.referralFeeBps
|
|
1549
|
+
);
|
|
1550
|
+
|
|
1551
|
+
// TODO: Move this side effect from here...
|
|
1552
|
+
const collateralAmount = this.amount.eq(new BN(U64_MAX))
|
|
1553
|
+
? this.amount
|
|
1554
|
+
: new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
1555
|
+
|
|
1556
|
+
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1557
|
+
? {
|
|
1558
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1559
|
+
reserveFarmState: PROGRAM_ID,
|
|
1560
|
+
}
|
|
1561
|
+
: {
|
|
1562
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1563
|
+
this.getObligationPda(),
|
|
1564
|
+
this.reserve.state.farmCollateral
|
|
1565
|
+
)[0],
|
|
1566
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1567
|
+
};
|
|
1568
|
+
|
|
1569
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
1570
|
+
this.lendingIxs.push(
|
|
1571
|
+
withdrawObligationCollateralAndRedeemReserveCollateralV2(
|
|
1572
|
+
{
|
|
1573
|
+
collateralAmount,
|
|
1574
|
+
},
|
|
1575
|
+
{
|
|
1576
|
+
withdrawAccounts: {
|
|
1577
|
+
owner: this.owner,
|
|
1578
|
+
obligation: this.getObligationPda(),
|
|
1579
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1580
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1581
|
+
withdrawReserve: this.reserve.address,
|
|
1582
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1583
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1584
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1585
|
+
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1586
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1587
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1588
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1589
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1590
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1591
|
+
},
|
|
1592
|
+
farmsAccounts: farmsAccounts,
|
|
1593
|
+
farmsProgram: farmsId,
|
|
1594
|
+
},
|
|
1595
|
+
this.kaminoMarket.programId
|
|
1596
|
+
)
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
/// @deprecated -- use addRepayIxV2 instead
|
|
1601
|
+
async addRepayIx() {
|
|
1602
|
+
this.lendingIxsLabels.push(
|
|
1603
|
+
`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
|
|
1604
|
+
);
|
|
1605
|
+
|
|
1606
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1607
|
+
|
|
1608
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1609
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1610
|
+
});
|
|
1611
|
+
|
|
1612
|
+
const repayIx = repayObligationLiquidity(
|
|
1613
|
+
{
|
|
1614
|
+
liquidityAmount: this.amount,
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
owner: this.payer,
|
|
1618
|
+
obligation: this.getObligationPda(),
|
|
1619
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1620
|
+
repayReserve: this.reserve.address,
|
|
1621
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1622
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1623
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1624
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1625
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1626
|
+
},
|
|
1627
|
+
this.kaminoMarket.programId
|
|
1628
|
+
);
|
|
1629
|
+
|
|
1630
|
+
repayIx.keys =
|
|
1631
|
+
this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1632
|
+
|
|
1633
|
+
this.lendingIxs.push(repayIx);
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
async addRepayIxV2() {
|
|
1637
|
+
this.lendingIxsLabels.push(
|
|
1638
|
+
`repayObligationLiquidityV2(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
|
|
1639
|
+
);
|
|
1640
|
+
|
|
1641
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1642
|
+
|
|
1643
|
+
const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1644
|
+
? {
|
|
1645
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1646
|
+
reserveFarmState: PROGRAM_ID,
|
|
1647
|
+
}
|
|
1648
|
+
: {
|
|
1649
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1650
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1651
|
+
};
|
|
1652
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1653
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1654
|
+
});
|
|
1655
|
+
|
|
1656
|
+
const repayIx = repayObligationLiquidityV2(
|
|
1657
|
+
{
|
|
1658
|
+
liquidityAmount: this.amount,
|
|
1659
|
+
},
|
|
1660
|
+
{
|
|
1661
|
+
repayAccounts: {
|
|
1662
|
+
owner: this.payer,
|
|
1663
|
+
obligation: this.getObligationPda(),
|
|
1664
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1665
|
+
repayReserve: this.reserve.address,
|
|
1666
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1667
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1668
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1669
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1670
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1671
|
+
},
|
|
1672
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1673
|
+
farmsAccounts,
|
|
1674
|
+
farmsProgram: farmsId,
|
|
1675
|
+
},
|
|
1676
|
+
this.kaminoMarket.programId
|
|
1677
|
+
);
|
|
1678
|
+
|
|
1679
|
+
repayIx.keys =
|
|
1680
|
+
this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1681
|
+
|
|
1682
|
+
this.lendingIxs.push(repayIx);
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1305
1685
|
async addDepositAndBorrowIx() {
|
|
1306
1686
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
1307
1687
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
@@ -1380,6 +1760,118 @@ export class KaminoAction {
|
|
|
1380
1760
|
this.lendingIxs.push(borrowIx);
|
|
1381
1761
|
}
|
|
1382
1762
|
|
|
1763
|
+
async addDepositAndBorrowIxV2() {
|
|
1764
|
+
const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1765
|
+
? {
|
|
1766
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1767
|
+
reserveFarmState: PROGRAM_ID,
|
|
1768
|
+
}
|
|
1769
|
+
: {
|
|
1770
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1771
|
+
this.getObligationPda(),
|
|
1772
|
+
this.reserve.state.farmCollateral
|
|
1773
|
+
)[0],
|
|
1774
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1775
|
+
};
|
|
1776
|
+
|
|
1777
|
+
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateralV2`);
|
|
1778
|
+
this.lendingIxsLabels.push(`borrowObligationLiquidityV2`);
|
|
1779
|
+
this.lendingIxs.push(
|
|
1780
|
+
depositReserveLiquidityAndObligationCollateralV2(
|
|
1781
|
+
{
|
|
1782
|
+
liquidityAmount: this.amount,
|
|
1783
|
+
},
|
|
1784
|
+
{
|
|
1785
|
+
depositAccounts: {
|
|
1786
|
+
owner: this.owner,
|
|
1787
|
+
obligation: this.getObligationPda(),
|
|
1788
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1789
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1790
|
+
reserve: this.reserve.address,
|
|
1791
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1792
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1793
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1794
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1795
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1796
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1797
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1798
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1799
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1800
|
+
},
|
|
1801
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
1802
|
+
farmsProgram: farmsId,
|
|
1803
|
+
},
|
|
1804
|
+
this.kaminoMarket.programId
|
|
1805
|
+
)
|
|
1806
|
+
);
|
|
1807
|
+
|
|
1808
|
+
if (!this.outflowReserve) {
|
|
1809
|
+
throw new Error(`outflowReserve not set`);
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1813
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
if (!this.outflowAmount) {
|
|
1817
|
+
throw new Error(`outflowAmount not set`);
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1821
|
+
if (depositReservesList.length === 0) {
|
|
1822
|
+
depositReservesList.push(this.reserve.address);
|
|
1823
|
+
}
|
|
1824
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1825
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(PublicKey.default)
|
|
1829
|
+
? {
|
|
1830
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1831
|
+
reserveFarmState: PROGRAM_ID,
|
|
1832
|
+
}
|
|
1833
|
+
: {
|
|
1834
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1835
|
+
this.getObligationPda(),
|
|
1836
|
+
this.outflowReserve.state.farmDebt!
|
|
1837
|
+
)[0],
|
|
1838
|
+
reserveFarmState: this.outflowReserve.state.farmDebt,
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
const borrowIx = borrowObligationLiquidityV2(
|
|
1842
|
+
{
|
|
1843
|
+
liquidityAmount: this.outflowAmount,
|
|
1844
|
+
},
|
|
1845
|
+
{
|
|
1846
|
+
borrowAccounts: {
|
|
1847
|
+
owner: this.owner,
|
|
1848
|
+
obligation: this.getObligationPda(),
|
|
1849
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1850
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1851
|
+
borrowReserve: this.outflowReserve.address,
|
|
1852
|
+
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1853
|
+
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
1854
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1855
|
+
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1856
|
+
referrerTokenState: referrerTokenStatePda(
|
|
1857
|
+
this.referrer,
|
|
1858
|
+
this.outflowReserve.address,
|
|
1859
|
+
this.kaminoMarket.programId
|
|
1860
|
+
)[0],
|
|
1861
|
+
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1862
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1863
|
+
},
|
|
1864
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1865
|
+
farmsProgram: farmsId,
|
|
1866
|
+
},
|
|
1867
|
+
this.kaminoMarket.programId
|
|
1868
|
+
);
|
|
1869
|
+
|
|
1870
|
+
borrowIx.keys = borrowIx.keys.concat([...depositReserveAccountMetas]);
|
|
1871
|
+
|
|
1872
|
+
this.lendingIxs.push(borrowIx);
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1383
1875
|
async addRepayAndWithdrawIxs() {
|
|
1384
1876
|
this.lendingIxsLabels.push(
|
|
1385
1877
|
`repayObligationLiquidity(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
|
|
@@ -1457,47 +1949,11 @@ export class KaminoAction {
|
|
|
1457
1949
|
);
|
|
1458
1950
|
}
|
|
1459
1951
|
|
|
1460
|
-
async
|
|
1461
|
-
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
|
|
1462
|
-
this.currentSlot,
|
|
1463
|
-
this.kaminoMarket.state.referralFeeBps
|
|
1464
|
-
);
|
|
1465
|
-
|
|
1466
|
-
const collateralAmount = this.amount.eq(new BN(U64_MAX))
|
|
1467
|
-
? this.amount
|
|
1468
|
-
: new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
1469
|
-
|
|
1470
|
-
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
1471
|
-
this.lendingIxs.push(
|
|
1472
|
-
withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
1473
|
-
{
|
|
1474
|
-
collateralAmount,
|
|
1475
|
-
},
|
|
1476
|
-
{
|
|
1477
|
-
owner: this.owner,
|
|
1478
|
-
obligation: this.getObligationPda(),
|
|
1479
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1480
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1481
|
-
withdrawReserve: this.reserve.address,
|
|
1482
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1483
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1484
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1485
|
-
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1486
|
-
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
1487
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1488
|
-
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1489
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1490
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1491
|
-
},
|
|
1492
|
-
this.kaminoMarket.programId
|
|
1493
|
-
)
|
|
1494
|
-
);
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
async addRepayIx() {
|
|
1952
|
+
async addRepayAndWithdrawIxsV2() {
|
|
1498
1953
|
this.lendingIxsLabels.push(
|
|
1499
|
-
`
|
|
1954
|
+
`repayObligationLiquidityV2(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
|
|
1500
1955
|
);
|
|
1956
|
+
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateralV2`);
|
|
1501
1957
|
|
|
1502
1958
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1503
1959
|
|
|
@@ -1505,28 +1961,102 @@ export class KaminoAction {
|
|
|
1505
1961
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1506
1962
|
});
|
|
1507
1963
|
|
|
1508
|
-
const
|
|
1964
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1965
|
+
? {
|
|
1966
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1967
|
+
reserveFarmState: PROGRAM_ID,
|
|
1968
|
+
}
|
|
1969
|
+
: {
|
|
1970
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1971
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
const repayIx = repayObligationLiquidityV2(
|
|
1509
1975
|
{
|
|
1510
1976
|
liquidityAmount: this.amount,
|
|
1511
1977
|
},
|
|
1512
1978
|
{
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1979
|
+
repayAccounts: {
|
|
1980
|
+
owner: this.owner,
|
|
1981
|
+
obligation: this.getObligationPda(),
|
|
1982
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1983
|
+
repayReserve: this.reserve!.address,
|
|
1984
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1985
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1986
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1987
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1988
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1989
|
+
},
|
|
1990
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1991
|
+
farmsAccounts: debtFarmsAccounts,
|
|
1992
|
+
farmsProgram: farmsId,
|
|
1522
1993
|
},
|
|
1523
1994
|
this.kaminoMarket.programId
|
|
1524
1995
|
);
|
|
1525
1996
|
|
|
1526
|
-
repayIx.keys =
|
|
1527
|
-
this.obligation!.state.elevationGroup > 0 ? repayIx.keys.concat([...depositReserveAccountMetas]) : repayIx.keys;
|
|
1997
|
+
repayIx.keys = repayIx.keys.concat([...depositReserveAccountMetas]);
|
|
1528
1998
|
|
|
1529
1999
|
this.lendingIxs.push(repayIx);
|
|
2000
|
+
if (!this.outflowReserve) {
|
|
2001
|
+
throw new Error(`outflowReserve not set`);
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
if (!this.additionalTokenAccountAddress) {
|
|
2005
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
if (!this.outflowAmount) {
|
|
2009
|
+
throw new Error(`outflowAmount not set`);
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(
|
|
2013
|
+
this.currentSlot,
|
|
2014
|
+
this.kaminoMarket.state.referralFeeBps
|
|
2015
|
+
);
|
|
2016
|
+
|
|
2017
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
2018
|
+
? {
|
|
2019
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2020
|
+
reserveFarmState: PROGRAM_ID,
|
|
2021
|
+
}
|
|
2022
|
+
: {
|
|
2023
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
2024
|
+
this.getObligationPda(),
|
|
2025
|
+
this.outflowReserve.state.farmCollateral
|
|
2026
|
+
)[0],
|
|
2027
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2028
|
+
};
|
|
2029
|
+
|
|
2030
|
+
this.lendingIxs.push(
|
|
2031
|
+
withdrawObligationCollateralAndRedeemReserveCollateralV2(
|
|
2032
|
+
{
|
|
2033
|
+
collateralAmount: this.outflowAmount.eq(new BN(U64_MAX))
|
|
2034
|
+
? this.outflowAmount
|
|
2035
|
+
: new BN(new Decimal(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
|
|
2036
|
+
},
|
|
2037
|
+
{
|
|
2038
|
+
withdrawAccounts: {
|
|
2039
|
+
owner: this.owner,
|
|
2040
|
+
obligation: this.getObligationPda(),
|
|
2041
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
2042
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
2043
|
+
withdrawReserve: this.outflowReserve.address,
|
|
2044
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
2045
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
2046
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
2047
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
2048
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
2049
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
2050
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
2051
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
2052
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2053
|
+
},
|
|
2054
|
+
farmsAccounts: collateralFarmsAccounts,
|
|
2055
|
+
farmsProgram: farmsId,
|
|
2056
|
+
},
|
|
2057
|
+
this.kaminoMarket.programId
|
|
2058
|
+
)
|
|
2059
|
+
);
|
|
1530
2060
|
}
|
|
1531
2061
|
|
|
1532
2062
|
async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
|
|
@@ -1581,15 +2111,97 @@ export class KaminoAction {
|
|
|
1581
2111
|
this.lendingIxs.push(liquidateIx);
|
|
1582
2112
|
}
|
|
1583
2113
|
|
|
2114
|
+
async addLiquidateIxV2(maxAllowedLtvOverridePercent: number = 0) {
|
|
2115
|
+
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateralV2`);
|
|
2116
|
+
if (!this.outflowReserve) {
|
|
2117
|
+
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
2118
|
+
}
|
|
2119
|
+
if (!this.additionalTokenAccountAddress) {
|
|
2120
|
+
throw Error(`Liquidating token account address is not defined`);
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
2124
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
2125
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
2126
|
+
});
|
|
2127
|
+
|
|
2128
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
2129
|
+
? {
|
|
2130
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2131
|
+
reserveFarmState: PROGRAM_ID,
|
|
2132
|
+
}
|
|
2133
|
+
: {
|
|
2134
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
2135
|
+
this.getObligationPda(),
|
|
2136
|
+
this.outflowReserve.state.farmCollateral
|
|
2137
|
+
)[0],
|
|
2138
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2139
|
+
};
|
|
2140
|
+
|
|
2141
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
2142
|
+
? {
|
|
2143
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2144
|
+
reserveFarmState: PROGRAM_ID,
|
|
2145
|
+
}
|
|
2146
|
+
: {
|
|
2147
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
2148
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2151
|
+
const liquidateIx = liquidateObligationAndRedeemReserveCollateralV2(
|
|
2152
|
+
{
|
|
2153
|
+
liquidityAmount: this.amount,
|
|
2154
|
+
// TODO: Configure this when updating liquidator with new interface
|
|
2155
|
+
minAcceptableReceivedLiquidityAmount: this.outflowAmount || new BN(0),
|
|
2156
|
+
maxAllowedLtvOverridePercent: new BN(maxAllowedLtvOverridePercent),
|
|
2157
|
+
},
|
|
2158
|
+
{
|
|
2159
|
+
liquidationAccounts: {
|
|
2160
|
+
liquidator: this.owner,
|
|
2161
|
+
obligation: this.getObligationPda(),
|
|
2162
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
2163
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
2164
|
+
repayReserve: this.reserve.address,
|
|
2165
|
+
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
2166
|
+
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
2167
|
+
withdrawReserve: this.outflowReserve.address,
|
|
2168
|
+
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
2169
|
+
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
2170
|
+
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
2171
|
+
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
2172
|
+
userSourceLiquidity: this.additionalTokenAccountAddress,
|
|
2173
|
+
userDestinationCollateral: this.userCollateralAccountAddress,
|
|
2174
|
+
userDestinationLiquidity: this.userTokenAccountAddress,
|
|
2175
|
+
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
2176
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
2177
|
+
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
2178
|
+
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
2179
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2180
|
+
},
|
|
2181
|
+
debtFarmsAccounts,
|
|
2182
|
+
collateralFarmsAccounts,
|
|
2183
|
+
farmsProgram: farmsId,
|
|
2184
|
+
},
|
|
2185
|
+
this.kaminoMarket.programId
|
|
2186
|
+
);
|
|
2187
|
+
liquidateIx.keys =
|
|
2188
|
+
this.obligation!.state.elevationGroup > 0
|
|
2189
|
+
? liquidateIx.keys.concat([...depositReserveAccountMetas])
|
|
2190
|
+
: liquidateIx.keys;
|
|
2191
|
+
this.lendingIxs.push(liquidateIx);
|
|
2192
|
+
}
|
|
2193
|
+
|
|
1584
2194
|
async addInBetweenIxs(
|
|
1585
2195
|
action: ActionType,
|
|
1586
2196
|
includeAtaIxns: boolean,
|
|
1587
2197
|
requestElevationGroup: boolean,
|
|
1588
|
-
addInitObligationForFarm: boolean
|
|
2198
|
+
addInitObligationForFarm: boolean,
|
|
2199
|
+
useV2Ixs: boolean
|
|
1589
2200
|
) {
|
|
1590
2201
|
await this.addSupportIxsWithoutInitObligation(
|
|
1591
2202
|
action,
|
|
1592
2203
|
includeAtaIxns,
|
|
2204
|
+
useV2Ixs,
|
|
1593
2205
|
'inBetween',
|
|
1594
2206
|
requestElevationGroup,
|
|
1595
2207
|
addInitObligationForFarm
|
|
@@ -1622,6 +2234,7 @@ export class KaminoAction {
|
|
|
1622
2234
|
async addSupportIxsWithoutInitObligation(
|
|
1623
2235
|
action: ActionType,
|
|
1624
2236
|
includeAtaIxns: boolean,
|
|
2237
|
+
useV2Ixs: boolean,
|
|
1625
2238
|
addAsSupportIx: AuxiliaryIx = 'setup',
|
|
1626
2239
|
requestElevationGroup: boolean = false,
|
|
1627
2240
|
addInitObligationForFarm: boolean = false,
|
|
@@ -1850,46 +2463,48 @@ export class KaminoAction {
|
|
|
1850
2463
|
}
|
|
1851
2464
|
}
|
|
1852
2465
|
|
|
1853
|
-
if (
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
// If this is an inbetween, it means it's part of a two-token-action
|
|
1885
|
-
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
1886
|
-
// add added to 'setup' ixns
|
|
1887
|
-
if (action === 'depositAndBorrow') {
|
|
1888
|
-
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
|
|
1889
|
-
} else if (action === 'repayAndWithdraw') {
|
|
1890
|
-
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2466
|
+
if (!useV2Ixs) {
|
|
2467
|
+
if (addAsSupportIx === 'setup') {
|
|
2468
|
+
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|
|
2469
|
+
// or the first of a two-token-action
|
|
2470
|
+
if (action === 'liquidate') {
|
|
2471
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2472
|
+
this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, ReserveFarmKind.Debt);
|
|
2473
|
+
} else if (
|
|
2474
|
+
action === 'depositAndBorrow' ||
|
|
2475
|
+
action === 'depositCollateral' ||
|
|
2476
|
+
action === 'withdraw' ||
|
|
2477
|
+
action === 'deposit'
|
|
2478
|
+
) {
|
|
2479
|
+
this.addRefreshFarmsForReserve(
|
|
2480
|
+
currentReserves,
|
|
2481
|
+
addAsSupportIx,
|
|
2482
|
+
ReserveFarmKind.Collateral,
|
|
2483
|
+
undefined,
|
|
2484
|
+
twoTokenAction
|
|
2485
|
+
);
|
|
2486
|
+
} else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
2487
|
+
this.addRefreshFarmsForReserve(
|
|
2488
|
+
currentReserves,
|
|
2489
|
+
addAsSupportIx,
|
|
2490
|
+
ReserveFarmKind.Debt,
|
|
2491
|
+
undefined,
|
|
2492
|
+
twoTokenAction
|
|
2493
|
+
);
|
|
2494
|
+
} else {
|
|
2495
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
2496
|
+
}
|
|
1891
2497
|
} else {
|
|
1892
|
-
|
|
2498
|
+
// If this is an inbetween, it means it's part of a two-token-action
|
|
2499
|
+
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
2500
|
+
// add added to 'setup' ixns
|
|
2501
|
+
if (action === 'depositAndBorrow') {
|
|
2502
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
|
|
2503
|
+
} else if (action === 'repayAndWithdraw') {
|
|
2504
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2505
|
+
} else {
|
|
2506
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
2507
|
+
}
|
|
1893
2508
|
}
|
|
1894
2509
|
}
|
|
1895
2510
|
}
|
|
@@ -1901,6 +2516,7 @@ export class KaminoAction {
|
|
|
1901
2516
|
requestElevationGroup: boolean,
|
|
1902
2517
|
includeUserMetadata: boolean,
|
|
1903
2518
|
addInitObligationForFarm: boolean,
|
|
2519
|
+
useV2Ixs: boolean,
|
|
1904
2520
|
twoTokenAction: boolean = false,
|
|
1905
2521
|
overrideElevationGroupRequest?: number
|
|
1906
2522
|
) {
|
|
@@ -1923,6 +2539,7 @@ export class KaminoAction {
|
|
|
1923
2539
|
await this.addSupportIxsWithoutInitObligation(
|
|
1924
2540
|
action,
|
|
1925
2541
|
includeAtaIxns,
|
|
2542
|
+
useV2Ixs,
|
|
1926
2543
|
'setup',
|
|
1927
2544
|
requestElevationGroup,
|
|
1928
2545
|
addInitObligationForFarm,
|
|
@@ -2136,13 +2753,6 @@ export class KaminoAction {
|
|
|
2136
2753
|
crank: PublicKey = this.payer,
|
|
2137
2754
|
twoTokenAction: boolean = false
|
|
2138
2755
|
) {
|
|
2139
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
2140
|
-
const getPda = (farm: PublicKey) =>
|
|
2141
|
-
PublicKey.findProgramAddressSync(
|
|
2142
|
-
[BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()],
|
|
2143
|
-
farmsId
|
|
2144
|
-
)[0];
|
|
2145
|
-
|
|
2146
2756
|
const farms: [
|
|
2147
2757
|
typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
|
|
2148
2758
|
PublicKey,
|
|
@@ -2155,7 +2765,7 @@ export class KaminoAction {
|
|
|
2155
2765
|
farms.push([
|
|
2156
2766
|
ReserveFarmKind.Collateral,
|
|
2157
2767
|
kaminoReserve.state.farmCollateral,
|
|
2158
|
-
|
|
2768
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
|
|
2159
2769
|
kaminoReserve,
|
|
2160
2770
|
]);
|
|
2161
2771
|
}
|
|
@@ -2163,7 +2773,7 @@ export class KaminoAction {
|
|
|
2163
2773
|
farms.push([
|
|
2164
2774
|
ReserveFarmKind.Debt,
|
|
2165
2775
|
kaminoReserve.state.farmDebt,
|
|
2166
|
-
|
|
2776
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
|
|
2167
2777
|
kaminoReserve,
|
|
2168
2778
|
]);
|
|
2169
2779
|
}
|
|
@@ -2244,28 +2854,21 @@ export class KaminoAction {
|
|
|
2244
2854
|
mode: typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
|
|
2245
2855
|
addAsSupportIx: AuxiliaryIx = 'setup'
|
|
2246
2856
|
): Promise<void> {
|
|
2247
|
-
const BASE_SEED_USER_STATE = Buffer.from('user');
|
|
2248
|
-
const getPda = (farm: PublicKey) =>
|
|
2249
|
-
PublicKey.findProgramAddressSync(
|
|
2250
|
-
[BASE_SEED_USER_STATE, farm.toBytes(), this.getObligationPda().toBytes()],
|
|
2251
|
-
farmsId
|
|
2252
|
-
)[0];
|
|
2253
|
-
|
|
2254
2857
|
const farms: [number, PublicKey, PublicKey][] = [];
|
|
2255
2858
|
|
|
2256
2859
|
if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
|
|
2257
|
-
const
|
|
2258
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
2860
|
+
const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmCollateral)[0];
|
|
2861
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
2259
2862
|
if (!account) {
|
|
2260
|
-
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral,
|
|
2863
|
+
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
|
|
2261
2864
|
}
|
|
2262
2865
|
}
|
|
2263
2866
|
|
|
2264
2867
|
if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
|
|
2265
|
-
const
|
|
2266
|
-
const account = await this.kaminoMarket.getConnection().getAccountInfo(
|
|
2868
|
+
const userPda = obligationFarmStatePda(this.getObligationPda(), reserve.state.farmDebt)[0];
|
|
2869
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(userPda);
|
|
2267
2870
|
if (!account) {
|
|
2268
|
-
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
2871
|
+
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
|
|
2269
2872
|
}
|
|
2270
2873
|
}
|
|
2271
2874
|
|