@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
package/src/idl/drift.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * IDL can be found at `target/idl/drift.json`.
6
6
  */
7
7
  export type Drift = {
8
- "address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH",
8
+ "address": "vELoC1audYbSYVRXn1vPaV8Axoa9oU6BYmNGZZBDZ1P",
9
9
  "metadata": {
10
10
  "name": "drift",
11
11
  "version": "2.162.0",
@@ -2884,6 +2884,59 @@ export type Drift = {
2884
2884
  ],
2885
2885
  "args": []
2886
2886
  },
2887
+ {
2888
+ "name": "forceWipeAccountsDevnet",
2889
+ "docs": [
2890
+ "Devnet-only escape hatch: cleans up accounts stranded by a layout-breaking",
2891
+ "program upgrade (or by a partial re-init). For each account passed via",
2892
+ "`remaining_accounts`:",
2893
+ "- drift-owned PDA → drain lamports (runtime GCs at end of tx)",
2894
+ "- token-program owned vault (drift_signer close-authority) → CPI",
2895
+ "`close_account`, rent refunded to admin",
2896
+ "Admin gate reads State's first pubkey field at raw offset 8..40 so it",
2897
+ "works regardless of the State layout currently on chain. `drift_signer_nonce`",
2898
+ "must match `State.signer_nonce`; mismatch fails the token CPI signature.",
2899
+ "Stripped from mainnet builds via `mainnet-beta`."
2900
+ ],
2901
+ "discriminator": [
2902
+ 105,
2903
+ 74,
2904
+ 87,
2905
+ 6,
2906
+ 166,
2907
+ 227,
2908
+ 138,
2909
+ 215
2910
+ ],
2911
+ "accounts": [
2912
+ {
2913
+ "name": "admin",
2914
+ "writable": true,
2915
+ "signer": true
2916
+ },
2917
+ {
2918
+ "name": "state",
2919
+ "docs": [
2920
+ "(cold-)admin pubkey at offset 8..40."
2921
+ ]
2922
+ },
2923
+ {
2924
+ "name": "driftSigner",
2925
+ "docs": [
2926
+ "at CPI time when closing token vaults; ignored otherwise."
2927
+ ]
2928
+ },
2929
+ {
2930
+ "name": "tokenProgram"
2931
+ }
2932
+ ],
2933
+ "args": [
2934
+ {
2935
+ "name": "driftSignerNonce",
2936
+ "type": "u8"
2937
+ }
2938
+ ]
2939
+ },
2887
2940
  {
2888
2941
  "name": "initialize",
2889
2942
  "discriminator": [
@@ -20,7 +20,11 @@ import { calculateOrderBaseAssetAmount } from '../math/orders';
20
20
  import { ZERO } from '../constants/numericConstants';
21
21
 
22
22
  export class OrderSubscriber {
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
  usersAccounts = new Map<string, { slot: number; userAccount: UserAccount }>();
25
29
  subscription: PollingSubscription | WebsocketSubscription | grpcSubscription;
26
30
  commitment: Commitment;
@@ -36,7 +40,13 @@ export class OrderSubscriber {
36
40
  fetchAllNonIdleUsers?: boolean;
37
41
 
38
42
  constructor(config: OrderSubscriberConfig) {
39
- this.driftClient = config.driftClient;
43
+ const velocityClient = config.velocityClient ?? config.driftClient;
44
+ if (!velocityClient) {
45
+ throw new Error(
46
+ 'OrderSubscriber: velocityClient (or deprecated driftClient) must be provided'
47
+ );
48
+ }
49
+ this.velocityClient = velocityClient;
40
50
  this.commitment = config.subscriptionConfig.commitment || 'processed';
41
51
  if (config.subscriptionConfig.type === 'polling') {
42
52
  this.subscription = new PollingSubscription({
@@ -72,9 +82,9 @@ export class OrderSubscriber {
72
82
  this.decodeFn = (name, data) => decodeUser(data);
73
83
  } else {
74
84
  this.decodeFn = (
75
- this.driftClient.program.account as any
85
+ this.velocityClient.program.account as any
76
86
  ).user.coder.accounts.decodeUnchecked.bind(
77
- (this.driftClient.program.account as any).user.coder.accounts
87
+ (this.velocityClient.program.account as any).user.coder.accounts
78
88
  );
79
89
  }
80
90
  this.eventEmitter = new EventEmitter();
@@ -100,7 +110,7 @@ export class OrderSubscriber {
100
110
 
101
111
  try {
102
112
  const rpcRequestArgs = [
103
- this.driftClient.program.programId.toBase58(),
113
+ this.velocityClient.program.programId.toBase58(),
104
114
  {
105
115
  commitment: this.commitment,
106
116
  filters,
@@ -111,7 +121,7 @@ export class OrderSubscriber {
111
121
 
112
122
  const rpcJSONResponse: any =
113
123
  // @ts-ignore
114
- await this.driftClient.connection._rpcRequest(
124
+ await this.velocityClient.connection._rpcRequest(
115
125
  'getProgramAccounts',
116
126
  rpcRequestArgs
117
127
  );
@@ -268,7 +278,7 @@ export class OrderSubscriber {
268
278
 
269
279
  public async addPubkey(userAccountPublicKey: PublicKey): Promise<void> {
270
280
  const accountInfo =
271
- await this.driftClient.connection.getAccountInfoAndContext(
281
+ await this.velocityClient.connection.getAccountInfoAndContext(
272
282
  userAccountPublicKey,
273
283
  this.commitment
274
284
  );
@@ -4,7 +4,9 @@ import { VelocityClient } from '../velocityClient';
4
4
  import { GrpcConfigs } from '../accounts/types';
5
5
 
6
6
  export type OrderSubscriberConfig = {
7
- driftClient: VelocityClient;
7
+ velocityClient?: VelocityClient;
8
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
9
+ driftClient?: VelocityClient;
8
10
  subscriptionConfig:
9
11
  | {
10
12
  type: 'polling';
@@ -22,7 +22,11 @@ export class PriorityFeeSubscriber {
22
22
  connection: Connection;
23
23
  frequencyMs: number;
24
24
  addresses: string[];
25
- driftMarkets?: VelocityMarketInfo[];
25
+ velocityMarkets?: VelocityMarketInfo[];
26
+ /** @deprecated Use `velocityMarkets` instead. `driftMarkets` will be removed in a future major. */
27
+ public get driftMarkets(): VelocityMarketInfo[] | undefined {
28
+ return this.velocityMarkets;
29
+ }
26
30
  customStrategy?: PriorityFeeStrategy;
27
31
  averageStrategy = new AverageOverSlotsStrategy();
28
32
  maxStrategy = new MaxOverSlotsStrategy();
@@ -54,7 +58,7 @@ export class PriorityFeeSubscriber {
54
58
  this.addresses = config.addresses
55
59
  ? config.addresses.map((address) => address.toBase58())
56
60
  : [];
57
- this.driftMarkets = config.driftMarkets;
61
+ this.velocityMarkets = config.velocityMarkets ?? config.driftMarkets;
58
62
 
59
63
  if (config.customStrategy) {
60
64
  this.customStrategy = config.customStrategy;
@@ -78,7 +82,7 @@ export class PriorityFeeSubscriber {
78
82
  } else {
79
83
  this.heliusRpcUrl = config.heliusRpcUrl;
80
84
  }
81
- } else if (this.priorityFeeMethod === PriorityFeeMethod.DRIFT) {
85
+ } else if (this.priorityFeeMethod === PriorityFeeMethod.VELOCITY) {
82
86
  this.velocityPriorityFeeEndpoint =
83
87
  config.velocityPriorityFeeEndpoint ?? config.driftPriorityFeeEndpoint;
84
88
  }
@@ -143,13 +147,13 @@ export class PriorityFeeSubscriber {
143
147
  }
144
148
 
145
149
  private async loadForDrift(): Promise<void> {
146
- if (!this.driftMarkets) {
150
+ if (!this.velocityMarkets) {
147
151
  return;
148
152
  }
149
153
  const sample = await fetchVelocityPriorityFee(
150
154
  this.velocityPriorityFeeEndpoint!,
151
- this.driftMarkets.map((m) => m.marketType),
152
- this.driftMarkets.map((m) => m.marketIndex)
155
+ this.velocityMarkets.map((m) => m.marketType),
156
+ this.velocityMarkets.map((m) => m.marketIndex)
153
157
  );
154
158
  if (sample.length > 0) {
155
159
  this.lastAvgStrategyResult = sample[HeliusPriorityLevel.MEDIUM];
@@ -223,7 +227,7 @@ export class PriorityFeeSubscriber {
223
227
  await this.loadForSolana();
224
228
  } else if (this.priorityFeeMethod === PriorityFeeMethod.HELIUS) {
225
229
  await this.loadForHelius();
226
- } else if (this.priorityFeeMethod === PriorityFeeMethod.DRIFT) {
230
+ } else if (this.priorityFeeMethod === PriorityFeeMethod.VELOCITY) {
227
231
  await this.loadForDrift();
228
232
  } else {
229
233
  throw new Error(`${this.priorityFeeMethod} load not implemented`);
@@ -250,7 +254,7 @@ export class PriorityFeeSubscriber {
250
254
  this.addresses = addresses.map((k) => k.toBase58());
251
255
  }
252
256
 
253
- public updateMarketTypeAndIndex(driftMarkets: VelocityMarketInfo[]) {
254
- this.driftMarkets = driftMarkets;
257
+ public updateMarketTypeAndIndex(velocityMarkets: VelocityMarketInfo[]) {
258
+ this.velocityMarkets = velocityMarkets;
255
259
  }
256
260
  }
@@ -10,33 +10,31 @@ import {
10
10
  } from './types';
11
11
 
12
12
  /**
13
- * takes advantage of /batchPriorityFees endpoint from drift hosted priority fee service
13
+ * takes advantage of /batchPriorityFees endpoint from Velocity hosted priority fee service
14
14
  */
15
15
  export class PriorityFeeSubscriberMap {
16
16
  frequencyMs: number;
17
17
  intervalId?: ReturnType<typeof setTimeout>;
18
18
 
19
- driftMarkets?: VelocityMarketInfo[];
20
- velocityPriorityFeeEndpoint?: string;
19
+ velocityMarkets?: VelocityMarketInfo[];
20
+ /** @deprecated Use `velocityMarkets` instead. `driftMarkets` will be removed in a future major. */
21
+ public get driftMarkets(): VelocityMarketInfo[] | undefined {
22
+ return this.velocityMarkets;
23
+ }
24
+ velocityPriorityFeeEndpoint: string;
21
25
  /** @deprecated Use `velocityPriorityFeeEndpoint` instead. `driftPriorityFeeEndpoint` will be removed in a future major. */
22
- public get driftPriorityFeeEndpoint(): string | undefined {
26
+ public get driftPriorityFeeEndpoint(): string {
23
27
  return this.velocityPriorityFeeEndpoint;
24
28
  }
25
29
  feesMap: Map<string, Map<number, VelocityPriorityFeeLevels>>; // marketType -> marketIndex -> priority fee
26
30
 
27
31
  public constructor(config: PriorityFeeSubscriberMapConfig) {
28
- this.frequencyMs = config.frequencyMs;
29
32
  this.frequencyMs =
30
33
  config.frequencyMs ?? DEFAULT_PRIORITY_FEE_MAP_FREQUENCY_MS;
31
- const endpoint =
32
- config.velocityPriorityFeeEndpoint ?? config.driftPriorityFeeEndpoint;
33
- if (!endpoint) {
34
- throw new Error(
35
- 'PriorityFeeSubscriberMap: velocityPriorityFeeEndpoint (or deprecated driftPriorityFeeEndpoint) must be provided'
36
- );
37
- }
38
- this.velocityPriorityFeeEndpoint = endpoint;
39
- this.driftMarkets = config.driftMarkets;
34
+ // Type-system guarantees at least one of the two is supplied.
35
+ this.velocityPriorityFeeEndpoint = (config.velocityPriorityFeeEndpoint ??
36
+ config.driftPriorityFeeEndpoint)!;
37
+ this.velocityMarkets = config.velocityMarkets ?? config.driftMarkets;
40
38
  this.feesMap = new Map<string, Map<number, VelocityPriorityFeeLevels>>();
41
39
  this.feesMap.set('perp', new Map<number, VelocityPriorityFeeLevels>());
42
40
  this.feesMap.set('spot', new Map<number, VelocityPriorityFeeLevels>());
@@ -68,22 +66,22 @@ export class PriorityFeeSubscriberMap {
68
66
 
69
67
  public async load(): Promise<void> {
70
68
  try {
71
- if (!this.driftMarkets) {
69
+ if (!this.velocityMarkets) {
72
70
  return;
73
71
  }
74
72
  const fees = await fetchVelocityPriorityFee(
75
- this.velocityPriorityFeeEndpoint!,
76
- this.driftMarkets.map((m) => m.marketType),
77
- this.driftMarkets.map((m) => m.marketIndex)
73
+ this.velocityPriorityFeeEndpoint,
74
+ this.velocityMarkets.map((m) => m.marketType),
75
+ this.velocityMarkets.map((m) => m.marketIndex)
78
76
  );
79
77
  this.updateFeesMap(fees);
80
78
  } catch (e) {
81
- console.error('Error fetching drift priority fees', e);
79
+ console.error('Error fetching priority fees', e);
82
80
  }
83
81
  }
84
82
 
85
- public updateMarketTypeAndIndex(driftMarkets: VelocityMarketInfo[]) {
86
- this.driftMarkets = driftMarkets;
83
+ public updateMarketTypeAndIndex(velocityMarkets: VelocityMarketInfo[]) {
84
+ this.velocityMarkets = velocityMarkets;
87
85
  }
88
86
 
89
87
  public getPriorityFees(
@@ -96,22 +94,22 @@ export class PriorityFeeSubscriberMap {
96
94
 
97
95
  /** Example usage:
98
96
  async function main() {
99
- const driftMarkets: VelocityMarketInfo[] = [
97
+ const velocityMarkets: VelocityMarketInfo[] = [
100
98
  { marketType: 'perp', marketIndex: 0 },
101
99
  { marketType: 'perp', marketIndex: 1 },
102
100
  { marketType: 'spot', marketIndex: 2 }
103
101
  ];
104
102
 
105
103
  const subscriber = new PriorityFeeSubscriberMap({
106
- velocityPriorityFeeEndpoint: 'https://dlob.drift.trade',
104
+ velocityPriorityFeeEndpoint: 'https://dlob.velocity.trade',
107
105
  frequencyMs: 5000,
108
- driftMarkets
106
+ velocityMarkets
109
107
  });
110
108
  await subscriber.subscribe();
111
109
 
112
110
  for (let i = 0; i < 20; i++) {
113
111
  await new Promise(resolve => setTimeout(resolve, 1000));
114
- driftMarkets.forEach(market => {
112
+ velocityMarkets.forEach(market => {
115
113
  const fees = subscriber.getPriorityFees(market.marketType, market.marketIndex);
116
114
  console.log(`Priority fees for ${market.marketType} market ${market.marketIndex}:`, fees);
117
115
  });
@@ -5,6 +5,7 @@ import {
5
5
  VelocityMarketInfo,
6
6
  VelocityPriorityFeeResponse,
7
7
  } from './velocityPriorityFeeMethod';
8
+ import { AtLeastOne } from '../util/deprecatedAlias';
8
9
 
9
10
  export const DEFAULT_PRIORITY_FEE_MAP_FREQUENCY_MS = 10_000;
10
11
 
@@ -22,7 +23,7 @@ export interface PriorityFeeStrategy {
22
23
  export enum PriorityFeeMethod {
23
24
  SOLANA = 'solana',
24
25
  HELIUS = 'helius',
25
- DRIFT = 'drift',
26
+ VELOCITY = 'velocity',
26
27
  }
27
28
 
28
29
  export type PriorityFeeSubscriberConfig = {
@@ -32,7 +33,9 @@ export type PriorityFeeSubscriberConfig = {
32
33
  frequencyMs?: number;
33
34
  /// addresses you plan to write lock, used to determine priority fees
34
35
  addresses?: PublicKey[];
35
- /// drift market type and index, optionally provide at initialization time if using priorityFeeMethod.DRIFT
36
+ /// market type and index, optionally provide at initialization time if using priorityFeeMethod.VELOCITY
37
+ velocityMarkets?: VelocityMarketInfo[];
38
+ /** @deprecated Use `velocityMarkets` instead. `driftMarkets` will be removed in a future major. */
36
39
  driftMarkets?: VelocityMarketInfo[];
37
40
  /// custom strategy to calculate priority fees, defaults to AVERAGE
38
41
  customStrategy?: PriorityFeeStrategy;
@@ -42,7 +45,7 @@ export type PriorityFeeSubscriberConfig = {
42
45
  slotsToCheck?: number;
43
46
  /// url for helius rpc, required if using priorityFeeMethod.HELIUS
44
47
  heliusRpcUrl?: string;
45
- /// url for drift cached priority fee endpoint, required if using priorityFeeMethod.DRIFT
48
+ /// url for Velocity cached priority fee endpoint, required if using priorityFeeMethod.VELOCITY
46
49
  velocityPriorityFeeEndpoint?: string;
47
50
  /** @deprecated Use `velocityPriorityFeeEndpoint` instead. `driftPriorityFeeEndpoint` will be removed in a future major. */
48
51
  driftPriorityFeeEndpoint?: string;
@@ -52,13 +55,15 @@ export type PriorityFeeSubscriberConfig = {
52
55
  priorityFeeMultiplier?: number;
53
56
  };
54
57
 
55
- export type PriorityFeeSubscriberMapConfig = {
58
+ type PriorityFeeSubscriberMapConfigBase = {
56
59
  /// frequency to make RPC calls to update priority fee samples, in milliseconds
57
60
  frequencyMs?: number;
58
- /// drift market type and associated market index to query
61
+ /// market type and associated market index to query
62
+ velocityMarkets?: VelocityMarketInfo[];
63
+ /** @deprecated Use `velocityMarkets` instead. `driftMarkets` will be removed in a future major. */
59
64
  driftMarkets?: VelocityMarketInfo[];
60
- /// url for drift cached priority fee endpoint
61
- velocityPriorityFeeEndpoint?: string;
62
- /** @deprecated Use `velocityPriorityFeeEndpoint` instead. `driftPriorityFeeEndpoint` will be removed in a future major. */
63
- driftPriorityFeeEndpoint?: string;
64
65
  };
66
+
67
+ /// url for Velocity cached priority fee endpoint
68
+ export type PriorityFeeSubscriberMapConfig = PriorityFeeSubscriberMapConfigBase &
69
+ AtLeastOne<'velocityPriorityFeeEndpoint', 'driftPriorityFeeEndpoint', string>;
@@ -1,10 +1,12 @@
1
- import { Commitment, Context, PublicKey } from '@solana/web3.js';
1
+ import { Context, PublicKey } from '@solana/web3.js';
2
2
  import { grpcProgramAccountSubscriber } from '../accounts/grpcProgramAccountSubscriber';
3
- import { GrpcConfigs, ResubOpts } from '../accounts/types';
3
+ import { GrpcConfigs } from '../accounts/types';
4
4
  import { SignedMsgUserOrdersAccount } from '../types';
5
5
  import { getSignedMsgUserOrdersFilter } from '../memcmp';
6
- import { SignedMsgUserOrdersAccountSubscriber } from './signedMsgUserAccountSubscriber';
7
- import { VelocityClient } from '../velocityClient';
6
+ import {
7
+ SignedMsgUserOrdersAccountSubscriber,
8
+ SignedMsgUserOrdersAccountSubscriberConfig,
9
+ } from './signedMsgUserAccountSubscriber';
8
10
 
9
11
  export class grpcSignedMsgUserOrdersAccountSubscriber extends SignedMsgUserOrdersAccountSubscriber {
10
12
  private grpcConfigs: GrpcConfigs;
@@ -12,26 +14,11 @@ export class grpcSignedMsgUserOrdersAccountSubscriber extends SignedMsgUserOrder
12
14
 
13
15
  constructor({
14
16
  grpcConfigs,
15
- driftClient,
16
- commitment,
17
- resubOpts,
18
- decodeFn,
19
- resyncIntervalMs,
20
- }: {
17
+ ...rest
18
+ }: SignedMsgUserOrdersAccountSubscriberConfig & {
21
19
  grpcConfigs: GrpcConfigs;
22
- driftClient: VelocityClient;
23
- commitment?: Commitment;
24
- resubOpts?: ResubOpts;
25
- decodeFn?: (name: string, data: Buffer) => SignedMsgUserOrdersAccount;
26
- resyncIntervalMs?: number;
27
20
  }) {
28
- super({
29
- driftClient,
30
- commitment,
31
- resubOpts,
32
- decodeFn,
33
- resyncIntervalMs,
34
- });
21
+ super(rest);
35
22
  this.grpcConfigs = grpcConfigs;
36
23
  }
37
24
 
@@ -42,7 +29,7 @@ export class grpcSignedMsgUserOrdersAccountSubscriber extends SignedMsgUserOrder
42
29
  this.grpcConfigs,
43
30
  'SingedMsgUserOrdersAccountMap',
44
31
  'signedMsgUserOrders',
45
- this.driftClient.program,
32
+ this.velocityClient.program,
46
33
  this.decodeFn,
47
34
  {
48
35
  filters: [getSignedMsgUserOrdersFilter()],
@@ -4,9 +4,17 @@ import { SignedMsgOrderId, SignedMsgUserOrdersAccount } from '../types';
4
4
  import { Commitment, Context, PublicKey } from '@solana/web3.js';
5
5
  import { ResubOpts } from '../accounts/types';
6
6
  import { VelocityClient } from '../velocityClient';
7
+ import { AtLeastOne } from '../util/deprecatedAlias';
7
8
  import StrictEventEmitter from 'strict-event-emitter-types';
8
9
  import { EventEmitter } from 'events';
9
10
 
11
+ export type SignedMsgUserOrdersAccountSubscriberConfig = {
12
+ commitment?: Commitment;
13
+ resubOpts?: ResubOpts;
14
+ decodeFn?: (name: string, data: Buffer) => SignedMsgUserOrdersAccount;
15
+ resyncIntervalMs?: number;
16
+ } & AtLeastOne<'velocityClient', 'driftClient', VelocityClient>;
17
+
10
18
  export interface SignedMsgUserOrdersAccountSubscriberEvents {
11
19
  onAccountUpdate: (
12
20
  activeSignedMsgOrderIds: SignedMsgOrderId[],
@@ -22,7 +30,11 @@ export interface SignedMsgUserOrdersAccountSubscriberEvents {
22
30
  }
23
31
 
24
32
  export class SignedMsgUserOrdersAccountSubscriber {
25
- protected driftClient: VelocityClient;
33
+ protected velocityClient: VelocityClient;
34
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
35
+ protected get driftClient(): VelocityClient {
36
+ return this.velocityClient;
37
+ }
26
38
  protected commitment: Commitment;
27
39
  protected resubOpts?: ResubOpts;
28
40
  protected resyncTimeoutId?: ReturnType<typeof setTimeout>;
@@ -47,27 +59,23 @@ export class SignedMsgUserOrdersAccountSubscriber {
47
59
  >;
48
60
 
49
61
  constructor({
62
+ velocityClient,
50
63
  driftClient,
51
64
  commitment,
52
65
  resubOpts,
53
66
  decodeFn,
54
67
  resyncIntervalMs,
55
- }: {
56
- driftClient: VelocityClient;
57
- commitment?: Commitment;
58
- resubOpts?: ResubOpts;
59
- decodeFn?: (name: string, data: Buffer) => SignedMsgUserOrdersAccount;
60
- resyncIntervalMs?: number;
61
- }) {
68
+ }: SignedMsgUserOrdersAccountSubscriberConfig) {
62
69
  this.commitment = commitment ?? 'confirmed';
63
70
  this.resubOpts = resubOpts;
64
- this.driftClient = driftClient;
71
+ // Type-system guarantees at least one of the two is supplied.
72
+ this.velocityClient = (velocityClient ?? driftClient)!;
65
73
  this.decodeFn =
66
74
  decodeFn ??
67
75
  (
68
- this.driftClient.program.account as any
76
+ this.velocityClient.program.account as any
69
77
  ).signedMsgUserOrders.coder.accounts.decodeUnchecked.bind(
70
- (this.driftClient.program.account as any).signedMsgUserOrders.coder
78
+ (this.velocityClient.program.account as any).signedMsgUserOrders.coder
71
79
  .accounts
72
80
  );
73
81
  this.resyncIntervalMs = resyncIntervalMs;
@@ -82,7 +90,7 @@ export class SignedMsgUserOrdersAccountSubscriber {
82
90
  new WebSocketProgramAccountSubscriber<SignedMsgUserOrdersAccount>(
83
91
  'SingedMsgUserOrdersAccountMap',
84
92
  'signedMsgUserOrders',
85
- this.driftClient.program,
93
+ this.velocityClient.program,
86
94
  this.decodeFn,
87
95
  {
88
96
  filters,
@@ -139,8 +147,8 @@ export class SignedMsgUserOrdersAccountSubscriber {
139
147
 
140
148
  try {
141
149
  const rpcResponseAndContext =
142
- await this.driftClient.connection.getProgramAccounts(
143
- this.driftClient.program.programId,
150
+ await this.velocityClient.connection.getProgramAccounts(
151
+ this.velocityClient.program.programId,
144
152
  {
145
153
  commitment: this.commitment,
146
154
  filters: [getSignedMsgUserOrdersFilter()],
@@ -4,6 +4,7 @@ import {
4
4
  } from '../constants/perpMarkets';
5
5
  import { VelocityClient } from '../velocityClient';
6
6
  import { VelocityEnv } from '../config';
7
+ import { AtLeastOne } from '../util/deprecatedAlias';
7
8
  import {
8
9
  getUserAccountPublicKey,
9
10
  getUserStatsAccountPublicKey,
@@ -27,10 +28,8 @@ export interface AccountGetter {
27
28
  mustGetUserAccount(publicKey: string): Promise<UserAccount>;
28
29
  }
29
30
 
30
- export type SwiftOrderSubscriberConfig = {
31
- driftClient: VelocityClient;
31
+ type SwiftOrderSubscriberConfigBase = {
32
32
  userAccountGetter?: AccountGetter;
33
- driftEnv: VelocityEnv;
34
33
  endpoint?: string;
35
34
  marketIndexes: number[];
36
35
  /**
@@ -41,6 +40,10 @@ export type SwiftOrderSubscriberConfig = {
41
40
  keypair: Keypair;
42
41
  };
43
42
 
43
+ export type SwiftOrderSubscriberConfig = SwiftOrderSubscriberConfigBase &
44
+ AtLeastOne<'velocityEnv', 'driftEnv', VelocityEnv> &
45
+ AtLeastOne<'velocityClient', 'driftClient', VelocityClient>;
46
+
44
47
  /**
45
48
  * Swift order message received from WebSocket
46
49
  */
@@ -70,7 +73,11 @@ export class SwiftOrderSubscriber {
70
73
  private heartbeatTimeout: ReturnType<typeof setTimeout> | null = null;
71
74
  private readonly heartbeatIntervalMs = 60000;
72
75
  private ws: WebSocket | null = null;
73
- private driftClient: VelocityClient;
76
+ private velocityClient: VelocityClient;
77
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
78
+ private get driftClient(): VelocityClient {
79
+ return this.velocityClient;
80
+ }
74
81
  public userAccountGetter?: AccountGetter; // In practice, this for now is just an OrderSubscriber or a UserMap
75
82
  public onOrder: (
76
83
  orderMessageRaw: SwiftOrderMessage,
@@ -83,7 +90,8 @@ export class SwiftOrderSubscriber {
83
90
  subscribed = false;
84
91
 
85
92
  constructor(private config: SwiftOrderSubscriberConfig) {
86
- this.driftClient = config.driftClient;
93
+ // Type-system guarantees at least one of the two is supplied.
94
+ this.velocityClient = (config.velocityClient ?? config.driftClient)!;
87
95
  this.userAccountGetter = config.userAccountGetter;
88
96
  }
89
97
 
@@ -97,10 +105,8 @@ export class SwiftOrderSubscriber {
97
105
  }
98
106
 
99
107
  getSymbolForMarketIndex(marketIndex: number): string {
100
- const markets =
101
- this.config.driftEnv === 'devnet'
102
- ? DevnetPerpMarkets
103
- : MainnetPerpMarkets;
108
+ const env = this.config.velocityEnv ?? this.config.driftEnv;
109
+ const markets = env === 'devnet' ? DevnetPerpMarkets : MainnetPerpMarkets;
104
110
  return markets[marketIndex].symbol;
105
111
  }
106
112
 
@@ -156,10 +162,12 @@ export class SwiftOrderSubscriber {
156
162
  ): Promise<void> {
157
163
  this.onOrder = onOrder;
158
164
 
165
+ const env = this.config.velocityEnv ?? this.config.driftEnv;
159
166
  const endpoint =
160
- this.config.endpoint || this.config.driftEnv === 'devnet'
167
+ this.config.endpoint ??
168
+ (env === 'devnet'
161
169
  ? 'wss://master.swift.drift.trade/ws'
162
- : 'wss://swift.drift.trade/ws';
170
+ : 'wss://swift.drift.trade/ws');
163
171
  const ws = new WebSocket(
164
172
  endpoint + '?pubkey=' + this.config.keypair.publicKey.toBase58()
165
173
  );
@@ -202,7 +210,7 @@ export class SwiftOrderSubscriber {
202
210
  )
203
211
  );
204
212
  const signedMessage =
205
- this.driftClient.decodeSignedMsgOrderParamsMessage(
213
+ this.velocityClient.decodeSignedMsgOrderParamsMessage(
206
214
  signedMsgOrderParamsBuf,
207
215
  isDelegateSigner
208
216
  );
@@ -279,7 +287,7 @@ export class SwiftOrderSubscriber {
279
287
  ).slice(0, 8)
280
288
  )
281
289
  );
282
- const signedMessage = this.driftClient.decodeSignedMsgOrderParamsMessage(
290
+ const signedMessage = this.velocityClient.decodeSignedMsgOrderParamsMessage(
283
291
  signedMsgOrderParamsBuf,
284
292
  isDelegateSigner
285
293
  );
@@ -289,14 +297,14 @@ export class SwiftOrderSubscriber {
289
297
  const takerUserPubkey = isDelegateSigner
290
298
  ? (signedMessage as SignedMsgOrderParamsDelegateMessage).takerPubkey
291
299
  : await getUserAccountPublicKey(
292
- this.driftClient.program.programId,
300
+ this.velocityClient.program.programId,
293
301
  takerAuthority,
294
302
  (signedMessage as SignedMsgOrderParamsMessage).subAccountId
295
303
  );
296
304
  const takerUserAccount = await this.userAccountGetter.mustGetUserAccount(
297
305
  takerUserPubkey.toString()
298
306
  );
299
- const ixs = await this.driftClient.getPlaceAndMakeSignedMsgPerpOrderIxs(
307
+ const ixs = await this.velocityClient.getPlaceAndMakeSignedMsgPerpOrderIxs(
300
308
  {
301
309
  orderParams: signedMsgOrderParamsBuf,
302
310
  signature: Buffer.from(orderMessageRaw.order_signature, 'base64'),
@@ -306,7 +314,7 @@ export class SwiftOrderSubscriber {
306
314
  taker: takerUserPubkey,
307
315
  takerUserAccount,
308
316
  takerStats: getUserStatsAccountPublicKey(
309
- this.driftClient.program.programId,
317
+ this.velocityClient.program.programId,
310
318
  takerUserAccount.authority
311
319
  ),
312
320
  signingAuthority: signingAuthority,