@drift-labs/sdk 2.48.0-beta.8 → 2.49.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/VERSION +1 -1
  2. package/lib/accounts/bulkAccountLoader.js +1 -1
  3. package/lib/accounts/pollingUserAccountSubscriber.js +11 -6
  4. package/lib/accounts/pollingUserStatsAccountSubscriber.js +11 -6
  5. package/lib/accounts/webSocketAccountSubscriber.js +1 -1
  6. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +3 -2
  7. package/lib/accounts/webSocketDriftClientAccountSubscriber.js +6 -5
  8. package/lib/accounts/webSocketProgramAccountSubscriber.js +1 -1
  9. package/lib/accounts/webSocketUserAccountSubscriber.js +1 -1
  10. package/lib/constants/spotMarkets.js +10 -0
  11. package/lib/dlob/orderBookLevels.js +1 -1
  12. package/lib/driftClient.js +3 -3
  13. package/lib/events/eventSubscriber.js +23 -2
  14. package/lib/events/pollingLogProvider.d.ts +1 -1
  15. package/lib/events/pollingLogProvider.js +1 -1
  16. package/lib/events/types.d.ts +9 -2
  17. package/lib/events/webSocketLogProvider.d.ts +15 -3
  18. package/lib/events/webSocketLogProvider.js +70 -7
  19. package/lib/idl/drift.json +1 -1
  20. package/lib/orderSubscriber/OrderSubscriber.d.ts +5 -1
  21. package/lib/orderSubscriber/OrderSubscriber.js +30 -7
  22. package/lib/orderSubscriber/WebsocketSubscription.d.ts +4 -1
  23. package/lib/orderSubscriber/WebsocketSubscription.js +4 -3
  24. package/lib/orderSubscriber/types.d.ts +3 -1
  25. package/lib/slot/SlotSubscriber.js +4 -2
  26. package/lib/user.js +6 -2
  27. package/package.json +1 -1
  28. package/src/accounts/bulkAccountLoader.ts +1 -1
  29. package/src/accounts/pollingUserAccountSubscriber.ts +15 -9
  30. package/src/accounts/pollingUserStatsAccountSubscriber.ts +16 -9
  31. package/src/accounts/webSocketAccountSubscriber.ts +1 -1
  32. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +13 -6
  33. package/src/accounts/webSocketProgramAccountSubscriber.ts +1 -1
  34. package/src/accounts/webSocketUserAccountSubscriber.ts +1 -1
  35. package/src/constants/spotMarkets.ts +10 -0
  36. package/src/dlob/orderBookLevels.ts +1 -1
  37. package/src/driftClient.ts +2 -1
  38. package/src/events/eventSubscriber.ts +46 -2
  39. package/src/events/pollingLogProvider.ts +2 -2
  40. package/src/events/types.ts +11 -2
  41. package/src/events/webSocketLogProvider.ts +82 -8
  42. package/src/idl/drift.json +1 -1
  43. package/src/orderSubscriber/OrderSubscriber.ts +52 -15
  44. package/src/orderSubscriber/WebsocketSubscription.ts +7 -2
  45. package/src/orderSubscriber/types.ts +3 -1
  46. package/src/slot/SlotSubscriber.ts +4 -2
  47. package/src/user.ts +5 -2
@@ -2,10 +2,11 @@ import { OrderSubscriber } from './OrderSubscriber';
2
2
  import { getNonIdleUserFilter, getUserFilter } from '../memcmp';
3
3
  import { WebSocketProgramAccountSubscriber } from '../accounts/webSocketProgramAccountSubscriber';
4
4
  import { UserAccount } from '../types';
5
- import { Context, PublicKey } from '@solana/web3.js';
5
+ import { Commitment, Context, PublicKey } from '@solana/web3.js';
6
6
 
7
7
  export class WebsocketSubscription {
8
8
  private orderSubscriber: OrderSubscriber;
9
+ private commitment: Commitment;
9
10
  private skipInitialLoad: boolean;
10
11
  private resubTimeoutMs?: number;
11
12
 
@@ -13,14 +14,17 @@ export class WebsocketSubscription {
13
14
 
14
15
  constructor({
15
16
  orderSubscriber,
17
+ commitment,
16
18
  skipInitialLoad = false,
17
19
  resubTimeoutMs,
18
20
  }: {
19
21
  orderSubscriber: OrderSubscriber;
22
+ commitment: Commitment;
20
23
  skipInitialLoad?: boolean;
21
24
  resubTimeoutMs?: number;
22
25
  }) {
23
26
  this.orderSubscriber = orderSubscriber;
27
+ this.commitment = commitment;
24
28
  this.skipInitialLoad = skipInitialLoad;
25
29
  this.resubTimeoutMs = resubTimeoutMs;
26
30
  }
@@ -36,7 +40,7 @@ export class WebsocketSubscription {
36
40
  ),
37
41
  {
38
42
  filters: [getUserFilter(), getNonIdleUserFilter()],
39
- commitment: this.orderSubscriber.driftClient.opts.commitment,
43
+ commitment: this.commitment,
40
44
  },
41
45
  this.resubTimeoutMs
42
46
  );
@@ -47,6 +51,7 @@ export class WebsocketSubscription {
47
51
  const userKey = accountId.toBase58();
48
52
  this.orderSubscriber.tryUpdateUserAccount(
49
53
  userKey,
54
+ 'decoded',
50
55
  account,
51
56
  context.slot
52
57
  );
@@ -1,4 +1,4 @@
1
- import { PublicKey } from '@solana/web3.js';
1
+ import { Commitment, PublicKey } from '@solana/web3.js';
2
2
  import { Order, UserAccount } from '../types';
3
3
  import { DriftClient } from '../driftClient';
4
4
 
@@ -8,11 +8,13 @@ export type OrderSubscriberConfig = {
8
8
  | {
9
9
  type: 'polling';
10
10
  frequency: number;
11
+ commitment?: Commitment;
11
12
  }
12
13
  | {
13
14
  type: 'websocket';
14
15
  skipInitialLoad?: boolean;
15
16
  resubTimeoutMs?: number;
17
+ commitment?: Commitment;
16
18
  };
17
19
  };
18
20
 
@@ -29,8 +29,10 @@ export class SlotSubscriber {
29
29
  this.currentSlot = await this.connection.getSlot('confirmed');
30
30
 
31
31
  this.subscriptionId = this.connection.onSlotChange((slotInfo) => {
32
- this.currentSlot = slotInfo.slot;
33
- this.eventEmitter.emit('newSlot', slotInfo.slot);
32
+ if (!this.currentSlot || this.currentSlot < slotInfo.slot) {
33
+ this.currentSlot = slotInfo.slot;
34
+ this.eventEmitter.emit('newSlot', slotInfo.slot);
35
+ }
34
36
  });
35
37
  }
36
38
 
package/src/user.ts CHANGED
@@ -113,8 +113,8 @@ export class User {
113
113
  this.accountSubscriber = new WebSocketUserAccountSubscriber(
114
114
  config.driftClient.program,
115
115
  config.userAccountPublicKey,
116
- config.accountSubscription.resubTimeoutMs,
117
- config.accountSubscription.commitment
116
+ config.accountSubscription?.resubTimeoutMs,
117
+ config.accountSubscription?.commitment
118
118
  );
119
119
  }
120
120
  this.eventEmitter = this.accountSubscriber.eventEmitter;
@@ -3041,6 +3041,7 @@ export class User {
3041
3041
  );
3042
3042
 
3043
3043
  const freeCollateral = this.getFreeCollateral();
3044
+ const initialMarginRequirement = this.getInitialMarginRequirement();
3044
3045
  const oracleData = this.getOracleDataForSpotMarket(marketIndex);
3045
3046
  const precisionIncrease = TEN.pow(new BN(spotMarket.decimals - 6));
3046
3047
 
@@ -3060,6 +3061,8 @@ export class User {
3060
3061
  let amountWithdrawable;
3061
3062
  if (assetWeight.eq(ZERO)) {
3062
3063
  amountWithdrawable = userDepositAmount;
3064
+ } else if (initialMarginRequirement.eq(ZERO)) {
3065
+ amountWithdrawable = userDepositAmount;
3063
3066
  } else {
3064
3067
  amountWithdrawable = divCeil(
3065
3068
  divCeil(freeCollateral.mul(MARGIN_PRECISION), assetWeight).mul(