@drift-labs/sdk 2.142.0-beta.14 → 2.142.0-beta.16

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.
@@ -36,13 +36,17 @@ function commitmentLevelToCommitment(
36
36
  }
37
37
  }
38
38
 
39
- export class grpcMultiAccountSubscriber<T> {
39
+ export class grpcMultiAccountSubscriber<T, U = undefined> {
40
40
  private client: Client;
41
41
  private stream: ClientDuplexStream<SubscribeRequest, SubscribeUpdate>;
42
42
  private commitmentLevel: CommitmentLevel;
43
43
  private program: Program;
44
44
  private accountName: string;
45
- private decodeBufferFn?: (buffer: Buffer, pubkey?: string) => T;
45
+ private decodeBufferFn?: (
46
+ buffer: Buffer,
47
+ pubkey?: string,
48
+ accountProps?: U
49
+ ) => T;
46
50
  private resubOpts?: ResubOpts;
47
51
  private onUnsubscribe?: () => Promise<void>;
48
52
 
@@ -54,10 +58,11 @@ export class grpcMultiAccountSubscriber<T> {
54
58
  private subscribedAccounts = new Set<string>();
55
59
  private onChangeMap = new Map<
56
60
  string,
57
- (data: T, context: Context, buffer: Buffer) => void
61
+ (data: T, context: Context, buffer: Buffer, accountProps: U) => void
58
62
  >();
59
63
 
60
64
  private dataMap = new Map<string, DataAndSlot<T>>();
65
+ private accountPropsMap = new Map<string, U | Array<U>>();
61
66
 
62
67
  private constructor(
63
68
  client: Client,
@@ -66,7 +71,8 @@ export class grpcMultiAccountSubscriber<T> {
66
71
  program: Program,
67
72
  decodeBuffer?: (buffer: Buffer, pubkey?: string) => T,
68
73
  resubOpts?: ResubOpts,
69
- onUnsubscribe?: () => Promise<void>
74
+ onUnsubscribe?: () => Promise<void>,
75
+ accountPropsMap?: Map<string, U | Array<U>>
70
76
  ) {
71
77
  this.client = client;
72
78
  this.commitmentLevel = commitmentLevel;
@@ -75,17 +81,19 @@ export class grpcMultiAccountSubscriber<T> {
75
81
  this.decodeBufferFn = decodeBuffer;
76
82
  this.resubOpts = resubOpts;
77
83
  this.onUnsubscribe = onUnsubscribe;
84
+ this.accountPropsMap = accountPropsMap;
78
85
  }
79
86
 
80
- public static async create<U>(
87
+ public static async create<T, U = undefined>(
81
88
  grpcConfigs: GrpcConfigs,
82
89
  accountName: string,
83
90
  program: Program,
84
- decodeBuffer?: (buffer: Buffer, pubkey?: string) => U,
91
+ decodeBuffer?: (buffer: Buffer, pubkey?: string, accountProps?: U) => T,
85
92
  resubOpts?: ResubOpts,
86
93
  clientProp?: Client,
87
- onUnsubscribe?: () => Promise<void>
88
- ): Promise<grpcMultiAccountSubscriber<U>> {
94
+ onUnsubscribe?: () => Promise<void>,
95
+ accountPropsMap?: Map<string, U | Array<U>>
96
+ ): Promise<grpcMultiAccountSubscriber<T, U>> {
89
97
  const client = clientProp
90
98
  ? clientProp
91
99
  : await createClient(
@@ -104,7 +112,8 @@ export class grpcMultiAccountSubscriber<T> {
104
112
  program,
105
113
  decodeBuffer,
106
114
  resubOpts,
107
- onUnsubscribe
115
+ onUnsubscribe,
116
+ accountPropsMap
108
117
  );
109
118
  }
110
119
 
@@ -176,7 +185,8 @@ export class grpcMultiAccountSubscriber<T> {
176
185
  accountId: PublicKey,
177
186
  data: T,
178
187
  context: Context,
179
- buffer: Buffer
188
+ buffer: Buffer,
189
+ accountProps: U
180
190
  ) => void
181
191
  ): Promise<void> {
182
192
  if (this.listenerId != null || this.isUnsubscribing) {
@@ -187,9 +197,9 @@ export class grpcMultiAccountSubscriber<T> {
187
197
  for (const pk of accounts) {
188
198
  const key = pk.toBase58();
189
199
  this.subscribedAccounts.add(key);
190
- this.onChangeMap.set(key, (data, ctx, buffer) => {
200
+ this.onChangeMap.set(key, (data, ctx, buffer, accountProps) => {
191
201
  this.setAccountData(key, data, ctx.slot);
192
- onChange(new PublicKey(key), data, ctx, buffer);
202
+ onChange(new PublicKey(key), data, ctx, buffer, accountProps);
193
203
  });
194
204
  }
195
205
 
@@ -235,23 +245,38 @@ export class grpcMultiAccountSubscriber<T> {
235
245
 
236
246
  const context = { slot } as Context;
237
247
  const buffer = accountInfo.data;
238
- const data = this.decodeBufferFn
239
- ? this.decodeBufferFn(buffer, accountPubkey)
240
- : this.program.account[this.accountName].coder.accounts.decode(
241
- this.capitalize(this.accountName),
242
- buffer
243
- );
244
-
245
- const handler = this.onChangeMap.get(accountPubkey);
246
- if (handler) {
247
- if (this.resubOpts?.resubTimeoutMs) {
248
- this.receivingData = true;
249
- clearTimeout(this.timeoutId);
250
- handler(data, context, buffer);
251
- this.setTimeout();
252
- } else {
253
- handler(data, context, buffer);
248
+ const accountProps = this.accountPropsMap?.get(accountPubkey);
249
+
250
+ const handleDataBuffer = (
251
+ context: Context,
252
+ buffer: Buffer,
253
+ accountProps: U
254
+ ) => {
255
+ const data = this.decodeBufferFn
256
+ ? this.decodeBufferFn(buffer, accountPubkey, accountProps)
257
+ : this.program.account[this.accountName].coder.accounts.decode(
258
+ this.capitalize(this.accountName),
259
+ buffer
260
+ );
261
+ const handler = this.onChangeMap.get(accountPubkey);
262
+ if (handler) {
263
+ if (this.resubOpts?.resubTimeoutMs) {
264
+ this.receivingData = true;
265
+ clearTimeout(this.timeoutId);
266
+ handler(data, context, buffer, accountProps);
267
+ this.setTimeout();
268
+ } else {
269
+ handler(data, context, buffer, accountProps);
270
+ }
271
+ }
272
+ };
273
+
274
+ if (Array.isArray(accountProps)) {
275
+ for (const props of accountProps) {
276
+ handleDataBuffer(context, buffer, props);
254
277
  }
278
+ } else {
279
+ handleDataBuffer(context, buffer, accountProps);
255
280
  }
256
281
  });
257
282
 
@@ -1373,6 +1373,16 @@ export class DriftClient {
1373
1373
  });
1374
1374
  }
1375
1375
 
1376
+ /**
1377
+ * Creates the transaction to add or update an approved builder.
1378
+ * This allows the builder to receive revenue share from referrals.
1379
+ *
1380
+ * @param builder - The public key of the builder to add or update.
1381
+ * @param maxFeeTenthBps - The maximum fee tenth bps to set for the builder.
1382
+ * @param add - Whether to add or update the builder. If the builder already exists, `add = true` will update the `maxFeeTenthBps`, otherwise it will add the builder. If `add = false`, the builder's `maxFeeTenthBps` will be set to 0.
1383
+ * @param txParams - The transaction parameters to use for the transaction.
1384
+ * @returns The transaction to add or update an approved builder.
1385
+ */
1376
1386
  public async changeApprovedBuilder(
1377
1387
  builder: PublicKey,
1378
1388
  maxFeeTenthBps: number,
@@ -1389,6 +1399,15 @@ export class DriftClient {
1389
1399
  return txSig;
1390
1400
  }
1391
1401
 
1402
+ /**
1403
+ * Creates the transaction instruction to add or update an approved builder.
1404
+ * This allows the builder to receive revenue share from referrals.
1405
+ *
1406
+ * @param builder - The public key of the builder to add or update.
1407
+ * @param maxFeeTenthBps - The maximum fee tenth bps to set for the builder.
1408
+ * @param add - Whether to add or update the builder. If the builder already exists, `add = true` will update the `maxFeeTenthBps`, otherwise it will add the builder. If `add = false`, the builder's `maxFeeTenthBps` will be set to 0.
1409
+ * @returns The transaction instruction to add or update an approved builder.
1410
+ */
1392
1411
  public async getChangeApprovedBuilderIx(
1393
1412
  builder: PublicKey,
1394
1413
  maxFeeTenthBps: number,