@drift-labs/sdk 2.48.0-beta.11 → 2.48.0-beta.13

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 CHANGED
@@ -1 +1 @@
1
- 2.48.0-beta.11
1
+ 2.48.0-beta.13
@@ -21,7 +21,7 @@ export declare class OrderSubscriber {
21
21
  constructor(config: OrderSubscriberConfig);
22
22
  subscribe(): Promise<void>;
23
23
  fetch(): Promise<void>;
24
- tryUpdateUserAccount(key: string, userAccount: UserAccount, slot: number): void;
24
+ tryUpdateUserAccount(key: string, dataType: 'raw' | 'decoded', data: string[] | UserAccount, slot: number): void;
25
25
  getDLOB(slot: number): Promise<DLOB>;
26
26
  getSlot(): number;
27
27
  unsubscribe(): Promise<void>;
@@ -55,11 +55,8 @@ class OrderSubscriber {
55
55
  const programAccountSet = new Set();
56
56
  for (const programAccount of rpcResponseAndContext.value) {
57
57
  const key = programAccount.pubkey.toString();
58
- // @ts-ignore
59
- const buffer = buffer_1.Buffer.from(programAccount.account.data[0], programAccount.account.data[1]);
60
58
  programAccountSet.add(key);
61
- const userAccount = this.driftClient.program.account.user.coder.accounts.decode('User', buffer);
62
- this.tryUpdateUserAccount(key, userAccount, slot);
59
+ this.tryUpdateUserAccount(key, 'raw', programAccount.account.data, slot);
63
60
  }
64
61
  for (const key of this.usersAccounts.keys()) {
65
62
  if (!programAccountSet.has(key)) {
@@ -75,12 +72,23 @@ class OrderSubscriber {
75
72
  this.fetchPromise = undefined;
76
73
  }
77
74
  }
78
- tryUpdateUserAccount(key, userAccount, slot) {
75
+ tryUpdateUserAccount(key, dataType, data, slot) {
79
76
  if (!this.mostRecentSlot || slot > this.mostRecentSlot) {
80
77
  this.mostRecentSlot = slot;
81
78
  }
82
79
  const slotAndUserAccount = this.usersAccounts.get(key);
83
80
  if (!slotAndUserAccount || slotAndUserAccount.slot < slot) {
81
+ let userAccount;
82
+ // Polling leads to a lot of redundant decoding, so we only decode if data is from a fresh slot
83
+ if (dataType === 'raw') {
84
+ // @ts-ignore
85
+ const buffer = buffer_1.Buffer.from(data[0], data[1]);
86
+ userAccount =
87
+ this.driftClient.program.account.user.coder.accounts.decodeUnchecked('User', buffer);
88
+ }
89
+ else {
90
+ userAccount = data;
91
+ }
84
92
  const newOrders = userAccount.orders.filter((order) => {
85
93
  var _a;
86
94
  return order.slot.toNumber() > ((_a = slotAndUserAccount === null || slotAndUserAccount === void 0 ? void 0 : slotAndUserAccount.slot) !== null && _a !== void 0 ? _a : 0) &&
@@ -18,7 +18,7 @@ class WebsocketSubscription {
18
18
  }
19
19
  await this.subscriber.subscribe((accountId, account, context) => {
20
20
  const userKey = accountId.toBase58();
21
- this.orderSubscriber.tryUpdateUserAccount(userKey, account, context.slot);
21
+ this.orderSubscriber.tryUpdateUserAccount(userKey, 'decoded', account, context.slot);
22
22
  });
23
23
  if (!this.skipInitialLoad) {
24
24
  await this.orderSubscriber.fetch();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.48.0-beta.11",
3
+ "version": "2.48.0-beta.13",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -83,18 +83,13 @@ export class OrderSubscriber {
83
83
  const programAccountSet = new Set<string>();
84
84
  for (const programAccount of rpcResponseAndContext.value) {
85
85
  const key = programAccount.pubkey.toString();
86
- // @ts-ignore
87
- const buffer = Buffer.from(
88
- programAccount.account.data[0],
89
- programAccount.account.data[1]
90
- );
91
86
  programAccountSet.add(key);
92
- const userAccount =
93
- this.driftClient.program.account.user.coder.accounts.decode(
94
- 'User',
95
- buffer
96
- ) as UserAccount;
97
- this.tryUpdateUserAccount(key, userAccount, slot);
87
+ this.tryUpdateUserAccount(
88
+ key,
89
+ 'raw',
90
+ programAccount.account.data,
91
+ slot
92
+ );
98
93
  }
99
94
 
100
95
  for (const key of this.usersAccounts.keys()) {
@@ -112,7 +107,8 @@ export class OrderSubscriber {
112
107
 
113
108
  tryUpdateUserAccount(
114
109
  key: string,
115
- userAccount: UserAccount,
110
+ dataType: 'raw' | 'decoded',
111
+ data: string[] | UserAccount,
116
112
  slot: number
117
113
  ): void {
118
114
  if (!this.mostRecentSlot || slot > this.mostRecentSlot) {
@@ -121,6 +117,21 @@ export class OrderSubscriber {
121
117
 
122
118
  const slotAndUserAccount = this.usersAccounts.get(key);
123
119
  if (!slotAndUserAccount || slotAndUserAccount.slot < slot) {
120
+ let userAccount: UserAccount;
121
+ // Polling leads to a lot of redundant decoding, so we only decode if data is from a fresh slot
122
+ if (dataType === 'raw') {
123
+ // @ts-ignore
124
+ const buffer = Buffer.from(data[0], data[1]);
125
+
126
+ userAccount =
127
+ this.driftClient.program.account.user.coder.accounts.decodeUnchecked(
128
+ 'User',
129
+ buffer
130
+ ) as UserAccount;
131
+ } else {
132
+ userAccount = data as UserAccount;
133
+ }
134
+
124
135
  const newOrders = userAccount.orders.filter(
125
136
  (order) =>
126
137
  order.slot.toNumber() > (slotAndUserAccount?.slot ?? 0) &&
@@ -47,6 +47,7 @@ export class WebsocketSubscription {
47
47
  const userKey = accountId.toBase58();
48
48
  this.orderSubscriber.tryUpdateUserAccount(
49
49
  userKey,
50
+ 'decoded',
50
51
  account,
51
52
  context.slot
52
53
  );