@drift-labs/sdk 2.146.0-beta.1 → 2.146.0-beta.3
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/webSocketProgramAccountSubscriberV2.d.ts +99 -7
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
- package/lib/browser/adminClient.d.ts +3 -1
- package/lib/browser/adminClient.js +24 -11
- package/lib/browser/driftClient.js +19 -17
- package/lib/browser/driftClientConfig.d.ts +7 -2
- package/lib/browser/index.d.ts +4 -0
- package/lib/browser/index.js +9 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +99 -7
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
- package/lib/node/adminClient.d.ts +3 -1
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +24 -11
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +19 -17
- package/lib/node/driftClientConfig.d.ts +7 -2
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +9 -1
- package/package.json +1 -1
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +566 -167
- package/src/adminClient.ts +29 -14
- package/src/driftClient.ts +7 -4
- package/src/driftClientConfig.ts +15 -8
- package/src/index.ts +4 -0
package/src/adminClient.ts
CHANGED
|
@@ -507,12 +507,6 @@ export class AdminClient extends DriftClient {
|
|
|
507
507
|
): Promise<TransactionSignature> {
|
|
508
508
|
const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
|
|
509
509
|
|
|
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
510
|
const initializeMarketIxs = await this.getInitializePerpMarketIx(
|
|
517
511
|
marketIndex,
|
|
518
512
|
priceOracle,
|
|
@@ -540,7 +534,6 @@ export class AdminClient extends DriftClient {
|
|
|
540
534
|
curveUpdateIntensity,
|
|
541
535
|
ammJitIntensity,
|
|
542
536
|
name,
|
|
543
|
-
mustInitializeAmmCache,
|
|
544
537
|
lpPoolId
|
|
545
538
|
);
|
|
546
539
|
const tx = await this.buildTransaction(initializeMarketIxs);
|
|
@@ -588,7 +581,6 @@ export class AdminClient extends DriftClient {
|
|
|
588
581
|
curveUpdateIntensity = 0,
|
|
589
582
|
ammJitIntensity = 0,
|
|
590
583
|
name = DEFAULT_MARKET_NAME,
|
|
591
|
-
includeInitAmmCacheIx = false,
|
|
592
584
|
lpPoolId: number = 0
|
|
593
585
|
): Promise<TransactionInstruction[]> {
|
|
594
586
|
const perpMarketPublicKey = await getPerpMarketPublicKey(
|
|
@@ -597,9 +589,6 @@ export class AdminClient extends DriftClient {
|
|
|
597
589
|
);
|
|
598
590
|
|
|
599
591
|
const ixs: TransactionInstruction[] = [];
|
|
600
|
-
if (includeInitAmmCacheIx) {
|
|
601
|
-
ixs.push(await this.getInitializeAmmCacheIx());
|
|
602
|
-
}
|
|
603
592
|
|
|
604
593
|
const nameBuffer = encodeName(name);
|
|
605
594
|
const initPerpIx = await this.program.instruction.initializePerpMarket(
|
|
@@ -663,9 +652,35 @@ export class AdminClient extends DriftClient {
|
|
|
663
652
|
return await this.program.instruction.initializeAmmCache({
|
|
664
653
|
accounts: {
|
|
665
654
|
state: await this.getStatePublicKey(),
|
|
666
|
-
admin: this.
|
|
667
|
-
? this.
|
|
668
|
-
: this.
|
|
655
|
+
admin: this.useHotWalletAdmin
|
|
656
|
+
? this.wallet.publicKey
|
|
657
|
+
: this.getStateAccount().admin,
|
|
658
|
+
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
659
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
660
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
public async resizeAmmCache(
|
|
666
|
+
txParams?: TxParams
|
|
667
|
+
): Promise<TransactionSignature> {
|
|
668
|
+
const initializeAmmCacheIx = await this.getInitializeAmmCacheIx();
|
|
669
|
+
|
|
670
|
+
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
|
|
671
|
+
|
|
672
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
673
|
+
|
|
674
|
+
return txSig;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
public async getResizeAmmCacheIx(): Promise<TransactionInstruction> {
|
|
678
|
+
return await this.program.instruction.resizeAmmCache({
|
|
679
|
+
accounts: {
|
|
680
|
+
state: await this.getStatePublicKey(),
|
|
681
|
+
admin: this.useHotWalletAdmin
|
|
682
|
+
? this.wallet.publicKey
|
|
683
|
+
: this.getStateAccount().admin,
|
|
669
684
|
ammCache: getAmmCachePublicKey(this.program.programId),
|
|
670
685
|
rent: SYSVAR_RENT_PUBKEY,
|
|
671
686
|
systemProgram: anchor.web3.SystemProgram.programId,
|
package/src/driftClient.ts
CHANGED
|
@@ -406,6 +406,8 @@ export class DriftClient {
|
|
|
406
406
|
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
407
407
|
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
408
408
|
commitment: config.accountSubscription?.commitment,
|
|
409
|
+
programUserAccountSubscriber:
|
|
410
|
+
config.accountSubscription?.programUserAccountSubscriber,
|
|
409
411
|
};
|
|
410
412
|
this.userStatsAccountSubscriptionConfig = {
|
|
411
413
|
type: 'websocket',
|
|
@@ -474,7 +476,10 @@ export class DriftClient {
|
|
|
474
476
|
}
|
|
475
477
|
);
|
|
476
478
|
} else {
|
|
477
|
-
|
|
479
|
+
const accountSubscriberClass =
|
|
480
|
+
config.accountSubscription?.driftClientAccountSubscriber ??
|
|
481
|
+
WebSocketDriftClientAccountSubscriber;
|
|
482
|
+
this.accountSubscriber = new accountSubscriberClass(
|
|
478
483
|
this.program,
|
|
479
484
|
config.perpMarketIndexes ?? [],
|
|
480
485
|
config.spotMarketIndexes ?? [],
|
|
@@ -485,9 +490,7 @@ export class DriftClient {
|
|
|
485
490
|
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
486
491
|
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
487
492
|
},
|
|
488
|
-
config.accountSubscription?.commitment
|
|
489
|
-
config.accountSubscription?.perpMarketAccountSubscriber,
|
|
490
|
-
config.accountSubscription?.oracleAccountSubscriber
|
|
493
|
+
config.accountSubscription?.commitment
|
|
491
494
|
);
|
|
492
495
|
}
|
|
493
496
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
package/src/driftClientConfig.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
PublicKey,
|
|
6
6
|
TransactionVersion,
|
|
7
7
|
} from '@solana/web3.js';
|
|
8
|
-
import { IWallet, TxParams } from './types';
|
|
8
|
+
import { IWallet, TxParams, UserAccount } from './types';
|
|
9
9
|
import { OracleInfo } from './oracles/types';
|
|
10
10
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
11
11
|
import { DriftEnv } from './config';
|
|
@@ -22,6 +22,9 @@ import { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscri
|
|
|
22
22
|
import { grpcDriftClientAccountSubscriberV2 } from './accounts/grpcDriftClientAccountSubscriberV2';
|
|
23
23
|
import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
|
|
24
24
|
import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
|
|
25
|
+
import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
26
|
+
import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDriftClientAccountSubscriber';
|
|
27
|
+
import { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
|
|
25
28
|
|
|
26
29
|
export type DriftClientConfig = {
|
|
27
30
|
connection: Connection;
|
|
@@ -78,6 +81,7 @@ export type DriftClientSubscriptionConfig =
|
|
|
78
81
|
resubTimeoutMs?: number;
|
|
79
82
|
logResubMessages?: boolean;
|
|
80
83
|
commitment?: Commitment;
|
|
84
|
+
programUserAccountSubscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
81
85
|
perpMarketAccountSubscriber?: new (
|
|
82
86
|
accountName: string,
|
|
83
87
|
program: Program,
|
|
@@ -86,14 +90,17 @@ export type DriftClientSubscriptionConfig =
|
|
|
86
90
|
resubOpts?: ResubOpts,
|
|
87
91
|
commitment?: Commitment
|
|
88
92
|
) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
/** If you use V2 here, whatever you pass for perpMarketAccountSubscriber will be ignored and it will use v2 under the hood regardless */
|
|
94
|
+
driftClientAccountSubscriber?: new (
|
|
91
95
|
program: Program,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
perpMarketIndexes: number[],
|
|
97
|
+
spotMarketIndexes: number[],
|
|
98
|
+
oracleInfos: OracleInfo[],
|
|
99
|
+
shouldFindAllMarketsAndOracles: boolean,
|
|
100
|
+
delistedMarketSetting: DelistedMarketSetting
|
|
101
|
+
) =>
|
|
102
|
+
| WebSocketDriftClientAccountSubscriber
|
|
103
|
+
| WebSocketDriftClientAccountSubscriberV2;
|
|
97
104
|
}
|
|
98
105
|
| {
|
|
99
106
|
type: 'polling';
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,10 @@ export * from './accounts/webSocketDriftClientAccountSubscriber';
|
|
|
12
12
|
export * from './accounts/webSocketInsuranceFundStakeAccountSubscriber';
|
|
13
13
|
export * from './accounts/webSocketHighLeverageModeConfigAccountSubscriber';
|
|
14
14
|
export { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscriberV2';
|
|
15
|
+
export { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
16
|
+
export { WebSocketProgramUserAccountSubscriber } from './accounts/websocketProgramUserAccountSubscriber';
|
|
17
|
+
export { WebSocketProgramAccountsSubscriberV2 } from './accounts/webSocketProgramAccountsSubscriberV2';
|
|
18
|
+
export { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
|
|
15
19
|
export * from './accounts/bulkAccountLoader';
|
|
16
20
|
export * from './accounts/bulkUserSubscription';
|
|
17
21
|
export * from './accounts/bulkUserStatsSubscription';
|