@velocity-exchange/sdk 0.0.2 → 0.0.5

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 (192) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +5 -6
  3. package/bunfig.toml +3 -0
  4. package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +4 -2
  5. package/lib/browser/auctionSubscriber/auctionSubscriber.js +9 -4
  6. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
  7. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
  8. package/lib/browser/auctionSubscriber/types.d.ts +4 -2
  9. package/lib/browser/config.d.ts +3 -8
  10. package/lib/browser/config.js +14 -22
  11. package/lib/browser/constituentMap/constituentMap.d.ts +4 -2
  12. package/lib/browser/constituentMap/constituentMap.js +14 -10
  13. package/lib/browser/core/VelocityCore.d.ts +4 -0
  14. package/lib/browser/core/VelocityCore.js +3 -1
  15. package/lib/browser/decode/user.js +5 -5
  16. package/lib/browser/dlob/DLOB.js +1 -1
  17. package/lib/browser/dlob/DLOBNode.js +1 -2
  18. package/lib/browser/dlob/DLOBSubscriber.d.ts +3 -1
  19. package/lib/browser/dlob/DLOBSubscriber.js +19 -10
  20. package/lib/browser/dlob/types.d.ts +3 -1
  21. package/lib/browser/idl/drift.d.ts +59 -6
  22. package/lib/browser/idl/drift.json +6049 -806
  23. package/lib/browser/math/auction.d.ts +1 -1
  24. package/lib/browser/math/auction.js +2 -9
  25. package/lib/browser/math/orders.js +3 -3
  26. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +3 -1
  27. package/lib/browser/orderSubscriber/OrderSubscriber.js +19 -11
  28. package/lib/browser/orderSubscriber/types.d.ts +3 -1
  29. package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +4 -2
  30. package/lib/browser/priorityFee/priorityFeeSubscriber.js +15 -11
  31. package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
  32. package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +18 -18
  33. package/lib/browser/priorityFee/types.d.ts +9 -5
  34. package/lib/browser/priorityFee/types.js +1 -1
  35. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
  36. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
  37. package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
  38. package/lib/browser/swift/signedMsgUserAccountSubscriber.js +10 -5
  39. package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -4
  40. package/lib/browser/swift/swiftOrderSubscriber.js +19 -11
  41. package/lib/browser/types.d.ts +2 -2
  42. package/lib/browser/user.d.ts +3 -1
  43. package/lib/browser/user.js +93 -86
  44. package/lib/browser/userConfig.d.ts +4 -2
  45. package/lib/browser/userMap/referrerMap.d.ts +5 -3
  46. package/lib/browser/userMap/referrerMap.js +18 -14
  47. package/lib/browser/userMap/revenueShareEscrowMap.d.ts +5 -3
  48. package/lib/browser/userMap/revenueShareEscrowMap.js +18 -14
  49. package/lib/browser/userMap/userMap.d.ts +3 -1
  50. package/lib/browser/userMap/userMap.js +24 -19
  51. package/lib/browser/userMap/userMapConfig.d.ts +4 -2
  52. package/lib/browser/userMap/userStatsMap.d.ts +5 -3
  53. package/lib/browser/userMap/userStatsMap.js +15 -11
  54. package/lib/browser/userStats.d.ts +3 -1
  55. package/lib/browser/userStats.js +21 -15
  56. package/lib/browser/userStatsConfig.d.ts +4 -2
  57. package/lib/browser/util/deprecatedAlias.d.ts +26 -0
  58. package/lib/browser/util/deprecatedAlias.js +10 -0
  59. package/lib/browser/velocityClient.d.ts +6 -6
  60. package/lib/browser/velocityClient.js +6 -6
  61. package/lib/browser/velocityClientConfig.d.ts +7 -4
  62. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +4 -2
  63. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
  64. package/lib/node/auctionSubscriber/auctionSubscriber.js +9 -4
  65. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
  66. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
  67. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
  68. package/lib/node/auctionSubscriber/types.d.ts +4 -2
  69. package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
  70. package/lib/node/config.d.ts +3 -8
  71. package/lib/node/config.d.ts.map +1 -1
  72. package/lib/node/config.js +14 -22
  73. package/lib/node/constituentMap/constituentMap.d.ts +4 -2
  74. package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
  75. package/lib/node/constituentMap/constituentMap.js +14 -10
  76. package/lib/node/core/VelocityCore.d.ts +4 -0
  77. package/lib/node/core/VelocityCore.d.ts.map +1 -1
  78. package/lib/node/core/VelocityCore.js +3 -1
  79. package/lib/node/decode/user.js +5 -5
  80. package/lib/node/dlob/DLOB.js +1 -1
  81. package/lib/node/dlob/DLOBNode.js +1 -2
  82. package/lib/node/dlob/DLOBSubscriber.d.ts +3 -1
  83. package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
  84. package/lib/node/dlob/DLOBSubscriber.js +19 -10
  85. package/lib/node/dlob/types.d.ts +3 -1
  86. package/lib/node/dlob/types.d.ts.map +1 -1
  87. package/lib/node/idl/drift.d.ts +59 -6
  88. package/lib/node/idl/drift.d.ts.map +1 -1
  89. package/lib/node/idl/drift.json +6049 -806
  90. package/lib/node/math/auction.d.ts +1 -1
  91. package/lib/node/math/auction.d.ts.map +1 -1
  92. package/lib/node/math/auction.js +2 -9
  93. package/lib/node/math/orders.d.ts.map +1 -1
  94. package/lib/node/math/orders.js +3 -3
  95. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +3 -1
  96. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  97. package/lib/node/orderSubscriber/OrderSubscriber.js +19 -11
  98. package/lib/node/orderSubscriber/types.d.ts +3 -1
  99. package/lib/node/orderSubscriber/types.d.ts.map +1 -1
  100. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +4 -2
  101. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
  102. package/lib/node/priorityFee/priorityFeeSubscriber.js +15 -11
  103. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
  104. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
  105. package/lib/node/priorityFee/priorityFeeSubscriberMap.js +18 -18
  106. package/lib/node/priorityFee/types.d.ts +9 -5
  107. package/lib/node/priorityFee/types.d.ts.map +1 -1
  108. package/lib/node/priorityFee/types.js +1 -1
  109. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
  110. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
  111. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
  112. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
  113. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
  114. package/lib/node/swift/signedMsgUserAccountSubscriber.js +10 -5
  115. package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -4
  116. package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
  117. package/lib/node/swift/swiftOrderSubscriber.js +19 -11
  118. package/lib/node/types.d.ts +2 -2
  119. package/lib/node/types.d.ts.map +1 -1
  120. package/lib/node/user.d.ts +3 -1
  121. package/lib/node/user.d.ts.map +1 -1
  122. package/lib/node/user.js +93 -86
  123. package/lib/node/userConfig.d.ts +4 -2
  124. package/lib/node/userConfig.d.ts.map +1 -1
  125. package/lib/node/userMap/referrerMap.d.ts +5 -3
  126. package/lib/node/userMap/referrerMap.d.ts.map +1 -1
  127. package/lib/node/userMap/referrerMap.js +18 -14
  128. package/lib/node/userMap/revenueShareEscrowMap.d.ts +5 -3
  129. package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
  130. package/lib/node/userMap/revenueShareEscrowMap.js +18 -14
  131. package/lib/node/userMap/userMap.d.ts +3 -1
  132. package/lib/node/userMap/userMap.d.ts.map +1 -1
  133. package/lib/node/userMap/userMap.js +24 -19
  134. package/lib/node/userMap/userMapConfig.d.ts +4 -2
  135. package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
  136. package/lib/node/userMap/userStatsMap.d.ts +5 -3
  137. package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
  138. package/lib/node/userMap/userStatsMap.js +15 -11
  139. package/lib/node/userStats.d.ts +3 -1
  140. package/lib/node/userStats.d.ts.map +1 -1
  141. package/lib/node/userStats.js +21 -15
  142. package/lib/node/userStatsConfig.d.ts +4 -2
  143. package/lib/node/userStatsConfig.d.ts.map +1 -1
  144. package/lib/node/util/deprecatedAlias.d.ts +27 -0
  145. package/lib/node/util/deprecatedAlias.d.ts.map +1 -0
  146. package/lib/node/util/deprecatedAlias.js +10 -0
  147. package/lib/node/velocityClient.d.ts +6 -6
  148. package/lib/node/velocityClient.d.ts.map +1 -1
  149. package/lib/node/velocityClient.js +6 -6
  150. package/lib/node/velocityClientConfig.d.ts +7 -4
  151. package/lib/node/velocityClientConfig.d.ts.map +1 -1
  152. package/package.json +1 -1
  153. package/src/auctionSubscriber/auctionSubscriber.ts +12 -6
  154. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -6
  155. package/src/auctionSubscriber/types.ts +5 -2
  156. package/src/config.ts +38 -27
  157. package/src/constituentMap/constituentMap.ts +17 -9
  158. package/src/core/VelocityCore.ts +6 -0
  159. package/src/decode/user.ts +5 -5
  160. package/src/dlob/DLOB.ts +1 -1
  161. package/src/dlob/DLOBNode.ts +1 -1
  162. package/src/dlob/DLOBSubscriber.ts +21 -11
  163. package/src/dlob/types.ts +3 -1
  164. package/src/idl/drift.json +23940 -18697
  165. package/src/idl/drift.ts +59 -6
  166. package/src/math/auction.ts +3 -10
  167. package/src/math/orders.ts +3 -6
  168. package/src/orderSubscriber/OrderSubscriber.ts +17 -7
  169. package/src/orderSubscriber/types.ts +3 -1
  170. package/src/priorityFee/priorityFeeSubscriber.ts +13 -9
  171. package/src/priorityFee/priorityFeeSubscriberMap.ts +23 -25
  172. package/src/priorityFee/types.ts +19 -9
  173. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +10 -23
  174. package/src/swift/signedMsgUserAccountSubscriber.ts +22 -14
  175. package/src/swift/swiftOrderSubscriber.ts +24 -16
  176. package/src/types.ts +2 -2
  177. package/src/user.ts +93 -82
  178. package/src/userConfig.ts +5 -2
  179. package/src/userMap/referrerMap.ts +19 -15
  180. package/src/userMap/revenueShareEscrowMap.ts +20 -16
  181. package/src/userMap/userMap.ts +20 -15
  182. package/src/userMap/userMapConfig.ts +6 -3
  183. package/src/userMap/userStatsMap.ts +19 -15
  184. package/src/userStats.ts +13 -7
  185. package/src/userStatsConfig.ts +5 -2
  186. package/src/util/deprecatedAlias.ts +21 -0
  187. package/src/velocityClient.ts +12 -12
  188. package/src/velocityClientConfig.ts +27 -42
  189. package/tests/auctions/test.ts +4 -4
  190. package/tests/decode/test.ts +1 -1
  191. package/tests/dlob/test.ts +5 -5
  192. package/tests/user/helpers.ts +1 -1
package/src/config.ts CHANGED
@@ -27,6 +27,9 @@ export type VelocityEnv = 'devnet' | 'mainnet-beta';
27
27
  /** @deprecated Use `VelocityEnv` instead. `DriftEnv` will be removed in a future major. */
28
28
  export type DriftEnv = VelocityEnv;
29
29
 
30
+ /** Widened env type accepted by `initialize()`; `'master'` is a legacy alias for `'devnet'`. */
31
+ export type LegacyVelocityEnv = VelocityEnv | 'master';
32
+
30
33
  export interface VelocityConfig {
31
34
  ENV: VelocityEnv;
32
35
  PYTH_ORACLE_MAPPING_ADDRESS: string;
@@ -50,7 +53,8 @@ export interface VelocityConfig {
50
53
  /** @deprecated Use `VelocityConfig` instead. `DriftConfig` will be removed in a future major. */
51
54
  export type DriftConfig = VelocityConfig;
52
55
 
53
- export const VELOCITY_PROGRAM_ID = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
56
+ export const VELOCITY_PROGRAM_ID =
57
+ 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
54
58
 
55
59
  /** @deprecated Use `VELOCITY_PROGRAM_ID` instead. `DRIFT_PROGRAM_ID` will be removed in a future major. */
56
60
  export const DRIFT_PROGRAM_ID = VELOCITY_PROGRAM_ID;
@@ -140,35 +144,40 @@ export const getConfig = (): VelocityConfig => currentConfig;
140
144
  * @param props
141
145
  * @returns
142
146
  */
147
+ /**
148
+ * Mirror a canonical/deprecated alias pair so the resolved config carries the
149
+ * same value under both keys regardless of which one the caller overrode.
150
+ */
151
+ const mirrorAlias = <
152
+ K1 extends keyof VelocityConfig,
153
+ K2 extends keyof VelocityConfig,
154
+ >(
155
+ merged: VelocityConfig,
156
+ override: Partial<VelocityConfig>,
157
+ canon: K1,
158
+ deprecated: K2
159
+ ): void => {
160
+ const value = override[canon] ?? override[deprecated] ?? merged[canon];
161
+ (merged[canon] as VelocityConfig[K1]) = value as VelocityConfig[K1];
162
+ (merged[deprecated] as VelocityConfig[K2]) = value as VelocityConfig[K2];
163
+ };
164
+
143
165
  export const initialize = (props: {
144
- env: VelocityEnv;
166
+ env: LegacyVelocityEnv;
145
167
  overrideEnv?: Partial<VelocityConfig>;
146
168
  }): VelocityConfig => {
147
169
  const override = props.overrideEnv ?? {};
148
-
149
- //@ts-ignore
150
- const base = props.env === 'master' ? configs['devnet'] : configs[props.env];
151
- const merged: VelocityConfig = { ...base, ...override };
152
-
153
- const overrodeVelocity = 'VELOCITY_PROGRAM_ID' in override;
154
- const overrodeDrift = 'DRIFT_PROGRAM_ID' in override;
155
- if (overrodeVelocity && !overrodeDrift) {
156
- merged.DRIFT_PROGRAM_ID = merged.VELOCITY_PROGRAM_ID;
157
- } else if (overrodeDrift && !overrodeVelocity) {
158
- merged.VELOCITY_PROGRAM_ID = merged.DRIFT_PROGRAM_ID;
159
- }
160
-
161
- const overrodeVelocityOracleReceiver =
162
- 'VELOCITY_ORACLE_RECEIVER_ID' in override;
163
- const overrodeDriftOracleReceiver = 'DRIFT_ORACLE_RECEIVER_ID' in override;
164
- if (overrodeVelocityOracleReceiver && !overrodeDriftOracleReceiver) {
165
- merged.DRIFT_ORACLE_RECEIVER_ID = merged.VELOCITY_ORACLE_RECEIVER_ID;
166
- } else if (overrodeDriftOracleReceiver && !overrodeVelocityOracleReceiver) {
167
- merged.VELOCITY_ORACLE_RECEIVER_ID = merged.DRIFT_ORACLE_RECEIVER_ID;
168
- }
169
-
170
- //@ts-ignore
171
- if (props.env === 'master') return merged;
170
+ const normalizedEnv: VelocityEnv =
171
+ props.env === 'master' ? 'devnet' : props.env;
172
+ const merged: VelocityConfig = { ...configs[normalizedEnv], ...override };
173
+
174
+ mirrorAlias(merged, override, 'VELOCITY_PROGRAM_ID', 'DRIFT_PROGRAM_ID');
175
+ mirrorAlias(
176
+ merged,
177
+ override,
178
+ 'VELOCITY_ORACLE_RECEIVER_ID',
179
+ 'DRIFT_ORACLE_RECEIVER_ID'
180
+ );
172
181
 
173
182
  currentConfig = merged;
174
183
  return currentConfig;
@@ -215,7 +224,9 @@ export function getMarketsAndOraclesForSubscription(
215
224
  };
216
225
  }
217
226
 
218
- export async function findAllMarketAndOracles(program: VelocityProgram): Promise<{
227
+ export async function findAllMarketAndOracles(
228
+ program: VelocityProgram
229
+ ): Promise<{
219
230
  perpMarketIndexes: number[];
220
231
  perpMarketAccounts: PerpMarketAccount[];
221
232
  spotMarketIndexes: number[];
@@ -17,7 +17,9 @@ import { getLpPoolPublicKey } from '../addresses/pda';
17
17
  const MAX_CONSTITUENT_SIZE_BYTES = 480; // TODO: update this when account is finalized
18
18
 
19
19
  export type ConstituentMapConfig = {
20
- driftClient: VelocityClient;
20
+ velocityClient?: VelocityClient;
21
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
22
+ driftClient?: VelocityClient;
21
23
  connection?: Connection;
22
24
  subscriptionConfig:
23
25
  | {
@@ -55,7 +57,7 @@ export interface ConstituentMapInterface {
55
57
  }
56
58
 
57
59
  export class ConstituentMap implements ConstituentMapInterface {
58
- private driftClient: VelocityClient;
60
+ private velocityClient: VelocityClient;
59
61
  private constituentMap = new Map<string, DataAndSlot<ConstituentAccount>>();
60
62
  private constituentAccountSubscriber: ConstituentAccountSubscriber;
61
63
  private additionalFilters?: MemcmpFilter[];
@@ -69,10 +71,16 @@ export class ConstituentMap implements ConstituentMapInterface {
69
71
  private decoder: 'base64' | 'base64+zstd';
70
72
 
71
73
  constructor(config: ConstituentMapConfig) {
72
- this.driftClient = config.driftClient;
74
+ const velocityClient = config.velocityClient ?? config.driftClient;
75
+ if (!velocityClient) {
76
+ throw new Error(
77
+ 'ConstituentMap: velocityClient (or deprecated driftClient) must be provided'
78
+ );
79
+ }
80
+ this.velocityClient = velocityClient;
73
81
  this.additionalFilters = config.additionalFilters;
74
82
  this.commitment = config.subscriptionConfig.commitment;
75
- this.connection = config.connection || this.driftClient.connection;
83
+ this.connection = config.connection || this.velocityClient.connection;
76
84
  this.lpPoolId = config.lpPoolId ?? 0;
77
85
  this.decoder = config.decoder ?? 'base64+zstd';
78
86
 
@@ -80,7 +88,7 @@ export class ConstituentMap implements ConstituentMapInterface {
80
88
  this.constituentAccountSubscriber =
81
89
  new PollingConstituentAccountSubscriber(
82
90
  this,
83
- this.driftClient.program,
91
+ this.velocityClient.program,
84
92
  config.subscriptionConfig.frequency,
85
93
  config.subscriptionConfig.commitment,
86
94
  this.getFilters()
@@ -89,7 +97,7 @@ export class ConstituentMap implements ConstituentMapInterface {
89
97
  this.constituentAccountSubscriber =
90
98
  new WebSocketConstituentAccountSubscriber(
91
99
  this,
92
- this.driftClient.program,
100
+ this.velocityClient.program,
93
101
  config.subscriptionConfig.resubTimeoutMs,
94
102
  config.subscriptionConfig.commitment,
95
103
  this.getFilters()
@@ -109,7 +117,7 @@ export class ConstituentMap implements ConstituentMapInterface {
109
117
  const filters = [
110
118
  getConstituentFilter(),
111
119
  getConstituentLpPoolFilter(
112
- getLpPoolPublicKey(this.driftClient.program.programId, this.lpPoolId)
120
+ getLpPoolPublicKey(this.velocityClient.program.programId, this.lpPoolId)
113
121
  ),
114
122
  ];
115
123
  if (this.additionalFilters) {
@@ -120,14 +128,14 @@ export class ConstituentMap implements ConstituentMapInterface {
120
128
 
121
129
  private decode(name: string, buffer: Buffer): ConstituentAccount {
122
130
  return (
123
- this.driftClient.program.account as any
131
+ this.velocityClient.program.account as any
124
132
  ).constituent.coder.accounts.decodeUnchecked(name, buffer);
125
133
  }
126
134
 
127
135
  public async sync(): Promise<void> {
128
136
  try {
129
137
  const rpcRequestArgs = [
130
- this.driftClient.program.programId.toBase58(),
138
+ this.velocityClient.program.programId.toBase58(),
131
139
  {
132
140
  commitment: this.commitment,
133
141
  filters: this.getFilters(),
@@ -329,3 +329,9 @@ export class VelocityCore {
329
329
  return [];
330
330
  }
331
331
  }
332
+
333
+ /** @deprecated Use `VelocityCore` instead. `DriftCore` will be removed in a future major. */
334
+ export const DriftCore = VelocityCore;
335
+
336
+ /** @deprecated Use `VelocityCore` instead. `DriftCore` will be removed in a future major. */
337
+ export type DriftCore = VelocityCore;
@@ -143,8 +143,8 @@ export function decodeUser(buffer: Buffer): UserAccount {
143
143
  const orders: Order[] = [];
144
144
  for (let i = 0; i < 32; i++) {
145
145
  // skip order if it's not open
146
- if (buffer.readUint8(offset + 82) !== 1) {
147
- offset += 96;
146
+ if (buffer.readUint8(offset + 86) !== 1) {
147
+ offset += 104;
148
148
  continue;
149
149
  }
150
150
 
@@ -166,8 +166,8 @@ export function decodeUser(buffer: Buffer): UserAccount {
166
166
  offset += 8;
167
167
  const maxTs = readSignedBigInt64LE(buffer, offset);
168
168
  offset += 8;
169
- const oraclePriceOffset = buffer.readInt32LE(offset);
170
- offset += 4;
169
+ const oraclePriceOffset = readSignedBigInt64LE(buffer, offset);
170
+ offset += 8;
171
171
  const orderId = buffer.readUInt32LE(offset);
172
172
  offset += 4;
173
173
  const marketIndex = buffer.readUInt16LE(offset);
@@ -245,7 +245,7 @@ export function decodeUser(buffer: Buffer): UserAccount {
245
245
  offset += 1;
246
246
  const bitFlags = buffer.readUint8(offset);
247
247
  offset += 1;
248
- offset += 1; // padding
248
+ offset += 5; // padding
249
249
  orders.push({
250
250
  slot,
251
251
  price,
package/src/dlob/DLOB.ts CHANGED
@@ -333,7 +333,7 @@ export class DLOB {
333
333
  isOneOfVariant(order.orderType, ['market', 'triggerMarket', 'oracle'])
334
334
  ) {
335
335
  type = 'market';
336
- } else if (order.oraclePriceOffset !== 0) {
336
+ } else if (!order.oraclePriceOffset.eq(ZERO)) {
337
337
  type = 'floatingLimit';
338
338
  } else {
339
339
  const isResting = isRestingLimitOrder(order, slot);
@@ -115,7 +115,7 @@ export class FloatingLimitOrderNode extends OrderNode {
115
115
  previous?: FloatingLimitOrderNode;
116
116
 
117
117
  getSortValue(order: Order): BN {
118
- return new BN(order.oraclePriceOffset);
118
+ return order.oraclePriceOffset;
119
119
  }
120
120
  }
121
121
 
@@ -20,7 +20,11 @@ import {
20
20
  import { BN } from '../isomorphic/anchor';
21
21
 
22
22
  export class DLOBSubscriber {
23
- driftClient: VelocityClient;
23
+ velocityClient: VelocityClient;
24
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
25
+ public get driftClient(): VelocityClient {
26
+ return this.velocityClient;
27
+ }
24
28
  dlobSource: DLOBSource;
25
29
  slotSource: SlotSource;
26
30
  updateFrequency: number;
@@ -28,7 +32,13 @@ export class DLOBSubscriber {
28
32
  dlob: DLOB;
29
33
  public eventEmitter: StrictEventEmitter<EventEmitter, DLOBSubscriberEvents>;
30
34
  constructor(config: DLOBSubscriptionConfig) {
31
- this.driftClient = config.driftClient;
35
+ const velocityClient = config.velocityClient ?? config.driftClient;
36
+ if (!velocityClient) {
37
+ throw new Error(
38
+ 'DLOBSubscriber: velocityClient (or deprecated driftClient) must be provided'
39
+ );
40
+ }
41
+ this.velocityClient = velocityClient;
32
42
  this.dlobSource = config.dlobSource;
33
43
  this.slotSource = config.slotSource;
34
44
  this.updateFrequency = config.updateFrequency;
@@ -93,7 +103,7 @@ export class DLOBSubscriber {
93
103
  }): L2OrderBook {
94
104
  if (marketName) {
95
105
  const derivedMarketInfo =
96
- this.driftClient.getMarketIndexAndType(marketName);
106
+ this.velocityClient.getMarketIndexAndType(marketName);
97
107
  if (!derivedMarketInfo) {
98
108
  throw new Error(`Market ${marketName} not found`);
99
109
  }
@@ -111,13 +121,13 @@ export class DLOBSubscriber {
111
121
  const isPerp = isVariant(marketType, 'perp');
112
122
  if (isPerp) {
113
123
  const perpMarketAccount =
114
- this.driftClient.getPerpMarketAccount(marketIndex);
115
- oraclePriceData = this.driftClient.getOracleDataForPerpMarket(
124
+ this.velocityClient.getPerpMarketAccount(marketIndex);
125
+ oraclePriceData = this.velocityClient.getOracleDataForPerpMarket(
116
126
  perpMarketAccount.marketIndex
117
127
  );
118
128
  } else {
119
129
  oraclePriceData =
120
- this.driftClient.getOracleDataForSpotMarket(marketIndex);
130
+ this.velocityClient.getOracleDataForSpotMarket(marketIndex);
121
131
  }
122
132
 
123
133
  if (isPerp && includeVamm) {
@@ -129,9 +139,9 @@ export class DLOBSubscriber {
129
139
 
130
140
  fallbackL2Generators = [
131
141
  getVammL2Generator({
132
- marketAccount: this.driftClient.getPerpMarketAccount(marketIndex),
142
+ marketAccount: this.velocityClient.getPerpMarketAccount(marketIndex),
133
143
  mmOraclePriceData:
134
- this.driftClient.getMMOracleDataForPerpMarket(marketIndex),
144
+ this.velocityClient.getMMOracleDataForPerpMarket(marketIndex),
135
145
  numOrders: numVammOrders ?? depth,
136
146
  topOfBookQuoteAmounts:
137
147
  marketIndex < 3
@@ -170,7 +180,7 @@ export class DLOBSubscriber {
170
180
  }): L3OrderBook {
171
181
  if (marketName) {
172
182
  const derivedMarketInfo =
173
- this.driftClient.getMarketIndexAndType(marketName);
183
+ this.velocityClient.getMarketIndexAndType(marketName);
174
184
  if (!derivedMarketInfo) {
175
185
  throw new Error(`Market ${marketName} not found`);
176
186
  }
@@ -188,10 +198,10 @@ export class DLOBSubscriber {
188
198
  const isPerp = isVariant(marketType, 'perp');
189
199
  if (isPerp) {
190
200
  oraclePriceData =
191
- this.driftClient.getOracleDataForPerpMarket(marketIndex);
201
+ this.velocityClient.getOracleDataForPerpMarket(marketIndex);
192
202
  } else {
193
203
  oraclePriceData =
194
- this.driftClient.getOracleDataForSpotMarket(marketIndex);
204
+ this.velocityClient.getOracleDataForSpotMarket(marketIndex);
195
205
  }
196
206
 
197
207
  return this.dlob.getL3({
package/src/dlob/types.ts CHANGED
@@ -2,7 +2,9 @@ import { DLOB } from './DLOB';
2
2
  import { VelocityClient } from '../velocityClient';
3
3
 
4
4
  export type DLOBSubscriptionConfig = {
5
- driftClient: VelocityClient;
5
+ velocityClient?: VelocityClient;
6
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
7
+ driftClient?: VelocityClient;
6
8
  dlobSource: DLOBSource;
7
9
  slotSource: SlotSource;
8
10
  updateFrequency: number;