@drift-labs/sdk 2.38.1-beta.1 → 2.38.1-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 CHANGED
@@ -1 +1 @@
1
- 2.38.1-beta.1
1
+ 2.38.1-beta.3
@@ -16,7 +16,7 @@ async function fetchUserAccountsUsingKeys(connection, program, userAccountPublic
16
16
  if (!accountInfo) {
17
17
  return undefined;
18
18
  }
19
- return program.account.user.coder.accounts.decode('User', accountInfo.data);
19
+ return program.account.user.coder.accounts.decodeUnchecked('User', accountInfo.data);
20
20
  });
21
21
  }
22
22
  exports.fetchUserAccountsUsingKeys = fetchUserAccountsUsingKeys;
@@ -24,7 +24,7 @@ async function fetchUserStatsAccount(connection, program, authority) {
24
24
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(program.programId, authority);
25
25
  const accountInfo = await connection.getAccountInfo(userStatsPublicKey, 'confirmed');
26
26
  return accountInfo
27
- ? program.account.user.coder.accounts.decode('UserStats', accountInfo.data)
27
+ ? program.account.user.coder.accounts.decodeUnchecked('UserStats', accountInfo.data)
28
28
  : undefined;
29
29
  }
30
30
  exports.fetchUserStatsAccount = fetchUserStatsAccount;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PollingDriftClientAccountSubscriber = void 0;
4
4
  const types_1 = require("./types");
5
- const anchor_1 = require("@coral-xyz/anchor");
6
5
  const events_1 = require("events");
7
6
  const pda_1 = require("../addresses/pda");
8
7
  const utils_1 = require("./utils");
@@ -138,18 +137,7 @@ class PollingDriftClientAccountSubscriber {
138
137
  accountToPoll.callbackId = await this.accountLoader.addAccount(accountToPoll.publicKey, (buffer, slot) => {
139
138
  if (!buffer)
140
139
  return;
141
- let account;
142
- try {
143
- account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
144
- }
145
- catch (e) {
146
- console.error(e);
147
- console.log('account key', accountToPoll.key);
148
- console.log('accountToPoll.publicKey', accountToPoll.publicKey.toString());
149
- console.log('buffer', buffer.toString('base64'));
150
- console.log('discriminator', anchor_1.BorshAccountsCoder.accountDiscriminator((0, utils_1.capitalize)(accountToPoll.key)).toString('base64'));
151
- return;
152
- }
140
+ const account = this.program.account[accountToPoll.key].coder.accounts.decodeUnchecked((0, utils_1.capitalize)(accountToPoll.key), buffer);
153
141
  const dataAndSlot = {
154
142
  data: account,
155
143
  slot,
@@ -188,7 +176,7 @@ class PollingDriftClientAccountSubscriber {
188
176
  for (const [_, accountToPoll] of this.accountsToPoll) {
189
177
  const { buffer, slot } = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey);
190
178
  if (buffer) {
191
- const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
179
+ const account = this.program.account[accountToPoll.key].coder.accounts.decodeUnchecked((0, utils_1.capitalize)(accountToPoll.key), buffer);
192
180
  if (accountToPoll.mapKey != undefined) {
193
181
  this[accountToPoll.key].set(accountToPoll.mapKey, {
194
182
  data: account,
@@ -37,7 +37,7 @@ class PollingUserAccountSubscriber {
37
37
  if (this.user && this.user.slot > slot) {
38
38
  return;
39
39
  }
40
- const account = this.program.account.user.coder.accounts.decode('User', buffer);
40
+ const account = this.program.account.user.coder.accounts.decodeUnchecked('User', buffer);
41
41
  this.user = { data: account, slot };
42
42
  this.eventEmitter.emit('userAccountUpdate', account);
43
43
  this.eventEmitter.emit('update');
@@ -57,7 +57,7 @@ class PollingUserAccountSubscriber {
57
57
  const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.userAccountPublicKey);
58
58
  const currentSlot = (_b = (_a = this.user) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0;
59
59
  if (buffer && slot > currentSlot) {
60
- const account = this.program.account.user.coder.accounts.decode('User', buffer);
60
+ const account = this.program.account.user.coder.accounts.decodeUnchecked('User', buffer);
61
61
  this.user = { data: account, slot };
62
62
  }
63
63
  }
@@ -37,7 +37,7 @@ class PollingUserStatsAccountSubscriber {
37
37
  if (this.userStats && this.userStats.slot > slot) {
38
38
  return;
39
39
  }
40
- const account = this.program.account.userStats.coder.accounts.decode('UserStats', buffer);
40
+ const account = this.program.account.userStats.coder.accounts.decodeUnchecked('UserStats', buffer);
41
41
  this.userStats = { data: account, slot };
42
42
  this.eventEmitter.emit('userStatsAccountUpdate', account);
43
43
  this.eventEmitter.emit('update');
@@ -57,7 +57,7 @@ class PollingUserStatsAccountSubscriber {
57
57
  const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.userStatsAccountPublicKey);
58
58
  const currentSlot = (_b = (_a = this.userStats) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0;
59
59
  if (buffer && slot > currentSlot) {
60
- const account = this.program.account.userStats.coder.accounts.decode('UserStats', buffer);
60
+ const account = this.program.account.userStats.coder.accounts.decodeUnchecked('UserStats', buffer);
61
61
  this.userStats = { data: account, slot };
62
62
  }
63
63
  }
@@ -78,7 +78,7 @@ class WebSocketAccountSubscriber {
78
78
  return this.decodeBufferFn(buffer);
79
79
  }
80
80
  else {
81
- return this.program.account[this.accountName].coder.accounts.decode((0, utils_1.capitalize)(this.accountName), buffer);
81
+ return this.program.account[this.accountName].coder.accounts.decodeUnchecked((0, utils_1.capitalize)(this.accountName), buffer);
82
82
  }
83
83
  }
84
84
  unsubscribe() {
@@ -76,7 +76,7 @@ class OrderSubscriber {
76
76
  tryUpdateUserAccount(key, buffer, slot) {
77
77
  const slotAndUserAccount = this.usersAccounts.get(key);
78
78
  if (!slotAndUserAccount || slotAndUserAccount.slot < slot) {
79
- const userAccount = this.driftClient.program.account.user.coder.accounts.decode('User', buffer);
79
+ const userAccount = this.driftClient.program.account.user.coder.accounts.decodeUnchecked('User', buffer);
80
80
  const newOrders = userAccount.orders.filter((order) => {
81
81
  var _a;
82
82
  return order.slot.toNumber() > ((_a = slotAndUserAccount === null || slotAndUserAccount === void 0 ? void 0 : slotAndUserAccount.slot) !== null && _a !== void 0 ? _a : 0) &&
@@ -165,7 +165,7 @@ class UserMap {
165
165
  }
166
166
  for (const [key, buffer] of programAccountBufferMap.entries()) {
167
167
  if (!this.has(key)) {
168
- const userAccount = this.driftClient.program.account.user.coder.accounts.decode('User', buffer);
168
+ const userAccount = this.driftClient.program.account.user.coder.accounts.decodeUnchecked('User', buffer);
169
169
  await this.addPubkey(new web3_js_1.PublicKey(key), userAccount);
170
170
  }
171
171
  }
@@ -175,7 +175,7 @@ class UserMap {
175
175
  this.userMap.delete(key);
176
176
  }
177
177
  else {
178
- const userAccount = this.driftClient.program.account.user.coder.accounts.decode('User', programAccountBufferMap.get(key));
178
+ const userAccount = this.driftClient.program.account.user.coder.accounts.decodeUnchecked('User', programAccountBufferMap.get(key));
179
179
  user.accountSubscriber.updateData(userAccount, slot);
180
180
  }
181
181
  }
@@ -141,7 +141,7 @@ class UserStatsMap {
141
141
  }
142
142
  for (const key of programAccountMap.keys()) {
143
143
  if (!this.has(key)) {
144
- const userStatsAccount = this.driftClient.program.account.userStats.coder.accounts.decode('UserStats', programAccountMap.get(key).data);
144
+ const userStatsAccount = this.driftClient.program.account.userStats.coder.accounts.decodeUnchecked('UserStats', programAccountMap.get(key).data);
145
145
  await this.addUserStat(new web3_js_1.PublicKey(key), userStatsAccount);
146
146
  }
147
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.38.1-beta.1",
3
+ "version": "2.38.1-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -36,7 +36,7 @@ export async function fetchUserAccountsUsingKeys(
36
36
  if (!accountInfo) {
37
37
  return undefined;
38
38
  }
39
- return program.account.user.coder.accounts.decode(
39
+ return program.account.user.coder.accounts.decodeUnchecked(
40
40
  'User',
41
41
  accountInfo.data
42
42
  ) as UserAccount;
@@ -58,7 +58,7 @@ export async function fetchUserStatsAccount(
58
58
  );
59
59
 
60
60
  return accountInfo
61
- ? (program.account.user.coder.accounts.decode(
61
+ ? (program.account.user.coder.accounts.decodeUnchecked(
62
62
  'UserStats',
63
63
  accountInfo.data
64
64
  ) as UserStatsAccount)
@@ -6,7 +6,7 @@ import {
6
6
  NotSubscribedError,
7
7
  OraclesToPoll,
8
8
  } from './types';
9
- import { BorshAccountsCoder, Program } from '@coral-xyz/anchor';
9
+ import { Program } from '@coral-xyz/anchor';
10
10
  import StrictEventEmitter from 'strict-event-emitter-types';
11
11
  import { EventEmitter } from 'events';
12
12
  import {
@@ -225,27 +225,9 @@ export class PollingDriftClientAccountSubscriber
225
225
  (buffer: Buffer, slot: number) => {
226
226
  if (!buffer) return;
227
227
 
228
- let account;
229
- try {
230
- account = this.program.account[
231
- accountToPoll.key
232
- ].coder.accounts.decode(capitalize(accountToPoll.key), buffer);
233
- } catch (e) {
234
- console.error(e);
235
- console.log('account key', accountToPoll.key);
236
- console.log(
237
- 'accountToPoll.publicKey',
238
- accountToPoll.publicKey.toString()
239
- );
240
- console.log('buffer', buffer.toString('base64'));
241
- console.log(
242
- 'discriminator',
243
- BorshAccountsCoder.accountDiscriminator(
244
- capitalize(accountToPoll.key)
245
- ).toString('base64')
246
- );
247
- return;
248
- }
228
+ const account = this.program.account[
229
+ accountToPoll.key
230
+ ].coder.accounts.decodeUnchecked(capitalize(accountToPoll.key), buffer);
249
231
  const dataAndSlot = {
250
232
  data: account,
251
233
  slot,
@@ -306,7 +288,7 @@ export class PollingDriftClientAccountSubscriber
306
288
  if (buffer) {
307
289
  const account = this.program.account[
308
290
  accountToPoll.key
309
- ].coder.accounts.decode(capitalize(accountToPoll.key), buffer);
291
+ ].coder.accounts.decodeUnchecked(capitalize(accountToPoll.key), buffer);
310
292
 
311
293
  if (accountToPoll.mapKey != undefined) {
312
294
  this[accountToPoll.key].set(accountToPoll.mapKey, {
@@ -71,10 +71,11 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
71
71
  return;
72
72
  }
73
73
 
74
- const account = this.program.account.user.coder.accounts.decode(
75
- 'User',
76
- buffer
77
- );
74
+ const account =
75
+ this.program.account.user.coder.accounts.decodeUnchecked(
76
+ 'User',
77
+ buffer
78
+ );
78
79
  this.user = { data: account, slot };
79
80
  this.eventEmitter.emit('userAccountUpdate', account);
80
81
  this.eventEmitter.emit('update');
@@ -99,7 +100,7 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
99
100
  );
100
101
  const currentSlot = this.user?.slot ?? 0;
101
102
  if (buffer && slot > currentSlot) {
102
- const account = this.program.account.user.coder.accounts.decode(
103
+ const account = this.program.account.user.coder.accounts.decodeUnchecked(
103
104
  'User',
104
105
  buffer
105
106
  );
@@ -74,10 +74,11 @@ export class PollingUserStatsAccountSubscriber
74
74
  return;
75
75
  }
76
76
 
77
- const account = this.program.account.userStats.coder.accounts.decode(
78
- 'UserStats',
79
- buffer
80
- );
77
+ const account =
78
+ this.program.account.userStats.coder.accounts.decodeUnchecked(
79
+ 'UserStats',
80
+ buffer
81
+ );
81
82
  this.userStats = { data: account, slot };
82
83
  this.eventEmitter.emit('userStatsAccountUpdate', account);
83
84
  this.eventEmitter.emit('update');
@@ -102,10 +103,11 @@ export class PollingUserStatsAccountSubscriber
102
103
  );
103
104
  const currentSlot = this.userStats?.slot ?? 0;
104
105
  if (buffer && slot > currentSlot) {
105
- const account = this.program.account.userStats.coder.accounts.decode(
106
- 'UserStats',
107
- buffer
108
- );
106
+ const account =
107
+ this.program.account.userStats.coder.accounts.decodeUnchecked(
108
+ 'UserStats',
109
+ buffer
110
+ );
109
111
  this.userStats = { data: account, slot };
110
112
  }
111
113
  }
@@ -112,10 +112,9 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
112
112
  if (this.decodeBufferFn) {
113
113
  return this.decodeBufferFn(buffer);
114
114
  } else {
115
- return this.program.account[this.accountName].coder.accounts.decode(
116
- capitalize(this.accountName),
117
- buffer
118
- );
115
+ return this.program.account[
116
+ this.accountName
117
+ ].coder.accounts.decodeUnchecked(capitalize(this.accountName), buffer);
119
118
  }
120
119
  }
121
120
 
@@ -106,7 +106,7 @@ export class OrderSubscriber {
106
106
  const slotAndUserAccount = this.usersAccounts.get(key);
107
107
  if (!slotAndUserAccount || slotAndUserAccount.slot < slot) {
108
108
  const userAccount =
109
- this.driftClient.program.account.user.coder.accounts.decode(
109
+ this.driftClient.program.account.user.coder.accounts.decodeUnchecked(
110
110
  'User',
111
111
  buffer
112
112
  ) as UserAccount;
@@ -235,7 +235,7 @@ export class UserMap implements UserMapInterface {
235
235
  for (const [key, buffer] of programAccountBufferMap.entries()) {
236
236
  if (!this.has(key)) {
237
237
  const userAccount =
238
- this.driftClient.program.account.user.coder.accounts.decode(
238
+ this.driftClient.program.account.user.coder.accounts.decodeUnchecked(
239
239
  'User',
240
240
  buffer
241
241
  );
@@ -249,7 +249,7 @@ export class UserMap implements UserMapInterface {
249
249
  this.userMap.delete(key);
250
250
  } else {
251
251
  const userAccount =
252
- this.driftClient.program.account.user.coder.accounts.decode(
252
+ this.driftClient.program.account.user.coder.accounts.decodeUnchecked(
253
253
  'User',
254
254
  programAccountBufferMap.get(key)
255
255
  );
@@ -197,7 +197,7 @@ export class UserStatsMap {
197
197
  for (const key of programAccountMap.keys()) {
198
198
  if (!this.has(key)) {
199
199
  const userStatsAccount =
200
- this.driftClient.program.account.userStats.coder.accounts.decode(
200
+ this.driftClient.program.account.userStats.coder.accounts.decodeUnchecked(
201
201
  'UserStats',
202
202
  programAccountMap.get(key).data
203
203
  );