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