@kamino-finance/klend-sdk 5.11.5-beta.0 → 5.11.6-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 +25 -35
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +225 -350
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +0 -1
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +0 -1
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/lut_utils.d.ts +29 -0
- package/dist/classes/lut_utils.d.ts.map +1 -0
- package/dist/classes/lut_utils.js +62 -0
- package/dist/classes/lut_utils.js.map +1 -0
- package/dist/classes/manager.d.ts +1 -6
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +1 -17
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +3 -3
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +16 -30
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -3
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +1 -6
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/vault.d.ts +0 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +22 -25
- package/dist/classes/vault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -6
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +7 -13
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -25
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js +1 -43
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +0 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +0 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +0 -13
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +1 -25
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.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 +5 -9
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -9
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +8 -35
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +2 -2
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +6 -11
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +7 -9
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +66 -78
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -4
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/ObligationType.d.ts +1 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +1 -2
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/lookupTable.d.ts +0 -27
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +0 -58
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +52 -7
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +3 -3
- package/dist/utils/oracle.d.ts.map +1 -1
- package/dist/utils/oracle.js +3 -4
- package/dist/utils/oracle.js.map +1 -1
- package/dist/utils/seeds.d.ts +1 -11
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +3 -13
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +7 -8
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +2 -2
- package/src/classes/action.ts +261 -504
- package/src/classes/index.ts +0 -1
- package/src/classes/lut_utils.ts +63 -0
- package/src/classes/manager.ts +1 -30
- package/src/classes/market.ts +25 -34
- package/src/classes/obligation.ts +1 -7
- package/src/classes/vault.ts +23 -24
- package/src/client.ts +3 -8
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +9 -17
- package/src/idl_codegen_kamino_vault/errors/custom.ts +0 -42
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +0 -2
- package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +0 -30
- package/src/idl_codegen_kamino_vault/types/index.ts +0 -2
- package/src/idl_kamino_vault.json +8 -35
- package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
- package/src/lending_operations/repay_with_collateral_operations.ts +29 -76
- package/src/lending_operations/swap_collateral_operations.ts +7 -19
- package/src/leverage/operations.ts +66 -114
- package/src/leverage/types.ts +4 -4
- package/src/utils/ObligationType.ts +1 -1
- package/src/utils/constants.ts +0 -1
- package/src/utils/lookupTable.ts +0 -62
- package/src/utils/managerTypes.ts +52 -10
- package/src/utils/oracle.ts +6 -7
- package/src/utils/seeds.ts +4 -14
- package/src/utils/userMetadata.ts +15 -16
package/src/classes/action.ts
CHANGED
|
@@ -21,7 +21,6 @@ import BN from 'bn.js';
|
|
|
21
21
|
import Decimal from 'decimal.js';
|
|
22
22
|
import {
|
|
23
23
|
borrowObligationLiquidity,
|
|
24
|
-
depositAndWithdraw,
|
|
25
24
|
borrowObligationLiquidityV2,
|
|
26
25
|
depositObligationCollateral,
|
|
27
26
|
depositObligationCollateralV2,
|
|
@@ -42,7 +41,6 @@ import {
|
|
|
42
41
|
RefreshObligationFarmsForReserveAccounts,
|
|
43
42
|
RefreshObligationFarmsForReserveArgs,
|
|
44
43
|
refreshReserve,
|
|
45
|
-
repayAndWithdrawAndRedeem,
|
|
46
44
|
repayObligationLiquidity,
|
|
47
45
|
repayObligationLiquidityV2,
|
|
48
46
|
requestElevationGroup,
|
|
@@ -63,11 +61,11 @@ import {
|
|
|
63
61
|
isNotNullPubkey,
|
|
64
62
|
PublicKeySet,
|
|
65
63
|
getAssociatedTokenAddress,
|
|
66
|
-
|
|
64
|
+
ScopeRefresh,
|
|
67
65
|
createAtasIdempotent,
|
|
68
66
|
obligationFarmStatePda,
|
|
69
67
|
} from '../utils';
|
|
70
|
-
import {
|
|
68
|
+
import { KaminoMarket } from './market';
|
|
71
69
|
import { KaminoObligation } from './obligation';
|
|
72
70
|
import { KaminoReserve } from './reserve';
|
|
73
71
|
import { ReserveFarmKind } from '../idl_codegen/types';
|
|
@@ -75,7 +73,7 @@ import { farmsId } from '@kamino-finance/farms-sdk';
|
|
|
75
73
|
import { Reserve } from '../idl_codegen/accounts';
|
|
76
74
|
import { VanillaObligation } from '../utils/ObligationType';
|
|
77
75
|
import { PROGRAM_ID } from '../lib';
|
|
78
|
-
import {
|
|
76
|
+
import { U16_MAX } from '@kamino-finance/scope-sdk';
|
|
79
77
|
|
|
80
78
|
const SOL_PADDING_FOR_INTEREST = new BN('1000000');
|
|
81
79
|
|
|
@@ -92,9 +90,7 @@ export type ActionType =
|
|
|
92
90
|
| 'repayAndWithdraw'
|
|
93
91
|
| 'refreshObligation'
|
|
94
92
|
| 'requestElevationGroup'
|
|
95
|
-
| 'withdrawReferrerFees'
|
|
96
|
-
| 'repayAndWithdrawV2'
|
|
97
|
-
| 'depositAndWithdraw';
|
|
93
|
+
| 'withdrawReferrerFees';
|
|
98
94
|
|
|
99
95
|
export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
|
|
100
96
|
|
|
@@ -415,7 +411,6 @@ export class KaminoAction {
|
|
|
415
411
|
owner: PublicKey,
|
|
416
412
|
obligation: KaminoObligation | ObligationType,
|
|
417
413
|
useV2Ixs: boolean,
|
|
418
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
419
414
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
420
415
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
421
416
|
requestElevationGroup: boolean = false, // to be requested *before* the deposit
|
|
@@ -423,6 +418,7 @@ export class KaminoAction {
|
|
|
423
418
|
createLookupTable: boolean = true,
|
|
424
419
|
referrer: PublicKey = PublicKey.default,
|
|
425
420
|
currentSlot: number = 0,
|
|
421
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
426
422
|
overrideElevationGroupRequest: number | undefined = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
427
423
|
) {
|
|
428
424
|
const axn = await KaminoAction.initialize(
|
|
@@ -441,6 +437,16 @@ export class KaminoAction {
|
|
|
441
437
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
442
438
|
}
|
|
443
439
|
|
|
440
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
441
|
+
...axn.depositReserves,
|
|
442
|
+
...axn.borrowReserves,
|
|
443
|
+
axn.reserve.address,
|
|
444
|
+
]).toArray();
|
|
445
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
446
|
+
|
|
447
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
448
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
449
|
+
}
|
|
444
450
|
await axn.addSupportIxs(
|
|
445
451
|
'deposit',
|
|
446
452
|
includeAtaIxns,
|
|
@@ -448,7 +454,6 @@ export class KaminoAction {
|
|
|
448
454
|
includeUserMetadata,
|
|
449
455
|
addInitObligationForFarm,
|
|
450
456
|
useV2Ixs,
|
|
451
|
-
scopeRefreshConfig,
|
|
452
457
|
createLookupTable,
|
|
453
458
|
undefined,
|
|
454
459
|
overrideElevationGroupRequest
|
|
@@ -463,10 +468,36 @@ export class KaminoAction {
|
|
|
463
468
|
return axn;
|
|
464
469
|
}
|
|
465
470
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
471
|
+
getTokenIdsForScopeRefresh(kaminoMarket: KaminoMarket, reserves: PublicKey[]): number[] {
|
|
472
|
+
const tokenIds: number[] = [];
|
|
473
|
+
|
|
474
|
+
for (const reserveAddress of reserves) {
|
|
475
|
+
const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
|
|
476
|
+
if (!reserve) {
|
|
477
|
+
throw new Error(`Reserve not found for reserve ${reserveAddress.toBase58()}`);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (!reserve.state.config.tokenInfo.scopeConfiguration.priceFeed.equals(PublicKey.default)) {
|
|
481
|
+
reserve.state.config.tokenInfo.scopeConfiguration.priceChain.map((x) => {
|
|
482
|
+
if (x !== U16_MAX) {
|
|
483
|
+
tokenIds.push(x);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
reserve.state.config.tokenInfo.scopeConfiguration.twapChain.map((x) => {
|
|
487
|
+
if (x !== U16_MAX) {
|
|
488
|
+
tokenIds.push(x);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return tokenIds;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
async addScopeRefreshIxs(tokens: number[], feed: string = 'hubble') {
|
|
498
|
+
this.preTxnIxsLabels.unshift(`refreshScopePrices`);
|
|
499
|
+
this.preTxnIxs.unshift(
|
|
500
|
+
await this.kaminoMarket.scope.refreshPriceListIx(
|
|
470
501
|
{
|
|
471
502
|
feed: feed,
|
|
472
503
|
},
|
|
@@ -482,7 +513,6 @@ export class KaminoAction {
|
|
|
482
513
|
owner: PublicKey,
|
|
483
514
|
obligation: KaminoObligation | ObligationType,
|
|
484
515
|
useV2Ixs: boolean,
|
|
485
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
486
516
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
487
517
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
488
518
|
requestElevationGroup: boolean = false,
|
|
@@ -490,6 +520,7 @@ export class KaminoAction {
|
|
|
490
520
|
createLookupTable: boolean = true,
|
|
491
521
|
referrer: PublicKey = PublicKey.default,
|
|
492
522
|
currentSlot: number = 0,
|
|
523
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
493
524
|
overrideElevationGroupRequest: number | undefined = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
494
525
|
) {
|
|
495
526
|
const axn = await KaminoAction.initialize(
|
|
@@ -507,16 +538,15 @@ export class KaminoAction {
|
|
|
507
538
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
508
539
|
}
|
|
509
540
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
541
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
542
|
+
...axn.depositReserves,
|
|
543
|
+
...axn.borrowReserves,
|
|
544
|
+
axn.reserve.address,
|
|
545
|
+
]).toArray();
|
|
546
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
547
|
+
|
|
548
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
549
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
520
550
|
}
|
|
521
551
|
|
|
522
552
|
await axn.addSupportIxs(
|
|
@@ -526,7 +556,6 @@ export class KaminoAction {
|
|
|
526
556
|
includeUserMetadata,
|
|
527
557
|
addInitObligationForFarm,
|
|
528
558
|
useV2Ixs,
|
|
529
|
-
scopeRefreshConfig,
|
|
530
559
|
createLookupTable,
|
|
531
560
|
undefined,
|
|
532
561
|
overrideElevationGroupRequest
|
|
@@ -547,12 +576,12 @@ export class KaminoAction {
|
|
|
547
576
|
mint: PublicKey,
|
|
548
577
|
owner: PublicKey,
|
|
549
578
|
obligation: KaminoObligation | ObligationType,
|
|
550
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
551
579
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
552
580
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
553
581
|
requestElevationGroup: boolean = false,
|
|
554
582
|
referrer: PublicKey = PublicKey.default,
|
|
555
|
-
currentSlot: number = 0
|
|
583
|
+
currentSlot: number = 0,
|
|
584
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
556
585
|
) {
|
|
557
586
|
const axn = await KaminoAction.initialize(
|
|
558
587
|
'mint',
|
|
@@ -570,6 +599,17 @@ export class KaminoAction {
|
|
|
570
599
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
571
600
|
}
|
|
572
601
|
|
|
602
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
603
|
+
...axn.depositReserves,
|
|
604
|
+
...axn.borrowReserves,
|
|
605
|
+
axn.reserve.address,
|
|
606
|
+
]).toArray();
|
|
607
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
608
|
+
|
|
609
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
610
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
611
|
+
}
|
|
612
|
+
|
|
573
613
|
await axn.addSupportIxs(
|
|
574
614
|
'mint',
|
|
575
615
|
includeAtaIxns,
|
|
@@ -577,7 +617,6 @@ export class KaminoAction {
|
|
|
577
617
|
false,
|
|
578
618
|
addInitObligationForFarm,
|
|
579
619
|
false,
|
|
580
|
-
scopeRefreshConfig,
|
|
581
620
|
false
|
|
582
621
|
);
|
|
583
622
|
axn.addDepositReserveLiquidityIx();
|
|
@@ -591,12 +630,12 @@ export class KaminoAction {
|
|
|
591
630
|
mint: PublicKey,
|
|
592
631
|
owner: PublicKey,
|
|
593
632
|
obligation: KaminoObligation | ObligationType,
|
|
594
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
595
633
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
596
634
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
597
635
|
requestElevationGroup: boolean = false,
|
|
598
636
|
referrer: PublicKey = PublicKey.default,
|
|
599
|
-
currentSlot: number = 0
|
|
637
|
+
currentSlot: number = 0,
|
|
638
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
600
639
|
) {
|
|
601
640
|
const axn = await KaminoAction.initialize(
|
|
602
641
|
'redeem',
|
|
@@ -614,6 +653,17 @@ export class KaminoAction {
|
|
|
614
653
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
615
654
|
}
|
|
616
655
|
|
|
656
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
657
|
+
...axn.depositReserves,
|
|
658
|
+
...axn.borrowReserves,
|
|
659
|
+
axn.reserve.address,
|
|
660
|
+
]).toArray();
|
|
661
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
662
|
+
|
|
663
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
664
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
665
|
+
}
|
|
666
|
+
|
|
617
667
|
await axn.addSupportIxs(
|
|
618
668
|
'redeem',
|
|
619
669
|
includeAtaIxns,
|
|
@@ -621,7 +671,6 @@ export class KaminoAction {
|
|
|
621
671
|
false,
|
|
622
672
|
addInitObligationForFarm,
|
|
623
673
|
false,
|
|
624
|
-
scopeRefreshConfig,
|
|
625
674
|
false
|
|
626
675
|
);
|
|
627
676
|
axn.addRedeemReserveCollateralIx();
|
|
@@ -636,14 +685,14 @@ export class KaminoAction {
|
|
|
636
685
|
owner: PublicKey,
|
|
637
686
|
obligation: KaminoObligation | ObligationType,
|
|
638
687
|
useV2Ixs: boolean,
|
|
639
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
640
688
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
641
689
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
642
690
|
requestElevationGroup: boolean = false,
|
|
643
691
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
644
692
|
createLookupTable: boolean = true,
|
|
645
693
|
referrer: PublicKey = PublicKey.default,
|
|
646
|
-
currentSlot: number = 0
|
|
694
|
+
currentSlot: number = 0,
|
|
695
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
647
696
|
) {
|
|
648
697
|
const axn = await KaminoAction.initialize(
|
|
649
698
|
'depositCollateral',
|
|
@@ -661,6 +710,17 @@ export class KaminoAction {
|
|
|
661
710
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
662
711
|
}
|
|
663
712
|
|
|
713
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
714
|
+
...axn.depositReserves,
|
|
715
|
+
...axn.borrowReserves,
|
|
716
|
+
axn.reserve.address,
|
|
717
|
+
]).toArray();
|
|
718
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
719
|
+
|
|
720
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
721
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
722
|
+
}
|
|
723
|
+
|
|
664
724
|
await axn.addSupportIxs(
|
|
665
725
|
'depositCollateral',
|
|
666
726
|
includeAtaIxns,
|
|
@@ -668,7 +728,6 @@ export class KaminoAction {
|
|
|
668
728
|
includeUserMetadata,
|
|
669
729
|
addInitObligationForFarm,
|
|
670
730
|
useV2Ixs,
|
|
671
|
-
scopeRefreshConfig,
|
|
672
731
|
createLookupTable
|
|
673
732
|
);
|
|
674
733
|
if (useV2Ixs) {
|
|
@@ -689,14 +748,14 @@ export class KaminoAction {
|
|
|
689
748
|
payer: PublicKey,
|
|
690
749
|
obligation: KaminoObligation | ObligationType,
|
|
691
750
|
useV2Ixs: boolean,
|
|
692
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
693
751
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
694
752
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
695
753
|
requestElevationGroup: boolean = false,
|
|
696
754
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
697
755
|
createLookupTable: boolean = true,
|
|
698
756
|
referrer: PublicKey = PublicKey.default,
|
|
699
|
-
currentSlot: number = 0
|
|
757
|
+
currentSlot: number = 0,
|
|
758
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
700
759
|
) {
|
|
701
760
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
702
761
|
kaminoMarket,
|
|
@@ -719,17 +778,18 @@ export class KaminoAction {
|
|
|
719
778
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
720
779
|
}
|
|
721
780
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
781
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
782
|
+
...axn.depositReserves,
|
|
783
|
+
...axn.borrowReserves,
|
|
784
|
+
axn.reserve.address,
|
|
785
|
+
axn.outflowReserve!.address,
|
|
786
|
+
]).toArray();
|
|
787
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
788
|
+
|
|
789
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
790
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
732
791
|
}
|
|
792
|
+
|
|
733
793
|
await axn.addSupportIxs(
|
|
734
794
|
'deposit',
|
|
735
795
|
includeAtaIxns,
|
|
@@ -737,7 +797,6 @@ export class KaminoAction {
|
|
|
737
797
|
includeUserMetadata,
|
|
738
798
|
addInitObligationForFarmForDeposit,
|
|
739
799
|
useV2Ixs,
|
|
740
|
-
undefined,
|
|
741
800
|
createLookupTable,
|
|
742
801
|
twoTokenAction
|
|
743
802
|
);
|
|
@@ -755,126 +814,6 @@ export class KaminoAction {
|
|
|
755
814
|
useV2Ixs
|
|
756
815
|
);
|
|
757
816
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
758
|
-
|
|
759
|
-
// Create the scope refresh ixn in here to ensure it's the first ixn in the txn
|
|
760
|
-
const allReserves = new PublicKeySet<PublicKey>([
|
|
761
|
-
...axn.depositReserves,
|
|
762
|
-
...axn.borrowReserves,
|
|
763
|
-
axn.reserve.address,
|
|
764
|
-
...(axn.outflowReserve ? [axn.outflowReserve.address] : []),
|
|
765
|
-
...(axn.preLoadedDepositReservesSameTx ? axn.preLoadedDepositReservesSameTx : []),
|
|
766
|
-
]).toArray();
|
|
767
|
-
const tokenIds = getTokenIdsForScopeRefresh(axn.kaminoMarket, allReserves);
|
|
768
|
-
|
|
769
|
-
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
770
|
-
await axn.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
771
|
-
}
|
|
772
|
-
return axn;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
static async buildDepositAndWithdrawV2Txns(
|
|
776
|
-
kaminoMarket: KaminoMarket,
|
|
777
|
-
depositAmount: string | BN,
|
|
778
|
-
depositMint: PublicKey,
|
|
779
|
-
withdrawAmount: string | BN,
|
|
780
|
-
withdrawMint: PublicKey,
|
|
781
|
-
payer: PublicKey,
|
|
782
|
-
currentSlot: number,
|
|
783
|
-
obligation: KaminoObligation | ObligationType,
|
|
784
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
785
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
786
|
-
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
787
|
-
requestElevationGroup: boolean = false,
|
|
788
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
789
|
-
createLookupTable: boolean = true,
|
|
790
|
-
referrer: PublicKey = PublicKey.default
|
|
791
|
-
) {
|
|
792
|
-
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
793
|
-
kaminoMarket,
|
|
794
|
-
'depositAndWithdraw',
|
|
795
|
-
depositAmount,
|
|
796
|
-
depositMint,
|
|
797
|
-
withdrawMint,
|
|
798
|
-
payer,
|
|
799
|
-
payer,
|
|
800
|
-
obligation,
|
|
801
|
-
withdrawAmount,
|
|
802
|
-
referrer,
|
|
803
|
-
currentSlot
|
|
804
|
-
);
|
|
805
|
-
const addInitObligationForFarm = true;
|
|
806
|
-
const twoTokenAction = true;
|
|
807
|
-
if (extraComputeBudget > 0) {
|
|
808
|
-
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
await axn.addSupportIxs(
|
|
812
|
-
'depositAndWithdraw',
|
|
813
|
-
includeAtaIxns,
|
|
814
|
-
requestElevationGroup,
|
|
815
|
-
includeUserMetadata,
|
|
816
|
-
addInitObligationForFarm,
|
|
817
|
-
true,
|
|
818
|
-
scopeRefreshConfig,
|
|
819
|
-
createLookupTable,
|
|
820
|
-
twoTokenAction
|
|
821
|
-
);
|
|
822
|
-
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
|
|
823
|
-
axn.addDepositAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
824
|
-
|
|
825
|
-
return axn;
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
static async buildRepayAndWithdrawV2Txns(
|
|
829
|
-
kaminoMarket: KaminoMarket,
|
|
830
|
-
repayAmount: string | BN,
|
|
831
|
-
repayMint: PublicKey,
|
|
832
|
-
withdrawAmount: string | BN,
|
|
833
|
-
withdrawMint: PublicKey,
|
|
834
|
-
payer: PublicKey,
|
|
835
|
-
currentSlot: number,
|
|
836
|
-
obligation: KaminoObligation | ObligationType,
|
|
837
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
838
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
839
|
-
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
840
|
-
requestElevationGroup: boolean = false,
|
|
841
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
842
|
-
createLookupTable: boolean = true,
|
|
843
|
-
referrer: PublicKey = PublicKey.default
|
|
844
|
-
) {
|
|
845
|
-
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
846
|
-
kaminoMarket,
|
|
847
|
-
'repayAndWithdrawV2',
|
|
848
|
-
repayAmount,
|
|
849
|
-
repayMint,
|
|
850
|
-
withdrawMint,
|
|
851
|
-
payer,
|
|
852
|
-
payer,
|
|
853
|
-
obligation,
|
|
854
|
-
withdrawAmount,
|
|
855
|
-
referrer,
|
|
856
|
-
currentSlot
|
|
857
|
-
);
|
|
858
|
-
const addInitObligationForFarm = true;
|
|
859
|
-
const twoTokenAction = true;
|
|
860
|
-
if (extraComputeBudget > 0) {
|
|
861
|
-
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
await axn.addSupportIxs(
|
|
865
|
-
'repayAndWithdrawV2',
|
|
866
|
-
includeAtaIxns,
|
|
867
|
-
requestElevationGroup,
|
|
868
|
-
includeUserMetadata,
|
|
869
|
-
addInitObligationForFarm,
|
|
870
|
-
true,
|
|
871
|
-
scopeRefreshConfig,
|
|
872
|
-
createLookupTable,
|
|
873
|
-
twoTokenAction
|
|
874
|
-
);
|
|
875
|
-
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
|
|
876
|
-
axn.addRepayAndWithdrawV2Ixs(withdrawCollateralAmount);
|
|
877
|
-
|
|
878
817
|
return axn;
|
|
879
818
|
}
|
|
880
819
|
|
|
@@ -888,13 +827,13 @@ export class KaminoAction {
|
|
|
888
827
|
currentSlot: number,
|
|
889
828
|
obligation: KaminoObligation | ObligationType,
|
|
890
829
|
useV2Ixs: boolean,
|
|
891
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
892
830
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
893
831
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
894
832
|
requestElevationGroup: boolean = false,
|
|
895
833
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
896
834
|
createLookupTable: boolean = true,
|
|
897
|
-
referrer: PublicKey = PublicKey.default
|
|
835
|
+
referrer: PublicKey = PublicKey.default,
|
|
836
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
898
837
|
) {
|
|
899
838
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
900
839
|
kaminoMarket,
|
|
@@ -916,6 +855,18 @@ export class KaminoAction {
|
|
|
916
855
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
917
856
|
}
|
|
918
857
|
|
|
858
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
859
|
+
...axn.depositReserves,
|
|
860
|
+
...axn.borrowReserves,
|
|
861
|
+
axn.reserve.address,
|
|
862
|
+
axn.outflowReserve!.address,
|
|
863
|
+
]).toArray();
|
|
864
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
865
|
+
|
|
866
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
867
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
868
|
+
}
|
|
869
|
+
|
|
919
870
|
await axn.addSupportIxs(
|
|
920
871
|
'repay',
|
|
921
872
|
includeAtaIxns,
|
|
@@ -923,7 +874,6 @@ export class KaminoAction {
|
|
|
923
874
|
includeUserMetadata,
|
|
924
875
|
addInitObligationForFarmForRepay,
|
|
925
876
|
useV2Ixs,
|
|
926
|
-
undefined,
|
|
927
877
|
createLookupTable,
|
|
928
878
|
twoTokenAction
|
|
929
879
|
);
|
|
@@ -943,19 +893,6 @@ export class KaminoAction {
|
|
|
943
893
|
useV2Ixs
|
|
944
894
|
);
|
|
945
895
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
946
|
-
// Create the scope refresh ixn in here to ensure it's the first ixn in the txn
|
|
947
|
-
const allReserves = new PublicKeySet<PublicKey>([
|
|
948
|
-
...axn.depositReserves,
|
|
949
|
-
...axn.borrowReserves,
|
|
950
|
-
axn.reserve.address,
|
|
951
|
-
...(axn.outflowReserve ? [axn.outflowReserve.address] : []),
|
|
952
|
-
...(axn.preLoadedDepositReservesSameTx ? axn.preLoadedDepositReservesSameTx : []),
|
|
953
|
-
]).toArray();
|
|
954
|
-
const tokenIds = getTokenIdsForScopeRefresh(axn.kaminoMarket, allReserves);
|
|
955
|
-
|
|
956
|
-
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
957
|
-
await axn.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
958
|
-
}
|
|
959
896
|
return axn;
|
|
960
897
|
}
|
|
961
898
|
|
|
@@ -966,7 +903,6 @@ export class KaminoAction {
|
|
|
966
903
|
owner: PublicKey,
|
|
967
904
|
obligation: KaminoObligation | ObligationType,
|
|
968
905
|
useV2Ixs: boolean,
|
|
969
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
970
906
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
971
907
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
972
908
|
requestElevationGroup: boolean = false, // to be requested *after* the withdraw
|
|
@@ -974,6 +910,7 @@ export class KaminoAction {
|
|
|
974
910
|
createLookupTable: boolean = true,
|
|
975
911
|
referrer: PublicKey = PublicKey.default,
|
|
976
912
|
currentSlot: number = 0,
|
|
913
|
+
scopeRefresh: ScopeRefresh | undefined = undefined,
|
|
977
914
|
overrideElevationGroupRequest?: number,
|
|
978
915
|
// Optional customizations which may be needed if the obligation was mutated by some previous ixn.
|
|
979
916
|
obligationCustomizations?: {
|
|
@@ -999,6 +936,17 @@ export class KaminoAction {
|
|
|
999
936
|
|
|
1000
937
|
axn.depositReserves.push(...(obligationCustomizations?.addedDepositReserves || []));
|
|
1001
938
|
|
|
939
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
940
|
+
...axn.depositReserves,
|
|
941
|
+
...axn.borrowReserves,
|
|
942
|
+
axn.reserve.address,
|
|
943
|
+
]).toArray();
|
|
944
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
945
|
+
|
|
946
|
+
if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
|
|
947
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
948
|
+
}
|
|
949
|
+
|
|
1002
950
|
await axn.addSupportIxs(
|
|
1003
951
|
'withdraw',
|
|
1004
952
|
includeAtaIxns,
|
|
@@ -1006,7 +954,6 @@ export class KaminoAction {
|
|
|
1006
954
|
includeUserMetadata,
|
|
1007
955
|
addInitObligationForFarm,
|
|
1008
956
|
useV2Ixs,
|
|
1009
|
-
scopeRefreshConfig,
|
|
1010
957
|
createLookupTable,
|
|
1011
958
|
false,
|
|
1012
959
|
overrideElevationGroupRequest
|
|
@@ -1046,7 +993,6 @@ export class KaminoAction {
|
|
|
1046
993
|
owner: PublicKey,
|
|
1047
994
|
obligation: KaminoObligation | ObligationType,
|
|
1048
995
|
useV2Ixs: boolean,
|
|
1049
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1050
996
|
currentSlot: number,
|
|
1051
997
|
payer: PublicKey | undefined = undefined,
|
|
1052
998
|
extraComputeBudget: number = 1_000_000,
|
|
@@ -1054,7 +1000,8 @@ export class KaminoAction {
|
|
|
1054
1000
|
requestElevationGroup: boolean = false,
|
|
1055
1001
|
includeUserMetadata: boolean = true,
|
|
1056
1002
|
createLookupTable: boolean = true,
|
|
1057
|
-
referrer: PublicKey = PublicKey.default
|
|
1003
|
+
referrer: PublicKey = PublicKey.default,
|
|
1004
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
1058
1005
|
) {
|
|
1059
1006
|
const axn = await KaminoAction.initialize(
|
|
1060
1007
|
'repay',
|
|
@@ -1073,6 +1020,17 @@ export class KaminoAction {
|
|
|
1073
1020
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
1074
1021
|
}
|
|
1075
1022
|
|
|
1023
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
1024
|
+
...axn.depositReserves,
|
|
1025
|
+
...axn.borrowReserves,
|
|
1026
|
+
axn.reserve.address,
|
|
1027
|
+
]).toArray();
|
|
1028
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
1029
|
+
|
|
1030
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
1031
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1076
1034
|
await axn.addSupportIxs(
|
|
1077
1035
|
'repay',
|
|
1078
1036
|
includeAtaIxns,
|
|
@@ -1080,7 +1038,6 @@ export class KaminoAction {
|
|
|
1080
1038
|
includeUserMetadata,
|
|
1081
1039
|
addInitObligationForFarm,
|
|
1082
1040
|
useV2Ixs,
|
|
1083
|
-
scopeRefreshConfig,
|
|
1084
1041
|
createLookupTable
|
|
1085
1042
|
);
|
|
1086
1043
|
if (useV2Ixs) {
|
|
@@ -1103,7 +1060,6 @@ export class KaminoAction {
|
|
|
1103
1060
|
obligationOwner: PublicKey,
|
|
1104
1061
|
obligation: KaminoObligation | ObligationType,
|
|
1105
1062
|
useV2Ixs: boolean,
|
|
1106
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1107
1063
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
1108
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
|
|
1109
1065
|
requestElevationGroup: boolean = false,
|
|
@@ -1111,7 +1067,8 @@ export class KaminoAction {
|
|
|
1111
1067
|
createLookupTable: boolean = true,
|
|
1112
1068
|
referrer: PublicKey = PublicKey.default,
|
|
1113
1069
|
maxAllowedLtvOverridePercent: number = 0,
|
|
1114
|
-
currentSlot: number = 0
|
|
1070
|
+
currentSlot: number = 0,
|
|
1071
|
+
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
1115
1072
|
) {
|
|
1116
1073
|
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
1117
1074
|
kaminoMarket,
|
|
@@ -1132,6 +1089,18 @@ export class KaminoAction {
|
|
|
1132
1089
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
1133
1090
|
}
|
|
1134
1091
|
|
|
1092
|
+
const allReserves = new PublicKeySet<PublicKey>([
|
|
1093
|
+
...axn.depositReserves,
|
|
1094
|
+
...axn.borrowReserves,
|
|
1095
|
+
axn.reserve.address,
|
|
1096
|
+
axn.outflowReserve!.address,
|
|
1097
|
+
]).toArray();
|
|
1098
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
1099
|
+
|
|
1100
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
1101
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1135
1104
|
await axn.addSupportIxs(
|
|
1136
1105
|
'liquidate',
|
|
1137
1106
|
includeAtaIxns,
|
|
@@ -1139,7 +1108,6 @@ export class KaminoAction {
|
|
|
1139
1108
|
includeUserMetadata,
|
|
1140
1109
|
addInitObligationForFarm,
|
|
1141
1110
|
useV2Ixs,
|
|
1142
|
-
scopeRefreshConfig,
|
|
1143
1111
|
createLookupTable
|
|
1144
1112
|
);
|
|
1145
1113
|
if (useV2Ixs) {
|
|
@@ -1168,17 +1136,6 @@ export class KaminoAction {
|
|
|
1168
1136
|
axn.preTxnIxs.push(...createAtaIxs);
|
|
1169
1137
|
axn.preTxnIxsLabels.push(`createAtasIxs[${axn.userTokenAccountAddress.toString()}]`);
|
|
1170
1138
|
|
|
1171
|
-
if (!axn.referrer.equals(PublicKey.default)) {
|
|
1172
|
-
const referrerTokenState = referrerTokenStatePda(
|
|
1173
|
-
axn.referrer,
|
|
1174
|
-
axn.reserve.address,
|
|
1175
|
-
axn.kaminoMarket.programId
|
|
1176
|
-
)[0];
|
|
1177
|
-
const account = await axn.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
1178
|
-
if (!account) {
|
|
1179
|
-
axn.addInitReferrerTokenStateIx(axn.reserve, referrerTokenState);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
1139
|
axn.addRefreshReserveIxs([axn.reserve.address]);
|
|
1183
1140
|
axn.addWithdrawReferrerFeesIxs();
|
|
1184
1141
|
|
|
@@ -1367,11 +1324,14 @@ export class KaminoAction {
|
|
|
1367
1324
|
addDepositIxV2() {
|
|
1368
1325
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1369
1326
|
? {
|
|
1370
|
-
obligationFarmUserState:
|
|
1371
|
-
reserveFarmState:
|
|
1327
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1328
|
+
reserveFarmState: PROGRAM_ID,
|
|
1372
1329
|
}
|
|
1373
1330
|
: {
|
|
1374
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1331
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1332
|
+
this.getObligationPda(),
|
|
1333
|
+
this.reserve.state.farmCollateral
|
|
1334
|
+
)[0],
|
|
1375
1335
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1376
1336
|
};
|
|
1377
1337
|
|
|
@@ -1432,11 +1392,14 @@ export class KaminoAction {
|
|
|
1432
1392
|
addDepositObligationCollateralIxV2() {
|
|
1433
1393
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1434
1394
|
? {
|
|
1435
|
-
obligationFarmUserState:
|
|
1436
|
-
reserveFarmState:
|
|
1395
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1396
|
+
reserveFarmState: PROGRAM_ID,
|
|
1437
1397
|
}
|
|
1438
1398
|
: {
|
|
1439
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1399
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1400
|
+
this.getObligationPda(),
|
|
1401
|
+
this.reserve.state.farmCollateral
|
|
1402
|
+
)[0],
|
|
1440
1403
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1441
1404
|
};
|
|
1442
1405
|
|
|
@@ -1514,11 +1477,11 @@ export class KaminoAction {
|
|
|
1514
1477
|
|
|
1515
1478
|
const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1516
1479
|
? {
|
|
1517
|
-
obligationFarmUserState:
|
|
1518
|
-
reserveFarmState:
|
|
1480
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1481
|
+
reserveFarmState: PROGRAM_ID,
|
|
1519
1482
|
}
|
|
1520
1483
|
: {
|
|
1521
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
1484
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1522
1485
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
1523
1486
|
};
|
|
1524
1487
|
|
|
@@ -1589,11 +1552,14 @@ export class KaminoAction {
|
|
|
1589
1552
|
async addWithdrawIxV2(collateralAmount: BN) {
|
|
1590
1553
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1591
1554
|
? {
|
|
1592
|
-
obligationFarmUserState:
|
|
1593
|
-
reserveFarmState:
|
|
1555
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1556
|
+
reserveFarmState: PROGRAM_ID,
|
|
1594
1557
|
}
|
|
1595
1558
|
: {
|
|
1596
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1559
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1560
|
+
this.getObligationPda(),
|
|
1561
|
+
this.reserve.state.farmCollateral
|
|
1562
|
+
)[0],
|
|
1597
1563
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1598
1564
|
};
|
|
1599
1565
|
|
|
@@ -1673,11 +1639,11 @@ export class KaminoAction {
|
|
|
1673
1639
|
|
|
1674
1640
|
const farmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1675
1641
|
? {
|
|
1676
|
-
obligationFarmUserState:
|
|
1677
|
-
reserveFarmState:
|
|
1642
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1643
|
+
reserveFarmState: PROGRAM_ID,
|
|
1678
1644
|
}
|
|
1679
1645
|
: {
|
|
1680
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
1646
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
1681
1647
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
1682
1648
|
};
|
|
1683
1649
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
@@ -1713,208 +1679,6 @@ export class KaminoAction {
|
|
|
1713
1679
|
this.lendingIxs.push(repayIx);
|
|
1714
1680
|
}
|
|
1715
1681
|
|
|
1716
|
-
addRepayAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
|
|
1717
|
-
this.lendingIxsLabels.push(
|
|
1718
|
-
`repayAndWithdrawAndRedeem(repayReserve=${this.reserve!.address})(withdrawReserve=${
|
|
1719
|
-
this.outflowReserve!.address
|
|
1720
|
-
})(obligation=${this.getObligationPda()})`
|
|
1721
|
-
);
|
|
1722
|
-
|
|
1723
|
-
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1724
|
-
|
|
1725
|
-
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1726
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1727
|
-
});
|
|
1728
|
-
const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
|
|
1729
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1730
|
-
});
|
|
1731
|
-
|
|
1732
|
-
if (!this.outflowAmount) {
|
|
1733
|
-
throw new Error(`outflowAmount not set`);
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
if (!this.outflowReserve) {
|
|
1737
|
-
throw new Error(`outflowReserve not set`);
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1741
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
1745
|
-
? {
|
|
1746
|
-
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1747
|
-
reserveFarmState: this.kaminoMarket.programId,
|
|
1748
|
-
}
|
|
1749
|
-
: {
|
|
1750
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1751
|
-
this.outflowReserve.state.farmCollateral,
|
|
1752
|
-
this.getObligationPda()
|
|
1753
|
-
),
|
|
1754
|
-
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1755
|
-
};
|
|
1756
|
-
|
|
1757
|
-
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
1758
|
-
? {
|
|
1759
|
-
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1760
|
-
reserveFarmState: this.kaminoMarket.programId,
|
|
1761
|
-
}
|
|
1762
|
-
: {
|
|
1763
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt, this.getObligationPda()),
|
|
1764
|
-
reserveFarmState: this.reserve.state.farmDebt,
|
|
1765
|
-
};
|
|
1766
|
-
|
|
1767
|
-
const repayAndWithdrawIx = repayAndWithdrawAndRedeem(
|
|
1768
|
-
{
|
|
1769
|
-
repayAmount: this.amount,
|
|
1770
|
-
withdrawCollateralAmount,
|
|
1771
|
-
},
|
|
1772
|
-
{
|
|
1773
|
-
repayAccounts: {
|
|
1774
|
-
owner: this.owner,
|
|
1775
|
-
obligation: this.getObligationPda(),
|
|
1776
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1777
|
-
repayReserve: this.reserve!.address,
|
|
1778
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1779
|
-
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1780
|
-
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1781
|
-
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1782
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1783
|
-
},
|
|
1784
|
-
withdrawAccounts: {
|
|
1785
|
-
owner: this.owner,
|
|
1786
|
-
obligation: this.getObligationPda(),
|
|
1787
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1788
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1789
|
-
withdrawReserve: this.outflowReserve.address,
|
|
1790
|
-
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1791
|
-
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1792
|
-
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1793
|
-
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1794
|
-
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1795
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1796
|
-
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1797
|
-
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1798
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1799
|
-
},
|
|
1800
|
-
collateralFarmsAccounts,
|
|
1801
|
-
debtFarmsAccounts,
|
|
1802
|
-
farmsProgram: farmsId,
|
|
1803
|
-
},
|
|
1804
|
-
this.kaminoMarket.programId
|
|
1805
|
-
);
|
|
1806
|
-
|
|
1807
|
-
repayAndWithdrawIx.keys = repayAndWithdrawIx.keys.concat([
|
|
1808
|
-
...depositReserveAccountMetas,
|
|
1809
|
-
...borrowReserveAccountMetas,
|
|
1810
|
-
]);
|
|
1811
|
-
|
|
1812
|
-
this.lendingIxs.push(repayAndWithdrawIx);
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
addDepositAndWithdrawV2Ixs(withdrawCollateralAmount: BN) {
|
|
1816
|
-
this.lendingIxsLabels.push(
|
|
1817
|
-
`depositAndWithdrawV2(depositReserve=${this.reserve!.address})(withdrawReserve=${
|
|
1818
|
-
this.outflowReserve!.address
|
|
1819
|
-
})(obligation=${this.getObligationPda()})`
|
|
1820
|
-
);
|
|
1821
|
-
|
|
1822
|
-
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1823
|
-
|
|
1824
|
-
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1825
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1826
|
-
});
|
|
1827
|
-
const borrowReserveAccountMetas = this.borrowReserves.map((reserve) => {
|
|
1828
|
-
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1829
|
-
});
|
|
1830
|
-
|
|
1831
|
-
if (!this.outflowAmount) {
|
|
1832
|
-
throw new Error(`outflowAmount not set`);
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
if (!this.outflowReserve) {
|
|
1836
|
-
throw new Error(`outflowReserve not set`);
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1840
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
const depositFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1844
|
-
? {
|
|
1845
|
-
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1846
|
-
reserveFarmState: this.kaminoMarket.programId,
|
|
1847
|
-
}
|
|
1848
|
-
: {
|
|
1849
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmCollateral, this.getObligationPda()),
|
|
1850
|
-
reserveFarmState: this.reserve.state.farmCollateral,
|
|
1851
|
-
};
|
|
1852
|
-
const withdrawFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
1853
|
-
? {
|
|
1854
|
-
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1855
|
-
reserveFarmState: this.kaminoMarket.programId,
|
|
1856
|
-
}
|
|
1857
|
-
: {
|
|
1858
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1859
|
-
this.outflowReserve.state.farmCollateral,
|
|
1860
|
-
this.getObligationPda()
|
|
1861
|
-
),
|
|
1862
|
-
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
1863
|
-
};
|
|
1864
|
-
|
|
1865
|
-
const depositAndWithdrawIx = depositAndWithdraw(
|
|
1866
|
-
{
|
|
1867
|
-
liquidityAmount: this.amount,
|
|
1868
|
-
withdrawCollateralAmount,
|
|
1869
|
-
},
|
|
1870
|
-
{
|
|
1871
|
-
depositAccounts: {
|
|
1872
|
-
owner: this.owner,
|
|
1873
|
-
obligation: this.getObligationPda(),
|
|
1874
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1875
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1876
|
-
reserve: this.reserve.address,
|
|
1877
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1878
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1879
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1880
|
-
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1881
|
-
userSourceLiquidity: this.userTokenAccountAddress,
|
|
1882
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1883
|
-
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1884
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1885
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1886
|
-
},
|
|
1887
|
-
withdrawAccounts: {
|
|
1888
|
-
owner: this.owner,
|
|
1889
|
-
obligation: this.getObligationPda(),
|
|
1890
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1891
|
-
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1892
|
-
withdrawReserve: this.outflowReserve.address,
|
|
1893
|
-
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1894
|
-
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1895
|
-
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1896
|
-
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1897
|
-
userDestinationLiquidity: this.additionalTokenAccountAddress,
|
|
1898
|
-
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1899
|
-
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1900
|
-
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1901
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1902
|
-
},
|
|
1903
|
-
depositFarmsAccounts,
|
|
1904
|
-
withdrawFarmsAccounts,
|
|
1905
|
-
farmsProgram: farmsId,
|
|
1906
|
-
},
|
|
1907
|
-
this.kaminoMarket.programId
|
|
1908
|
-
);
|
|
1909
|
-
|
|
1910
|
-
depositAndWithdrawIx.keys = depositAndWithdrawIx.keys.concat([
|
|
1911
|
-
...depositReserveAccountMetas,
|
|
1912
|
-
...borrowReserveAccountMetas,
|
|
1913
|
-
]);
|
|
1914
|
-
|
|
1915
|
-
this.lendingIxs.push(depositAndWithdrawIx);
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1918
1682
|
async addDepositAndBorrowIx() {
|
|
1919
1683
|
this.lendingIxsLabels.push(`depositReserveLiquidityAndObligationCollateral`);
|
|
1920
1684
|
this.lendingIxsLabels.push(`borrowObligationLiquidity`);
|
|
@@ -1996,11 +1760,14 @@ export class KaminoAction {
|
|
|
1996
1760
|
async addDepositAndBorrowIxV2() {
|
|
1997
1761
|
const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1998
1762
|
? {
|
|
1999
|
-
obligationFarmUserState:
|
|
2000
|
-
reserveFarmState:
|
|
1763
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1764
|
+
reserveFarmState: PROGRAM_ID,
|
|
2001
1765
|
}
|
|
2002
1766
|
: {
|
|
2003
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1767
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1768
|
+
this.getObligationPda(),
|
|
1769
|
+
this.reserve.state.farmCollateral
|
|
1770
|
+
)[0],
|
|
2004
1771
|
reserveFarmState: this.reserve.state.farmCollateral,
|
|
2005
1772
|
};
|
|
2006
1773
|
|
|
@@ -2057,11 +1824,14 @@ export class KaminoAction {
|
|
|
2057
1824
|
|
|
2058
1825
|
const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(PublicKey.default)
|
|
2059
1826
|
? {
|
|
2060
|
-
obligationFarmUserState:
|
|
2061
|
-
reserveFarmState:
|
|
1827
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1828
|
+
reserveFarmState: PROGRAM_ID,
|
|
2062
1829
|
}
|
|
2063
1830
|
: {
|
|
2064
|
-
obligationFarmUserState: obligationFarmStatePda(
|
|
1831
|
+
obligationFarmUserState: obligationFarmStatePda(
|
|
1832
|
+
this.getObligationPda(),
|
|
1833
|
+
this.outflowReserve.state.farmDebt!
|
|
1834
|
+
)[0],
|
|
2065
1835
|
reserveFarmState: this.outflowReserve.state.farmDebt,
|
|
2066
1836
|
};
|
|
2067
1837
|
|
|
@@ -2183,11 +1953,11 @@ export class KaminoAction {
|
|
|
2183
1953
|
|
|
2184
1954
|
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
2185
1955
|
? {
|
|
2186
|
-
obligationFarmUserState:
|
|
2187
|
-
reserveFarmState:
|
|
1956
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
1957
|
+
reserveFarmState: PROGRAM_ID,
|
|
2188
1958
|
}
|
|
2189
1959
|
: {
|
|
2190
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
1960
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
2191
1961
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
2192
1962
|
};
|
|
2193
1963
|
|
|
@@ -2231,14 +2001,14 @@ export class KaminoAction {
|
|
|
2231
2001
|
|
|
2232
2002
|
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
2233
2003
|
? {
|
|
2234
|
-
obligationFarmUserState:
|
|
2235
|
-
reserveFarmState:
|
|
2004
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2005
|
+
reserveFarmState: PROGRAM_ID,
|
|
2236
2006
|
}
|
|
2237
2007
|
: {
|
|
2238
2008
|
obligationFarmUserState: obligationFarmStatePda(
|
|
2239
|
-
this.
|
|
2240
|
-
this.
|
|
2241
|
-
),
|
|
2009
|
+
this.getObligationPda(),
|
|
2010
|
+
this.outflowReserve.state.farmCollateral
|
|
2011
|
+
)[0],
|
|
2242
2012
|
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2243
2013
|
};
|
|
2244
2014
|
|
|
@@ -2272,7 +2042,7 @@ export class KaminoAction {
|
|
|
2272
2042
|
);
|
|
2273
2043
|
}
|
|
2274
2044
|
|
|
2275
|
-
addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
|
|
2045
|
+
async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0) {
|
|
2276
2046
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
2277
2047
|
if (!this.outflowReserve) {
|
|
2278
2048
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
@@ -2340,24 +2110,24 @@ export class KaminoAction {
|
|
|
2340
2110
|
|
|
2341
2111
|
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
2342
2112
|
? {
|
|
2343
|
-
obligationFarmUserState:
|
|
2344
|
-
reserveFarmState:
|
|
2113
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2114
|
+
reserveFarmState: PROGRAM_ID,
|
|
2345
2115
|
}
|
|
2346
2116
|
: {
|
|
2347
2117
|
obligationFarmUserState: obligationFarmStatePda(
|
|
2348
|
-
this.
|
|
2349
|
-
this.
|
|
2350
|
-
),
|
|
2118
|
+
this.getObligationPda(),
|
|
2119
|
+
this.outflowReserve.state.farmCollateral
|
|
2120
|
+
)[0],
|
|
2351
2121
|
reserveFarmState: this.outflowReserve.state.farmCollateral,
|
|
2352
2122
|
};
|
|
2353
2123
|
|
|
2354
2124
|
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(PublicKey.default)
|
|
2355
2125
|
? {
|
|
2356
|
-
obligationFarmUserState:
|
|
2357
|
-
reserveFarmState:
|
|
2126
|
+
obligationFarmUserState: PROGRAM_ID,
|
|
2127
|
+
reserveFarmState: PROGRAM_ID,
|
|
2358
2128
|
}
|
|
2359
2129
|
: {
|
|
2360
|
-
obligationFarmUserState: obligationFarmStatePda(this.reserve.state.farmDebt
|
|
2130
|
+
obligationFarmUserState: obligationFarmStatePda(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
2361
2131
|
reserveFarmState: this.reserve.state.farmDebt,
|
|
2362
2132
|
};
|
|
2363
2133
|
|
|
@@ -2469,9 +2239,7 @@ export class KaminoAction {
|
|
|
2469
2239
|
'repay',
|
|
2470
2240
|
'depositAndBorrow',
|
|
2471
2241
|
'repayAndWithdraw',
|
|
2472
|
-
'repayAndWithdrawV2',
|
|
2473
2242
|
'refreshObligation',
|
|
2474
|
-
'depositAndWithdraw',
|
|
2475
2243
|
].includes(action)
|
|
2476
2244
|
) {
|
|
2477
2245
|
// The support ixns in order are:
|
|
@@ -2489,17 +2257,12 @@ export class KaminoAction {
|
|
|
2489
2257
|
|
|
2490
2258
|
let currentReserves: KaminoReserve[] = [];
|
|
2491
2259
|
|
|
2492
|
-
if (
|
|
2493
|
-
action === 'liquidate' ||
|
|
2494
|
-
action === 'depositAndBorrow' ||
|
|
2495
|
-
action === 'repayAndWithdraw' ||
|
|
2496
|
-
action === 'repayAndWithdrawV2'
|
|
2497
|
-
) {
|
|
2260
|
+
if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
2498
2261
|
if (!this.outflowReserve) {
|
|
2499
2262
|
throw new Error('outflowReserve is undefined');
|
|
2500
2263
|
}
|
|
2501
2264
|
|
|
2502
|
-
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw'
|
|
2265
|
+
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
2503
2266
|
currentReserves = [this.reserve, this.outflowReserve];
|
|
2504
2267
|
if (action === 'depositAndBorrow') {
|
|
2505
2268
|
if (this.obligation) {
|
|
@@ -2538,19 +2301,13 @@ export class KaminoAction {
|
|
|
2538
2301
|
action === 'depositAndBorrow' ||
|
|
2539
2302
|
action === 'depositCollateral' ||
|
|
2540
2303
|
action === 'withdraw' ||
|
|
2541
|
-
action === 'deposit'
|
|
2542
|
-
action === 'depositAndWithdraw'
|
|
2304
|
+
action === 'deposit'
|
|
2543
2305
|
) {
|
|
2544
2306
|
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Collateral, addAsSupportIx);
|
|
2545
|
-
if (this.outflowReserve
|
|
2307
|
+
if (this.outflowReserve) {
|
|
2546
2308
|
await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Debt, addAsSupportIx);
|
|
2547
2309
|
}
|
|
2548
|
-
} else if (
|
|
2549
|
-
action === 'repayAndWithdraw' ||
|
|
2550
|
-
action === 'borrow' ||
|
|
2551
|
-
action === 'repay' ||
|
|
2552
|
-
action === 'repayAndWithdrawV2'
|
|
2553
|
-
) {
|
|
2310
|
+
} else if (action === 'repayAndWithdraw' || action === 'borrow' || action === 'repay') {
|
|
2554
2311
|
// todo - probably don't need to add both debt and collateral for everything here
|
|
2555
2312
|
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
|
|
2556
2313
|
if (this.outflowReserve) {
|
|
@@ -2581,7 +2338,7 @@ export class KaminoAction {
|
|
|
2581
2338
|
}
|
|
2582
2339
|
|
|
2583
2340
|
if (requestElevationGroup) {
|
|
2584
|
-
if (action === 'repay'
|
|
2341
|
+
if (action === 'repay') {
|
|
2585
2342
|
const repayObligationLiquidity = this.obligation!.borrows.get(this.reserve.address);
|
|
2586
2343
|
|
|
2587
2344
|
if (!repayObligationLiquidity) {
|
|
@@ -2743,7 +2500,6 @@ export class KaminoAction {
|
|
|
2743
2500
|
includeUserMetadata: boolean,
|
|
2744
2501
|
addInitObligationForFarm: boolean,
|
|
2745
2502
|
useV2Ixs: boolean,
|
|
2746
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
2747
2503
|
createLookupTable: boolean,
|
|
2748
2504
|
twoTokenAction: boolean = false,
|
|
2749
2505
|
overrideElevationGroupRequest?: number
|
|
@@ -2764,6 +2520,13 @@ export class KaminoAction {
|
|
|
2764
2520
|
this.addInitUserMetadataIxs(lookupTable);
|
|
2765
2521
|
}
|
|
2766
2522
|
|
|
2523
|
+
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
2524
|
+
await this.addInitReferrerTokenStateIx(this.reserve);
|
|
2525
|
+
}
|
|
2526
|
+
// depositAndBorrow
|
|
2527
|
+
if (action === 'deposit' && this.outflowReserve) {
|
|
2528
|
+
await this.addInitReferrerTokenStateIx(this.outflowReserve);
|
|
2529
|
+
}
|
|
2767
2530
|
await this.addInitObligationIxs();
|
|
2768
2531
|
}
|
|
2769
2532
|
|
|
@@ -2777,19 +2540,6 @@ export class KaminoAction {
|
|
|
2777
2540
|
twoTokenAction,
|
|
2778
2541
|
overrideElevationGroupRequest
|
|
2779
2542
|
);
|
|
2780
|
-
|
|
2781
|
-
const allReserves = new PublicKeySet<PublicKey>([
|
|
2782
|
-
...this.depositReserves,
|
|
2783
|
-
...this.borrowReserves,
|
|
2784
|
-
this.reserve.address,
|
|
2785
|
-
...(this.outflowReserve ? [this.outflowReserve.address] : []),
|
|
2786
|
-
...(this.preLoadedDepositReservesSameTx ? this.preLoadedDepositReservesSameTx : []),
|
|
2787
|
-
]).toArray();
|
|
2788
|
-
const tokenIds = getTokenIdsForScopeRefresh(this.kaminoMarket, allReserves);
|
|
2789
|
-
|
|
2790
|
-
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
2791
|
-
await this.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
2792
|
-
}
|
|
2793
2543
|
}
|
|
2794
2544
|
|
|
2795
2545
|
private static optionalAccount(pubkey: PublicKey, programId: PublicKey = PROGRAM_ID): PublicKey {
|
|
@@ -3009,7 +2759,7 @@ export class KaminoAction {
|
|
|
3009
2759
|
farms.push([
|
|
3010
2760
|
ReserveFarmKind.Collateral,
|
|
3011
2761
|
kaminoReserve.state.farmCollateral,
|
|
3012
|
-
obligationFarmStatePda(kaminoReserve.state.farmCollateral
|
|
2762
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmCollateral)[0],
|
|
3013
2763
|
kaminoReserve,
|
|
3014
2764
|
]);
|
|
3015
2765
|
}
|
|
@@ -3017,7 +2767,7 @@ export class KaminoAction {
|
|
|
3017
2767
|
farms.push([
|
|
3018
2768
|
ReserveFarmKind.Debt,
|
|
3019
2769
|
kaminoReserve.state.farmDebt,
|
|
3020
|
-
obligationFarmStatePda(kaminoReserve.state.farmDebt
|
|
2770
|
+
obligationFarmStatePda(this.getObligationPda(), kaminoReserve.state.farmDebt)[0],
|
|
3021
2771
|
kaminoReserve,
|
|
3022
2772
|
]);
|
|
3023
2773
|
}
|
|
@@ -3101,18 +2851,18 @@ export class KaminoAction {
|
|
|
3101
2851
|
const farms: [number, PublicKey, PublicKey][] = [];
|
|
3102
2852
|
|
|
3103
2853
|
if (mode === ReserveFarmKind.Collateral && isNotNullPubkey(reserve.state.farmCollateral)) {
|
|
3104
|
-
const
|
|
3105
|
-
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);
|
|
3106
2856
|
if (!account) {
|
|
3107
|
-
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral,
|
|
2857
|
+
farms.push([ReserveFarmKind.Collateral.discriminator, reserve.state.farmCollateral, userPda]);
|
|
3108
2858
|
}
|
|
3109
2859
|
}
|
|
3110
2860
|
|
|
3111
2861
|
if (mode === ReserveFarmKind.Debt && isNotNullPubkey(reserve.state.farmDebt)) {
|
|
3112
|
-
const
|
|
3113
|
-
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);
|
|
3114
2864
|
if (!account) {
|
|
3115
|
-
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt,
|
|
2865
|
+
farms.push([ReserveFarmKind.Debt.discriminator, reserve.state.farmDebt, userPda]);
|
|
3116
2866
|
}
|
|
3117
2867
|
}
|
|
3118
2868
|
|
|
@@ -3146,7 +2896,7 @@ export class KaminoAction {
|
|
|
3146
2896
|
});
|
|
3147
2897
|
}
|
|
3148
2898
|
|
|
3149
|
-
private addInitObligationIxs() {
|
|
2899
|
+
private async addInitObligationIxs() {
|
|
3150
2900
|
if (!this.obligation) {
|
|
3151
2901
|
const obligationPda = this.getObligationPda();
|
|
3152
2902
|
const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
|
|
@@ -3198,21 +2948,29 @@ export class KaminoAction {
|
|
|
3198
2948
|
this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
|
|
3199
2949
|
}
|
|
3200
2950
|
|
|
3201
|
-
private addInitReferrerTokenStateIx(reserve: KaminoReserve
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
2951
|
+
private async addInitReferrerTokenStateIx(reserve: KaminoReserve) {
|
|
2952
|
+
if (this.referrer.equals(PublicKey.default)) {
|
|
2953
|
+
return;
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
const referrerTokenState = referrerTokenStatePda(this.referrer, reserve.address, this.kaminoMarket.programId)[0];
|
|
2957
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
2958
|
+
if (!account) {
|
|
2959
|
+
const initReferrerTokenStateIx = initReferrerTokenState(
|
|
2960
|
+
{
|
|
2961
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
2962
|
+
payer: this.owner,
|
|
2963
|
+
reserve: reserve.address,
|
|
2964
|
+
referrer: this.referrer,
|
|
2965
|
+
referrerTokenState,
|
|
2966
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
2967
|
+
systemProgram: SystemProgram.programId,
|
|
2968
|
+
},
|
|
2969
|
+
this.kaminoMarket.programId
|
|
2970
|
+
);
|
|
2971
|
+
this.setupIxs.unshift(initReferrerTokenStateIx);
|
|
2972
|
+
this.setupIxsLabels.unshift(`InitReferrerTokenState[${referrerTokenState.toString()} res=${reserve.address}]`);
|
|
2973
|
+
}
|
|
3216
2974
|
}
|
|
3217
2975
|
|
|
3218
2976
|
private addWithdrawReferrerFeesIxs() {
|
|
@@ -3361,7 +3119,7 @@ export class KaminoAction {
|
|
|
3361
3119
|
|
|
3362
3120
|
let safeRepay = new BN(this.amount);
|
|
3363
3121
|
|
|
3364
|
-
if (this.obligation &&
|
|
3122
|
+
if (this.obligation && action === 'repay' && this.amount.eq(new BN(U64_MAX))) {
|
|
3365
3123
|
const borrow = this.obligation.state.borrows.find(
|
|
3366
3124
|
(borrow) => borrow.borrowReserve.toString() === this.reserve.address.toString()
|
|
3367
3125
|
);
|
|
@@ -3375,7 +3133,7 @@ export class KaminoAction {
|
|
|
3375
3133
|
this.currentSlot,
|
|
3376
3134
|
this.kaminoMarket.state.referralFeeBps
|
|
3377
3135
|
);
|
|
3378
|
-
|
|
3136
|
+
// TODO: shouldn't this calc be added to all other stuff as well?
|
|
3379
3137
|
safeRepay = new BN(
|
|
3380
3138
|
Math.floor(
|
|
3381
3139
|
KaminoObligation.getBorrowAmount(borrow)
|
|
@@ -3403,7 +3161,6 @@ export class KaminoAction {
|
|
|
3403
3161
|
const sendAction =
|
|
3404
3162
|
action === 'deposit' ||
|
|
3405
3163
|
action === 'repay' ||
|
|
3406
|
-
action === 'repayAndWithdrawV2' ||
|
|
3407
3164
|
action === 'mint' ||
|
|
3408
3165
|
(action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
3409
3166
|
|
|
@@ -3513,7 +3270,7 @@ export class KaminoAction {
|
|
|
3513
3270
|
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
3514
3271
|
primaryMint = inflowTokenMint;
|
|
3515
3272
|
secondaryMint = outflowTokenMint;
|
|
3516
|
-
} else if (action === 'repayAndWithdraw'
|
|
3273
|
+
} else if (action === 'repayAndWithdraw') {
|
|
3517
3274
|
primaryMint = inflowTokenMint;
|
|
3518
3275
|
secondaryMint = outflowTokenMint;
|
|
3519
3276
|
userTokenAccountAddress = userInflowTokenAccountAddress;
|