@drift-labs/sdk 2.146.0-beta.0 → 2.146.0-beta.10

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.
Files changed (47) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +99 -7
  3. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
  4. package/lib/browser/adminClient.d.ts +5 -1
  5. package/lib/browser/adminClient.js +57 -23
  6. package/lib/browser/constants/perpMarkets.js +0 -2
  7. package/lib/browser/decode/user.js +4 -0
  8. package/lib/browser/driftClient.js +19 -17
  9. package/lib/browser/driftClientConfig.d.ts +7 -2
  10. package/lib/browser/idl/drift.json +35 -1
  11. package/lib/browser/index.d.ts +4 -0
  12. package/lib/browser/index.js +9 -1
  13. package/lib/browser/types.d.ts +2 -0
  14. package/lib/browser/user.js +2 -0
  15. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +99 -7
  16. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
  17. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
  18. package/lib/node/adminClient.d.ts +5 -1
  19. package/lib/node/adminClient.d.ts.map +1 -1
  20. package/lib/node/adminClient.js +57 -23
  21. package/lib/node/constants/perpMarkets.d.ts.map +1 -1
  22. package/lib/node/constants/perpMarkets.js +0 -2
  23. package/lib/node/decode/user.d.ts.map +1 -1
  24. package/lib/node/decode/user.js +4 -0
  25. package/lib/node/driftClient.d.ts.map +1 -1
  26. package/lib/node/driftClient.js +19 -17
  27. package/lib/node/driftClientConfig.d.ts +7 -2
  28. package/lib/node/driftClientConfig.d.ts.map +1 -1
  29. package/lib/node/idl/drift.json +35 -1
  30. package/lib/node/index.d.ts +4 -0
  31. package/lib/node/index.d.ts.map +1 -1
  32. package/lib/node/index.js +9 -1
  33. package/lib/node/types.d.ts +2 -0
  34. package/lib/node/types.d.ts.map +1 -1
  35. package/lib/node/user.d.ts.map +1 -1
  36. package/lib/node/user.js +2 -0
  37. package/package.json +1 -1
  38. package/src/accounts/webSocketProgramAccountSubscriberV2.ts +566 -167
  39. package/src/adminClient.ts +74 -25
  40. package/src/constants/perpMarkets.ts +0 -3
  41. package/src/decode/user.ts +7 -0
  42. package/src/driftClient.ts +7 -4
  43. package/src/driftClientConfig.ts +15 -8
  44. package/src/idl/drift.json +36 -2
  45. package/src/index.ts +4 -0
  46. package/src/types.ts +2 -0
  47. package/src/user.ts +2 -0
@@ -540,8 +540,8 @@ export class AdminClient extends DriftClient {
540
540
  curveUpdateIntensity,
541
541
  ammJitIntensity,
542
542
  name,
543
- mustInitializeAmmCache,
544
- lpPoolId
543
+ lpPoolId,
544
+ mustInitializeAmmCache
545
545
  );
546
546
  const tx = await this.buildTransaction(initializeMarketIxs);
547
547
 
@@ -588,8 +588,8 @@ export class AdminClient extends DriftClient {
588
588
  curveUpdateIntensity = 0,
589
589
  ammJitIntensity = 0,
590
590
  name = DEFAULT_MARKET_NAME,
591
- includeInitAmmCacheIx = false,
592
- lpPoolId: number = 0
591
+ lpPoolId: number = 0,
592
+ includeInitAmmCacheIx = false
593
593
  ): Promise<TransactionInstruction[]> {
594
594
  const perpMarketPublicKey = await getPerpMarketPublicKey(
595
595
  this.program.programId,
@@ -597,6 +597,7 @@ export class AdminClient extends DriftClient {
597
597
  );
598
598
 
599
599
  const ixs: TransactionInstruction[] = [];
600
+
600
601
  if (includeInitAmmCacheIx) {
601
602
  ixs.push(await this.getInitializeAmmCacheIx());
602
603
  }
@@ -663,9 +664,35 @@ export class AdminClient extends DriftClient {
663
664
  return await this.program.instruction.initializeAmmCache({
664
665
  accounts: {
665
666
  state: await this.getStatePublicKey(),
666
- admin: this.isSubscribed
667
- ? this.getStateAccount().admin
668
- : this.wallet.publicKey,
667
+ admin: this.useHotWalletAdmin
668
+ ? this.wallet.publicKey
669
+ : this.getStateAccount().admin,
670
+ ammCache: getAmmCachePublicKey(this.program.programId),
671
+ rent: SYSVAR_RENT_PUBKEY,
672
+ systemProgram: anchor.web3.SystemProgram.programId,
673
+ },
674
+ });
675
+ }
676
+
677
+ public async resizeAmmCache(
678
+ txParams?: TxParams
679
+ ): Promise<TransactionSignature> {
680
+ const initializeAmmCacheIx = await this.getResizeAmmCacheIx();
681
+
682
+ const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
683
+
684
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
685
+
686
+ return txSig;
687
+ }
688
+
689
+ public async getResizeAmmCacheIx(): Promise<TransactionInstruction> {
690
+ return await this.program.instruction.resizeAmmCache({
691
+ accounts: {
692
+ state: await this.getStatePublicKey(),
693
+ admin: this.useHotWalletAdmin
694
+ ? this.wallet.publicKey
695
+ : this.getStateAccount().admin,
669
696
  ammCache: getAmmCachePublicKey(this.program.programId),
670
697
  rent: SYSVAR_RENT_PUBKEY,
671
698
  systemProgram: anchor.web3.SystemProgram.programId,
@@ -673,6 +700,28 @@ export class AdminClient extends DriftClient {
673
700
  });
674
701
  }
675
702
 
703
+ public async deleteAmmCache(
704
+ txParams?: TxParams
705
+ ): Promise<TransactionSignature> {
706
+ const deleteAmmCacheIx = await this.getDeleteAmmCacheIx();
707
+
708
+ const tx = await this.buildTransaction(deleteAmmCacheIx, txParams);
709
+
710
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
711
+
712
+ return txSig;
713
+ }
714
+
715
+ public async getDeleteAmmCacheIx(): Promise<TransactionInstruction> {
716
+ return await this.program.instruction.deleteAmmCache({
717
+ accounts: {
718
+ state: await this.getStatePublicKey(),
719
+ admin: this.getStateAccount().admin,
720
+ ammCache: getAmmCachePublicKey(this.program.programId),
721
+ },
722
+ });
723
+ }
724
+
676
725
  public async updateInitialAmmCacheInfo(
677
726
  perpMarketIndexes: number[],
678
727
  txParams?: TxParams
@@ -699,9 +748,9 @@ export class AdminClient extends DriftClient {
699
748
  return await this.program.instruction.updateInitialAmmCacheInfo({
700
749
  accounts: {
701
750
  state: await this.getStatePublicKey(),
702
- admin: this.isSubscribed
703
- ? this.getStateAccount().admin
704
- : this.wallet.publicKey,
751
+ admin: this.useHotWalletAdmin
752
+ ? this.wallet.publicKey
753
+ : this.getStateAccount().admin,
705
754
  ammCache: getAmmCachePublicKey(this.program.programId),
706
755
  },
707
756
  remainingAccounts,
@@ -759,9 +808,9 @@ export class AdminClient extends DriftClient {
759
808
  {
760
809
  accounts: {
761
810
  state: await this.getStatePublicKey(),
762
- admin: this.isSubscribed
763
- ? this.getStateAccount().admin
764
- : this.wallet.publicKey,
811
+ admin: this.useHotWalletAdmin
812
+ ? this.wallet.publicKey
813
+ : this.getStateAccount().admin,
765
814
  ammCache: getAmmCachePublicKey(this.program.programId),
766
815
  },
767
816
  }
@@ -783,9 +832,9 @@ export class AdminClient extends DriftClient {
783
832
  return this.program.instruction.resetAmmCache({
784
833
  accounts: {
785
834
  state: await this.getStatePublicKey(),
786
- admin: this.isSubscribed
787
- ? this.getStateAccount().admin
788
- : this.wallet.publicKey,
835
+ admin: this.useHotWalletAdmin
836
+ ? this.wallet.publicKey
837
+ : this.getStateAccount().admin,
789
838
  ammCache: getAmmCachePublicKey(this.program.programId),
790
839
  systemProgram: anchor.web3.SystemProgram.programId,
791
840
  },
@@ -5508,9 +5557,9 @@ export class AdminClient extends DriftClient {
5508
5557
  {
5509
5558
  accounts: {
5510
5559
  constituent,
5511
- admin: this.isSubscribed
5512
- ? this.getStateAccount().admin
5513
- : this.wallet.publicKey,
5560
+ admin: this.useHotWalletAdmin
5561
+ ? this.wallet.publicKey
5562
+ : this.getStateAccount().admin,
5514
5563
  state: await this.getStatePublicKey(),
5515
5564
  },
5516
5565
  }
@@ -6398,9 +6447,9 @@ export class AdminClient extends DriftClient {
6398
6447
  lpExchangeFeeExcluscionScalar ?? null,
6399
6448
  {
6400
6449
  accounts: {
6401
- admin: this.isSubscribed
6402
- ? this.getStateAccount().admin
6403
- : this.wallet.publicKey,
6450
+ admin: this.useHotWalletAdmin
6451
+ ? this.wallet.publicKey
6452
+ : this.getStateAccount().admin,
6404
6453
  state: await this.getStatePublicKey(),
6405
6454
  perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
6406
6455
  },
@@ -6429,9 +6478,9 @@ export class AdminClient extends DriftClient {
6429
6478
  pausedOperations,
6430
6479
  {
6431
6480
  accounts: {
6432
- admin: this.isSubscribed
6433
- ? this.getStateAccount().admin
6434
- : this.wallet.publicKey,
6481
+ admin: this.useHotWalletAdmin
6482
+ ? this.wallet.publicKey
6483
+ : this.getStateAccount().admin,
6435
6484
  state: await this.getStatePublicKey(),
6436
6485
  perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
6437
6486
  },
@@ -1297,9 +1297,6 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
1297
1297
  oracle: new PublicKey('GAzR3C5cn7gGVvuqJB57wSYTPWP3n2Lw4mRJRxvTvqYy'),
1298
1298
  launchTs: 1747318237000,
1299
1299
  oracleSource: OracleSource.PYTH_LAZER,
1300
- pythFeedId:
1301
- '0x6d74813ee17291d5be18a355fe4d43fd300d625caea6554d49f740e7d112141e',
1302
- pythLazerId: 1571,
1303
1300
  },
1304
1301
  {
1305
1302
  fullName: 'PUMP',
@@ -84,6 +84,11 @@ export function decodeUser(buffer: Buffer): UserAccount {
84
84
  const quoteAssetAmount = readSignedBigInt64LE(buffer, offset + 16);
85
85
  const lpShares = readUnsignedBigInt64LE(buffer, offset + 64);
86
86
  const openOrders = buffer.readUInt8(offset + 94);
87
+ const positionFlag = buffer.readUInt8(offset + 95);
88
+ const isolatedPositionScaledBalance = readUnsignedBigInt64LE(
89
+ buffer,
90
+ offset + 96
91
+ );
87
92
 
88
93
  if (
89
94
  baseAssetAmount.eq(ZERO) &&
@@ -135,6 +140,8 @@ export function decodeUser(buffer: Buffer): UserAccount {
135
140
  openOrders,
136
141
  perLpBase,
137
142
  maxMarginRatio,
143
+ isolatedPositionScaledBalance,
144
+ positionFlag,
138
145
  });
139
146
  }
140
147
 
@@ -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
- this.accountSubscriber = new WebSocketDriftClientAccountSubscriber(
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;
@@ -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
- oracleAccountSubscriber?: new (
90
- accountName: string,
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
- accountPublicKey: PublicKey,
93
- decodeBuffer?: (buffer: Buffer) => any,
94
- resubOpts?: ResubOpts,
95
- commitment?: Commitment
96
- ) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
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';
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.145.0",
2
+ "version": "2.145.1",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -4453,6 +4453,37 @@
4453
4453
  ],
4454
4454
  "args": []
4455
4455
  },
4456
+ {
4457
+ "name": "resizeAmmCache",
4458
+ "accounts": [
4459
+ {
4460
+ "name": "admin",
4461
+ "isMut": true,
4462
+ "isSigner": true
4463
+ },
4464
+ {
4465
+ "name": "state",
4466
+ "isMut": false,
4467
+ "isSigner": false
4468
+ },
4469
+ {
4470
+ "name": "ammCache",
4471
+ "isMut": true,
4472
+ "isSigner": false
4473
+ },
4474
+ {
4475
+ "name": "rent",
4476
+ "isMut": false,
4477
+ "isSigner": false
4478
+ },
4479
+ {
4480
+ "name": "systemProgram",
4481
+ "isMut": false,
4482
+ "isSigner": false
4483
+ }
4484
+ ],
4485
+ "args": []
4486
+ },
4456
4487
  {
4457
4488
  "name": "updateInitialAmmCacheInfo",
4458
4489
  "accounts": [
@@ -15118,6 +15149,9 @@
15118
15149
  },
15119
15150
  {
15120
15151
  "name": "SafeMMOracle"
15152
+ },
15153
+ {
15154
+ "name": "Margin"
15121
15155
  }
15122
15156
  ]
15123
15157
  }
@@ -19745,4 +19779,4 @@
19745
19779
  "msg": "Invalid Lp Pool Id for Operation"
19746
19780
  }
19747
19781
  ]
19748
- }
19782
+ }
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';
package/src/types.ts CHANGED
@@ -1136,6 +1136,8 @@ export type PerpPosition = {
1136
1136
  lastBaseAssetAmountPerLp: BN;
1137
1137
  lastQuoteAssetAmountPerLp: BN;
1138
1138
  perLpBase: number;
1139
+ isolatedPositionScaledBalance: BN;
1140
+ positionFlag: number;
1139
1141
  };
1140
1142
 
1141
1143
  export type UserStatsAccount = {
package/src/user.ts CHANGED
@@ -338,6 +338,8 @@ export class User {
338
338
  lastQuoteAssetAmountPerLp: ZERO,
339
339
  perLpBase: 0,
340
340
  maxMarginRatio: 0,
341
+ isolatedPositionScaledBalance: ZERO,
342
+ positionFlag: 0,
341
343
  };
342
344
  }
343
345