@kamino-finance/klend-sdk 5.10.34 → 5.10.35-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +28 -20
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +317 -137
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +10 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.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 +10 -10
- 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_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +22 -1
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +5 -3
- 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.map +1 -1
- package/dist/leverage/operations.js +19 -13
- package/dist/leverage/operations.js.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/lookupTable.d.ts +27 -0
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +58 -0
- package/dist/utils/lookupTable.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 +11 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +16 -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 +3 -3
- package/src/classes/action.ts +476 -141
- package/src/classes/manager.ts +13 -0
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +2 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +7 -8
- 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_calcs.ts +14 -5
- package/src/lending_operations/repay_with_collateral_operations.ts +28 -3
- package/src/lending_operations/swap_collateral_operations.ts +6 -5
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +28 -18
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +5 -11
- package/src/utils/lookupTable.ts +62 -0
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/seeds.ts +18 -0
- package/src/utils/userMetadata.ts +9 -14
- package/dist/classes/lut_utils.d.ts +0 -29
- package/dist/classes/lut_utils.d.ts.map +0 -1
- package/dist/classes/lut_utils.js +0 -62
- package/dist/classes/lut_utils.js.map +0 -1
- package/src/classes/lut_utils.ts +0 -63
package/src/classes/action.ts
CHANGED
|
@@ -21,6 +21,7 @@ import BN from 'bn.js';
|
|
|
21
21
|
import Decimal from 'decimal.js';
|
|
22
22
|
import {
|
|
23
23
|
borrowObligationLiquidity,
|
|
24
|
+
depositAndWithdraw,
|
|
24
25
|
depositObligationCollateral,
|
|
25
26
|
depositReserveLiquidity,
|
|
26
27
|
depositReserveLiquidityAndObligationCollateral,
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
RefreshObligationFarmsForReserveAccounts,
|
|
38
39
|
RefreshObligationFarmsForReserveArgs,
|
|
39
40
|
refreshReserve,
|
|
41
|
+
repayAndWithdrawAndRedeem,
|
|
40
42
|
repayObligationLiquidity,
|
|
41
43
|
requestElevationGroup,
|
|
42
44
|
RequestElevationGroupAccounts,
|
|
@@ -54,11 +56,10 @@ import {
|
|
|
54
56
|
createLookupTableIx,
|
|
55
57
|
isNotNullPubkey,
|
|
56
58
|
PublicKeySet,
|
|
57
|
-
WRAPPED_SOL_MINT,
|
|
58
59
|
getAssociatedTokenAddress,
|
|
59
60
|
ScopeRefresh,
|
|
60
61
|
createAtasIdempotent,
|
|
61
|
-
|
|
62
|
+
obligationFarmStatePda,
|
|
62
63
|
} from '../utils';
|
|
63
64
|
import { KaminoMarket } from './market';
|
|
64
65
|
import { KaminoObligation } from './obligation';
|
|
@@ -85,7 +86,9 @@ export type ActionType =
|
|
|
85
86
|
| 'repayAndWithdraw'
|
|
86
87
|
| 'refreshObligation'
|
|
87
88
|
| 'requestElevationGroup'
|
|
88
|
-
| 'withdrawReferrerFees'
|
|
89
|
+
| 'withdrawReferrerFees'
|
|
90
|
+
| 'repayAndWithdrawV2'
|
|
91
|
+
| 'depositAndWithdraw';
|
|
89
92
|
|
|
90
93
|
export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
|
|
91
94
|
|
|
@@ -322,10 +325,6 @@ export class KaminoAction {
|
|
|
322
325
|
...(action === 'depositAndBorrow' ? [outflowReserve!] : []),
|
|
323
326
|
]).toArray().length;
|
|
324
327
|
|
|
325
|
-
if (distinctReserveCount > POSITION_LIMIT) {
|
|
326
|
-
throw Error(`Obligation already has max number of positions: ${POSITION_LIMIT}`);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
328
|
return {
|
|
330
329
|
kaminoObligation,
|
|
331
330
|
depositReserves,
|
|
@@ -413,6 +412,7 @@ export class KaminoAction {
|
|
|
413
412
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
414
413
|
requestElevationGroup: boolean = false, // to be requested *before* the deposit
|
|
415
414
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
415
|
+
createLookupTable: boolean = true,
|
|
416
416
|
referrer: PublicKey = PublicKey.default,
|
|
417
417
|
currentSlot: number = 0,
|
|
418
418
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
@@ -450,6 +450,8 @@ export class KaminoAction {
|
|
|
450
450
|
requestElevationGroup,
|
|
451
451
|
includeUserMetadata,
|
|
452
452
|
addInitObligationForFarm,
|
|
453
|
+
false,
|
|
454
|
+
createLookupTable,
|
|
453
455
|
undefined,
|
|
454
456
|
overrideElevationGroupRequest
|
|
455
457
|
);
|
|
@@ -507,6 +509,7 @@ export class KaminoAction {
|
|
|
507
509
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
508
510
|
requestElevationGroup: boolean = false,
|
|
509
511
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
512
|
+
createLookupTable: boolean = true,
|
|
510
513
|
referrer: PublicKey = PublicKey.default,
|
|
511
514
|
currentSlot: number = 0,
|
|
512
515
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
@@ -544,6 +547,8 @@ export class KaminoAction {
|
|
|
544
547
|
requestElevationGroup,
|
|
545
548
|
includeUserMetadata,
|
|
546
549
|
addInitObligationForFarm,
|
|
550
|
+
false,
|
|
551
|
+
createLookupTable,
|
|
547
552
|
undefined,
|
|
548
553
|
overrideElevationGroupRequest
|
|
549
554
|
);
|
|
@@ -562,7 +567,6 @@ export class KaminoAction {
|
|
|
562
567
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
563
568
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
564
569
|
requestElevationGroup: boolean = false,
|
|
565
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
566
570
|
referrer: PublicKey = PublicKey.default,
|
|
567
571
|
currentSlot: number = 0,
|
|
568
572
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -598,8 +602,10 @@ export class KaminoAction {
|
|
|
598
602
|
'mint',
|
|
599
603
|
includeAtaIxns,
|
|
600
604
|
requestElevationGroup,
|
|
601
|
-
|
|
602
|
-
addInitObligationForFarm
|
|
605
|
+
false,
|
|
606
|
+
addInitObligationForFarm,
|
|
607
|
+
false,
|
|
608
|
+
false
|
|
603
609
|
);
|
|
604
610
|
axn.addDepositReserveLiquidityIx();
|
|
605
611
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
@@ -615,7 +621,6 @@ export class KaminoAction {
|
|
|
615
621
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
616
622
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
617
623
|
requestElevationGroup: boolean = false,
|
|
618
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
619
624
|
referrer: PublicKey = PublicKey.default,
|
|
620
625
|
currentSlot: number = 0,
|
|
621
626
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -651,8 +656,10 @@ export class KaminoAction {
|
|
|
651
656
|
'redeem',
|
|
652
657
|
includeAtaIxns,
|
|
653
658
|
requestElevationGroup,
|
|
654
|
-
|
|
655
|
-
addInitObligationForFarm
|
|
659
|
+
false,
|
|
660
|
+
addInitObligationForFarm,
|
|
661
|
+
false,
|
|
662
|
+
false
|
|
656
663
|
);
|
|
657
664
|
axn.addRedeemReserveCollateralIx();
|
|
658
665
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
@@ -669,6 +676,7 @@ export class KaminoAction {
|
|
|
669
676
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
670
677
|
requestElevationGroup: boolean = false,
|
|
671
678
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
679
|
+
createLookupTable: boolean = true,
|
|
672
680
|
referrer: PublicKey = PublicKey.default,
|
|
673
681
|
currentSlot: number = 0,
|
|
674
682
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -705,7 +713,9 @@ export class KaminoAction {
|
|
|
705
713
|
includeAtaIxns,
|
|
706
714
|
requestElevationGroup,
|
|
707
715
|
includeUserMetadata,
|
|
708
|
-
addInitObligationForFarm
|
|
716
|
+
addInitObligationForFarm,
|
|
717
|
+
false,
|
|
718
|
+
createLookupTable
|
|
709
719
|
);
|
|
710
720
|
axn.addDepositObligationCollateralIx();
|
|
711
721
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
@@ -724,6 +734,7 @@ export class KaminoAction {
|
|
|
724
734
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
725
735
|
requestElevationGroup: boolean = false,
|
|
726
736
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
737
|
+
createLookupTable: boolean = true,
|
|
727
738
|
referrer: PublicKey = PublicKey.default,
|
|
728
739
|
currentSlot: number = 0,
|
|
729
740
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -767,9 +778,11 @@ export class KaminoAction {
|
|
|
767
778
|
requestElevationGroup,
|
|
768
779
|
includeUserMetadata,
|
|
769
780
|
addInitObligationForFarmForDeposit,
|
|
781
|
+
false,
|
|
782
|
+
createLookupTable,
|
|
770
783
|
twoTokenAction
|
|
771
784
|
);
|
|
772
|
-
|
|
785
|
+
axn.addDepositAndBorrowIx();
|
|
773
786
|
await axn.addInBetweenIxs(
|
|
774
787
|
'depositAndBorrow',
|
|
775
788
|
includeAtaIxns,
|
|
@@ -780,6 +793,132 @@ export class KaminoAction {
|
|
|
780
793
|
return axn;
|
|
781
794
|
}
|
|
782
795
|
|
|
796
|
+
static async buildDepositAndWithdrawV2Txns(
|
|
797
|
+
kaminoMarket: KaminoMarket,
|
|
798
|
+
depositAmount: string | BN,
|
|
799
|
+
depositMint: PublicKey,
|
|
800
|
+
withdrawAmount: string | BN,
|
|
801
|
+
withdrawMint: PublicKey,
|
|
802
|
+
payer: PublicKey,
|
|
803
|
+
currentSlot: number,
|
|
804
|
+
obligation: KaminoObligation | ObligationType,
|
|
805
|
+
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
806
|
+
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
807
|
+
requestElevationGroup: boolean = false,
|
|
808
|
+
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
809
|
+
referrer: PublicKey = PublicKey.default,
|
|
810
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
811
|
+
) {
|
|
812
|
+
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
813
|
+
kaminoMarket,
|
|
814
|
+
'depositAndWithdraw',
|
|
815
|
+
depositAmount,
|
|
816
|
+
depositMint,
|
|
817
|
+
withdrawMint,
|
|
818
|
+
payer,
|
|
819
|
+
payer,
|
|
820
|
+
obligation,
|
|
821
|
+
withdrawAmount,
|
|
822
|
+
referrer,
|
|
823
|
+
currentSlot
|
|
824
|
+
);
|
|
825
|
+
const addInitObligationForFarm = true;
|
|
826
|
+
const twoTokenAction = true;
|
|
827
|
+
if (extraComputeBudget > 0) {
|
|
828
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
832
|
+
...axn.depositReserves,
|
|
833
|
+
...axn.borrowReserves,
|
|
834
|
+
axn.reserve.address,
|
|
835
|
+
axn.outflowReserve!.address,
|
|
836
|
+
]).toArray();
|
|
837
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
838
|
+
|
|
839
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
840
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
await axn.addSupportIxs(
|
|
844
|
+
'depositAndWithdraw',
|
|
845
|
+
includeAtaIxns,
|
|
846
|
+
requestElevationGroup,
|
|
847
|
+
includeUserMetadata,
|
|
848
|
+
addInitObligationForFarm,
|
|
849
|
+
true,
|
|
850
|
+
twoTokenAction
|
|
851
|
+
);
|
|
852
|
+
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
|
|
853
|
+
axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
854
|
+
|
|
855
|
+
return axn;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
static async buildRepayAndWithdrawV2Txns(
|
|
859
|
+
kaminoMarket: KaminoMarket,
|
|
860
|
+
repayAmount: string | BN,
|
|
861
|
+
repayMint: PublicKey,
|
|
862
|
+
withdrawAmount: string | BN,
|
|
863
|
+
withdrawMint: PublicKey,
|
|
864
|
+
payer: PublicKey,
|
|
865
|
+
currentSlot: number,
|
|
866
|
+
obligation: KaminoObligation | ObligationType,
|
|
867
|
+
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
868
|
+
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
869
|
+
requestElevationGroup: boolean = false,
|
|
870
|
+
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
871
|
+
createLookupTable: boolean = true,
|
|
872
|
+
referrer: PublicKey = PublicKey.default,
|
|
873
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
874
|
+
) {
|
|
875
|
+
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
876
|
+
kaminoMarket,
|
|
877
|
+
'repayAndWithdrawV2',
|
|
878
|
+
repayAmount,
|
|
879
|
+
repayMint,
|
|
880
|
+
withdrawMint,
|
|
881
|
+
payer,
|
|
882
|
+
payer,
|
|
883
|
+
obligation,
|
|
884
|
+
withdrawAmount,
|
|
885
|
+
referrer,
|
|
886
|
+
currentSlot
|
|
887
|
+
);
|
|
888
|
+
const addInitObligationForFarm = true;
|
|
889
|
+
const twoTokenAction = true;
|
|
890
|
+
if (extraComputeBudget > 0) {
|
|
891
|
+
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
895
|
+
...axn.depositReserves,
|
|
896
|
+
...axn.borrowReserves,
|
|
897
|
+
axn.reserve.address,
|
|
898
|
+
axn.outflowReserve!.address,
|
|
899
|
+
]).toArray();
|
|
900
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
901
|
+
|
|
902
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
903
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
await axn.addSupportIxs(
|
|
907
|
+
'repayAndWithdrawV2',
|
|
908
|
+
includeAtaIxns,
|
|
909
|
+
requestElevationGroup,
|
|
910
|
+
includeUserMetadata,
|
|
911
|
+
addInitObligationForFarm,
|
|
912
|
+
true,
|
|
913
|
+
createLookupTable,
|
|
914
|
+
twoTokenAction
|
|
915
|
+
);
|
|
916
|
+
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
|
|
917
|
+
axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
918
|
+
|
|
919
|
+
return axn;
|
|
920
|
+
}
|
|
921
|
+
|
|
783
922
|
static async buildRepayAndWithdrawTxns(
|
|
784
923
|
kaminoMarket: KaminoMarket,
|
|
785
924
|
repayAmount: string | BN,
|
|
@@ -793,6 +932,7 @@ export class KaminoAction {
|
|
|
793
932
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
794
933
|
requestElevationGroup: boolean = false,
|
|
795
934
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
935
|
+
createLookupTable: boolean = true,
|
|
796
936
|
referrer: PublicKey = PublicKey.default,
|
|
797
937
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
798
938
|
) {
|
|
@@ -834,6 +974,8 @@ export class KaminoAction {
|
|
|
834
974
|
requestElevationGroup,
|
|
835
975
|
includeUserMetadata,
|
|
836
976
|
addInitObligationForFarmForRepay,
|
|
977
|
+
false,
|
|
978
|
+
createLookupTable,
|
|
837
979
|
twoTokenAction
|
|
838
980
|
);
|
|
839
981
|
|
|
@@ -860,6 +1002,7 @@ export class KaminoAction {
|
|
|
860
1002
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
861
1003
|
requestElevationGroup: boolean = false, // to be requested *after* the withdraw
|
|
862
1004
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
1005
|
+
createLookupTable: boolean = true,
|
|
863
1006
|
referrer: PublicKey = PublicKey.default,
|
|
864
1007
|
currentSlot: number = 0,
|
|
865
1008
|
scopeRefresh: ScopeRefresh | undefined = undefined,
|
|
@@ -906,12 +1049,14 @@ export class KaminoAction {
|
|
|
906
1049
|
includeUserMetadata,
|
|
907
1050
|
addInitObligationForFarm,
|
|
908
1051
|
false,
|
|
1052
|
+
createLookupTable,
|
|
1053
|
+
false,
|
|
909
1054
|
overrideElevationGroupRequest
|
|
910
1055
|
);
|
|
911
1056
|
|
|
912
1057
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
913
1058
|
|
|
914
|
-
|
|
1059
|
+
axn.addWithdrawIx(collateralAmount);
|
|
915
1060
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
916
1061
|
|
|
917
1062
|
return axn;
|
|
@@ -944,6 +1089,7 @@ export class KaminoAction {
|
|
|
944
1089
|
includeAtaIxns: boolean = true,
|
|
945
1090
|
requestElevationGroup: boolean = false,
|
|
946
1091
|
includeUserMetadata: boolean = true,
|
|
1092
|
+
createLookupTable: boolean = true,
|
|
947
1093
|
referrer: PublicKey = PublicKey.default,
|
|
948
1094
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
949
1095
|
) {
|
|
@@ -980,9 +1126,11 @@ export class KaminoAction {
|
|
|
980
1126
|
includeAtaIxns,
|
|
981
1127
|
requestElevationGroup,
|
|
982
1128
|
includeUserMetadata,
|
|
983
|
-
addInitObligationForFarm
|
|
1129
|
+
addInitObligationForFarm,
|
|
1130
|
+
false,
|
|
1131
|
+
createLookupTable
|
|
984
1132
|
);
|
|
985
|
-
|
|
1133
|
+
axn.addRepayIx();
|
|
986
1134
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
987
1135
|
|
|
988
1136
|
return axn;
|
|
@@ -1001,6 +1149,7 @@ export class KaminoAction {
|
|
|
1001
1149
|
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
1150
|
requestElevationGroup: boolean = false,
|
|
1003
1151
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
1152
|
+
createLookupTable: boolean = true,
|
|
1004
1153
|
referrer: PublicKey = PublicKey.default,
|
|
1005
1154
|
maxAllowedLtvOverridePercent: number = 0,
|
|
1006
1155
|
currentSlot: number = 0,
|
|
@@ -1042,9 +1191,11 @@ export class KaminoAction {
|
|
|
1042
1191
|
includeAtaIxns,
|
|
1043
1192
|
requestElevationGroup,
|
|
1044
1193
|
includeUserMetadata,
|
|
1045
|
-
addInitObligationForFarm
|
|
1194
|
+
addInitObligationForFarm,
|
|
1195
|
+
false,
|
|
1196
|
+
createLookupTable
|
|
1046
1197
|
);
|
|
1047
|
-
|
|
1198
|
+
axn.addLiquidateIx(maxAllowedLtvOverridePercent);
|
|
1048
1199
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
1049
1200
|
|
|
1050
1201
|
return axn;
|
|
@@ -1308,7 +1459,7 @@ export class KaminoAction {
|
|
|
1308
1459
|
this.lendingIxs.push(borrowIx);
|
|
1309
1460
|
}
|
|
1310
1461
|
|
|
1311
|
-
|
|
1462
|
+
addDepositAndBorrowIx() {
|
|
1312
1463
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
1313
1464
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
1314
1465
|
this.lendingIxs.push(
|
|
@@ -1386,7 +1537,7 @@ export class KaminoAction {
|
|
|
1386
1537
|
this.lendingIxs.push(borrowIx);
|
|
1387
1538
|
}
|
|
1388
1539
|
|
|
1389
|
-
|
|
1540
|
+
addRepayAndWithdrawIxs(withdrawCollateralAmount: BN) {
|
|
1390
1541
|
this.lendingIxsLabels.push(
|
|
1391
1542
|
`repayObligationLiquidity(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
|
|
1392
1543
|
);
|
|
@@ -1456,7 +1607,209 @@ export class KaminoAction {
|
|
|
1456
1607
|
);
|
|
1457
1608
|
}
|
|
1458
1609
|
|
|
1459
|
-
|
|
1610
|
+
addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
|
|
1611
|
+
this.lendingIxsLabels.push(
|
|
1612
|
+
`repayAndWithdrawAndRedeem(repayReserve=${this.reserve!.address})(withdrawReserve=${
|
|
1613
|
+
this.outflowReserve!.address
|
|
1614
|
+
})(obligation=${this.getObligationPda()})`
|
|
1615
|
+
);
|
|
1616
|
+
|
|
1617
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1618
|
+
|
|
1619
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1620
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1621
|
+
});
|
|
1622
|
+
const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
|
|
1623
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1624
|
+
});
|
|
1625
|
+
|
|
1626
|
+
if (!this.outflowAmount) {
|
|
1627
|
+
throw new Error(`outflowAmount not set`);
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
if (!this.outflowReserve) {
|
|
1631
|
+
throw new Error(`outflowReserve not set`);
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1635
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
1639
|
+
? {
|
|
1640
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1641
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1642
|
+
}
|
|
1643
|
+
: {
|
|
1644
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1645
|
+
this.outflowReserve.state.farmCollateral,
|
|
1646
|
+
this.getObligationPda()
|
|
1647
|
+
),
|
|
1648
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1652
|
+
? {
|
|
1653
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1654
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1655
|
+
}
|
|
1656
|
+
: {
|
|
1657
|
+
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
|
|
1658
|
+
reserveFarmState: this.reserve.state.farmDebt,
|
|
1659
|
+
};
|
|
1660
|
+
|
|
1661
|
+
const repayAndWithdrawIx = repayAndWithdrawAndRedeem(
|
|
1662
|
+
{
|
|
1663
|
+
repayAmount: this.amount,
|
|
1664
|
+
withdrawCollateralAmount,
|
|
1665
|
+
},
|
|
1666
|
+
{
|
|
1667
|
+
repayAccounts: {
|
|
1668
|
+
owner: this.owner,
|
|
1669
|
+
obligation: this.getObligationPda(),
|
|
1670
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1671
|
+
repayReserve: this.reserve!.address,
|
|
1672
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1673
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1674
|
+
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1675
|
+
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1676
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1677
|
+
},
|
|
1678
|
+
withdrawAccounts: {
|
|
1679
|
+
owner: this.owner,
|
|
1680
|
+
obligation: this.getObligationPda(),
|
|
1681
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1682
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1683
|
+
withdrawReserve: this.outflowReserve.address,
|
|
1684
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1685
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1686
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1687
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1688
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1689
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1690
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1691
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1692
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1693
|
+
},
|
|
1694
|
+
collateralFarmsAccounts,
|
|
1695
|
+
debtFarmsAccounts,
|
|
1696
|
+
farmsProgram: farmsId,
|
|
1697
|
+
},
|
|
1698
|
+
this.kaminoMarket.programId
|
|
1699
|
+
);
|
|
1700
|
+
|
|
1701
|
+
repayAndWithdrawIx.keys = repayAndWithdrawIx.keys.concat([
|
|
1702
|
+
...depositReserveAccountMetas,
|
|
1703
|
+
...borrowReserveAccountMetas,
|
|
1704
|
+
]);
|
|
1705
|
+
|
|
1706
|
+
this.lendingIxs.push(repayAndWithdrawIx);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
addDepositAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
|
|
1710
|
+
this.lendingIxsLabels.push(
|
|
1711
|
+
`depositAndWithdrawV2(depositReserve=${this.reserve!.address})(withdrawReserve=${
|
|
1712
|
+
this.outflowReserve!.address
|
|
1713
|
+
})(obligation=${this.getObligationPda()})`
|
|
1714
|
+
);
|
|
1715
|
+
|
|
1716
|
+
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1717
|
+
|
|
1718
|
+
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1719
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1720
|
+
});
|
|
1721
|
+
const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
|
|
1722
|
+
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1723
|
+
});
|
|
1724
|
+
|
|
1725
|
+
if (!this.outflowAmount) {
|
|
1726
|
+
throw new Error(`outflowAmount not set`);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
if (!this.outflowReserve) {
|
|
1730
|
+
throw new Error(`outflowReserve not set`);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
if (!this.additionalTokenAccountAddress) {
|
|
1734
|
+
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1738
|
+
? {
|
|
1739
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1740
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1741
|
+
}
|
|
1742
|
+
: {
|
|
1743
|
+
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
|
|
1744
|
+
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1745
|
+
};
|
|
1746
|
+
const withdrawFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
1747
|
+
? {
|
|
1748
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1749
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1750
|
+
}
|
|
1751
|
+
: {
|
|
1752
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1753
|
+
this.outflowReserve.state.farmCollateral,
|
|
1754
|
+
this.getObligationPda()
|
|
1755
|
+
),
|
|
1756
|
+
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
const depositAndWithdrawIx = depositAndWithdraw(
|
|
1760
|
+
{
|
|
1761
|
+
liquidityAmount: this.amount,
|
|
1762
|
+
withdrawCollateralAmount,
|
|
1763
|
+
},
|
|
1764
|
+
{
|
|
1765
|
+
depositAccounts: {
|
|
1766
|
+
owner: this.owner,
|
|
1767
|
+
obligation: this.getObligationPda(),
|
|
1768
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1769
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1770
|
+
reserve: this.reserve.address,
|
|
1771
|
+
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1772
|
+
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1773
|
+
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1774
|
+
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1775
|
+
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1776
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1777
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1778
|
+
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1779
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1780
|
+
},
|
|
1781
|
+
withdrawAccounts: {
|
|
1782
|
+
owner: this.owner,
|
|
1783
|
+
obligation: this.getObligationPda(),
|
|
1784
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1785
|
+
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1786
|
+
withdrawReserve: this.outflowReserve.address,
|
|
1787
|
+
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1788
|
+
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1789
|
+
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1790
|
+
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1791
|
+
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1792
|
+
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1793
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1794
|
+
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1795
|
+
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1796
|
+
},
|
|
1797
|
+
depositFarmsAccounts,
|
|
1798
|
+
withdrawFarmsAccounts,
|
|
1799
|
+
farmsProgram: farmsId,
|
|
1800
|
+
},
|
|
1801
|
+
this.kaminoMarket.programId
|
|
1802
|
+
);
|
|
1803
|
+
|
|
1804
|
+
depositAndWithdrawIx.keys = depositAndWithdrawIx.keys.concat([
|
|
1805
|
+
...depositReserveAccountMetas,
|
|
1806
|
+
...borrowReserveAccountMetas,
|
|
1807
|
+
]);
|
|
1808
|
+
|
|
1809
|
+
this.lendingIxs.push(depositAndWithdrawIx);
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
addWithdrawIx(withdrawCollateralAmount: BN) {
|
|
1460
1813
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
1461
1814
|
this.lendingIxs.push(
|
|
1462
1815
|
withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
@@ -1484,7 +1837,7 @@ export class KaminoAction {
|
|
|
1484
1837
|
);
|
|
1485
1838
|
}
|
|
1486
1839
|
|
|
1487
|
-
|
|
1840
|
+
addRepayIx() {
|
|
1488
1841
|
this.lendingIxsLabels.push(
|
|
1489
1842
|
`repayObligationLiquidity(reserve=${this.reserve.address})(obligation=${this.getObligationPda()})`
|
|
1490
1843
|
);
|
|
@@ -1519,7 +1872,7 @@ export class KaminoAction {
|
|
|
1519
1872
|
this.lendingIxs.push(repayIx);
|
|
1520
1873
|
}
|
|
1521
1874
|
|
|
1522
|
-
|
|
1875
|
+
addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
|
|
1523
1876
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
1524
1877
|
if (!this.outflowReserve) {
|
|
1525
1878
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
@@ -1580,6 +1933,7 @@ export class KaminoAction {
|
|
|
1580
1933
|
await this.addSupportIxsWithoutInitObligation(
|
|
1581
1934
|
action,
|
|
1582
1935
|
includeAtaIxns,
|
|
1936
|
+
false,
|
|
1583
1937
|
'inBetween',
|
|
1584
1938
|
requestElevationGroup,
|
|
1585
1939
|
addInitObligationForFarm
|
|
@@ -1612,6 +1966,7 @@ export class KaminoAction {
|
|
|
1612
1966
|
async addSupportIxsWithoutInitObligation(
|
|
1613
1967
|
action: ActionType,
|
|
1614
1968
|
includeAtaIxns: boolean,
|
|
1969
|
+
useV2Ixs: boolean,
|
|
1615
1970
|
addAsSupportIx: AuxiliaryIx = 'setup',
|
|
1616
1971
|
requestElevationGroup: boolean = false,
|
|
1617
1972
|
addInitObligationForFarm: boolean = false,
|
|
@@ -1633,6 +1988,7 @@ export class KaminoAction {
|
|
|
1633
1988
|
'repay',
|
|
1634
1989
|
'depositAndBorrow',
|
|
1635
1990
|
'repayAndWithdraw',
|
|
1991
|
+
'repayAndWithdrawV2',
|
|
1636
1992
|
'refreshObligation',
|
|
1637
1993
|
].includes(action)
|
|
1638
1994
|
) {
|
|
@@ -1651,12 +2007,17 @@ export class KaminoAction {
|
|
|
1651
2007
|
|
|
1652
2008
|
let currentReserves: KaminoReserve[] = [];
|
|
1653
2009
|
|
|
1654
|
-
if (
|
|
2010
|
+
if (
|
|
2011
|
+
action === 'liquidate' ||
|
|
2012
|
+
action === 'depositAndBorrow' ||
|
|
2013
|
+
action === 'repayAndWithdraw' ||
|
|
2014
|
+
action === 'repayAndWithdrawV2'
|
|
2015
|
+
) {
|
|
1655
2016
|
if (!this.outflowReserve) {
|
|
1656
2017
|
throw new Error('outflowReserve is undefined');
|
|
1657
2018
|
}
|
|
1658
2019
|
|
|
1659
|
-
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
2020
|
+
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
|
|
1660
2021
|
currentReserves = [this.reserve, this.outflowReserve];
|
|
1661
2022
|
if (action === 'depositAndBorrow') {
|
|
1662
2023
|
if (this.obligation) {
|
|
@@ -1701,7 +2062,12 @@ export class KaminoAction {
|
|
|
1701
2062
|
if (this.outflowReserve) {
|
|
1702
2063
|
await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Debt, addAsSupportIx);
|
|
1703
2064
|
}
|
|
1704
|
-
} else if (
|
|
2065
|
+
} else if (
|
|
2066
|
+
action === 'repayAndWithdraw' ||
|
|
2067
|
+
action === 'borrow' ||
|
|
2068
|
+
action === 'repay' ||
|
|
2069
|
+
action === 'repayAndWithdrawV2'
|
|
2070
|
+
) {
|
|
1705
2071
|
// todo - probably don't need to add both debt and collateral for everything here
|
|
1706
2072
|
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
|
|
1707
2073
|
if (this.outflowReserve) {
|
|
@@ -1732,7 +2098,7 @@ export class KaminoAction {
|
|
|
1732
2098
|
}
|
|
1733
2099
|
|
|
1734
2100
|
if (requestElevationGroup) {
|
|
1735
|
-
if (action === 'repay') {
|
|
2101
|
+
if (action === 'repay' || action === 'repayAndWithdrawV2') {
|
|
1736
2102
|
const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
|
|
1737
2103
|
|
|
1738
2104
|
if (!repayObligationLiquidity) {
|
|
@@ -1840,46 +2206,48 @@ export class KaminoAction {
|
|
|
1840
2206
|
}
|
|
1841
2207
|
}
|
|
1842
2208
|
|
|
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);
|
|
2209
|
+
if (!useV2Ixs) {
|
|
2210
|
+
if (addAsSupportIx === 'setup') {
|
|
2211
|
+
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|
|
2212
|
+
// or the first of a two-token-action
|
|
2213
|
+
if (action === 'liquidate') {
|
|
2214
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2215
|
+
this.addRefreshFarmsForReserve([this.reserve], addAsSupportIx, ReserveFarmKind.Debt);
|
|
2216
|
+
} else if (
|
|
2217
|
+
action === 'depositAndBorrow' ||
|
|
2218
|
+
action === 'depositCollateral' ||
|
|
2219
|
+
action === 'withdraw' ||
|
|
2220
|
+
action === 'deposit'
|
|
2221
|
+
) {
|
|
2222
|
+
this.addRefreshFarmsForReserve(
|
|
2223
|
+
currentReserves,
|
|
2224
|
+
addAsSupportIx,
|
|
2225
|
+
ReserveFarmKind.Collateral,
|
|
2226
|
+
undefined,
|
|
2227
|
+
twoTokenAction
|
|
2228
|
+
);
|
|
2229
|
+
} else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
2230
|
+
this.addRefreshFarmsForReserve(
|
|
2231
|
+
currentReserves,
|
|
2232
|
+
addAsSupportIx,
|
|
2233
|
+
ReserveFarmKind.Debt,
|
|
2234
|
+
undefined,
|
|
2235
|
+
twoTokenAction
|
|
2236
|
+
);
|
|
2237
|
+
} else {
|
|
2238
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
2239
|
+
}
|
|
1881
2240
|
} else {
|
|
1882
|
-
|
|
2241
|
+
// If this is an inbetween, it means it's part of a two-token-action
|
|
2242
|
+
// so we skip the refresh farm obligation of the first reserve as that operation already happened
|
|
2243
|
+
// add added to 'setup' ixns
|
|
2244
|
+
if (action === 'depositAndBorrow') {
|
|
2245
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Debt);
|
|
2246
|
+
} else if (action === 'repayAndWithdraw') {
|
|
2247
|
+
this.addRefreshFarmsForReserve([this.outflowReserve!], addAsSupportIx, ReserveFarmKind.Collateral);
|
|
2248
|
+
} else {
|
|
2249
|
+
throw new Error(`Could not decide on refresh farm for action ${action}`);
|
|
2250
|
+
}
|
|
1883
2251
|
}
|
|
1884
2252
|
}
|
|
1885
2253
|
}
|
|
@@ -1891,13 +2259,25 @@ export class KaminoAction {
|
|
|
1891
2259
|
requestElevationGroup: boolean,
|
|
1892
2260
|
includeUserMetadata: boolean,
|
|
1893
2261
|
addInitObligationForFarm: boolean,
|
|
2262
|
+
useV2Ixs: boolean,
|
|
2263
|
+
createLookupTable: boolean,
|
|
1894
2264
|
twoTokenAction: boolean = false,
|
|
1895
2265
|
overrideElevationGroupRequest?: number
|
|
1896
2266
|
) {
|
|
1897
2267
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1898
2268
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1899
2269
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
1900
|
-
|
|
2270
|
+
let lookupTable: PublicKey = PublicKey.default;
|
|
2271
|
+
if (createLookupTable) {
|
|
2272
|
+
const [createLutIx, lookupTableAddress] = await createLookupTableIx(
|
|
2273
|
+
this.kaminoMarket.getConnection(),
|
|
2274
|
+
this.owner
|
|
2275
|
+
);
|
|
2276
|
+
lookupTable = lookupTableAddress;
|
|
2277
|
+
this.setupIxs.push(createLutIx);
|
|
2278
|
+
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
2279
|
+
}
|
|
2280
|
+
this.addInitUserMetadataIxs(lookupTable);
|
|
1901
2281
|
}
|
|
1902
2282
|
|
|
1903
2283
|
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
@@ -1907,12 +2287,13 @@ export class KaminoAction {
|
|
|
1907
2287
|
if (action === 'deposit' && this.outflowReserve) {
|
|
1908
2288
|
await this.addInitReferrerTokenStateIx(this.outflowReserve);
|
|
1909
2289
|
}
|
|
1910
|
-
|
|
2290
|
+
this.addInitObligationIxs();
|
|
1911
2291
|
}
|
|
1912
2292
|
|
|
1913
2293
|
await this.addSupportIxsWithoutInitObligation(
|
|
1914
2294
|
action,
|
|
1915
2295
|
includeAtaIxns,
|
|
2296
|
+
useV2Ixs,
|
|
1916
2297
|
'setup',
|
|
1917
2298
|
requestElevationGroup,
|
|
1918
2299
|
addInitObligationForFarm,
|
|
@@ -2126,13 +2507,6 @@ export class KaminoAction {
|
|
|
2126
2507
|
crank: PublicKey = this.payer,
|
|
2127
2508
|
twoTokenAction: boolean = false
|
|
2128
2509
|
) {
|
|
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
2510
|
const farms: [
|
|
2137
2511
|
typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
|
|
2138
2512
|
PublicKey,
|
|
@@ -2145,7 +2519,7 @@ export class KaminoAction {
|
|
|
2145
2519
|
farms.push([
|
|
2146
2520
|
ReserveFarmKind.Collateral,
|
|
2147
2521
|
kaminoReserve.state.farmCollateral,
|
|
2148
|
-
|
|
2522
|
+
obligationFarmStatePda(kaminoReserve.state.farmCollateral, this.getObligationPda()),
|
|
2149
2523
|
kaminoReserve,
|
|
2150
2524
|
]);
|
|
2151
2525
|
}
|
|
@@ -2153,7 +2527,7 @@ export class KaminoAction {
|
|
|
2153
2527
|
farms.push([
|
|
2154
2528
|
ReserveFarmKind.Debt,
|
|
2155
2529
|
kaminoReserve.state.farmDebt,
|
|
2156
|
-
|
|
2530
|
+
obligationFarmStatePda(kaminoReserve.state.farmDebt, this.getObligationPda()),
|
|
2157
2531
|
kaminoReserve,
|
|
2158
2532
|
]);
|
|
2159
2533
|
}
|
|
@@ -2234,17 +2608,10 @@ export class KaminoAction {
|
|
|
2234
2608
|
mode: typeof ReserveFarmKind.Collateral | typeof ReserveFarmKind.Debt,
|
|
2235
2609
|
addAsSupportIx: AuxiliaryIx = 'setup'
|
|
2236
2610
|
): 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
2611
|
const farms: [number, PublicKey, PublicKey][] = [];
|
|
2245
2612
|
|
|
2246
2613
|
if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
|
|
2247
|
-
const pda =
|
|
2614
|
+
const pda = obligationFarmStatePda(reserve.state.farmCollateral, this.getObligationPda());
|
|
2248
2615
|
const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
|
|
2249
2616
|
if (!account) {
|
|
2250
2617
|
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, pda]);
|
|
@@ -2252,10 +2619,10 @@ export class KaminoAction {
|
|
|
2252
2619
|
}
|
|
2253
2620
|
|
|
2254
2621
|
if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
|
|
2255
|
-
const pda =
|
|
2622
|
+
const pda = obligationFarmStatePda(reserve.state.farmDebt, this.getObligationPda());
|
|
2256
2623
|
const account = await this.kaminoMarket.getConnection().getAccountInfo(pda);
|
|
2257
2624
|
if (!account) {
|
|
2258
|
-
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
2625
|
+
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, pda]);
|
|
2259
2626
|
}
|
|
2260
2627
|
}
|
|
2261
2628
|
|
|
@@ -2289,7 +2656,7 @@ export class KaminoAction {
|
|
|
2289
2656
|
});
|
|
2290
2657
|
}
|
|
2291
2658
|
|
|
2292
|
-
private
|
|
2659
|
+
private addInitObligationIxs() {
|
|
2293
2660
|
if (!this.obligation) {
|
|
2294
2661
|
const obligationPda = this.getObligationPda();
|
|
2295
2662
|
const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
|
|
@@ -2318,10 +2685,7 @@ export class KaminoAction {
|
|
|
2318
2685
|
}
|
|
2319
2686
|
}
|
|
2320
2687
|
|
|
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()}]`);
|
|
2688
|
+
private addInitUserMetadataIxs(lookupTableAddress: PublicKey) {
|
|
2325
2689
|
const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
|
|
2326
2690
|
const referrerUserMetadataAddress = this.referrer.equals(PublicKey.default)
|
|
2327
2691
|
? this.kaminoMarket.programId
|
|
@@ -2401,11 +2765,11 @@ export class KaminoAction {
|
|
|
2401
2765
|
}
|
|
2402
2766
|
|
|
2403
2767
|
private async addAtaIxs(action: ActionType) {
|
|
2404
|
-
if (this.mint.equals(
|
|
2768
|
+
if (this.mint.equals(NATIVE_MINT) || this.secondaryMint?.equals(NATIVE_MINT)) {
|
|
2405
2769
|
await this.updateWSOLAccount(action);
|
|
2406
2770
|
}
|
|
2407
2771
|
|
|
2408
|
-
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(
|
|
2772
|
+
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(NATIVE_MINT)) {
|
|
2409
2773
|
const [, createUserTokenAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
2410
2774
|
this.owner,
|
|
2411
2775
|
this.reserve.getLiquidityMint(),
|
|
@@ -2414,13 +2778,8 @@ export class KaminoAction {
|
|
|
2414
2778
|
this.userTokenAccountAddress
|
|
2415
2779
|
);
|
|
2416
2780
|
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
2420
|
-
} else {
|
|
2421
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2422
|
-
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
2423
|
-
}
|
|
2781
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2782
|
+
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
2424
2783
|
}
|
|
2425
2784
|
|
|
2426
2785
|
if (action === 'liquidate') {
|
|
@@ -2435,13 +2794,9 @@ export class KaminoAction {
|
|
|
2435
2794
|
this.outflowReserve.getLiquidityTokenProgram(),
|
|
2436
2795
|
this.userTokenAccountAddress
|
|
2437
2796
|
);
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
} else {
|
|
2442
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2443
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
2444
|
-
}
|
|
2797
|
+
|
|
2798
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2799
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
2445
2800
|
|
|
2446
2801
|
const [, createUserCollateralAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
2447
2802
|
this.owner,
|
|
@@ -2451,23 +2806,15 @@ export class KaminoAction {
|
|
|
2451
2806
|
this.userCollateralAccountAddress
|
|
2452
2807
|
);
|
|
2453
2808
|
|
|
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
|
-
}
|
|
2809
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
2810
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2461
2811
|
|
|
2462
2812
|
if (!this.additionalTokenAccountAddress) {
|
|
2463
2813
|
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
2464
2814
|
}
|
|
2465
2815
|
}
|
|
2466
2816
|
|
|
2467
|
-
if (
|
|
2468
|
-
action === 'depositAndBorrow' ||
|
|
2469
|
-
(action === 'repayAndWithdraw' && !this.secondaryMint?.equals(WRAPPED_SOL_MINT))
|
|
2470
|
-
) {
|
|
2817
|
+
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(NATIVE_MINT))) {
|
|
2471
2818
|
if (!this.additionalTokenAccountAddress) {
|
|
2472
2819
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
2473
2820
|
}
|
|
@@ -2515,13 +2862,8 @@ export class KaminoAction {
|
|
|
2515
2862
|
this.userCollateralAccountAddress
|
|
2516
2863
|
);
|
|
2517
2864
|
|
|
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
|
-
}
|
|
2865
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
2866
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
2525
2867
|
}
|
|
2526
2868
|
}
|
|
2527
2869
|
|
|
@@ -2537,7 +2879,7 @@ export class KaminoAction {
|
|
|
2537
2879
|
|
|
2538
2880
|
let safeRepay = new BN(this.amount);
|
|
2539
2881
|
|
|
2540
|
-
if (this.obligation && action === 'repay' && this.amount.eq(new BN(U64_MAX))) {
|
|
2882
|
+
if (this.obligation && (action === 'repay' || action === 'repayAndWithdrawV2') && this.amount.eq(new BN(U64_MAX))) {
|
|
2541
2883
|
const borrow = this.obligation.state.borrows.find(
|
|
2542
2884
|
(borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
|
|
2543
2885
|
);
|
|
@@ -2551,7 +2893,7 @@ export class KaminoAction {
|
|
|
2551
2893
|
this.currentSlot,
|
|
2552
2894
|
this.kaminoMarket.state.referralFeeBps
|
|
2553
2895
|
);
|
|
2554
|
-
|
|
2896
|
+
|
|
2555
2897
|
safeRepay = new BN(
|
|
2556
2898
|
Math.floor(
|
|
2557
2899
|
KaminoObligation.getBorrowAmount(borrow)
|
|
@@ -2564,7 +2906,7 @@ export class KaminoAction {
|
|
|
2564
2906
|
}
|
|
2565
2907
|
|
|
2566
2908
|
let userTokenAccountAddress = this.userTokenAccountAddress;
|
|
2567
|
-
if (this.secondaryMint?.equals(
|
|
2909
|
+
if (this.secondaryMint?.equals(NATIVE_MINT)) {
|
|
2568
2910
|
if (!this.additionalTokenAccountAddress) {
|
|
2569
2911
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
2570
2912
|
}
|
|
@@ -2579,8 +2921,9 @@ export class KaminoAction {
|
|
|
2579
2921
|
const sendAction =
|
|
2580
2922
|
action === 'deposit' ||
|
|
2581
2923
|
action === 'repay' ||
|
|
2924
|
+
action === 'repayAndWithdrawV2' ||
|
|
2582
2925
|
action === 'mint' ||
|
|
2583
|
-
(action === 'liquidate' && this.secondaryMint?.equals(
|
|
2926
|
+
(action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
2584
2927
|
|
|
2585
2928
|
const transferLamportsIx = SystemProgram.transfer({
|
|
2586
2929
|
fromPubkey: this.owner,
|
|
@@ -2623,14 +2966,6 @@ export class KaminoAction {
|
|
|
2623
2966
|
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
2624
2967
|
}
|
|
2625
2968
|
|
|
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
2969
|
this.setupIxs.unshift(...preIxs);
|
|
2635
2970
|
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
2636
2971
|
this.cleanupIxs.push(...postIxs);
|
|
@@ -2696,7 +3031,7 @@ export class KaminoAction {
|
|
|
2696
3031
|
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
2697
3032
|
primaryMint = inflowTokenMint;
|
|
2698
3033
|
secondaryMint = outflowTokenMint;
|
|
2699
|
-
} else if (action === 'repayAndWithdraw') {
|
|
3034
|
+
} else if (action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
|
|
2700
3035
|
primaryMint = inflowTokenMint;
|
|
2701
3036
|
secondaryMint = outflowTokenMint;
|
|
2702
3037
|
userTokenAccountAddress = userInflowTokenAccountAddress;
|