@velocity-exchange/sdk 0.0.1 → 0.0.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.
Files changed (161) hide show
  1. package/README.md +5 -6
  2. package/bunfig.toml +3 -0
  3. package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +4 -2
  4. package/lib/browser/auctionSubscriber/auctionSubscriber.js +9 -4
  5. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
  6. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
  7. package/lib/browser/auctionSubscriber/types.d.ts +4 -2
  8. package/lib/browser/config.d.ts +3 -8
  9. package/lib/browser/config.js +14 -22
  10. package/lib/browser/constituentMap/constituentMap.d.ts +4 -2
  11. package/lib/browser/constituentMap/constituentMap.js +14 -10
  12. package/lib/browser/core/VelocityCore.d.ts +4 -0
  13. package/lib/browser/core/VelocityCore.js +3 -1
  14. package/lib/browser/dlob/DLOBSubscriber.d.ts +3 -1
  15. package/lib/browser/dlob/DLOBSubscriber.js +19 -10
  16. package/lib/browser/dlob/types.d.ts +3 -1
  17. package/lib/browser/idl/drift.d.ts +54 -1
  18. package/lib/browser/idl/drift.json +6046 -803
  19. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +3 -1
  20. package/lib/browser/orderSubscriber/OrderSubscriber.js +19 -11
  21. package/lib/browser/orderSubscriber/types.d.ts +3 -1
  22. package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +4 -2
  23. package/lib/browser/priorityFee/priorityFeeSubscriber.js +15 -11
  24. package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
  25. package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +18 -18
  26. package/lib/browser/priorityFee/types.d.ts +9 -5
  27. package/lib/browser/priorityFee/types.js +1 -1
  28. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
  29. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
  30. package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
  31. package/lib/browser/swift/signedMsgUserAccountSubscriber.js +10 -5
  32. package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -4
  33. package/lib/browser/swift/swiftOrderSubscriber.js +19 -11
  34. package/lib/browser/user.d.ts +3 -1
  35. package/lib/browser/user.js +93 -86
  36. package/lib/browser/userConfig.d.ts +4 -2
  37. package/lib/browser/userMap/referrerMap.d.ts +5 -3
  38. package/lib/browser/userMap/referrerMap.js +18 -14
  39. package/lib/browser/userMap/revenueShareEscrowMap.d.ts +5 -3
  40. package/lib/browser/userMap/revenueShareEscrowMap.js +18 -14
  41. package/lib/browser/userMap/userMap.d.ts +3 -1
  42. package/lib/browser/userMap/userMap.js +24 -19
  43. package/lib/browser/userMap/userMapConfig.d.ts +4 -2
  44. package/lib/browser/userMap/userStatsMap.d.ts +5 -3
  45. package/lib/browser/userMap/userStatsMap.js +15 -11
  46. package/lib/browser/userStats.d.ts +3 -1
  47. package/lib/browser/userStats.js +21 -15
  48. package/lib/browser/userStatsConfig.d.ts +4 -2
  49. package/lib/browser/util/deprecatedAlias.d.ts +26 -0
  50. package/lib/browser/util/deprecatedAlias.js +10 -0
  51. package/lib/browser/velocityClient.js +5 -5
  52. package/lib/browser/velocityClientConfig.d.ts +7 -4
  53. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +4 -2
  54. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
  55. package/lib/node/auctionSubscriber/auctionSubscriber.js +9 -4
  56. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
  57. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
  58. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
  59. package/lib/node/auctionSubscriber/types.d.ts +4 -2
  60. package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
  61. package/lib/node/config.d.ts +3 -8
  62. package/lib/node/config.d.ts.map +1 -1
  63. package/lib/node/config.js +14 -22
  64. package/lib/node/constituentMap/constituentMap.d.ts +4 -2
  65. package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
  66. package/lib/node/constituentMap/constituentMap.js +14 -10
  67. package/lib/node/core/VelocityCore.d.ts +4 -0
  68. package/lib/node/core/VelocityCore.d.ts.map +1 -1
  69. package/lib/node/core/VelocityCore.js +3 -1
  70. package/lib/node/dlob/DLOBSubscriber.d.ts +3 -1
  71. package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
  72. package/lib/node/dlob/DLOBSubscriber.js +19 -10
  73. package/lib/node/dlob/types.d.ts +3 -1
  74. package/lib/node/dlob/types.d.ts.map +1 -1
  75. package/lib/node/idl/drift.d.ts +54 -1
  76. package/lib/node/idl/drift.d.ts.map +1 -1
  77. package/lib/node/idl/drift.json +6046 -803
  78. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +3 -1
  79. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  80. package/lib/node/orderSubscriber/OrderSubscriber.js +19 -11
  81. package/lib/node/orderSubscriber/types.d.ts +3 -1
  82. package/lib/node/orderSubscriber/types.d.ts.map +1 -1
  83. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +4 -2
  84. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
  85. package/lib/node/priorityFee/priorityFeeSubscriber.js +15 -11
  86. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
  87. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
  88. package/lib/node/priorityFee/priorityFeeSubscriberMap.js +18 -18
  89. package/lib/node/priorityFee/types.d.ts +9 -5
  90. package/lib/node/priorityFee/types.d.ts.map +1 -1
  91. package/lib/node/priorityFee/types.js +1 -1
  92. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
  93. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
  94. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
  95. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
  96. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
  97. package/lib/node/swift/signedMsgUserAccountSubscriber.js +10 -5
  98. package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -4
  99. package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
  100. package/lib/node/swift/swiftOrderSubscriber.js +19 -11
  101. package/lib/node/user.d.ts +3 -1
  102. package/lib/node/user.d.ts.map +1 -1
  103. package/lib/node/user.js +93 -86
  104. package/lib/node/userConfig.d.ts +4 -2
  105. package/lib/node/userConfig.d.ts.map +1 -1
  106. package/lib/node/userMap/referrerMap.d.ts +5 -3
  107. package/lib/node/userMap/referrerMap.d.ts.map +1 -1
  108. package/lib/node/userMap/referrerMap.js +18 -14
  109. package/lib/node/userMap/revenueShareEscrowMap.d.ts +5 -3
  110. package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
  111. package/lib/node/userMap/revenueShareEscrowMap.js +18 -14
  112. package/lib/node/userMap/userMap.d.ts +3 -1
  113. package/lib/node/userMap/userMap.d.ts.map +1 -1
  114. package/lib/node/userMap/userMap.js +24 -19
  115. package/lib/node/userMap/userMapConfig.d.ts +4 -2
  116. package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
  117. package/lib/node/userMap/userStatsMap.d.ts +5 -3
  118. package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
  119. package/lib/node/userMap/userStatsMap.js +15 -11
  120. package/lib/node/userStats.d.ts +3 -1
  121. package/lib/node/userStats.d.ts.map +1 -1
  122. package/lib/node/userStats.js +21 -15
  123. package/lib/node/userStatsConfig.d.ts +4 -2
  124. package/lib/node/userStatsConfig.d.ts.map +1 -1
  125. package/lib/node/util/deprecatedAlias.d.ts +27 -0
  126. package/lib/node/util/deprecatedAlias.d.ts.map +1 -0
  127. package/lib/node/util/deprecatedAlias.js +10 -0
  128. package/lib/node/velocityClient.js +5 -5
  129. package/lib/node/velocityClientConfig.d.ts +7 -4
  130. package/lib/node/velocityClientConfig.d.ts.map +1 -1
  131. package/package.json +2 -3
  132. package/src/auctionSubscriber/auctionSubscriber.ts +12 -6
  133. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -6
  134. package/src/auctionSubscriber/types.ts +5 -2
  135. package/src/config.ts +35 -27
  136. package/src/constituentMap/constituentMap.ts +17 -9
  137. package/src/core/VelocityCore.ts +6 -0
  138. package/src/dlob/DLOBSubscriber.ts +21 -11
  139. package/src/dlob/types.ts +3 -1
  140. package/src/idl/drift.json +23940 -18697
  141. package/src/idl/drift.ts +54 -1
  142. package/src/orderSubscriber/OrderSubscriber.ts +17 -7
  143. package/src/orderSubscriber/types.ts +3 -1
  144. package/src/priorityFee/priorityFeeSubscriber.ts +13 -9
  145. package/src/priorityFee/priorityFeeSubscriberMap.ts +23 -25
  146. package/src/priorityFee/types.ts +14 -9
  147. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +10 -23
  148. package/src/swift/signedMsgUserAccountSubscriber.ts +22 -14
  149. package/src/swift/swiftOrderSubscriber.ts +24 -16
  150. package/src/user.ts +93 -82
  151. package/src/userConfig.ts +5 -2
  152. package/src/userMap/referrerMap.ts +19 -15
  153. package/src/userMap/revenueShareEscrowMap.ts +20 -16
  154. package/src/userMap/userMap.ts +20 -15
  155. package/src/userMap/userMapConfig.ts +6 -3
  156. package/src/userMap/userStatsMap.ts +19 -15
  157. package/src/userStats.ts +13 -7
  158. package/src/userStatsConfig.ts +5 -2
  159. package/src/util/deprecatedAlias.ts +25 -0
  160. package/src/velocityClient.ts +6 -6
  161. package/src/velocityClientConfig.ts +25 -42
@@ -28,7 +28,11 @@ export class ReferrerMap {
28
28
  * Will be undefined if the referrer is not in the map yet.
29
29
  */
30
30
  private referrerReferrerInfoMap = new Map<string, ReferrerInfo>();
31
- private driftClient: VelocityClient;
31
+ private velocityClient: VelocityClient;
32
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
33
+ private get driftClient(): VelocityClient {
34
+ return this.velocityClient;
35
+ }
32
36
  private parallelSync: boolean;
33
37
 
34
38
  private fetchPromise?: Promise<void>;
@@ -37,10 +41,10 @@ export class ReferrerMap {
37
41
  /**
38
42
  * Creates a new UserStatsMap instance.
39
43
  *
40
- * @param {VelocityClient} driftClient - The VelocityClient instance.
44
+ * @param {VelocityClient} velocityClient - The VelocityClient instance.
41
45
  */
42
- constructor(driftClient: VelocityClient, parallelSync?: boolean) {
43
- this.driftClient = driftClient;
46
+ constructor(velocityClient: VelocityClient, parallelSync?: boolean) {
47
+ this.velocityClient = velocityClient;
44
48
  this.parallelSync = parallelSync !== undefined ? parallelSync : true;
45
49
  }
46
50
 
@@ -52,7 +56,7 @@ export class ReferrerMap {
52
56
  return;
53
57
  }
54
58
 
55
- await this.driftClient.subscribe();
59
+ await this.velocityClient.subscribe();
56
60
  await this.sync();
57
61
  }
58
62
 
@@ -69,11 +73,11 @@ export class ReferrerMap {
69
73
  this.authorityReferrerMap.set(authority, referrer);
70
74
  } else if (referrer === undefined) {
71
75
  const userStatsAccountPublicKey = getUserStatsAccountPublicKey(
72
- this.driftClient.program.programId,
76
+ this.velocityClient.program.programId,
73
77
  new PublicKey(authority)
74
78
  );
75
79
  const buffer = (
76
- await this.driftClient.connection.getAccountInfo(
80
+ await this.velocityClient.connection.getAccountInfo(
77
81
  userStatsAccountPublicKey,
78
82
  'processed'
79
83
  )
@@ -118,12 +122,12 @@ export class ReferrerMap {
118
122
  const referrerKey = new PublicKey(referrer);
119
123
  const referrerInfo = {
120
124
  referrer: getUserAccountPublicKeySync(
121
- this.driftClient.program.programId,
125
+ this.velocityClient.program.programId,
122
126
  referrerKey,
123
127
  0
124
128
  ),
125
129
  referrerStats: getUserStatsAccountPublicKey(
126
- this.driftClient.program.programId,
130
+ this.velocityClient.program.programId,
127
131
  referrerKey
128
132
  ),
129
133
  };
@@ -171,9 +175,9 @@ export class ReferrerMap {
171
175
 
172
176
  public async syncAll(): Promise<void> {
173
177
  const rpcRequestArgs = [
174
- this.driftClient.program.programId.toBase58(),
178
+ this.velocityClient.program.programId.toBase58(),
175
179
  {
176
- commitment: this.driftClient.opts.commitment,
180
+ commitment: this.velocityClient.opts.commitment,
177
181
  filters: [getUserStatsFilter()],
178
182
  encoding: 'base64',
179
183
  dataSlice: {
@@ -186,7 +190,7 @@ export class ReferrerMap {
186
190
 
187
191
  const rpcJSONResponse: any =
188
192
  // @ts-ignore
189
- await this.driftClient.connection._rpcRequest(
193
+ await this.velocityClient.connection._rpcRequest(
190
194
  'getProgramAccounts',
191
195
  rpcRequestArgs
192
196
  );
@@ -211,9 +215,9 @@ export class ReferrerMap {
211
215
 
212
216
  async syncReferrer(referrerFilter: MemcmpFilter): Promise<void> {
213
217
  const rpcRequestArgs = [
214
- this.driftClient.program.programId.toBase58(),
218
+ this.velocityClient.program.programId.toBase58(),
215
219
  {
216
- commitment: this.driftClient.opts.commitment,
220
+ commitment: this.velocityClient.opts.commitment,
217
221
  filters: [getUserStatsFilter(), referrerFilter],
218
222
  encoding: 'base64',
219
223
  dataSlice: {
@@ -226,7 +230,7 @@ export class ReferrerMap {
226
230
 
227
231
  const rpcJSONResponse: any =
228
232
  // @ts-ignore
229
- await this.driftClient.connection._rpcRequest(
233
+ await this.velocityClient.connection._rpcRequest(
230
234
  'getProgramAccounts',
231
235
  rpcRequestArgs
232
236
  );
@@ -9,7 +9,11 @@ export class RevenueShareEscrowMap {
9
9
  * map from authority pubkey to RevenueShareEscrow account data.
10
10
  */
11
11
  private authorityEscrowMap = new Map<string, RevenueShareEscrowAccount>();
12
- private driftClient: VelocityClient;
12
+ private velocityClient: VelocityClient;
13
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
14
+ private get driftClient(): VelocityClient {
15
+ return this.velocityClient;
16
+ }
13
17
  private parallelSync: boolean;
14
18
 
15
19
  private fetchPromise?: Promise<void>;
@@ -18,11 +22,11 @@ export class RevenueShareEscrowMap {
18
22
  /**
19
23
  * Creates a new RevenueShareEscrowMap instance.
20
24
  *
21
- * @param {VelocityClient} driftClient - The VelocityClient instance.
25
+ * @param {VelocityClient} velocityClient - The VelocityClient instance.
22
26
  * @param {boolean} parallelSync - Whether to sync accounts in parallel.
23
27
  */
24
- constructor(driftClient: VelocityClient, parallelSync?: boolean) {
25
- this.driftClient = driftClient;
28
+ constructor(velocityClient: VelocityClient, parallelSync?: boolean) {
29
+ this.velocityClient = velocityClient;
26
30
  this.parallelSync = parallelSync !== undefined ? parallelSync : true;
27
31
  }
28
32
 
@@ -34,7 +38,7 @@ export class RevenueShareEscrowMap {
34
38
  return;
35
39
  }
36
40
 
37
- await this.driftClient.subscribe();
41
+ await this.velocityClient.subscribe();
38
42
  await this.sync();
39
43
  }
40
44
 
@@ -65,19 +69,19 @@ export class RevenueShareEscrowMap {
65
69
 
66
70
  public async addRevenueShareEscrow(authority: string) {
67
71
  const escrowAccountPublicKey = getRevenueShareEscrowAccountPublicKey(
68
- this.driftClient.program.programId,
72
+ this.velocityClient.program.programId,
69
73
  new PublicKey(authority)
70
74
  );
71
75
 
72
76
  try {
73
- const accountInfo = await this.driftClient.connection.getAccountInfo(
77
+ const accountInfo = await this.velocityClient.connection.getAccountInfo(
74
78
  escrowAccountPublicKey,
75
79
  'processed'
76
80
  );
77
81
 
78
82
  if (accountInfo && accountInfo.data) {
79
83
  const escrow = (
80
- this.driftClient.program.account as any
84
+ this.velocityClient.program.account as any
81
85
  ).revenueShareEscrow.coder.accounts.decode(
82
86
  'revenueShareEscrow',
83
87
  accountInfo.data
@@ -123,15 +127,15 @@ export class RevenueShareEscrowMap {
123
127
  return this.fetchPromise;
124
128
  }
125
129
  for (const authority of this.authorityEscrowMap.keys()) {
126
- const accountInfo = await this.driftClient.connection.getAccountInfo(
130
+ const accountInfo = await this.velocityClient.connection.getAccountInfo(
127
131
  getRevenueShareEscrowAccountPublicKey(
128
- this.driftClient.program.programId,
132
+ this.velocityClient.program.programId,
129
133
  new PublicKey(authority)
130
134
  ),
131
135
  'confirmed'
132
136
  );
133
137
  const escrowNew = (
134
- this.driftClient.program.account as any
138
+ this.velocityClient.program.account as any
135
139
  ).revenueShareEscrow.coder.accounts.decode(
136
140
  'revenueShareEscrow',
137
141
  accountInfo.data
@@ -142,9 +146,9 @@ export class RevenueShareEscrowMap {
142
146
 
143
147
  public async syncAll(): Promise<void> {
144
148
  const rpcRequestArgs = [
145
- this.driftClient.program.programId.toBase58(),
149
+ this.velocityClient.program.programId.toBase58(),
146
150
  {
147
- commitment: this.driftClient.opts.commitment,
151
+ commitment: this.velocityClient.opts.commitment,
148
152
  filters: [getRevenueShareEscrowFilter()],
149
153
  encoding: 'base64',
150
154
  withContext: true,
@@ -153,7 +157,7 @@ export class RevenueShareEscrowMap {
153
157
 
154
158
  const rpcJSONResponse: any =
155
159
  // @ts-ignore
156
- await this.driftClient.connection._rpcRequest(
160
+ await this.velocityClient.connection._rpcRequest(
157
161
  'getProgramAccounts',
158
162
  rpcRequestArgs
159
163
  );
@@ -182,7 +186,7 @@ export class RevenueShareEscrowMap {
182
186
  );
183
187
 
184
188
  const escrow = (
185
- this.driftClient.program.account as any
189
+ this.velocityClient.program.account as any
186
190
  ).revenueShareEscrow.coder.accounts.decode(
187
191
  'revenueShareEscrow',
188
192
  buffer
@@ -209,7 +213,7 @@ export class RevenueShareEscrowMap {
209
213
  );
210
214
 
211
215
  const escrow = (
212
- this.driftClient.program.account as any
216
+ this.velocityClient.program.account as any
213
217
  ).revenueShareEscrow.coder.accounts.decode(
214
218
  'revenueShareEscrow',
215
219
  buffer
@@ -77,7 +77,11 @@ export interface UserMapInterface {
77
77
 
78
78
  export class UserMap implements UserMapInterface {
79
79
  private userMap = new Map<string, DataAndSlot<User>>();
80
- driftClient: VelocityClient;
80
+ velocityClient: VelocityClient;
81
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
82
+ public get driftClient(): VelocityClient {
83
+ return this.velocityClient;
84
+ }
81
85
  eventEmitter: StrictEventEmitter<EventEmitter, UserEvents>;
82
86
  private connection: Connection;
83
87
  private commitment: Commitment;
@@ -109,18 +113,19 @@ export class UserMap implements UserMapInterface {
109
113
  * Constructs a new UserMap instance.
110
114
  */
111
115
  constructor(config: UserMapConfig) {
112
- this.driftClient = config.driftClient;
116
+ // Type-system guarantees at least one of the two is supplied.
117
+ this.velocityClient = (config.velocityClient ?? config.driftClient)!;
113
118
  if (config.connection) {
114
119
  this.connection = config.connection;
115
120
  } else {
116
- this.connection = this.driftClient.connection;
121
+ this.connection = this.velocityClient.connection;
117
122
  }
118
123
  this.commitment =
119
124
  config.subscriptionConfig.type === 'websocket' ||
120
125
  config.subscriptionConfig.type === 'polling'
121
126
  ? config.subscriptionConfig.commitment ??
122
- this.driftClient.opts.commitment
123
- : this.driftClient.opts.commitment;
127
+ this.velocityClient.opts.commitment
128
+ : this.velocityClient.opts.commitment;
124
129
  this.includeIdle = config.includeIdle ?? false;
125
130
  this.filterByPoolId = config.filterByPoolId;
126
131
  this.additionalFilters = config.additionalFilters;
@@ -132,9 +137,9 @@ export class UserMap implements UserMapInterface {
132
137
  decodeFn = (name, buffer) => decodeUser(buffer);
133
138
  } else {
134
139
  decodeFn = (
135
- this.driftClient.program.account as any
140
+ this.velocityClient.program.account as any
136
141
  ).user.coder.accounts.decodeUnchecked.bind(
137
- (this.driftClient.program.account as any).user.coder.accounts
142
+ (this.velocityClient.program.account as any).user.coder.accounts
138
143
  );
139
144
  }
140
145
  this.decode = decodeFn;
@@ -183,11 +188,11 @@ export class UserMap implements UserMapInterface {
183
188
  return;
184
189
  }
185
190
 
186
- await this.driftClient.subscribe();
191
+ await this.velocityClient.subscribe();
187
192
  this.lastNumberOfSubAccounts =
188
- this.driftClient.getStateAccount().numberOfSubAccounts;
193
+ this.velocityClient.getStateAccount().numberOfSubAccounts;
189
194
  if (!this.disableSyncOnTotalAccountsChange) {
190
- this.driftClient.eventEmitter.on(
195
+ this.velocityClient.eventEmitter.on(
191
196
  'stateAccountUpdate',
192
197
  this.stateAccountUpdateCallback
193
198
  );
@@ -203,13 +208,13 @@ export class UserMap implements UserMapInterface {
203
208
  accountSubscription?: UserSubscriptionConfig
204
209
  ) {
205
210
  const user = new User({
206
- driftClient: this.driftClient,
211
+ velocityClient: this.velocityClient,
207
212
  userAccountPublicKey,
208
213
  accountSubscription: accountSubscription ?? {
209
214
  type: 'custom',
210
215
  // OneShotUserAccountSubscriber used here so we don't load up the RPC with AccountSubscribes
211
216
  userAccountSubscriber: new OneShotUserAccountSubscriber(
212
- this.driftClient.program,
217
+ this.velocityClient.program,
213
218
  userAccountPublicKey,
214
219
  userAccount,
215
220
  slot,
@@ -428,7 +433,7 @@ export class UserMap implements UserMapInterface {
428
433
 
429
434
  try {
430
435
  const rpcRequestArgs = [
431
- this.driftClient.program.programId.toBase58(),
436
+ this.velocityClient.program.programId.toBase58(),
432
437
  {
433
438
  commitment: this.commitment,
434
439
  filters: this.getFilters(),
@@ -526,7 +531,7 @@ export class UserMap implements UserMapInterface {
526
531
 
527
532
  try {
528
533
  const accountsPrefetch = await this.connection.getProgramAccounts(
529
- this.driftClient.program.programId,
534
+ this.velocityClient.program.programId,
530
535
  {
531
536
  dataSlice: { offset: 0, length: 0 },
532
537
  filters: this.getFilters(),
@@ -642,7 +647,7 @@ export class UserMap implements UserMapInterface {
642
647
 
643
648
  if (this.lastNumberOfSubAccounts) {
644
649
  if (!this.disableSyncOnTotalAccountsChange) {
645
- this.driftClient.eventEmitter.removeListener(
650
+ this.velocityClient.eventEmitter.removeListener(
646
651
  'stateAccountUpdate',
647
652
  this.stateAccountUpdateCallback
648
653
  );
@@ -1,6 +1,7 @@
1
1
  import { Commitment, Connection, MemcmpFilter } from '@solana/web3.js';
2
2
  import { VelocityClient } from '../velocityClient';
3
3
  import { GrpcConfigs } from '../accounts/types';
4
+ import { AtLeastOne } from '../util/deprecatedAlias';
4
5
 
5
6
  // passed into UserMap.getUniqueAuthorities to filter users
6
7
  export type UserAccountFilterCriteria = {
@@ -18,9 +19,8 @@ export type SyncConfig =
18
19
  concurrencyLimit?: number;
19
20
  };
20
21
 
21
- export type UserMapConfig = {
22
- driftClient: VelocityClient;
23
- // connection object to use specifically for the UserMap. If undefined, will use the driftClient's connection
22
+ type UserMapConfigBase = {
23
+ // connection object to use specifically for the UserMap. If undefined, will use the velocityClient's connection
24
24
  connection?: Connection;
25
25
  subscriptionConfig:
26
26
  | {
@@ -64,3 +64,6 @@ export type UserMapConfig = {
64
64
 
65
65
  additionalFilters?: MemcmpFilter[];
66
66
  };
67
+
68
+ export type UserMapConfig = UserMapConfigBase &
69
+ AtLeastOne<'velocityClient', 'driftClient', VelocityClient>;
@@ -26,7 +26,11 @@ export class UserStatsMap {
26
26
  * map from authority pubkey to UserStats
27
27
  */
28
28
  private userStatsMap = new Map<string, UserStats>();
29
- private driftClient: VelocityClient;
29
+ private velocityClient: VelocityClient;
30
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
31
+ private get driftClient(): VelocityClient {
32
+ return this.velocityClient;
33
+ }
30
34
  private bulkAccountLoader: BulkAccountLoader;
31
35
  private decode;
32
36
  private syncConfig: SyncConfig;
@@ -37,19 +41,19 @@ export class UserStatsMap {
37
41
  /**
38
42
  * Creates a new UserStatsMap instance.
39
43
  *
40
- * @param {VelocityClient} driftClient - The VelocityClient instance.
44
+ * @param {VelocityClient} velocityClient - The VelocityClient instance.
41
45
  * @param {BulkAccountLoader} [bulkAccountLoader] - If not provided, a new BulkAccountLoader with polling disabled will be created.
42
46
  */
43
47
  constructor(
44
- driftClient: VelocityClient,
48
+ velocityClient: VelocityClient,
45
49
  bulkAccountLoader?: BulkAccountLoader,
46
50
  syncConfig?: SyncConfig
47
51
  ) {
48
- this.driftClient = driftClient;
52
+ this.velocityClient = velocityClient;
49
53
  if (!bulkAccountLoader) {
50
54
  bulkAccountLoader = new BulkAccountLoader(
51
- driftClient.connection,
52
- driftClient.opts.commitment,
55
+ velocityClient.connection,
56
+ velocityClient.opts.commitment,
53
57
  0
54
58
  );
55
59
  }
@@ -60,9 +64,9 @@ export class UserStatsMap {
60
64
  };
61
65
 
62
66
  this.decode = (
63
- this.driftClient.program.account as any
67
+ this.velocityClient.program.account as any
64
68
  ).userStats.coder.accounts.decodeUnchecked.bind(
65
- (this.driftClient.program.account as any).userStats.coder.accounts
69
+ (this.velocityClient.program.account as any).userStats.coder.accounts
66
70
  );
67
71
  }
68
72
 
@@ -71,7 +75,7 @@ export class UserStatsMap {
71
75
  return;
72
76
  }
73
77
 
74
- await this.driftClient.subscribe();
78
+ await this.velocityClient.subscribe();
75
79
  await this.sync(authorities);
76
80
  }
77
81
 
@@ -87,9 +91,9 @@ export class UserStatsMap {
87
91
  skipFetch?: boolean
88
92
  ) {
89
93
  const userStat = new UserStats({
90
- driftClient: this.driftClient,
94
+ velocityClient: this.velocityClient,
91
95
  userStatsAccountPublicKey: getUserStatsAccountPublicKey(
92
- this.driftClient.program.programId,
96
+ this.velocityClient.program.programId,
93
97
  authority
94
98
  ),
95
99
  accountSubscription: {
@@ -252,8 +256,8 @@ export class UserStatsMap {
252
256
  let accountsToLoad = authorities;
253
257
  if (authorities.length === 0) {
254
258
  const accountsPrefetch =
255
- await this.driftClient.connection.getProgramAccounts(
256
- this.driftClient.program.programId,
259
+ await this.velocityClient.connection.getProgramAccounts(
260
+ this.velocityClient.program.programId,
257
261
  {
258
262
  dataSlice: { offset: 0, length: 0 },
259
263
  filters: [getUserStatsFilter()],
@@ -295,10 +299,10 @@ export class UserStatsMap {
295
299
  const chunk = accountsToLoad.slice(i, i + chunkSize);
296
300
  tasks.push(async () => {
297
301
  const accountInfos =
298
- await this.driftClient.connection.getMultipleAccountsInfoAndContext(
302
+ await this.velocityClient.connection.getMultipleAccountsInfoAndContext(
299
303
  chunk,
300
304
  {
301
- commitment: this.driftClient.opts.commitment,
305
+ commitment: this.velocityClient.opts.commitment,
302
306
  }
303
307
  );
304
308
 
package/src/userStats.ts CHANGED
@@ -17,24 +17,30 @@ import {
17
17
  import { grpcUserStatsAccountSubscriber } from './accounts/grpcUserStatsAccountSubscriber';
18
18
 
19
19
  export class UserStats {
20
- driftClient: VelocityClient;
20
+ velocityClient: VelocityClient;
21
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
22
+ public get driftClient(): VelocityClient {
23
+ return this.velocityClient;
24
+ }
21
25
  userStatsAccountPublicKey: PublicKey;
22
26
  accountSubscriber: UserStatsAccountSubscriber;
23
27
  isSubscribed: boolean;
24
28
 
25
29
  public constructor(config: UserStatsConfig) {
26
- this.driftClient = config.driftClient;
30
+ // Type-system guarantees at least one of the two is supplied.
31
+ const velocityClient = (config.velocityClient ?? config.driftClient)!;
32
+ this.velocityClient = velocityClient;
27
33
  this.userStatsAccountPublicKey = config.userStatsAccountPublicKey;
28
34
  if (config.accountSubscription?.type === 'polling') {
29
35
  this.accountSubscriber = new PollingUserStatsAccountSubscriber(
30
- config.driftClient.program,
36
+ velocityClient.program,
31
37
  config.userStatsAccountPublicKey,
32
38
  config.accountSubscription.accountLoader
33
39
  );
34
40
  } else if (config.accountSubscription?.type === 'grpc') {
35
41
  this.accountSubscriber = new grpcUserStatsAccountSubscriber(
36
42
  config.accountSubscription.grpcConfigs,
37
- config.driftClient.program,
43
+ velocityClient.program,
38
44
  config.userStatsAccountPublicKey,
39
45
  {
40
46
  resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
@@ -43,7 +49,7 @@ export class UserStats {
43
49
  );
44
50
  } else if (config.accountSubscription?.type === 'websocket') {
45
51
  this.accountSubscriber = new WebSocketUserStatsAccountSubscriber(
46
- config.driftClient.program,
52
+ velocityClient.program,
47
53
  config.userStatsAccountPublicKey,
48
54
  {
49
55
  resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
@@ -95,12 +101,12 @@ export class UserStats {
95
101
  } else {
96
102
  return {
97
103
  referrer: getUserAccountPublicKeySync(
98
- this.driftClient.program.programId,
104
+ this.velocityClient.program.programId,
99
105
  this.getAccount().referrer,
100
106
  0
101
107
  ),
102
108
  referrerStats: getUserStatsAccountPublicKey(
103
- this.driftClient.program.programId,
109
+ this.velocityClient.program.programId,
104
110
  this.getAccount().referrer
105
111
  ),
106
112
  };
@@ -2,13 +2,16 @@ import { VelocityClient } from './velocityClient';
2
2
  import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
4
  import { GrpcConfigs, UserStatsAccountSubscriber } from './accounts/types';
5
+ import { AtLeastOne } from './util/deprecatedAlias';
5
6
 
6
- export type UserStatsConfig = {
7
+ type UserStatsConfigBase = {
7
8
  accountSubscription?: UserStatsSubscriptionConfig;
8
- driftClient: VelocityClient;
9
9
  userStatsAccountPublicKey: PublicKey;
10
10
  };
11
11
 
12
+ export type UserStatsConfig = UserStatsConfigBase &
13
+ AtLeastOne<'velocityClient', 'driftClient', VelocityClient>;
14
+
12
15
  export type UserStatsSubscriptionConfig =
13
16
  | {
14
17
  type: 'websocket';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Type helpers for expressing the Drift → Velocity rename surface.
3
+ *
4
+ * The SDK exposes paired keys (`velocityX` canonical, `driftX` deprecated) on
5
+ * several config objects. {@link AtLeastOne} captures the "callers must supply
6
+ * one of the two" contract at the type level so the runtime fallback in the
7
+ * consuming class can rely on the value being present.
8
+ */
9
+
10
+ /**
11
+ * `AtLeastOne<A, B, T>` requires the caller to set at least one of two keys
12
+ * (`A` canonical, `B` deprecated) to a value of type `T`. Whichever the caller
13
+ * omits remains optional.
14
+ *
15
+ * Use this to express "rename `B` to `A`, but keep `B` accepted until the next
16
+ * major" on a config object without dropping back to "both optional + runtime
17
+ * throw".
18
+ */
19
+ export type AtLeastOne<
20
+ A extends string,
21
+ B extends string,
22
+ T
23
+ > =
24
+ | ({ [K in A]: T } & { [K in B]?: T })
25
+ | ({ [K in A]?: T } & { [K in B]: T });
@@ -429,7 +429,7 @@ export class VelocityClient {
429
429
 
430
430
  if (config.userStats) {
431
431
  this.userStats = new UserStats({
432
- driftClient: this,
432
+ velocityClient: this,
433
433
  userStatsAccountPublicKey: getUserStatsAccountPublicKey(
434
434
  this.program.programId,
435
435
  this.authority
@@ -539,7 +539,7 @@ export class VelocityClient {
539
539
  );
540
540
 
541
541
  return new User({
542
- driftClient: this,
542
+ velocityClient: this,
543
543
  userAccountPublicKey,
544
544
  accountSubscription: accountSubscriptionConfig,
545
545
  });
@@ -820,7 +820,7 @@ export class VelocityClient {
820
820
  this.userStats = undefined;
821
821
 
822
822
  this.userStats = new UserStats({
823
- driftClient: this,
823
+ velocityClient: this,
824
824
  userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
825
825
  accountSubscription: this.userStatsAccountSubscriptionConfig,
826
826
  });
@@ -868,7 +868,7 @@ export class VelocityClient {
868
868
  this.userStats = undefined;
869
869
 
870
870
  this.userStats = new UserStats({
871
- driftClient: this,
871
+ velocityClient: this,
872
872
  userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
873
873
  accountSubscription: this.userStatsAccountSubscriptionConfig,
874
874
  });
@@ -903,7 +903,7 @@ export class VelocityClient {
903
903
  }
904
904
 
905
905
  this.userStats = new UserStats({
906
- driftClient: this,
906
+ velocityClient: this,
907
907
  userStatsAccountPublicKey: this.userStatsAccountPublicKey,
908
908
  accountSubscription: this.userStatsAccountSubscriptionConfig,
909
909
  });
@@ -5322,7 +5322,7 @@ export class VelocityClient {
5322
5322
  withBuilder = hasBuilder(userOrder);
5323
5323
  }
5324
5324
  } else if (isSignedMsg) {
5325
- // Order hasn't been placed yet, we cant tell if it has a builder or not.
5325
+ // Order hasn't been placed yet, we can't tell if it has a builder or not.
5326
5326
  // Include it optimistically
5327
5327
  withBuilder = true;
5328
5328
  }