@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/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": [
@@ -19727,7 +19780,7 @@ export type Drift = {
19727
19780
  {
19728
19781
  "name": "oraclePriceOffset",
19729
19782
  "type": {
19730
- "option": "i32"
19783
+ "option": "i64"
19731
19784
  }
19732
19785
  },
19733
19786
  {
@@ -19968,7 +20021,7 @@ export type Drift = {
19968
20021
  "If set, the order limit price is the oracle price + this offset",
19969
20022
  "precision: PRICE_PRECISION"
19970
20023
  ],
19971
- "type": "i32"
20024
+ "type": "i64"
19972
20025
  },
19973
20026
  {
19974
20027
  "name": "orderId",
@@ -20105,7 +20158,7 @@ export type Drift = {
20105
20158
  "type": {
20106
20159
  "array": [
20107
20160
  "u8",
20108
- 1
20161
+ 5
20109
20162
  ]
20110
20163
  }
20111
20164
  }
@@ -20631,7 +20684,7 @@ export type Drift = {
20631
20684
  {
20632
20685
  "name": "oraclePriceOffset",
20633
20686
  "type": {
20634
- "option": "i32"
20687
+ "option": "i64"
20635
20688
  }
20636
20689
  },
20637
20690
  {
@@ -21813,7 +21866,7 @@ export type Drift = {
21813
21866
  {
21814
21867
  "name": "bitFlags",
21815
21868
  "docs": [
21816
- "Bit flags (e.g., for high leverage mode)"
21869
+ "Order bit flags"
21817
21870
  ],
21818
21871
  "type": "u8"
21819
21872
  },
@@ -95,7 +95,7 @@ export function getAuctionPrice(
95
95
  ) {
96
96
  return getAuctionPriceForFixedAuction(order, slot);
97
97
  } else if (isVariant(order.orderType, 'limit')) {
98
- if (order.oraclePriceOffset != null && order.oraclePriceOffset !== 0) {
98
+ if (order.oraclePriceOffset != null && !order.oraclePriceOffset.eq(ZERO)) {
99
99
  return getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice);
100
100
  } else {
101
101
  return getAuctionPriceForFixedAuction(order, slot);
@@ -207,7 +207,7 @@ export function deriveOracleAuctionParams({
207
207
  min: BN;
208
208
  max: BN;
209
209
  };
210
- }): { auctionStartPrice: BN; auctionEndPrice: BN; oraclePriceOffset: number } {
210
+ }): { auctionStartPrice: BN; auctionEndPrice: BN; oraclePriceOffset: BN } {
211
211
  let oraclePriceOffset;
212
212
 
213
213
  if (limitPrice.eq(ZERO) || oraclePrice.eq(ZERO)) {
@@ -222,13 +222,6 @@ export function deriveOracleAuctionParams({
222
222
  : auctionEndPrice.sub(oraclePrice).sub(ONE);
223
223
  }
224
224
 
225
- let oraclePriceOffsetNum;
226
- try {
227
- oraclePriceOffsetNum = oraclePriceOffset.toNumber();
228
- } catch (e) {
229
- oraclePriceOffsetNum = 0;
230
- }
231
-
232
225
  if (auctionPriceCaps) {
233
226
  auctionStartPrice = BN.min(
234
227
  BN.max(auctionStartPrice, auctionPriceCaps.min),
@@ -243,7 +236,7 @@ export function deriveOracleAuctionParams({
243
236
  return {
244
237
  auctionStartPrice: auctionStartPrice.sub(oraclePrice),
245
238
  auctionEndPrice: auctionEndPrice.sub(oraclePrice),
246
- oraclePriceOffset: oraclePriceOffsetNum,
239
+ oraclePriceOffset: oraclePriceOffset,
247
240
  };
248
241
  }
249
242
 
@@ -168,11 +168,8 @@ export function getLimitPrice<T extends MarketTypeStr>(
168
168
  ): BN | undefined {
169
169
  if (hasAuctionPrice(order, slot)) {
170
170
  return getAuctionPrice(order, slot, oraclePriceData.price);
171
- } else if (order.oraclePriceOffset !== 0) {
172
- return BN.max(
173
- oraclePriceData.price.add(new BN(order.oraclePriceOffset)),
174
- ONE
175
- );
171
+ } else if (!order.oraclePriceOffset.eq(ZERO)) {
172
+ return BN.max(oraclePriceData.price.add(order.oraclePriceOffset), ONE);
176
173
  } else if (order.price.eq(ZERO)) {
177
174
  return fallbackPrice;
178
175
  } else {
@@ -183,7 +180,7 @@ export function getLimitPrice<T extends MarketTypeStr>(
183
180
  export function hasLimitPrice(order: Order, slot: number): boolean {
184
181
  return (
185
182
  order.price.gt(ZERO) ||
186
- order.oraclePriceOffset != 0 ||
183
+ !order.oraclePriceOffset.eq(ZERO) ||
187
184
  !isAuctionComplete(order, slot)
188
185
  );
189
186
  }
@@ -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,20 @@ 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 =
69
+ PriorityFeeSubscriberMapConfigBase &
70
+ AtLeastOne<
71
+ 'velocityPriorityFeeEndpoint',
72
+ 'driftPriorityFeeEndpoint',
73
+ string
74
+ >;
@@ -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()],