@drift-labs/sdk 2.145.0-beta.2 → 2.145.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/VERSION +1 -1
- package/lib/browser/accounts/types.d.ts +13 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +53 -0
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +453 -0
- package/lib/browser/addresses/pda.d.ts +9 -0
- package/lib/browser/addresses/pda.js +60 -1
- package/lib/browser/adminClient.d.ts +160 -8
- package/lib/browser/adminClient.js +754 -18
- package/lib/browser/constituentMap/constituentMap.d.ts +64 -0
- package/lib/browser/constituentMap/constituentMap.js +170 -0
- package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.d.ts +24 -0
- package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.js +60 -0
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +24 -0
- package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +58 -0
- package/lib/browser/driftClient.d.ts +89 -2
- package/lib/browser/driftClient.js +486 -27
- package/lib/browser/driftClientConfig.d.ts +2 -7
- package/lib/browser/idl/drift.json +4304 -1380
- package/lib/browser/index.d.ts +1 -4
- package/lib/browser/index.js +2 -9
- package/lib/browser/memcmp.d.ts +3 -1
- package/lib/browser/memcmp.js +19 -1
- package/lib/browser/types.d.ts +147 -0
- package/lib/browser/types.js +13 -1
- package/lib/node/accounts/types.d.ts +13 -1
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +54 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +453 -0
- package/lib/node/addresses/pda.d.ts +9 -0
- package/lib/node/addresses/pda.d.ts.map +1 -1
- package/lib/node/addresses/pda.js +60 -1
- package/lib/node/adminClient.d.ts +160 -8
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +754 -18
- package/lib/node/constituentMap/constituentMap.d.ts +65 -0
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -0
- package/lib/node/constituentMap/constituentMap.js +170 -0
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts +25 -0
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -0
- package/lib/node/constituentMap/pollingConstituentAccountSubscriber.js +60 -0
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +25 -0
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -0
- package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +58 -0
- package/lib/node/driftClient.d.ts +89 -2
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +486 -27
- package/lib/node/driftClientConfig.d.ts +2 -7
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/idl/drift.json +4304 -1380
- package/lib/node/index.d.ts +1 -4
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +2 -9
- package/lib/node/memcmp.d.ts +3 -1
- package/lib/node/memcmp.d.ts.map +1 -1
- package/lib/node/memcmp.js +19 -1
- package/lib/node/types.d.ts +147 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +13 -1
- package/package.json +1 -1
- package/src/accounts/types.ts +20 -0
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +596 -0
- package/src/addresses/pda.ts +115 -1
- package/src/adminClient.ts +1612 -41
- package/src/constituentMap/constituentMap.ts +285 -0
- package/src/constituentMap/pollingConstituentAccountSubscriber.ts +97 -0
- package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +112 -0
- package/src/driftClient.ts +1097 -17
- package/src/driftClientConfig.ts +8 -15
- package/src/idl/drift.json +4304 -1380
- package/src/index.ts +1 -4
- package/src/memcmp.ts +23 -1
- package/src/types.ts +160 -0
package/src/adminClient.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AddressLookupTableAccount,
|
|
3
|
+
Keypair,
|
|
4
|
+
LAMPORTS_PER_SOL,
|
|
2
5
|
PublicKey,
|
|
3
6
|
SystemProgram,
|
|
4
7
|
SYSVAR_RENT_PUBKEY,
|
|
@@ -16,6 +19,11 @@ import {
|
|
|
16
19
|
SpotFulfillmentConfigStatus,
|
|
17
20
|
IfRebalanceConfigParams,
|
|
18
21
|
TxParams,
|
|
22
|
+
AddAmmConstituentMappingDatum,
|
|
23
|
+
SwapReduceOnly,
|
|
24
|
+
InitializeConstituentParams,
|
|
25
|
+
ConstituentStatus,
|
|
26
|
+
LPPoolAccount,
|
|
19
27
|
} from './types';
|
|
20
28
|
import { DEFAULT_MARKET_NAME, encodeName } from './userName';
|
|
21
29
|
import { BN } from '@coral-xyz/anchor';
|
|
@@ -41,9 +49,25 @@ import {
|
|
|
41
49
|
getTokenProgramForSpotMarket,
|
|
42
50
|
getIfRebalanceConfigPublicKey,
|
|
43
51
|
getInsuranceFundStakeAccountPublicKey,
|
|
52
|
+
getLpPoolPublicKey,
|
|
53
|
+
getAmmConstituentMappingPublicKey,
|
|
54
|
+
getConstituentTargetBasePublicKey,
|
|
55
|
+
getConstituentPublicKey,
|
|
56
|
+
getConstituentVaultPublicKey,
|
|
57
|
+
getAmmCachePublicKey,
|
|
58
|
+
getLpPoolTokenVaultPublicKey,
|
|
59
|
+
getDriftSignerPublicKey,
|
|
60
|
+
getConstituentCorrelationsPublicKey,
|
|
44
61
|
} from './addresses/pda';
|
|
45
62
|
import { squareRootBN } from './math/utils';
|
|
46
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
createInitializeMint2Instruction,
|
|
65
|
+
createMintToInstruction,
|
|
66
|
+
createTransferCheckedInstruction,
|
|
67
|
+
getAssociatedTokenAddressSync,
|
|
68
|
+
MINT_SIZE,
|
|
69
|
+
TOKEN_PROGRAM_ID,
|
|
70
|
+
} from '@solana/spl-token';
|
|
47
71
|
import { DriftClient } from './driftClient';
|
|
48
72
|
import {
|
|
49
73
|
PEG_PRECISION,
|
|
@@ -60,6 +84,8 @@ import { PROGRAM_ID as PHOENIX_PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
|
|
|
60
84
|
import { DRIFT_ORACLE_RECEIVER_ID } from './config';
|
|
61
85
|
import { getFeedIdUint8Array } from './util/pythOracleUtils';
|
|
62
86
|
import { FUEL_RESET_LOG_ACCOUNT } from './constants/txConstants';
|
|
87
|
+
import { JupiterClient, QuoteResponse } from './jupiter/jupiterClient';
|
|
88
|
+
import { SwapMode } from './swap/UnifiedSwapClient';
|
|
63
89
|
|
|
64
90
|
const OPENBOOK_PROGRAM_ID = new PublicKey(
|
|
65
91
|
'opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb'
|
|
@@ -476,11 +502,18 @@ export class AdminClient extends DriftClient {
|
|
|
476
502
|
concentrationCoefScale = ONE,
|
|
477
503
|
curveUpdateIntensity = 0,
|
|
478
504
|
ammJitIntensity = 0,
|
|
479
|
-
name = DEFAULT_MARKET_NAME
|
|
505
|
+
name = DEFAULT_MARKET_NAME,
|
|
506
|
+
lpPoolId: number = 0
|
|
480
507
|
): Promise<TransactionSignature> {
|
|
481
508
|
const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
|
|
482
509
|
|
|
483
|
-
const
|
|
510
|
+
const ammCachePublicKey = getAmmCachePublicKey(this.program.programId);
|
|
511
|
+
const ammCacheAccount = await this.connection.getAccountInfo(
|
|
512
|
+
ammCachePublicKey
|
|
513
|
+
);
|
|
514
|
+
const mustInitializeAmmCache = ammCacheAccount?.data == null;
|
|
515
|
+
|
|
516
|
+
const initializeMarketIxs = await this.getInitializePerpMarketIx(
|
|
484
517
|
marketIndex,
|
|
485
518
|
priceOracle,
|
|
486
519
|
baseAssetReserve,
|
|
@@ -506,9 +539,11 @@ export class AdminClient extends DriftClient {
|
|
|
506
539
|
concentrationCoefScale,
|
|
507
540
|
curveUpdateIntensity,
|
|
508
541
|
ammJitIntensity,
|
|
509
|
-
name
|
|
542
|
+
name,
|
|
543
|
+
mustInitializeAmmCache,
|
|
544
|
+
lpPoolId
|
|
510
545
|
);
|
|
511
|
-
const tx = await this.buildTransaction(
|
|
546
|
+
const tx = await this.buildTransaction(initializeMarketIxs);
|
|
512
547
|
|
|
513
548
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
514
549
|
|
|
@@ -552,15 +587,22 @@ export class AdminClient extends DriftClient {
|
|
|
552
587
|
concentrationCoefScale = ONE,
|
|
553
588
|
curveUpdateIntensity = 0,
|
|
554
589
|
ammJitIntensity = 0,
|
|
555
|
-
name = DEFAULT_MARKET_NAME
|
|
556
|
-
|
|
590
|
+
name = DEFAULT_MARKET_NAME,
|
|
591
|
+
includeInitAmmCacheIx = false,
|
|
592
|
+
lpPoolId: number = 0
|
|
593
|
+
): Promise<TransactionInstruction[]> {
|
|
557
594
|
const perpMarketPublicKey = await getPerpMarketPublicKey(
|
|
558
595
|
this.program.programId,
|
|
559
596
|
marketIndex
|
|
560
597
|
);
|
|
561
598
|
|
|
599
|
+
const ixs: TransactionInstruction[] = [];
|
|
600
|
+
if (includeInitAmmCacheIx) {
|
|
601
|
+
ixs.push(await this.getInitializeAmmCacheIx());
|
|
602
|
+
}
|
|
603
|
+
|
|
562
604
|
const nameBuffer = encodeName(name);
|
|
563
|
-
|
|
605
|
+
const initPerpIx = await this.program.instruction.initializePerpMarket(
|
|
564
606
|
marketIndex,
|
|
565
607
|
baseAssetReserve,
|
|
566
608
|
quoteAssetReserve,
|
|
@@ -586,6 +628,7 @@ export class AdminClient extends DriftClient {
|
|
|
586
628
|
curveUpdateIntensity,
|
|
587
629
|
ammJitIntensity,
|
|
588
630
|
nameBuffer,
|
|
631
|
+
lpPoolId,
|
|
589
632
|
{
|
|
590
633
|
accounts: {
|
|
591
634
|
state: await this.getStatePublicKey(),
|
|
@@ -594,11 +637,159 @@ export class AdminClient extends DriftClient {
|
|
|
594
637
|
: this.wallet.publicKey,
|
|
595
638
|
oracle: priceOracle,
|
|
596
639
|
perpMarket: perpMarketPublicKey,
|
|
640
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
597
641
|
rent: SYSVAR_RENT_PUBKEY,
|
|
598
642
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
599
643
|
},
|
|
600
644
|
}
|
|
601
645
|
);
|
|
646
|
+
ixs.push(initPerpIx);
|
|
647
|
+
return ixs;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
public async initializeAmmCache(
|
|
651
|
+
txParams?: TxParams
|
|
652
|
+
): Promise<TransactionSignature> {
|
|
653
|
+
const initializeAmmCacheIx = await this.getInitializeAmmCacheIx();
|
|
654
|
+
|
|
655
|
+
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
|
|
656
|
+
|
|
657
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
658
|
+
|
|
659
|
+
return txSig;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
public async getInitializeAmmCacheIx(): Promise<TransactionInstruction> {
|
|
663
|
+
return await this.program.instruction.initializeAmmCache({
|
|
664
|
+
accounts: {
|
|
665
|
+
state: await this.getStatePublicKey(),
|
|
666
|
+
admin: this.isSubscribed
|
|
667
|
+
? this.getStateAccount().admin
|
|
668
|
+
: this.wallet.publicKey,
|
|
669
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
670
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
671
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
public async updateInitialAmmCacheInfo(
|
|
677
|
+
perpMarketIndexes: number[],
|
|
678
|
+
txParams?: TxParams
|
|
679
|
+
): Promise<TransactionSignature> {
|
|
680
|
+
const initializeAmmCacheIx = await this.getUpdateInitialAmmCacheInfoIx(
|
|
681
|
+
perpMarketIndexes
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
|
|
685
|
+
|
|
686
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
687
|
+
|
|
688
|
+
return txSig;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
public async getUpdateInitialAmmCacheInfoIx(
|
|
692
|
+
perpMarketIndexes: number[]
|
|
693
|
+
): Promise<TransactionInstruction> {
|
|
694
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
695
|
+
userAccounts: [],
|
|
696
|
+
readablePerpMarketIndex: perpMarketIndexes,
|
|
697
|
+
readableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
698
|
+
});
|
|
699
|
+
return await this.program.instruction.updateInitialAmmCacheInfo({
|
|
700
|
+
accounts: {
|
|
701
|
+
state: await this.getStatePublicKey(),
|
|
702
|
+
admin: this.isSubscribed
|
|
703
|
+
? this.getStateAccount().admin
|
|
704
|
+
: this.wallet.publicKey,
|
|
705
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
706
|
+
},
|
|
707
|
+
remainingAccounts,
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
public async overrideAmmCacheInfo(
|
|
712
|
+
perpMarketIndex: number,
|
|
713
|
+
params: {
|
|
714
|
+
quoteOwedFromLpPool?: BN;
|
|
715
|
+
lastSettleTs?: BN;
|
|
716
|
+
lastFeePoolTokenAmount?: BN;
|
|
717
|
+
lastNetPnlPoolTokenAmount?: BN;
|
|
718
|
+
ammPositionScalar?: number;
|
|
719
|
+
ammInventoryLimit?: BN;
|
|
720
|
+
},
|
|
721
|
+
txParams?: TxParams
|
|
722
|
+
): Promise<TransactionSignature> {
|
|
723
|
+
const initializeAmmCacheIx = await this.getOverrideAmmCacheInfoIx(
|
|
724
|
+
perpMarketIndex,
|
|
725
|
+
params
|
|
726
|
+
);
|
|
727
|
+
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
|
|
728
|
+
|
|
729
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
730
|
+
|
|
731
|
+
return txSig;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
public async getOverrideAmmCacheInfoIx(
|
|
735
|
+
perpMarketIndex: number,
|
|
736
|
+
params: {
|
|
737
|
+
quoteOwedFromLpPool?: BN;
|
|
738
|
+
lastSettleSlot?: BN;
|
|
739
|
+
lastFeePoolTokenAmount?: BN;
|
|
740
|
+
lastNetPnlPoolTokenAmount?: BN;
|
|
741
|
+
ammPositionScalar?: number;
|
|
742
|
+
ammInventoryLimit?: BN;
|
|
743
|
+
}
|
|
744
|
+
): Promise<TransactionInstruction> {
|
|
745
|
+
return this.program.instruction.overrideAmmCacheInfo(
|
|
746
|
+
perpMarketIndex,
|
|
747
|
+
Object.assign(
|
|
748
|
+
{},
|
|
749
|
+
{
|
|
750
|
+
quoteOwedFromLpPool: null,
|
|
751
|
+
lastSettleSlot: null,
|
|
752
|
+
lastFeePoolTokenAmount: null,
|
|
753
|
+
lastNetPnlPoolTokenAmount: null,
|
|
754
|
+
ammPositionScalar: null,
|
|
755
|
+
ammInventoryLimit: null,
|
|
756
|
+
},
|
|
757
|
+
params
|
|
758
|
+
),
|
|
759
|
+
{
|
|
760
|
+
accounts: {
|
|
761
|
+
state: await this.getStatePublicKey(),
|
|
762
|
+
admin: this.isSubscribed
|
|
763
|
+
? this.getStateAccount().admin
|
|
764
|
+
: this.wallet.publicKey,
|
|
765
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
766
|
+
},
|
|
767
|
+
}
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
public async resetAmmCache(
|
|
772
|
+
txParams?: TxParams
|
|
773
|
+
): Promise<TransactionSignature> {
|
|
774
|
+
const initializeAmmCacheIx = await this.getResetAmmCacheIx();
|
|
775
|
+
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
|
|
776
|
+
|
|
777
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
778
|
+
|
|
779
|
+
return txSig;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
public async getResetAmmCacheIx(): Promise<TransactionInstruction> {
|
|
783
|
+
return this.program.instruction.resetAmmCache({
|
|
784
|
+
accounts: {
|
|
785
|
+
state: await this.getStatePublicKey(),
|
|
786
|
+
admin: this.isSubscribed
|
|
787
|
+
? this.getStateAccount().admin
|
|
788
|
+
: this.wallet.publicKey,
|
|
789
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
790
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
791
|
+
},
|
|
792
|
+
});
|
|
602
793
|
}
|
|
603
794
|
|
|
604
795
|
public async initializePredictionMarket(
|
|
@@ -872,6 +1063,76 @@ export class AdminClient extends DriftClient {
|
|
|
872
1063
|
);
|
|
873
1064
|
}
|
|
874
1065
|
|
|
1066
|
+
public async updatePerpMarketLpPoolId(
|
|
1067
|
+
perpMarketIndex: number,
|
|
1068
|
+
lpPoolId: number
|
|
1069
|
+
) {
|
|
1070
|
+
const updatePerpMarketLpPoolIIx = await this.getUpdatePerpMarketLpPoolIdIx(
|
|
1071
|
+
perpMarketIndex,
|
|
1072
|
+
lpPoolId
|
|
1073
|
+
);
|
|
1074
|
+
|
|
1075
|
+
const tx = await this.buildTransaction(updatePerpMarketLpPoolIIx);
|
|
1076
|
+
|
|
1077
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1078
|
+
|
|
1079
|
+
return txSig;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
public async getUpdatePerpMarketLpPoolIdIx(
|
|
1083
|
+
perpMarketIndex: number,
|
|
1084
|
+
lpPoolId: number
|
|
1085
|
+
): Promise<TransactionInstruction> {
|
|
1086
|
+
return await this.program.instruction.updatePerpMarketLpPoolId(lpPoolId, {
|
|
1087
|
+
accounts: {
|
|
1088
|
+
state: await this.getStatePublicKey(),
|
|
1089
|
+
admin: this.isSubscribed
|
|
1090
|
+
? this.getStateAccount().admin
|
|
1091
|
+
: this.wallet.publicKey,
|
|
1092
|
+
perpMarket: await getPerpMarketPublicKey(
|
|
1093
|
+
this.program.programId,
|
|
1094
|
+
perpMarketIndex
|
|
1095
|
+
),
|
|
1096
|
+
},
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
public async updatePerpMarketLpPoolStatus(
|
|
1101
|
+
perpMarketIndex: number,
|
|
1102
|
+
lpStatus: number
|
|
1103
|
+
) {
|
|
1104
|
+
const updatePerpMarketLpPoolStatusIx =
|
|
1105
|
+
await this.getUpdatePerpMarketLpPoolStatusIx(perpMarketIndex, lpStatus);
|
|
1106
|
+
|
|
1107
|
+
const tx = await this.buildTransaction(updatePerpMarketLpPoolStatusIx);
|
|
1108
|
+
|
|
1109
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1110
|
+
|
|
1111
|
+
return txSig;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
public async getUpdatePerpMarketLpPoolStatusIx(
|
|
1115
|
+
perpMarketIndex: number,
|
|
1116
|
+
lpStatus: number
|
|
1117
|
+
): Promise<TransactionInstruction> {
|
|
1118
|
+
return await this.program.instruction.updatePerpMarketLpPoolStatus(
|
|
1119
|
+
lpStatus,
|
|
1120
|
+
{
|
|
1121
|
+
accounts: {
|
|
1122
|
+
state: await this.getStatePublicKey(),
|
|
1123
|
+
admin: this.isSubscribed
|
|
1124
|
+
? this.getStateAccount().admin
|
|
1125
|
+
: this.wallet.publicKey,
|
|
1126
|
+
perpMarket: await getPerpMarketPublicKey(
|
|
1127
|
+
this.program.programId,
|
|
1128
|
+
perpMarketIndex
|
|
1129
|
+
),
|
|
1130
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
1131
|
+
},
|
|
1132
|
+
}
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
875
1136
|
public async moveAmmToPrice(
|
|
876
1137
|
perpMarketIndex: number,
|
|
877
1138
|
targetPrice: BN
|
|
@@ -1062,6 +1323,13 @@ export class AdminClient extends DriftClient {
|
|
|
1062
1323
|
sourceVault: PublicKey
|
|
1063
1324
|
): Promise<TransactionInstruction> {
|
|
1064
1325
|
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
1326
|
+
const remainingAccounts = [
|
|
1327
|
+
{
|
|
1328
|
+
pubkey: spotMarket.mint,
|
|
1329
|
+
isWritable: false,
|
|
1330
|
+
isSigner: false,
|
|
1331
|
+
},
|
|
1332
|
+
];
|
|
1065
1333
|
|
|
1066
1334
|
return await this.program.instruction.depositIntoPerpMarketFeePool(amount, {
|
|
1067
1335
|
accounts: {
|
|
@@ -1079,6 +1347,7 @@ export class AdminClient extends DriftClient {
|
|
|
1079
1347
|
spotMarketVault: spotMarket.vault,
|
|
1080
1348
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1081
1349
|
},
|
|
1350
|
+
remainingAccounts,
|
|
1082
1351
|
});
|
|
1083
1352
|
}
|
|
1084
1353
|
|
|
@@ -2349,6 +2618,7 @@ export class AdminClient extends DriftClient {
|
|
|
2349
2618
|
),
|
|
2350
2619
|
oracle: oracle,
|
|
2351
2620
|
oldOracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
|
|
2621
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
2352
2622
|
},
|
|
2353
2623
|
}
|
|
2354
2624
|
);
|
|
@@ -3159,6 +3429,7 @@ export class AdminClient extends DriftClient {
|
|
|
3159
3429
|
this.program.programId,
|
|
3160
3430
|
perpMarketIndex
|
|
3161
3431
|
),
|
|
3432
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
3162
3433
|
},
|
|
3163
3434
|
}
|
|
3164
3435
|
);
|
|
@@ -4653,9 +4924,9 @@ export class AdminClient extends DriftClient {
|
|
|
4653
4924
|
): Promise<TransactionInstruction> {
|
|
4654
4925
|
return await this.program.instruction.zeroMmOracleFields({
|
|
4655
4926
|
accounts: {
|
|
4656
|
-
admin: this.
|
|
4657
|
-
? this.
|
|
4658
|
-
: this.
|
|
4927
|
+
admin: this.useHotWalletAdmin
|
|
4928
|
+
? this.wallet.publicKey
|
|
4929
|
+
: this.getStateAccount().admin,
|
|
4659
4930
|
state: await this.getStatePublicKey(),
|
|
4660
4931
|
perpMarket: await getPerpMarketPublicKey(
|
|
4661
4932
|
this.program.programId,
|
|
@@ -4693,6 +4964,61 @@ export class AdminClient extends DriftClient {
|
|
|
4693
4964
|
);
|
|
4694
4965
|
}
|
|
4695
4966
|
|
|
4967
|
+
public async updateFeatureBitFlagsBuilderCodes(
|
|
4968
|
+
enable: boolean
|
|
4969
|
+
): Promise<TransactionSignature> {
|
|
4970
|
+
const updateFeatureBitFlagsBuilderCodesIx =
|
|
4971
|
+
await this.getUpdateFeatureBitFlagsBuilderCodesIx(enable);
|
|
4972
|
+
|
|
4973
|
+
const tx = await this.buildTransaction(updateFeatureBitFlagsBuilderCodesIx);
|
|
4974
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
4975
|
+
|
|
4976
|
+
return txSig;
|
|
4977
|
+
}
|
|
4978
|
+
|
|
4979
|
+
public async getUpdateFeatureBitFlagsBuilderCodesIx(
|
|
4980
|
+
enable: boolean
|
|
4981
|
+
): Promise<TransactionInstruction> {
|
|
4982
|
+
return this.program.instruction.updateFeatureBitFlagsBuilderCodes(enable, {
|
|
4983
|
+
accounts: {
|
|
4984
|
+
admin: this.useHotWalletAdmin
|
|
4985
|
+
? this.wallet.publicKey
|
|
4986
|
+
: this.getStateAccount().admin,
|
|
4987
|
+
state: await this.getStatePublicKey(),
|
|
4988
|
+
},
|
|
4989
|
+
});
|
|
4990
|
+
}
|
|
4991
|
+
|
|
4992
|
+
public async updateFeatureBitFlagsBuilderReferral(
|
|
4993
|
+
enable: boolean
|
|
4994
|
+
): Promise<TransactionSignature> {
|
|
4995
|
+
const updateFeatureBitFlagsBuilderReferralIx =
|
|
4996
|
+
await this.getUpdateFeatureBitFlagsBuilderReferralIx(enable);
|
|
4997
|
+
|
|
4998
|
+
const tx = await this.buildTransaction(
|
|
4999
|
+
updateFeatureBitFlagsBuilderReferralIx
|
|
5000
|
+
);
|
|
5001
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
5002
|
+
|
|
5003
|
+
return txSig;
|
|
5004
|
+
}
|
|
5005
|
+
|
|
5006
|
+
public async getUpdateFeatureBitFlagsBuilderReferralIx(
|
|
5007
|
+
enable: boolean
|
|
5008
|
+
): Promise<TransactionInstruction> {
|
|
5009
|
+
return this.program.instruction.updateFeatureBitFlagsBuilderReferral(
|
|
5010
|
+
enable,
|
|
5011
|
+
{
|
|
5012
|
+
accounts: {
|
|
5013
|
+
admin: this.useHotWalletAdmin
|
|
5014
|
+
? this.wallet.publicKey
|
|
5015
|
+
: this.getStateAccount().admin,
|
|
5016
|
+
state: await this.getStatePublicKey(),
|
|
5017
|
+
},
|
|
5018
|
+
}
|
|
5019
|
+
);
|
|
5020
|
+
}
|
|
5021
|
+
|
|
4696
5022
|
public async updateFeatureBitFlagsMedianTriggerPrice(
|
|
4697
5023
|
enable: boolean
|
|
4698
5024
|
): Promise<TransactionSignature> {
|
|
@@ -4821,49 +5147,50 @@ export class AdminClient extends DriftClient {
|
|
|
4821
5147
|
);
|
|
4822
5148
|
}
|
|
4823
5149
|
|
|
4824
|
-
public async
|
|
5150
|
+
public async updateFeatureBitFlagsSettleLpPool(
|
|
4825
5151
|
enable: boolean
|
|
4826
5152
|
): Promise<TransactionSignature> {
|
|
4827
|
-
const
|
|
4828
|
-
await this.
|
|
5153
|
+
const updateFeatureBitFlagsSettleLpPoolIx =
|
|
5154
|
+
await this.getUpdateFeatureBitFlagsSettleLpPoolIx(enable);
|
|
4829
5155
|
|
|
4830
|
-
const tx = await this.buildTransaction(
|
|
5156
|
+
const tx = await this.buildTransaction(updateFeatureBitFlagsSettleLpPoolIx);
|
|
4831
5157
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
4832
5158
|
|
|
4833
5159
|
return txSig;
|
|
4834
5160
|
}
|
|
4835
5161
|
|
|
4836
|
-
public async
|
|
5162
|
+
public async getUpdateFeatureBitFlagsSettleLpPoolIx(
|
|
4837
5163
|
enable: boolean
|
|
4838
5164
|
): Promise<TransactionInstruction> {
|
|
4839
|
-
return this.program.instruction.
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
: this.
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
5165
|
+
return await this.program.instruction.updateFeatureBitFlagsSettleLpPool(
|
|
5166
|
+
enable,
|
|
5167
|
+
{
|
|
5168
|
+
accounts: {
|
|
5169
|
+
admin: this.useHotWalletAdmin
|
|
5170
|
+
? this.wallet.publicKey
|
|
5171
|
+
: this.getStateAccount().admin,
|
|
5172
|
+
state: await this.getStatePublicKey(),
|
|
5173
|
+
},
|
|
5174
|
+
}
|
|
5175
|
+
);
|
|
4847
5176
|
}
|
|
4848
5177
|
|
|
4849
|
-
public async
|
|
5178
|
+
public async updateFeatureBitFlagsSwapLpPool(
|
|
4850
5179
|
enable: boolean
|
|
4851
5180
|
): Promise<TransactionSignature> {
|
|
4852
|
-
const
|
|
4853
|
-
await this.
|
|
5181
|
+
const updateFeatureBitFlagsSettleLpPoolIx =
|
|
5182
|
+
await this.getUpdateFeatureBitFlagsSwapLpPoolIx(enable);
|
|
4854
5183
|
|
|
4855
|
-
const tx = await this.buildTransaction(
|
|
4856
|
-
updateFeatureBitFlagsBuilderReferralIx
|
|
4857
|
-
);
|
|
5184
|
+
const tx = await this.buildTransaction(updateFeatureBitFlagsSettleLpPoolIx);
|
|
4858
5185
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
4859
5186
|
|
|
4860
5187
|
return txSig;
|
|
4861
5188
|
}
|
|
4862
5189
|
|
|
4863
|
-
public async
|
|
5190
|
+
public async getUpdateFeatureBitFlagsSwapLpPoolIx(
|
|
4864
5191
|
enable: boolean
|
|
4865
5192
|
): Promise<TransactionInstruction> {
|
|
4866
|
-
return this.program.instruction.
|
|
5193
|
+
return await this.program.instruction.updateFeatureBitFlagsSwapLpPool(
|
|
4867
5194
|
enable,
|
|
4868
5195
|
{
|
|
4869
5196
|
accounts: {
|
|
@@ -4876,22 +5203,50 @@ export class AdminClient extends DriftClient {
|
|
|
4876
5203
|
);
|
|
4877
5204
|
}
|
|
4878
5205
|
|
|
4879
|
-
public async
|
|
4880
|
-
|
|
4881
|
-
disable: boolean
|
|
5206
|
+
public async updateFeatureBitFlagsMintRedeemLpPool(
|
|
5207
|
+
enable: boolean
|
|
4882
5208
|
): Promise<TransactionSignature> {
|
|
4883
|
-
const
|
|
4884
|
-
await this.
|
|
5209
|
+
const updateFeatureBitFlagsSettleLpPoolIx =
|
|
5210
|
+
await this.getUpdateFeatureBitFlagsMintRedeemLpPoolIx(enable);
|
|
4885
5211
|
|
|
4886
|
-
const tx = await this.buildTransaction(
|
|
5212
|
+
const tx = await this.buildTransaction(updateFeatureBitFlagsSettleLpPoolIx);
|
|
4887
5213
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
4888
5214
|
|
|
4889
5215
|
return txSig;
|
|
4890
5216
|
}
|
|
4891
5217
|
|
|
4892
|
-
public async
|
|
4893
|
-
|
|
4894
|
-
|
|
5218
|
+
public async getUpdateFeatureBitFlagsMintRedeemLpPoolIx(
|
|
5219
|
+
enable: boolean
|
|
5220
|
+
): Promise<TransactionInstruction> {
|
|
5221
|
+
return await this.program.instruction.updateFeatureBitFlagsMintRedeemLpPool(
|
|
5222
|
+
enable,
|
|
5223
|
+
{
|
|
5224
|
+
accounts: {
|
|
5225
|
+
admin: this.useHotWalletAdmin
|
|
5226
|
+
? this.wallet.publicKey
|
|
5227
|
+
: this.getStateAccount().admin,
|
|
5228
|
+
state: await this.getStatePublicKey(),
|
|
5229
|
+
},
|
|
5230
|
+
}
|
|
5231
|
+
);
|
|
5232
|
+
}
|
|
5233
|
+
|
|
5234
|
+
public async adminDisableUpdatePerpBidAskTwap(
|
|
5235
|
+
authority: PublicKey,
|
|
5236
|
+
disable: boolean
|
|
5237
|
+
): Promise<TransactionSignature> {
|
|
5238
|
+
const disableBidAskTwapUpdateIx =
|
|
5239
|
+
await this.getAdminDisableUpdatePerpBidAskTwapIx(authority, disable);
|
|
5240
|
+
|
|
5241
|
+
const tx = await this.buildTransaction(disableBidAskTwapUpdateIx);
|
|
5242
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
5243
|
+
|
|
5244
|
+
return txSig;
|
|
5245
|
+
}
|
|
5246
|
+
|
|
5247
|
+
public async getAdminDisableUpdatePerpBidAskTwapIx(
|
|
5248
|
+
authority: PublicKey,
|
|
5249
|
+
disable: boolean
|
|
4895
5250
|
): Promise<TransactionInstruction> {
|
|
4896
5251
|
return await this.program.instruction.adminDisableUpdatePerpBidAskTwap(
|
|
4897
5252
|
disable,
|
|
@@ -4909,4 +5264,1220 @@ export class AdminClient extends DriftClient {
|
|
|
4909
5264
|
}
|
|
4910
5265
|
);
|
|
4911
5266
|
}
|
|
5267
|
+
|
|
5268
|
+
public async initializeLpPool(
|
|
5269
|
+
lpPoolId: number,
|
|
5270
|
+
minMintFee: BN,
|
|
5271
|
+
maxAum: BN,
|
|
5272
|
+
maxSettleQuoteAmountPerMarket: BN,
|
|
5273
|
+
mint: Keypair,
|
|
5274
|
+
whitelistMint?: PublicKey
|
|
5275
|
+
): Promise<TransactionSignature> {
|
|
5276
|
+
const ixs = await this.getInitializeLpPoolIx(
|
|
5277
|
+
lpPoolId,
|
|
5278
|
+
minMintFee,
|
|
5279
|
+
maxAum,
|
|
5280
|
+
maxSettleQuoteAmountPerMarket,
|
|
5281
|
+
mint,
|
|
5282
|
+
whitelistMint
|
|
5283
|
+
);
|
|
5284
|
+
const tx = await this.buildTransaction(ixs);
|
|
5285
|
+
const { txSig } = await this.sendTransaction(tx, [mint]);
|
|
5286
|
+
return txSig;
|
|
5287
|
+
}
|
|
5288
|
+
|
|
5289
|
+
public async getInitializeLpPoolIx(
|
|
5290
|
+
lpPoolId: number,
|
|
5291
|
+
minMintFee: BN,
|
|
5292
|
+
maxAum: BN,
|
|
5293
|
+
maxSettleQuoteAmountPerMarket: BN,
|
|
5294
|
+
mint: Keypair,
|
|
5295
|
+
whitelistMint?: PublicKey
|
|
5296
|
+
): Promise<TransactionInstruction[]> {
|
|
5297
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5298
|
+
const ammConstituentMapping = getAmmConstituentMappingPublicKey(
|
|
5299
|
+
this.program.programId,
|
|
5300
|
+
lpPool
|
|
5301
|
+
);
|
|
5302
|
+
const constituentTargetBase = getConstituentTargetBasePublicKey(
|
|
5303
|
+
this.program.programId,
|
|
5304
|
+
lpPool
|
|
5305
|
+
);
|
|
5306
|
+
|
|
5307
|
+
const lamports =
|
|
5308
|
+
await this.program.provider.connection.getMinimumBalanceForRentExemption(
|
|
5309
|
+
MINT_SIZE
|
|
5310
|
+
);
|
|
5311
|
+
const createMintAccountIx = SystemProgram.createAccount({
|
|
5312
|
+
fromPubkey: this.wallet.publicKey,
|
|
5313
|
+
newAccountPubkey: mint.publicKey,
|
|
5314
|
+
space: MINT_SIZE,
|
|
5315
|
+
lamports: Math.min(0.05 * LAMPORTS_PER_SOL, lamports), // should be 0.0014616 ? but bankrun returns 10 SOL
|
|
5316
|
+
programId: TOKEN_PROGRAM_ID,
|
|
5317
|
+
});
|
|
5318
|
+
const createMintIx = createInitializeMint2Instruction(
|
|
5319
|
+
mint.publicKey,
|
|
5320
|
+
6,
|
|
5321
|
+
lpPool,
|
|
5322
|
+
null,
|
|
5323
|
+
TOKEN_PROGRAM_ID
|
|
5324
|
+
);
|
|
5325
|
+
|
|
5326
|
+
return [
|
|
5327
|
+
createMintAccountIx,
|
|
5328
|
+
createMintIx,
|
|
5329
|
+
this.program.instruction.initializeLpPool(
|
|
5330
|
+
lpPoolId,
|
|
5331
|
+
minMintFee,
|
|
5332
|
+
maxAum,
|
|
5333
|
+
maxSettleQuoteAmountPerMarket,
|
|
5334
|
+
whitelistMint ?? PublicKey.default,
|
|
5335
|
+
{
|
|
5336
|
+
accounts: {
|
|
5337
|
+
admin: this.wallet.publicKey,
|
|
5338
|
+
lpPool,
|
|
5339
|
+
lpPoolTokenVault: getLpPoolTokenVaultPublicKey(
|
|
5340
|
+
this.program.programId,
|
|
5341
|
+
lpPool
|
|
5342
|
+
),
|
|
5343
|
+
constituentCorrelations: getConstituentCorrelationsPublicKey(
|
|
5344
|
+
this.program.programId,
|
|
5345
|
+
lpPool
|
|
5346
|
+
),
|
|
5347
|
+
ammConstituentMapping,
|
|
5348
|
+
constituentTargetBase,
|
|
5349
|
+
mint: mint.publicKey,
|
|
5350
|
+
state: await this.getStatePublicKey(),
|
|
5351
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5352
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
5353
|
+
systemProgram: SystemProgram.programId,
|
|
5354
|
+
},
|
|
5355
|
+
signers: [mint],
|
|
5356
|
+
}
|
|
5357
|
+
),
|
|
5358
|
+
];
|
|
5359
|
+
}
|
|
5360
|
+
|
|
5361
|
+
public async initializeConstituent(
|
|
5362
|
+
lpPoolId: number,
|
|
5363
|
+
initializeConstituentParams: InitializeConstituentParams
|
|
5364
|
+
): Promise<TransactionSignature> {
|
|
5365
|
+
const ixs = await this.getInitializeConstituentIx(
|
|
5366
|
+
lpPoolId,
|
|
5367
|
+
initializeConstituentParams
|
|
5368
|
+
);
|
|
5369
|
+
const tx = await this.buildTransaction(ixs);
|
|
5370
|
+
const { txSig } = await this.sendTransaction(tx, []);
|
|
5371
|
+
return txSig;
|
|
5372
|
+
}
|
|
5373
|
+
|
|
5374
|
+
public async getInitializeConstituentIx(
|
|
5375
|
+
lpPoolId: number,
|
|
5376
|
+
initializeConstituentParams: InitializeConstituentParams
|
|
5377
|
+
): Promise<TransactionInstruction[]> {
|
|
5378
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5379
|
+
const spotMarketIndex = initializeConstituentParams.spotMarketIndex;
|
|
5380
|
+
const constituentTargetBase = getConstituentTargetBasePublicKey(
|
|
5381
|
+
this.program.programId,
|
|
5382
|
+
lpPool
|
|
5383
|
+
);
|
|
5384
|
+
const constituent = getConstituentPublicKey(
|
|
5385
|
+
this.program.programId,
|
|
5386
|
+
lpPool,
|
|
5387
|
+
spotMarketIndex
|
|
5388
|
+
);
|
|
5389
|
+
const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
|
|
5390
|
+
|
|
5391
|
+
return [
|
|
5392
|
+
this.program.instruction.initializeConstituent(
|
|
5393
|
+
spotMarketIndex,
|
|
5394
|
+
initializeConstituentParams.decimals,
|
|
5395
|
+
initializeConstituentParams.maxWeightDeviation,
|
|
5396
|
+
initializeConstituentParams.swapFeeMin,
|
|
5397
|
+
initializeConstituentParams.swapFeeMax,
|
|
5398
|
+
initializeConstituentParams.maxBorrowTokenAmount,
|
|
5399
|
+
initializeConstituentParams.oracleStalenessThreshold,
|
|
5400
|
+
initializeConstituentParams.costToTrade,
|
|
5401
|
+
initializeConstituentParams.constituentDerivativeIndex != null
|
|
5402
|
+
? initializeConstituentParams.constituentDerivativeIndex
|
|
5403
|
+
: null,
|
|
5404
|
+
initializeConstituentParams.constituentDerivativeDepegThreshold != null
|
|
5405
|
+
? initializeConstituentParams.constituentDerivativeDepegThreshold
|
|
5406
|
+
: ZERO,
|
|
5407
|
+
initializeConstituentParams.constituentDerivativeIndex != null
|
|
5408
|
+
? initializeConstituentParams.derivativeWeight
|
|
5409
|
+
: ZERO,
|
|
5410
|
+
initializeConstituentParams.volatility != null
|
|
5411
|
+
? initializeConstituentParams.volatility
|
|
5412
|
+
: 10,
|
|
5413
|
+
initializeConstituentParams.gammaExecution != null
|
|
5414
|
+
? initializeConstituentParams.gammaExecution
|
|
5415
|
+
: 2,
|
|
5416
|
+
initializeConstituentParams.gammaInventory != null
|
|
5417
|
+
? initializeConstituentParams.gammaInventory
|
|
5418
|
+
: 2,
|
|
5419
|
+
initializeConstituentParams.xi != null
|
|
5420
|
+
? initializeConstituentParams.xi
|
|
5421
|
+
: 2,
|
|
5422
|
+
initializeConstituentParams.constituentCorrelations,
|
|
5423
|
+
{
|
|
5424
|
+
accounts: {
|
|
5425
|
+
admin: this.wallet.publicKey,
|
|
5426
|
+
lpPool,
|
|
5427
|
+
constituentTargetBase,
|
|
5428
|
+
constituent,
|
|
5429
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
5430
|
+
systemProgram: SystemProgram.programId,
|
|
5431
|
+
state: await this.getStatePublicKey(),
|
|
5432
|
+
spotMarketMint: spotMarketAccount.mint,
|
|
5433
|
+
constituentVault: getConstituentVaultPublicKey(
|
|
5434
|
+
this.program.programId,
|
|
5435
|
+
lpPool,
|
|
5436
|
+
spotMarketIndex
|
|
5437
|
+
),
|
|
5438
|
+
constituentCorrelations: getConstituentCorrelationsPublicKey(
|
|
5439
|
+
this.program.programId,
|
|
5440
|
+
lpPool
|
|
5441
|
+
),
|
|
5442
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
5443
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
5444
|
+
},
|
|
5445
|
+
signers: [],
|
|
5446
|
+
}
|
|
5447
|
+
),
|
|
5448
|
+
];
|
|
5449
|
+
}
|
|
5450
|
+
|
|
5451
|
+
public async updateConstituentStatus(
|
|
5452
|
+
constituent: PublicKey,
|
|
5453
|
+
constituentStatus: ConstituentStatus
|
|
5454
|
+
): Promise<TransactionSignature> {
|
|
5455
|
+
const updateConstituentStatusIx = await this.getUpdateConstituentStatusIx(
|
|
5456
|
+
constituent,
|
|
5457
|
+
constituentStatus
|
|
5458
|
+
);
|
|
5459
|
+
|
|
5460
|
+
const tx = await this.buildTransaction(updateConstituentStatusIx);
|
|
5461
|
+
|
|
5462
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
5463
|
+
|
|
5464
|
+
return txSig;
|
|
5465
|
+
}
|
|
5466
|
+
|
|
5467
|
+
public async getUpdateConstituentStatusIx(
|
|
5468
|
+
constituent: PublicKey,
|
|
5469
|
+
constituentStatus: ConstituentStatus
|
|
5470
|
+
): Promise<TransactionInstruction> {
|
|
5471
|
+
return await this.program.instruction.updateConstituentStatus(
|
|
5472
|
+
constituentStatus,
|
|
5473
|
+
{
|
|
5474
|
+
accounts: {
|
|
5475
|
+
constituent,
|
|
5476
|
+
admin: this.isSubscribed
|
|
5477
|
+
? this.getStateAccount().admin
|
|
5478
|
+
: this.wallet.publicKey,
|
|
5479
|
+
state: await this.getStatePublicKey(),
|
|
5480
|
+
},
|
|
5481
|
+
}
|
|
5482
|
+
);
|
|
5483
|
+
}
|
|
5484
|
+
|
|
5485
|
+
public async updateConstituentPausedOperations(
|
|
5486
|
+
constituent: PublicKey,
|
|
5487
|
+
pausedOperations: number
|
|
5488
|
+
): Promise<TransactionSignature> {
|
|
5489
|
+
const updateConstituentPausedOperationsIx =
|
|
5490
|
+
await this.getUpdateConstituentPausedOperationsIx(
|
|
5491
|
+
constituent,
|
|
5492
|
+
pausedOperations
|
|
5493
|
+
);
|
|
5494
|
+
|
|
5495
|
+
const tx = await this.buildTransaction(updateConstituentPausedOperationsIx);
|
|
5496
|
+
|
|
5497
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
5498
|
+
|
|
5499
|
+
return txSig;
|
|
5500
|
+
}
|
|
5501
|
+
|
|
5502
|
+
public async getUpdateConstituentPausedOperationsIx(
|
|
5503
|
+
constituent: PublicKey,
|
|
5504
|
+
pausedOperations: number
|
|
5505
|
+
): Promise<TransactionInstruction> {
|
|
5506
|
+
return await this.program.instruction.updateConstituentPausedOperations(
|
|
5507
|
+
pausedOperations,
|
|
5508
|
+
{
|
|
5509
|
+
accounts: {
|
|
5510
|
+
constituent,
|
|
5511
|
+
admin: this.isSubscribed
|
|
5512
|
+
? this.getStateAccount().admin
|
|
5513
|
+
: this.wallet.publicKey,
|
|
5514
|
+
state: await this.getStatePublicKey(),
|
|
5515
|
+
},
|
|
5516
|
+
}
|
|
5517
|
+
);
|
|
5518
|
+
}
|
|
5519
|
+
|
|
5520
|
+
public async updateConstituentParams(
|
|
5521
|
+
lpPoolId: number,
|
|
5522
|
+
constituentPublicKey: PublicKey,
|
|
5523
|
+
updateConstituentParams: {
|
|
5524
|
+
maxWeightDeviation?: BN;
|
|
5525
|
+
swapFeeMin?: BN;
|
|
5526
|
+
swapFeeMax?: BN;
|
|
5527
|
+
maxBorrowTokenAmount?: BN;
|
|
5528
|
+
oracleStalenessThreshold?: BN;
|
|
5529
|
+
costToTradeBps?: number;
|
|
5530
|
+
derivativeWeight?: BN;
|
|
5531
|
+
constituentDerivativeIndex?: number;
|
|
5532
|
+
volatility?: BN;
|
|
5533
|
+
gammaExecution?: number;
|
|
5534
|
+
gammaInventory?: number;
|
|
5535
|
+
xi?: number;
|
|
5536
|
+
}
|
|
5537
|
+
): Promise<TransactionSignature> {
|
|
5538
|
+
const ixs = await this.getUpdateConstituentParamsIx(
|
|
5539
|
+
lpPoolId,
|
|
5540
|
+
constituentPublicKey,
|
|
5541
|
+
updateConstituentParams
|
|
5542
|
+
);
|
|
5543
|
+
const tx = await this.buildTransaction(ixs);
|
|
5544
|
+
const { txSig } = await this.sendTransaction(tx, []);
|
|
5545
|
+
return txSig;
|
|
5546
|
+
}
|
|
5547
|
+
|
|
5548
|
+
public async getUpdateConstituentParamsIx(
|
|
5549
|
+
lpPoolId: number,
|
|
5550
|
+
constituentPublicKey: PublicKey,
|
|
5551
|
+
updateConstituentParams: {
|
|
5552
|
+
maxWeightDeviation?: BN;
|
|
5553
|
+
swapFeeMin?: BN;
|
|
5554
|
+
swapFeeMax?: BN;
|
|
5555
|
+
maxBorrowTokenAmount?: BN;
|
|
5556
|
+
oracleStalenessThreshold?: BN;
|
|
5557
|
+
derivativeWeight?: BN;
|
|
5558
|
+
constituentDerivativeIndex?: number;
|
|
5559
|
+
volatility?: BN;
|
|
5560
|
+
gammaExecution?: number;
|
|
5561
|
+
gammaInventory?: number;
|
|
5562
|
+
xi?: number;
|
|
5563
|
+
}
|
|
5564
|
+
): Promise<TransactionInstruction[]> {
|
|
5565
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5566
|
+
return [
|
|
5567
|
+
this.program.instruction.updateConstituentParams(
|
|
5568
|
+
Object.assign(
|
|
5569
|
+
{
|
|
5570
|
+
maxWeightDeviation: null,
|
|
5571
|
+
swapFeeMin: null,
|
|
5572
|
+
swapFeeMax: null,
|
|
5573
|
+
maxBorrowTokenAmount: null,
|
|
5574
|
+
oracleStalenessThreshold: null,
|
|
5575
|
+
costToTradeBps: null,
|
|
5576
|
+
stablecoinWeight: null,
|
|
5577
|
+
derivativeWeight: null,
|
|
5578
|
+
constituentDerivativeIndex: null,
|
|
5579
|
+
volatility: null,
|
|
5580
|
+
gammaExecution: null,
|
|
5581
|
+
gammaInventory: null,
|
|
5582
|
+
xi: null,
|
|
5583
|
+
},
|
|
5584
|
+
updateConstituentParams
|
|
5585
|
+
),
|
|
5586
|
+
{
|
|
5587
|
+
accounts: {
|
|
5588
|
+
admin: this.wallet.publicKey,
|
|
5589
|
+
constituent: constituentPublicKey,
|
|
5590
|
+
state: await this.getStatePublicKey(),
|
|
5591
|
+
lpPool,
|
|
5592
|
+
constituentTargetBase: getConstituentTargetBasePublicKey(
|
|
5593
|
+
this.program.programId,
|
|
5594
|
+
lpPool
|
|
5595
|
+
),
|
|
5596
|
+
},
|
|
5597
|
+
signers: [],
|
|
5598
|
+
}
|
|
5599
|
+
),
|
|
5600
|
+
];
|
|
5601
|
+
}
|
|
5602
|
+
|
|
5603
|
+
public async updateLpPoolParams(
|
|
5604
|
+
lpPoolId: number,
|
|
5605
|
+
updateLpPoolParams: {
|
|
5606
|
+
maxSettleQuoteAmount?: BN;
|
|
5607
|
+
volatility?: BN;
|
|
5608
|
+
gammaExecution?: number;
|
|
5609
|
+
xi?: number;
|
|
5610
|
+
whitelistMint?: PublicKey;
|
|
5611
|
+
maxAum?: BN;
|
|
5612
|
+
}
|
|
5613
|
+
): Promise<TransactionSignature> {
|
|
5614
|
+
const ixs = await this.getUpdateLpPoolParamsIx(
|
|
5615
|
+
lpPoolId,
|
|
5616
|
+
updateLpPoolParams
|
|
5617
|
+
);
|
|
5618
|
+
const tx = await this.buildTransaction(ixs);
|
|
5619
|
+
const { txSig } = await this.sendTransaction(tx, []);
|
|
5620
|
+
return txSig;
|
|
5621
|
+
}
|
|
5622
|
+
|
|
5623
|
+
public async getUpdateLpPoolParamsIx(
|
|
5624
|
+
lpPoolId: number,
|
|
5625
|
+
updateLpPoolParams: {
|
|
5626
|
+
maxSettleQuoteAmount?: BN;
|
|
5627
|
+
volatility?: BN;
|
|
5628
|
+
gammaExecution?: number;
|
|
5629
|
+
xi?: number;
|
|
5630
|
+
whitelistMint?: PublicKey;
|
|
5631
|
+
maxAum?: BN;
|
|
5632
|
+
}
|
|
5633
|
+
): Promise<TransactionInstruction[]> {
|
|
5634
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5635
|
+
return [
|
|
5636
|
+
this.program.instruction.updateLpPoolParams(
|
|
5637
|
+
Object.assign(
|
|
5638
|
+
{
|
|
5639
|
+
maxSettleQuoteAmount: null,
|
|
5640
|
+
volatility: null,
|
|
5641
|
+
gammaExecution: null,
|
|
5642
|
+
xi: null,
|
|
5643
|
+
whitelistMint: null,
|
|
5644
|
+
maxAum: null,
|
|
5645
|
+
},
|
|
5646
|
+
updateLpPoolParams
|
|
5647
|
+
),
|
|
5648
|
+
{
|
|
5649
|
+
accounts: {
|
|
5650
|
+
admin: this.wallet.publicKey,
|
|
5651
|
+
state: await this.getStatePublicKey(),
|
|
5652
|
+
lpPool,
|
|
5653
|
+
},
|
|
5654
|
+
signers: [],
|
|
5655
|
+
}
|
|
5656
|
+
),
|
|
5657
|
+
];
|
|
5658
|
+
}
|
|
5659
|
+
|
|
5660
|
+
public async addAmmConstituentMappingData(
|
|
5661
|
+
lpPoolId: number,
|
|
5662
|
+
addAmmConstituentMappingData: AddAmmConstituentMappingDatum[]
|
|
5663
|
+
): Promise<TransactionSignature> {
|
|
5664
|
+
const ixs = await this.getAddAmmConstituentMappingDataIx(
|
|
5665
|
+
lpPoolId,
|
|
5666
|
+
addAmmConstituentMappingData
|
|
5667
|
+
);
|
|
5668
|
+
const tx = await this.buildTransaction(ixs);
|
|
5669
|
+
const { txSig } = await this.sendTransaction(tx, []);
|
|
5670
|
+
return txSig;
|
|
5671
|
+
}
|
|
5672
|
+
|
|
5673
|
+
public async getAddAmmConstituentMappingDataIx(
|
|
5674
|
+
lpPoolId: number,
|
|
5675
|
+
addAmmConstituentMappingData: AddAmmConstituentMappingDatum[]
|
|
5676
|
+
): Promise<TransactionInstruction[]> {
|
|
5677
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5678
|
+
const ammConstituentMapping = getAmmConstituentMappingPublicKey(
|
|
5679
|
+
this.program.programId,
|
|
5680
|
+
lpPool
|
|
5681
|
+
);
|
|
5682
|
+
const constituentTargetBase = getConstituentTargetBasePublicKey(
|
|
5683
|
+
this.program.programId,
|
|
5684
|
+
lpPool
|
|
5685
|
+
);
|
|
5686
|
+
return [
|
|
5687
|
+
this.program.instruction.addAmmConstituentMappingData(
|
|
5688
|
+
addAmmConstituentMappingData,
|
|
5689
|
+
{
|
|
5690
|
+
accounts: {
|
|
5691
|
+
admin: this.wallet.publicKey,
|
|
5692
|
+
lpPool,
|
|
5693
|
+
ammConstituentMapping,
|
|
5694
|
+
constituentTargetBase,
|
|
5695
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
5696
|
+
systemProgram: SystemProgram.programId,
|
|
5697
|
+
state: await this.getStatePublicKey(),
|
|
5698
|
+
},
|
|
5699
|
+
}
|
|
5700
|
+
),
|
|
5701
|
+
];
|
|
5702
|
+
}
|
|
5703
|
+
|
|
5704
|
+
public async updateAmmConstituentMappingData(
|
|
5705
|
+
lpPoolId: number,
|
|
5706
|
+
addAmmConstituentMappingData: AddAmmConstituentMappingDatum[]
|
|
5707
|
+
): Promise<TransactionSignature> {
|
|
5708
|
+
const ixs = await this.getUpdateAmmConstituentMappingDataIx(
|
|
5709
|
+
lpPoolId,
|
|
5710
|
+
addAmmConstituentMappingData
|
|
5711
|
+
);
|
|
5712
|
+
const tx = await this.buildTransaction(ixs);
|
|
5713
|
+
const { txSig } = await this.sendTransaction(tx, []);
|
|
5714
|
+
return txSig;
|
|
5715
|
+
}
|
|
5716
|
+
|
|
5717
|
+
public async getUpdateAmmConstituentMappingDataIx(
|
|
5718
|
+
lpPoolId: number,
|
|
5719
|
+
addAmmConstituentMappingData: AddAmmConstituentMappingDatum[]
|
|
5720
|
+
): Promise<TransactionInstruction[]> {
|
|
5721
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5722
|
+
const ammConstituentMapping = getAmmConstituentMappingPublicKey(
|
|
5723
|
+
this.program.programId,
|
|
5724
|
+
lpPool
|
|
5725
|
+
);
|
|
5726
|
+
return [
|
|
5727
|
+
this.program.instruction.updateAmmConstituentMappingData(
|
|
5728
|
+
addAmmConstituentMappingData,
|
|
5729
|
+
{
|
|
5730
|
+
accounts: {
|
|
5731
|
+
admin: this.wallet.publicKey,
|
|
5732
|
+
lpPool,
|
|
5733
|
+
ammConstituentMapping,
|
|
5734
|
+
systemProgram: SystemProgram.programId,
|
|
5735
|
+
state: await this.getStatePublicKey(),
|
|
5736
|
+
},
|
|
5737
|
+
}
|
|
5738
|
+
),
|
|
5739
|
+
];
|
|
5740
|
+
}
|
|
5741
|
+
|
|
5742
|
+
public async removeAmmConstituentMappingData(
|
|
5743
|
+
lpPoolId: number,
|
|
5744
|
+
perpMarketIndex: number,
|
|
5745
|
+
constituentIndex: number
|
|
5746
|
+
): Promise<TransactionSignature> {
|
|
5747
|
+
const ixs = await this.getRemoveAmmConstituentMappingDataIx(
|
|
5748
|
+
lpPoolId,
|
|
5749
|
+
perpMarketIndex,
|
|
5750
|
+
constituentIndex
|
|
5751
|
+
);
|
|
5752
|
+
const tx = await this.buildTransaction(ixs);
|
|
5753
|
+
const { txSig } = await this.sendTransaction(tx, []);
|
|
5754
|
+
return txSig;
|
|
5755
|
+
}
|
|
5756
|
+
|
|
5757
|
+
public async getRemoveAmmConstituentMappingDataIx(
|
|
5758
|
+
lpPoolId: number,
|
|
5759
|
+
perpMarketIndex: number,
|
|
5760
|
+
constituentIndex: number
|
|
5761
|
+
): Promise<TransactionInstruction[]> {
|
|
5762
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5763
|
+
const ammConstituentMapping = getAmmConstituentMappingPublicKey(
|
|
5764
|
+
this.program.programId,
|
|
5765
|
+
lpPool
|
|
5766
|
+
);
|
|
5767
|
+
|
|
5768
|
+
return [
|
|
5769
|
+
this.program.instruction.removeAmmConstituentMappingData(
|
|
5770
|
+
perpMarketIndex,
|
|
5771
|
+
constituentIndex,
|
|
5772
|
+
{
|
|
5773
|
+
accounts: {
|
|
5774
|
+
admin: this.wallet.publicKey,
|
|
5775
|
+
lpPool,
|
|
5776
|
+
ammConstituentMapping,
|
|
5777
|
+
systemProgram: SystemProgram.programId,
|
|
5778
|
+
state: await this.getStatePublicKey(),
|
|
5779
|
+
},
|
|
5780
|
+
}
|
|
5781
|
+
),
|
|
5782
|
+
];
|
|
5783
|
+
}
|
|
5784
|
+
|
|
5785
|
+
public async updateConstituentCorrelationData(
|
|
5786
|
+
lpPoolId: number,
|
|
5787
|
+
index1: number,
|
|
5788
|
+
index2: number,
|
|
5789
|
+
correlation: BN
|
|
5790
|
+
): Promise<TransactionSignature> {
|
|
5791
|
+
const ixs = await this.getUpdateConstituentCorrelationDataIx(
|
|
5792
|
+
lpPoolId,
|
|
5793
|
+
index1,
|
|
5794
|
+
index2,
|
|
5795
|
+
correlation
|
|
5796
|
+
);
|
|
5797
|
+
const tx = await this.buildTransaction(ixs);
|
|
5798
|
+
const { txSig } = await this.sendTransaction(tx, []);
|
|
5799
|
+
return txSig;
|
|
5800
|
+
}
|
|
5801
|
+
|
|
5802
|
+
public async getUpdateConstituentCorrelationDataIx(
|
|
5803
|
+
lpPoolId: number,
|
|
5804
|
+
index1: number,
|
|
5805
|
+
index2: number,
|
|
5806
|
+
correlation: BN
|
|
5807
|
+
): Promise<TransactionInstruction[]> {
|
|
5808
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5809
|
+
return [
|
|
5810
|
+
this.program.instruction.updateConstituentCorrelationData(
|
|
5811
|
+
index1,
|
|
5812
|
+
index2,
|
|
5813
|
+
correlation,
|
|
5814
|
+
{
|
|
5815
|
+
accounts: {
|
|
5816
|
+
admin: this.wallet.publicKey,
|
|
5817
|
+
lpPool,
|
|
5818
|
+
constituentCorrelations: getConstituentCorrelationsPublicKey(
|
|
5819
|
+
this.program.programId,
|
|
5820
|
+
lpPool
|
|
5821
|
+
),
|
|
5822
|
+
state: await this.getStatePublicKey(),
|
|
5823
|
+
},
|
|
5824
|
+
}
|
|
5825
|
+
),
|
|
5826
|
+
];
|
|
5827
|
+
}
|
|
5828
|
+
|
|
5829
|
+
/**
|
|
5830
|
+
* Get the drift begin_swap and end_swap instructions
|
|
5831
|
+
*
|
|
5832
|
+
* @param outMarketIndex the market index of the token you're buying
|
|
5833
|
+
* @param inMarketIndex the market index of the token you're selling
|
|
5834
|
+
* @param amountIn the amount of the token to sell
|
|
5835
|
+
* @param inTokenAccount the token account to move the tokens being sold (admin signer ata for lp swap)
|
|
5836
|
+
* @param outTokenAccount the token account to receive the tokens being bought (admin signer ata for lp swap)
|
|
5837
|
+
* @param limitPrice the limit price of the swap
|
|
5838
|
+
* @param reduceOnly
|
|
5839
|
+
* @param userAccountPublicKey optional, specify a custom userAccountPublicKey to use instead of getting the current user account; can be helpful if the account is being created within the current tx
|
|
5840
|
+
*/
|
|
5841
|
+
public async getSwapIx(
|
|
5842
|
+
{
|
|
5843
|
+
lpPoolId,
|
|
5844
|
+
outMarketIndex,
|
|
5845
|
+
inMarketIndex,
|
|
5846
|
+
amountIn,
|
|
5847
|
+
inTokenAccount,
|
|
5848
|
+
outTokenAccount,
|
|
5849
|
+
limitPrice,
|
|
5850
|
+
reduceOnly,
|
|
5851
|
+
userAccountPublicKey,
|
|
5852
|
+
}: {
|
|
5853
|
+
lpPoolId: number;
|
|
5854
|
+
outMarketIndex: number;
|
|
5855
|
+
inMarketIndex: number;
|
|
5856
|
+
amountIn: BN;
|
|
5857
|
+
inTokenAccount: PublicKey;
|
|
5858
|
+
outTokenAccount: PublicKey;
|
|
5859
|
+
limitPrice?: BN;
|
|
5860
|
+
reduceOnly?: SwapReduceOnly;
|
|
5861
|
+
userAccountPublicKey?: PublicKey;
|
|
5862
|
+
},
|
|
5863
|
+
lpSwap?: boolean
|
|
5864
|
+
): Promise<{
|
|
5865
|
+
beginSwapIx: TransactionInstruction;
|
|
5866
|
+
endSwapIx: TransactionInstruction;
|
|
5867
|
+
}> {
|
|
5868
|
+
if (!lpSwap) {
|
|
5869
|
+
return super.getSwapIx({
|
|
5870
|
+
outMarketIndex,
|
|
5871
|
+
inMarketIndex,
|
|
5872
|
+
amountIn,
|
|
5873
|
+
inTokenAccount,
|
|
5874
|
+
outTokenAccount,
|
|
5875
|
+
limitPrice,
|
|
5876
|
+
reduceOnly,
|
|
5877
|
+
userAccountPublicKey,
|
|
5878
|
+
});
|
|
5879
|
+
}
|
|
5880
|
+
const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
5881
|
+
const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
5882
|
+
|
|
5883
|
+
const outTokenProgram = this.getTokenProgramForSpotMarket(outSpotMarket);
|
|
5884
|
+
const inTokenProgram = this.getTokenProgramForSpotMarket(inSpotMarket);
|
|
5885
|
+
|
|
5886
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
5887
|
+
const outConstituent = getConstituentPublicKey(
|
|
5888
|
+
this.program.programId,
|
|
5889
|
+
lpPool,
|
|
5890
|
+
outMarketIndex
|
|
5891
|
+
);
|
|
5892
|
+
const inConstituent = getConstituentPublicKey(
|
|
5893
|
+
this.program.programId,
|
|
5894
|
+
lpPool,
|
|
5895
|
+
inMarketIndex
|
|
5896
|
+
);
|
|
5897
|
+
|
|
5898
|
+
const outConstituentTokenAccount = getConstituentVaultPublicKey(
|
|
5899
|
+
this.program.programId,
|
|
5900
|
+
lpPool,
|
|
5901
|
+
outMarketIndex
|
|
5902
|
+
);
|
|
5903
|
+
const inConstituentTokenAccount = getConstituentVaultPublicKey(
|
|
5904
|
+
this.program.programId,
|
|
5905
|
+
lpPool,
|
|
5906
|
+
inMarketIndex
|
|
5907
|
+
);
|
|
5908
|
+
|
|
5909
|
+
const beginSwapIx = this.program.instruction.beginLpSwap(
|
|
5910
|
+
inMarketIndex,
|
|
5911
|
+
outMarketIndex,
|
|
5912
|
+
amountIn,
|
|
5913
|
+
{
|
|
5914
|
+
accounts: {
|
|
5915
|
+
state: await this.getStatePublicKey(),
|
|
5916
|
+
admin: this.wallet.publicKey,
|
|
5917
|
+
signerOutTokenAccount: outTokenAccount,
|
|
5918
|
+
signerInTokenAccount: inTokenAccount,
|
|
5919
|
+
constituentOutTokenAccount: outConstituentTokenAccount,
|
|
5920
|
+
constituentInTokenAccount: inConstituentTokenAccount,
|
|
5921
|
+
outConstituent,
|
|
5922
|
+
inConstituent,
|
|
5923
|
+
lpPool,
|
|
5924
|
+
instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5925
|
+
tokenProgram: inTokenProgram,
|
|
5926
|
+
},
|
|
5927
|
+
}
|
|
5928
|
+
);
|
|
5929
|
+
|
|
5930
|
+
const remainingAccounts = [];
|
|
5931
|
+
remainingAccounts.push({
|
|
5932
|
+
pubkey: outTokenProgram,
|
|
5933
|
+
isWritable: false,
|
|
5934
|
+
isSigner: false,
|
|
5935
|
+
});
|
|
5936
|
+
|
|
5937
|
+
const endSwapIx = this.program.instruction.endLpSwap(
|
|
5938
|
+
inMarketIndex,
|
|
5939
|
+
outMarketIndex,
|
|
5940
|
+
{
|
|
5941
|
+
accounts: {
|
|
5942
|
+
state: await this.getStatePublicKey(),
|
|
5943
|
+
admin: this.wallet.publicKey,
|
|
5944
|
+
signerOutTokenAccount: outTokenAccount,
|
|
5945
|
+
signerInTokenAccount: inTokenAccount,
|
|
5946
|
+
constituentOutTokenAccount: outConstituentTokenAccount,
|
|
5947
|
+
constituentInTokenAccount: inConstituentTokenAccount,
|
|
5948
|
+
outConstituent,
|
|
5949
|
+
inConstituent,
|
|
5950
|
+
lpPool,
|
|
5951
|
+
tokenProgram: inTokenProgram,
|
|
5952
|
+
instructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5953
|
+
},
|
|
5954
|
+
remainingAccounts,
|
|
5955
|
+
}
|
|
5956
|
+
);
|
|
5957
|
+
|
|
5958
|
+
return { beginSwapIx, endSwapIx };
|
|
5959
|
+
}
|
|
5960
|
+
|
|
5961
|
+
public async getLpJupiterSwapIxV6({
|
|
5962
|
+
jupiterClient,
|
|
5963
|
+
outMarketIndex,
|
|
5964
|
+
inMarketIndex,
|
|
5965
|
+
amount,
|
|
5966
|
+
slippageBps,
|
|
5967
|
+
swapMode,
|
|
5968
|
+
onlyDirectRoutes,
|
|
5969
|
+
quote,
|
|
5970
|
+
lpPoolId,
|
|
5971
|
+
}: {
|
|
5972
|
+
jupiterClient: JupiterClient;
|
|
5973
|
+
outMarketIndex: number;
|
|
5974
|
+
inMarketIndex: number;
|
|
5975
|
+
outAssociatedTokenAccount?: PublicKey;
|
|
5976
|
+
inAssociatedTokenAccount?: PublicKey;
|
|
5977
|
+
amount: BN;
|
|
5978
|
+
slippageBps?: number;
|
|
5979
|
+
swapMode?: SwapMode;
|
|
5980
|
+
onlyDirectRoutes?: boolean;
|
|
5981
|
+
quote?: QuoteResponse;
|
|
5982
|
+
lpPoolId: number;
|
|
5983
|
+
}): Promise<{
|
|
5984
|
+
ixs: TransactionInstruction[];
|
|
5985
|
+
lookupTables: AddressLookupTableAccount[];
|
|
5986
|
+
}> {
|
|
5987
|
+
const outMarket = this.getSpotMarketAccount(outMarketIndex);
|
|
5988
|
+
const inMarket = this.getSpotMarketAccount(inMarketIndex);
|
|
5989
|
+
|
|
5990
|
+
if (!quote) {
|
|
5991
|
+
const fetchedQuote = await jupiterClient.getQuote({
|
|
5992
|
+
inputMint: inMarket.mint,
|
|
5993
|
+
outputMint: outMarket.mint,
|
|
5994
|
+
amount,
|
|
5995
|
+
slippageBps,
|
|
5996
|
+
swapMode,
|
|
5997
|
+
onlyDirectRoutes,
|
|
5998
|
+
});
|
|
5999
|
+
|
|
6000
|
+
quote = fetchedQuote;
|
|
6001
|
+
}
|
|
6002
|
+
|
|
6003
|
+
if (!quote) {
|
|
6004
|
+
throw new Error("Could not fetch Jupiter's quote. Please try again.");
|
|
6005
|
+
}
|
|
6006
|
+
|
|
6007
|
+
const isExactOut = swapMode === 'ExactOut' || quote.swapMode === 'ExactOut';
|
|
6008
|
+
const amountIn = new BN(quote.inAmount);
|
|
6009
|
+
const exactOutBufferedAmountIn = amountIn.muln(1001).divn(1000); // Add 10bp buffer
|
|
6010
|
+
|
|
6011
|
+
const transaction = await jupiterClient.getSwap({
|
|
6012
|
+
quote,
|
|
6013
|
+
userPublicKey: this.provider.wallet.publicKey,
|
|
6014
|
+
slippageBps,
|
|
6015
|
+
});
|
|
6016
|
+
|
|
6017
|
+
const { transactionMessage, lookupTables } =
|
|
6018
|
+
await jupiterClient.getTransactionMessageAndLookupTables({
|
|
6019
|
+
transaction,
|
|
6020
|
+
});
|
|
6021
|
+
|
|
6022
|
+
const jupiterInstructions = jupiterClient.getJupiterInstructions({
|
|
6023
|
+
transactionMessage,
|
|
6024
|
+
inputMint: inMarket.mint,
|
|
6025
|
+
outputMint: outMarket.mint,
|
|
6026
|
+
});
|
|
6027
|
+
|
|
6028
|
+
const preInstructions = [];
|
|
6029
|
+
const tokenProgram = this.getTokenProgramForSpotMarket(outMarket);
|
|
6030
|
+
const outAssociatedTokenAccount = await this.getAssociatedTokenAccount(
|
|
6031
|
+
outMarket.marketIndex,
|
|
6032
|
+
false,
|
|
6033
|
+
tokenProgram
|
|
6034
|
+
);
|
|
6035
|
+
|
|
6036
|
+
const outAccountInfo = await this.connection.getAccountInfo(
|
|
6037
|
+
outAssociatedTokenAccount
|
|
6038
|
+
);
|
|
6039
|
+
if (!outAccountInfo) {
|
|
6040
|
+
preInstructions.push(
|
|
6041
|
+
this.createAssociatedTokenAccountIdempotentInstruction(
|
|
6042
|
+
outAssociatedTokenAccount,
|
|
6043
|
+
this.provider.wallet.publicKey,
|
|
6044
|
+
this.provider.wallet.publicKey,
|
|
6045
|
+
outMarket.mint,
|
|
6046
|
+
tokenProgram
|
|
6047
|
+
)
|
|
6048
|
+
);
|
|
6049
|
+
}
|
|
6050
|
+
|
|
6051
|
+
const inTokenProgram = this.getTokenProgramForSpotMarket(inMarket);
|
|
6052
|
+
const inAssociatedTokenAccount = await this.getAssociatedTokenAccount(
|
|
6053
|
+
inMarket.marketIndex,
|
|
6054
|
+
false,
|
|
6055
|
+
inTokenProgram
|
|
6056
|
+
);
|
|
6057
|
+
|
|
6058
|
+
const inAccountInfo = await this.connection.getAccountInfo(
|
|
6059
|
+
inAssociatedTokenAccount
|
|
6060
|
+
);
|
|
6061
|
+
if (!inAccountInfo) {
|
|
6062
|
+
preInstructions.push(
|
|
6063
|
+
this.createAssociatedTokenAccountIdempotentInstruction(
|
|
6064
|
+
inAssociatedTokenAccount,
|
|
6065
|
+
this.provider.wallet.publicKey,
|
|
6066
|
+
this.provider.wallet.publicKey,
|
|
6067
|
+
inMarket.mint,
|
|
6068
|
+
tokenProgram
|
|
6069
|
+
)
|
|
6070
|
+
);
|
|
6071
|
+
}
|
|
6072
|
+
|
|
6073
|
+
const { beginSwapIx, endSwapIx } = await this.getSwapIx({
|
|
6074
|
+
lpPoolId,
|
|
6075
|
+
outMarketIndex,
|
|
6076
|
+
inMarketIndex,
|
|
6077
|
+
amountIn: isExactOut ? exactOutBufferedAmountIn : amountIn,
|
|
6078
|
+
inTokenAccount: inAssociatedTokenAccount,
|
|
6079
|
+
outTokenAccount: outAssociatedTokenAccount,
|
|
6080
|
+
});
|
|
6081
|
+
|
|
6082
|
+
const ixs = [
|
|
6083
|
+
...preInstructions,
|
|
6084
|
+
beginSwapIx,
|
|
6085
|
+
...jupiterInstructions,
|
|
6086
|
+
endSwapIx,
|
|
6087
|
+
];
|
|
6088
|
+
|
|
6089
|
+
return { ixs, lookupTables };
|
|
6090
|
+
}
|
|
6091
|
+
|
|
6092
|
+
public async getDevnetLpSwapIxs(
|
|
6093
|
+
amountIn: BN,
|
|
6094
|
+
amountOut: BN,
|
|
6095
|
+
externalUserAuthority: PublicKey,
|
|
6096
|
+
externalUserInTokenAccount: PublicKey,
|
|
6097
|
+
externalUserOutTokenAccount: PublicKey,
|
|
6098
|
+
inSpotMarketIndex: number,
|
|
6099
|
+
outSpotMarketIndex: number
|
|
6100
|
+
): Promise<TransactionInstruction[]> {
|
|
6101
|
+
const inSpotMarketAccount = this.getSpotMarketAccount(inSpotMarketIndex);
|
|
6102
|
+
const outSpotMarketAccount = this.getSpotMarketAccount(outSpotMarketIndex);
|
|
6103
|
+
|
|
6104
|
+
const outTokenAccount = await this.getAssociatedTokenAccount(
|
|
6105
|
+
outSpotMarketAccount.marketIndex,
|
|
6106
|
+
false,
|
|
6107
|
+
getTokenProgramForSpotMarket(outSpotMarketAccount)
|
|
6108
|
+
);
|
|
6109
|
+
const inTokenAccount = await this.getAssociatedTokenAccount(
|
|
6110
|
+
inSpotMarketAccount.marketIndex,
|
|
6111
|
+
false,
|
|
6112
|
+
getTokenProgramForSpotMarket(inSpotMarketAccount)
|
|
6113
|
+
);
|
|
6114
|
+
|
|
6115
|
+
const externalCreateInTokenAccountIx =
|
|
6116
|
+
this.createAssociatedTokenAccountIdempotentInstruction(
|
|
6117
|
+
externalUserInTokenAccount,
|
|
6118
|
+
this.wallet.publicKey,
|
|
6119
|
+
externalUserAuthority,
|
|
6120
|
+
this.getSpotMarketAccount(inSpotMarketIndex)!.mint
|
|
6121
|
+
);
|
|
6122
|
+
|
|
6123
|
+
const externalCreateOutTokenAccountIx =
|
|
6124
|
+
this.createAssociatedTokenAccountIdempotentInstruction(
|
|
6125
|
+
externalUserOutTokenAccount,
|
|
6126
|
+
this.wallet.publicKey,
|
|
6127
|
+
externalUserAuthority,
|
|
6128
|
+
this.getSpotMarketAccount(outSpotMarketIndex)!.mint
|
|
6129
|
+
);
|
|
6130
|
+
|
|
6131
|
+
const outTransferIx = createTransferCheckedInstruction(
|
|
6132
|
+
externalUserOutTokenAccount,
|
|
6133
|
+
outSpotMarketAccount.mint,
|
|
6134
|
+
outTokenAccount,
|
|
6135
|
+
externalUserAuthority,
|
|
6136
|
+
amountOut.toNumber(),
|
|
6137
|
+
outSpotMarketAccount.decimals,
|
|
6138
|
+
undefined,
|
|
6139
|
+
getTokenProgramForSpotMarket(outSpotMarketAccount)
|
|
6140
|
+
);
|
|
6141
|
+
|
|
6142
|
+
const inTransferIx = createTransferCheckedInstruction(
|
|
6143
|
+
inTokenAccount,
|
|
6144
|
+
inSpotMarketAccount.mint,
|
|
6145
|
+
externalUserInTokenAccount,
|
|
6146
|
+
this.wallet.publicKey,
|
|
6147
|
+
amountIn.toNumber(),
|
|
6148
|
+
inSpotMarketAccount.decimals,
|
|
6149
|
+
undefined,
|
|
6150
|
+
getTokenProgramForSpotMarket(inSpotMarketAccount)
|
|
6151
|
+
);
|
|
6152
|
+
|
|
6153
|
+
const ixs = [
|
|
6154
|
+
externalCreateInTokenAccountIx,
|
|
6155
|
+
externalCreateOutTokenAccountIx,
|
|
6156
|
+
outTransferIx,
|
|
6157
|
+
inTransferIx,
|
|
6158
|
+
];
|
|
6159
|
+
return ixs;
|
|
6160
|
+
}
|
|
6161
|
+
|
|
6162
|
+
public async getAllDevnetLpSwapIxs(
|
|
6163
|
+
lpPoolId: number,
|
|
6164
|
+
inMarketIndex: number,
|
|
6165
|
+
outMarketIndex: number,
|
|
6166
|
+
inAmount: BN,
|
|
6167
|
+
minOutAmount: BN,
|
|
6168
|
+
externalUserAuthority: PublicKey
|
|
6169
|
+
) {
|
|
6170
|
+
const { beginSwapIx, endSwapIx } = await this.getSwapIx(
|
|
6171
|
+
{
|
|
6172
|
+
lpPoolId,
|
|
6173
|
+
inMarketIndex,
|
|
6174
|
+
outMarketIndex,
|
|
6175
|
+
amountIn: inAmount,
|
|
6176
|
+
inTokenAccount: await this.getAssociatedTokenAccount(
|
|
6177
|
+
inMarketIndex,
|
|
6178
|
+
false
|
|
6179
|
+
),
|
|
6180
|
+
outTokenAccount: await this.getAssociatedTokenAccount(
|
|
6181
|
+
outMarketIndex,
|
|
6182
|
+
false
|
|
6183
|
+
),
|
|
6184
|
+
},
|
|
6185
|
+
true
|
|
6186
|
+
);
|
|
6187
|
+
|
|
6188
|
+
const devnetLpSwapIxs = await this.getDevnetLpSwapIxs(
|
|
6189
|
+
inAmount,
|
|
6190
|
+
minOutAmount,
|
|
6191
|
+
externalUserAuthority,
|
|
6192
|
+
await this.getAssociatedTokenAccount(
|
|
6193
|
+
inMarketIndex,
|
|
6194
|
+
false,
|
|
6195
|
+
getTokenProgramForSpotMarket(this.getSpotMarketAccount(inMarketIndex)),
|
|
6196
|
+
externalUserAuthority
|
|
6197
|
+
),
|
|
6198
|
+
await this.getAssociatedTokenAccount(
|
|
6199
|
+
outMarketIndex,
|
|
6200
|
+
false,
|
|
6201
|
+
getTokenProgramForSpotMarket(this.getSpotMarketAccount(outMarketIndex)),
|
|
6202
|
+
externalUserAuthority
|
|
6203
|
+
),
|
|
6204
|
+
inMarketIndex,
|
|
6205
|
+
outMarketIndex
|
|
6206
|
+
);
|
|
6207
|
+
|
|
6208
|
+
return [
|
|
6209
|
+
beginSwapIx,
|
|
6210
|
+
...devnetLpSwapIxs,
|
|
6211
|
+
endSwapIx,
|
|
6212
|
+
] as TransactionInstruction[];
|
|
6213
|
+
}
|
|
6214
|
+
|
|
6215
|
+
public async depositWithdrawToProgramVault(
|
|
6216
|
+
lpPoolId: number,
|
|
6217
|
+
depositMarketIndex: number,
|
|
6218
|
+
borrowMarketIndex: number,
|
|
6219
|
+
amountToDeposit: BN,
|
|
6220
|
+
amountToBorrow: BN
|
|
6221
|
+
): Promise<TransactionSignature> {
|
|
6222
|
+
const { depositIx, withdrawIx } =
|
|
6223
|
+
await this.getDepositWithdrawToProgramVaultIxs(
|
|
6224
|
+
lpPoolId,
|
|
6225
|
+
depositMarketIndex,
|
|
6226
|
+
borrowMarketIndex,
|
|
6227
|
+
amountToDeposit,
|
|
6228
|
+
amountToBorrow
|
|
6229
|
+
);
|
|
6230
|
+
|
|
6231
|
+
const tx = await this.buildTransaction([depositIx, withdrawIx]);
|
|
6232
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6233
|
+
return txSig;
|
|
6234
|
+
}
|
|
6235
|
+
|
|
6236
|
+
public async getDepositWithdrawToProgramVaultIxs(
|
|
6237
|
+
lpPoolId: number,
|
|
6238
|
+
depositMarketIndex: number,
|
|
6239
|
+
borrowMarketIndex: number,
|
|
6240
|
+
amountToDeposit: BN,
|
|
6241
|
+
amountToBorrow: BN
|
|
6242
|
+
): Promise<{
|
|
6243
|
+
depositIx: TransactionInstruction;
|
|
6244
|
+
withdrawIx: TransactionInstruction;
|
|
6245
|
+
}> {
|
|
6246
|
+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
|
|
6247
|
+
const depositSpotMarket = this.getSpotMarketAccount(depositMarketIndex);
|
|
6248
|
+
const withdrawSpotMarket = this.getSpotMarketAccount(borrowMarketIndex);
|
|
6249
|
+
|
|
6250
|
+
const depositTokenProgram =
|
|
6251
|
+
this.getTokenProgramForSpotMarket(depositSpotMarket);
|
|
6252
|
+
const withdrawTokenProgram =
|
|
6253
|
+
this.getTokenProgramForSpotMarket(withdrawSpotMarket);
|
|
6254
|
+
|
|
6255
|
+
const depositConstituent = getConstituentPublicKey(
|
|
6256
|
+
this.program.programId,
|
|
6257
|
+
lpPool,
|
|
6258
|
+
depositMarketIndex
|
|
6259
|
+
);
|
|
6260
|
+
const withdrawConstituent = getConstituentPublicKey(
|
|
6261
|
+
this.program.programId,
|
|
6262
|
+
lpPool,
|
|
6263
|
+
borrowMarketIndex
|
|
6264
|
+
);
|
|
6265
|
+
|
|
6266
|
+
const depositConstituentTokenAccount = getConstituentVaultPublicKey(
|
|
6267
|
+
this.program.programId,
|
|
6268
|
+
lpPool,
|
|
6269
|
+
depositMarketIndex
|
|
6270
|
+
);
|
|
6271
|
+
const withdrawConstituentTokenAccount = getConstituentVaultPublicKey(
|
|
6272
|
+
this.program.programId,
|
|
6273
|
+
lpPool,
|
|
6274
|
+
borrowMarketIndex
|
|
6275
|
+
);
|
|
6276
|
+
|
|
6277
|
+
const depositIx = this.program.instruction.depositToProgramVault(
|
|
6278
|
+
amountToDeposit,
|
|
6279
|
+
{
|
|
6280
|
+
accounts: {
|
|
6281
|
+
state: await this.getStatePublicKey(),
|
|
6282
|
+
admin: this.wallet.publicKey,
|
|
6283
|
+
constituent: depositConstituent,
|
|
6284
|
+
constituentTokenAccount: depositConstituentTokenAccount,
|
|
6285
|
+
spotMarket: depositSpotMarket.pubkey,
|
|
6286
|
+
spotMarketVault: depositSpotMarket.vault,
|
|
6287
|
+
tokenProgram: depositTokenProgram,
|
|
6288
|
+
mint: depositSpotMarket.mint,
|
|
6289
|
+
oracle: depositSpotMarket.oracle,
|
|
6290
|
+
},
|
|
6291
|
+
}
|
|
6292
|
+
);
|
|
6293
|
+
|
|
6294
|
+
const withdrawIx = this.program.instruction.withdrawFromProgramVault(
|
|
6295
|
+
amountToBorrow,
|
|
6296
|
+
{
|
|
6297
|
+
accounts: {
|
|
6298
|
+
state: await this.getStatePublicKey(),
|
|
6299
|
+
admin: this.wallet.publicKey,
|
|
6300
|
+
constituent: withdrawConstituent,
|
|
6301
|
+
constituentTokenAccount: withdrawConstituentTokenAccount,
|
|
6302
|
+
spotMarket: withdrawSpotMarket.pubkey,
|
|
6303
|
+
spotMarketVault: withdrawSpotMarket.vault,
|
|
6304
|
+
tokenProgram: withdrawTokenProgram,
|
|
6305
|
+
mint: withdrawSpotMarket.mint,
|
|
6306
|
+
driftSigner: getDriftSignerPublicKey(this.program.programId),
|
|
6307
|
+
oracle: withdrawSpotMarket.oracle,
|
|
6308
|
+
},
|
|
6309
|
+
}
|
|
6310
|
+
);
|
|
6311
|
+
|
|
6312
|
+
return { depositIx, withdrawIx };
|
|
6313
|
+
}
|
|
6314
|
+
|
|
6315
|
+
public async depositToProgramVault(
|
|
6316
|
+
lpPoolId: number,
|
|
6317
|
+
depositMarketIndex: number,
|
|
6318
|
+
amountToDeposit: BN
|
|
6319
|
+
): Promise<TransactionSignature> {
|
|
6320
|
+
const depositIx = await this.getDepositToProgramVaultIx(
|
|
6321
|
+
lpPoolId,
|
|
6322
|
+
depositMarketIndex,
|
|
6323
|
+
amountToDeposit
|
|
6324
|
+
);
|
|
6325
|
+
|
|
6326
|
+
const tx = await this.buildTransaction([depositIx]);
|
|
6327
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6328
|
+
return txSig;
|
|
6329
|
+
}
|
|
6330
|
+
|
|
6331
|
+
public async withdrawFromProgramVault(
|
|
6332
|
+
lpPoolId: number,
|
|
6333
|
+
borrowMarketIndex: number,
|
|
6334
|
+
amountToWithdraw: BN
|
|
6335
|
+
): Promise<TransactionSignature> {
|
|
6336
|
+
const withdrawIx = await this.getWithdrawFromProgramVaultIx(
|
|
6337
|
+
lpPoolId,
|
|
6338
|
+
borrowMarketIndex,
|
|
6339
|
+
amountToWithdraw
|
|
6340
|
+
);
|
|
6341
|
+
const tx = await this.buildTransaction([withdrawIx]);
|
|
6342
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6343
|
+
return txSig;
|
|
6344
|
+
}
|
|
6345
|
+
|
|
6346
|
+
public async getDepositToProgramVaultIx(
|
|
6347
|
+
lpPoolId: number,
|
|
6348
|
+
depositMarketIndex: number,
|
|
6349
|
+
amountToDeposit: BN
|
|
6350
|
+
): Promise<TransactionInstruction> {
|
|
6351
|
+
const { depositIx } = await this.getDepositWithdrawToProgramVaultIxs(
|
|
6352
|
+
lpPoolId,
|
|
6353
|
+
depositMarketIndex,
|
|
6354
|
+
depositMarketIndex,
|
|
6355
|
+
amountToDeposit,
|
|
6356
|
+
new BN(0)
|
|
6357
|
+
);
|
|
6358
|
+
return depositIx;
|
|
6359
|
+
}
|
|
6360
|
+
|
|
6361
|
+
public async getWithdrawFromProgramVaultIx(
|
|
6362
|
+
lpPoolId: number,
|
|
6363
|
+
borrowMarketIndex: number,
|
|
6364
|
+
amountToWithdraw: BN
|
|
6365
|
+
): Promise<TransactionInstruction> {
|
|
6366
|
+
const { withdrawIx } = await this.getDepositWithdrawToProgramVaultIxs(
|
|
6367
|
+
lpPoolId,
|
|
6368
|
+
borrowMarketIndex,
|
|
6369
|
+
borrowMarketIndex,
|
|
6370
|
+
new BN(0),
|
|
6371
|
+
amountToWithdraw
|
|
6372
|
+
);
|
|
6373
|
+
return withdrawIx;
|
|
6374
|
+
}
|
|
6375
|
+
|
|
6376
|
+
public async updatePerpMarketLpPoolFeeTransferScalar(
|
|
6377
|
+
marketIndex: number,
|
|
6378
|
+
lpFeeTransferScalar?: number,
|
|
6379
|
+
lpExchangeFeeExcluscionScalar?: number
|
|
6380
|
+
) {
|
|
6381
|
+
const ix = await this.getUpdatePerpMarketLpPoolFeeTransferScalarIx(
|
|
6382
|
+
marketIndex,
|
|
6383
|
+
lpFeeTransferScalar,
|
|
6384
|
+
lpExchangeFeeExcluscionScalar
|
|
6385
|
+
);
|
|
6386
|
+
const tx = await this.buildTransaction(ix);
|
|
6387
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6388
|
+
return txSig;
|
|
6389
|
+
}
|
|
6390
|
+
|
|
6391
|
+
public async getUpdatePerpMarketLpPoolFeeTransferScalarIx(
|
|
6392
|
+
marketIndex: number,
|
|
6393
|
+
lpFeeTransferScalar?: number,
|
|
6394
|
+
lpExchangeFeeExcluscionScalar?: number
|
|
6395
|
+
): Promise<TransactionInstruction> {
|
|
6396
|
+
return this.program.instruction.updatePerpMarketLpPoolFeeTransferScalar(
|
|
6397
|
+
lpFeeTransferScalar ?? null,
|
|
6398
|
+
lpExchangeFeeExcluscionScalar ?? null,
|
|
6399
|
+
{
|
|
6400
|
+
accounts: {
|
|
6401
|
+
admin: this.isSubscribed
|
|
6402
|
+
? this.getStateAccount().admin
|
|
6403
|
+
: this.wallet.publicKey,
|
|
6404
|
+
state: await this.getStatePublicKey(),
|
|
6405
|
+
perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
6406
|
+
},
|
|
6407
|
+
}
|
|
6408
|
+
);
|
|
6409
|
+
}
|
|
6410
|
+
|
|
6411
|
+
public async updatePerpMarketLpPoolPausedOperations(
|
|
6412
|
+
marketIndex: number,
|
|
6413
|
+
pausedOperations: number
|
|
6414
|
+
) {
|
|
6415
|
+
const ix = await this.getUpdatePerpMarketLpPoolPausedOperationsIx(
|
|
6416
|
+
marketIndex,
|
|
6417
|
+
pausedOperations
|
|
6418
|
+
);
|
|
6419
|
+
const tx = await this.buildTransaction(ix);
|
|
6420
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6421
|
+
return txSig;
|
|
6422
|
+
}
|
|
6423
|
+
|
|
6424
|
+
public async getUpdatePerpMarketLpPoolPausedOperationsIx(
|
|
6425
|
+
marketIndex: number,
|
|
6426
|
+
pausedOperations: number
|
|
6427
|
+
): Promise<TransactionInstruction> {
|
|
6428
|
+
return this.program.instruction.updatePerpMarketLpPoolPausedOperations(
|
|
6429
|
+
pausedOperations,
|
|
6430
|
+
{
|
|
6431
|
+
accounts: {
|
|
6432
|
+
admin: this.isSubscribed
|
|
6433
|
+
? this.getStateAccount().admin
|
|
6434
|
+
: this.wallet.publicKey,
|
|
6435
|
+
state: await this.getStatePublicKey(),
|
|
6436
|
+
perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
6437
|
+
},
|
|
6438
|
+
}
|
|
6439
|
+
);
|
|
6440
|
+
}
|
|
6441
|
+
|
|
6442
|
+
public async mintLpWhitelistToken(
|
|
6443
|
+
lpPool: LPPoolAccount,
|
|
6444
|
+
authority: PublicKey
|
|
6445
|
+
): Promise<TransactionSignature> {
|
|
6446
|
+
const ix = await this.getMintLpWhitelistTokenIx(lpPool, authority);
|
|
6447
|
+
const tx = await this.buildTransaction(ix);
|
|
6448
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6449
|
+
return txSig;
|
|
6450
|
+
}
|
|
6451
|
+
|
|
6452
|
+
public async getMintLpWhitelistTokenIx(
|
|
6453
|
+
lpPool: LPPoolAccount,
|
|
6454
|
+
authority: PublicKey
|
|
6455
|
+
): Promise<TransactionInstruction[]> {
|
|
6456
|
+
const mintAmount = 1000;
|
|
6457
|
+
const associatedTokenAccount = getAssociatedTokenAddressSync(
|
|
6458
|
+
lpPool.whitelistMint,
|
|
6459
|
+
authority,
|
|
6460
|
+
false
|
|
6461
|
+
);
|
|
6462
|
+
|
|
6463
|
+
const ixs: TransactionInstruction[] = [];
|
|
6464
|
+
const createInstruction =
|
|
6465
|
+
this.createAssociatedTokenAccountIdempotentInstruction(
|
|
6466
|
+
associatedTokenAccount,
|
|
6467
|
+
this.wallet.publicKey,
|
|
6468
|
+
authority,
|
|
6469
|
+
lpPool.whitelistMint
|
|
6470
|
+
);
|
|
6471
|
+
ixs.push(createInstruction);
|
|
6472
|
+
const mintToInstruction = createMintToInstruction(
|
|
6473
|
+
lpPool.whitelistMint,
|
|
6474
|
+
associatedTokenAccount,
|
|
6475
|
+
this.wallet.publicKey,
|
|
6476
|
+
mintAmount,
|
|
6477
|
+
[],
|
|
6478
|
+
TOKEN_PROGRAM_ID
|
|
6479
|
+
);
|
|
6480
|
+
ixs.push(mintToInstruction);
|
|
6481
|
+
return ixs;
|
|
6482
|
+
}
|
|
4912
6483
|
}
|