@velocity-exchange/sdk 0.0.2 → 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 +1 -1
  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
@@ -13,13 +13,19 @@ const tweetnacl_util_1 = require("tweetnacl-util");
13
13
  const ws_1 = __importDefault(require("ws"));
14
14
  const sha256_1 = require("@noble/hashes/sha256");
15
15
  class SwiftOrderSubscriber {
16
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
17
+ get driftClient() {
18
+ return this.velocityClient;
19
+ }
16
20
  constructor(config) {
21
+ var _a;
17
22
  this.config = config;
18
23
  this.heartbeatTimeout = null;
19
24
  this.heartbeatIntervalMs = 60000;
20
25
  this.ws = null;
21
26
  this.subscribed = false;
22
- this.driftClient = config.driftClient;
27
+ // Type-system guarantees at least one of the two is supplied.
28
+ this.velocityClient = ((_a = config.velocityClient) !== null && _a !== void 0 ? _a : config.driftClient);
23
29
  this.userAccountGetter = config.userAccountGetter;
24
30
  }
25
31
  unsubscribe() {
@@ -31,9 +37,9 @@ class SwiftOrderSubscriber {
31
37
  }
32
38
  }
33
39
  getSymbolForMarketIndex(marketIndex) {
34
- const markets = this.config.driftEnv === 'devnet'
35
- ? perpMarkets_1.DevnetPerpMarkets
36
- : perpMarkets_1.MainnetPerpMarkets;
40
+ var _a;
41
+ const env = (_a = this.config.velocityEnv) !== null && _a !== void 0 ? _a : this.config.driftEnv;
42
+ const markets = env === 'devnet' ? perpMarkets_1.DevnetPerpMarkets : perpMarkets_1.MainnetPerpMarkets;
37
43
  return markets[marketIndex].symbol;
38
44
  }
39
45
  generateChallengeResponse(nonce) {
@@ -66,10 +72,12 @@ class SwiftOrderSubscriber {
66
72
  }
67
73
  }
68
74
  async subscribe(onOrder, acceptSanitized = false, acceptDepositTrade = false) {
75
+ var _a, _b;
69
76
  this.onOrder = onOrder;
70
- const endpoint = this.config.endpoint || this.config.driftEnv === 'devnet'
77
+ const env = (_a = this.config.velocityEnv) !== null && _a !== void 0 ? _a : this.config.driftEnv;
78
+ const endpoint = (_b = this.config.endpoint) !== null && _b !== void 0 ? _b : (env === 'devnet'
71
79
  ? 'wss://master.swift.drift.trade/ws'
72
- : 'wss://swift.drift.trade/ws';
80
+ : 'wss://swift.drift.trade/ws');
73
81
  const ws = new ws_1.default(endpoint + '?pubkey=' + this.config.keypair.publicKey.toBase58());
74
82
  this.ws = ws;
75
83
  ws.on('open', async () => {
@@ -97,7 +105,7 @@ class SwiftOrderSubscriber {
97
105
  const isDelegateSigner = signedMsgOrderParamsBuf
98
106
  .slice(0, 8)
99
107
  .equals(Uint8Array.from(Buffer.from((0, sha256_1.sha256)('global' + ':' + 'SignedMsgOrderParamsDelegateMessage')).slice(0, 8)));
100
- const signedMessage = this.driftClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf, isDelegateSigner);
108
+ const signedMessage = this.velocityClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf, isDelegateSigner);
101
109
  if (!signedMessage.signedMsgOrderParams.price) {
102
110
  console.error(`order has no price: ${JSON.stringify(signedMessage.signedMsgOrderParams)}`);
103
111
  return;
@@ -139,20 +147,20 @@ class SwiftOrderSubscriber {
139
147
  const isDelegateSigner = signedMsgOrderParamsBuf
140
148
  .slice(0, 8)
141
149
  .equals(Uint8Array.from(Buffer.from((0, sha256_1.sha256)('global' + ':' + 'SignedMsgOrderParamsDelegateMessage')).slice(0, 8)));
142
- const signedMessage = this.driftClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf, isDelegateSigner);
150
+ const signedMessage = this.velocityClient.decodeSignedMsgOrderParamsMessage(signedMsgOrderParamsBuf, isDelegateSigner);
143
151
  const takerAuthority = new web3_js_1.PublicKey(orderMessageRaw.taker_authority);
144
152
  const signingAuthority = new web3_js_1.PublicKey(orderMessageRaw.signing_authority);
145
153
  const takerUserPubkey = isDelegateSigner
146
154
  ? signedMessage.takerPubkey
147
- : await (0, pda_1.getUserAccountPublicKey)(this.driftClient.program.programId, takerAuthority, signedMessage.subAccountId);
155
+ : await (0, pda_1.getUserAccountPublicKey)(this.velocityClient.program.programId, takerAuthority, signedMessage.subAccountId);
148
156
  const takerUserAccount = await this.userAccountGetter.mustGetUserAccount(takerUserPubkey.toString());
149
- const ixs = await this.driftClient.getPlaceAndMakeSignedMsgPerpOrderIxs({
157
+ const ixs = await this.velocityClient.getPlaceAndMakeSignedMsgPerpOrderIxs({
150
158
  orderParams: signedMsgOrderParamsBuf,
151
159
  signature: Buffer.from(orderMessageRaw.order_signature, 'base64'),
152
160
  }, (0, tweetnacl_util_1.decodeUTF8)(orderMessageRaw.uuid), {
153
161
  taker: takerUserPubkey,
154
162
  takerUserAccount,
155
- takerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, takerUserAccount.authority),
163
+ takerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.velocityClient.program.programId, takerUserAccount.authority),
156
164
  signingAuthority: signingAuthority,
157
165
  }, Object.assign({}, makerOrderParams, {
158
166
  postOnly: types_1.PostOnlyParams.MUST_POST_ONLY,
@@ -27,7 +27,9 @@ import { StrictOraclePrice } from './oracles/strictOraclePrice';
27
27
  import { IsolatedMarginCalculation, MarginCalculation } from './marginCalculation';
28
28
  export type MarginType = 'Cross' | 'Isolated';
29
29
  export declare class User {
30
- driftClient: VelocityClient;
30
+ velocityClient: VelocityClient;
31
+ /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
32
+ get driftClient(): VelocityClient;
31
33
  userAccountPublicKey: PublicKey;
32
34
  accountSubscriber: UserAccountSubscriber;
33
35
  _isSubscribed: boolean;