@velocity-exchange/sdk 0.4.0 → 0.6.1

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 (325) hide show
  1. package/README.md +3 -3
  2. package/lib/browser/adminClient.d.ts +52 -0
  3. package/lib/browser/adminClient.js +97 -0
  4. package/lib/browser/config.js +6 -7
  5. package/lib/browser/constants/numericConstants.d.ts +1 -1
  6. package/lib/browser/constants/numericConstants.js +1 -1
  7. package/lib/browser/decode/user.js +5 -1
  8. package/lib/browser/idl/velocity.d.ts +191 -15
  9. package/lib/browser/idl/velocity.json +192 -16
  10. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -0
  11. package/lib/browser/orderSubscriber/OrderSubscriber.js +10 -4
  12. package/lib/browser/pyth/pythLazerSubscriber.js +37 -27
  13. package/lib/browser/types.d.ts +6 -0
  14. package/lib/browser/user.d.ts +20 -3
  15. package/lib/browser/user.js +52 -4
  16. package/lib/browser/velocityClient.d.ts +46 -10
  17. package/lib/browser/velocityClient.js +107 -35
  18. package/lib/node/adminClient.d.ts +52 -0
  19. package/lib/node/adminClient.d.ts.map +1 -1
  20. package/lib/node/adminClient.js +97 -0
  21. package/lib/node/config.d.ts.map +1 -1
  22. package/lib/node/config.js +6 -7
  23. package/lib/node/constants/numericConstants.d.ts +1 -1
  24. package/lib/node/constants/numericConstants.d.ts.map +1 -1
  25. package/lib/node/constants/numericConstants.js +1 -1
  26. package/lib/node/decode/user.d.ts.map +1 -1
  27. package/lib/node/decode/user.js +5 -1
  28. package/lib/node/idl/velocity.d.ts +191 -15
  29. package/lib/node/idl/velocity.d.ts.map +1 -1
  30. package/lib/node/idl/velocity.json +192 -16
  31. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -0
  32. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  33. package/lib/node/orderSubscriber/OrderSubscriber.js +10 -4
  34. package/lib/node/pyth/pythLazerSubscriber.d.ts.map +1 -1
  35. package/lib/node/pyth/pythLazerSubscriber.js +37 -27
  36. package/lib/node/types.d.ts +6 -0
  37. package/lib/node/types.d.ts.map +1 -1
  38. package/lib/node/user.d.ts +20 -3
  39. package/lib/node/user.d.ts.map +1 -1
  40. package/lib/node/user.js +52 -4
  41. package/lib/node/velocityClient.d.ts +46 -10
  42. package/lib/node/velocityClient.d.ts.map +1 -1
  43. package/lib/node/velocityClient.js +107 -35
  44. package/package.json +7 -3
  45. package/.prettierignore +0 -1
  46. package/CHANGELOG.md +0 -132
  47. package/build-browser.js +0 -58
  48. package/bunfig.toml +0 -3
  49. package/esbuild-shims.js +0 -12
  50. package/scripts/deposit-isolated-positions.ts +0 -110
  51. package/scripts/find-flagged-users.ts +0 -213
  52. package/scripts/grpc-client-test-comparison.ts +0 -372
  53. package/scripts/grpc-multiuser-client-test-comparison.ts +0 -158
  54. package/scripts/postbuild.js +0 -95
  55. package/scripts/single-grpc-client-test.ts +0 -284
  56. package/scripts/withdraw-isolated-positions.ts +0 -174
  57. package/src/accounts/README_WebSocketAccountSubscriberV2.md +0 -95
  58. package/src/accounts/README_WebSocketProgramAccountSubscriberV2.md +0 -135
  59. package/src/accounts/basicUserAccountSubscriber.ts +0 -79
  60. package/src/accounts/basicUserStatsAccountSubscriber.ts +0 -87
  61. package/src/accounts/bulkAccountLoader.ts +0 -358
  62. package/src/accounts/bulkUserStatsSubscription.ts +0 -40
  63. package/src/accounts/bulkUserSubscription.ts +0 -39
  64. package/src/accounts/customizedCadenceBulkAccountLoader.ts +0 -250
  65. package/src/accounts/fetch.ts +0 -200
  66. package/src/accounts/grpcAccountSubscriber.ts +0 -225
  67. package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +0 -73
  68. package/src/accounts/grpcMultiAccountSubscriber.ts +0 -566
  69. package/src/accounts/grpcMultiUserAccountSubscriber.ts +0 -328
  70. package/src/accounts/grpcProgramAccountSubscriber.ts +0 -264
  71. package/src/accounts/grpcUserAccountSubscriber.ts +0 -63
  72. package/src/accounts/grpcUserStatsAccountSubscriber.ts +0 -65
  73. package/src/accounts/grpcVelocityClientAccountSubscriber.ts +0 -257
  74. package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +0 -941
  75. package/src/accounts/laserProgramAccountSubscriber.ts +0 -266
  76. package/src/accounts/oneShotUserAccountSubscriber.ts +0 -88
  77. package/src/accounts/oneShotUserStatsAccountSubscriber.ts +0 -94
  78. package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +0 -223
  79. package/src/accounts/pollingOracleAccountSubscriber.ts +0 -151
  80. package/src/accounts/pollingTokenAccountSubscriber.ts +0 -147
  81. package/src/accounts/pollingUserAccountSubscriber.ts +0 -198
  82. package/src/accounts/pollingUserStatsAccountSubscriber.ts +0 -180
  83. package/src/accounts/pollingVelocityClientAccountSubscriber.ts +0 -774
  84. package/src/accounts/testBulkAccountLoader.ts +0 -59
  85. package/src/accounts/types.ts +0 -428
  86. package/src/accounts/utils.ts +0 -90
  87. package/src/accounts/webSocketAccountSubscriber.ts +0 -304
  88. package/src/accounts/webSocketAccountSubscriberV2.ts +0 -536
  89. package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +0 -171
  90. package/src/accounts/webSocketProgramAccountSubscriber.ts +0 -244
  91. package/src/accounts/webSocketProgramAccountSubscriberV2.ts +0 -1048
  92. package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +0 -1042
  93. package/src/accounts/webSocketUserAccountSubscriber.ts +0 -139
  94. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +0 -131
  95. package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +0 -865
  96. package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +0 -897
  97. package/src/accounts/websocketProgramUserAccountSubscriber.ts +0 -127
  98. package/src/addresses/marketAddresses.ts +0 -28
  99. package/src/addresses/pda.ts +0 -620
  100. package/src/adminClient.ts +0 -8136
  101. package/src/assert/assert.ts +0 -5
  102. package/src/auctionSubscriber/auctionSubscriber.ts +0 -86
  103. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +0 -99
  104. package/src/auctionSubscriber/index.ts +0 -9
  105. package/src/auctionSubscriber/types.ts +0 -30
  106. package/src/bankrun/bankrunConnection.ts +0 -630
  107. package/src/blockhashSubscriber/BlockhashSubscriber.ts +0 -160
  108. package/src/blockhashSubscriber/index.ts +0 -6
  109. package/src/blockhashSubscriber/types.ts +0 -13
  110. package/src/clock/clockSubscriber.ts +0 -146
  111. package/src/config.ts +0 -312
  112. package/src/constants/index.ts +0 -9
  113. package/src/constants/numericConstants.ts +0 -194
  114. package/src/constants/perpMarkets.ts +0 -127
  115. package/src/constants/spotMarkets.ts +0 -104
  116. package/src/constants/txConstants.ts +0 -2
  117. package/src/constituentMap/constituentMap.ts +0 -305
  118. package/src/constituentMap/pollingConstituentAccountSubscriber.ts +0 -99
  119. package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +0 -121
  120. package/src/core/VelocityCore.ts +0 -606
  121. package/src/core/index.ts +0 -12
  122. package/src/core/instructions/deposit.ts +0 -64
  123. package/src/core/instructions/fill.ts +0 -51
  124. package/src/core/instructions/funding.ts +0 -33
  125. package/src/core/instructions/liquidation.ts +0 -55
  126. package/src/core/instructions/orders.ts +0 -84
  127. package/src/core/instructions/perpOrders.ts +0 -312
  128. package/src/core/instructions/settlement.ts +0 -40
  129. package/src/core/instructions/trigger.ts +0 -41
  130. package/src/core/instructions/withdraw.ts +0 -65
  131. package/src/core/remainingAccounts.ts +0 -320
  132. package/src/core/signedMsg.ts +0 -109
  133. package/src/decode/customCoder.ts +0 -148
  134. package/src/decode/user.ts +0 -401
  135. package/src/dlob/DLOB.ts +0 -2793
  136. package/src/dlob/DLOBNode.ts +0 -305
  137. package/src/dlob/DLOBSubscriber.ts +0 -269
  138. package/src/dlob/NodeList.ts +0 -244
  139. package/src/dlob/orderBookLevels.ts +0 -695
  140. package/src/dlob/types.ts +0 -37
  141. package/src/events/eventList.ts +0 -114
  142. package/src/events/eventSubscriber.ts +0 -521
  143. package/src/events/eventsServerLogProvider.ts +0 -189
  144. package/src/events/fetchLogs.ts +0 -219
  145. package/src/events/parse.ts +0 -271
  146. package/src/events/pollingLogProvider.ts +0 -113
  147. package/src/events/sort.ts +0 -51
  148. package/src/events/txEventCache.ts +0 -92
  149. package/src/events/types.ts +0 -337
  150. package/src/events/webSocketLogProvider.ts +0 -152
  151. package/src/factory/bigNum.ts +0 -709
  152. package/src/factory/oracleClient.ts +0 -73
  153. package/src/idl/pyth.json +0 -142
  154. package/src/idl/pyth.ts +0 -97
  155. package/src/idl/pyth_solana_receiver.json +0 -628
  156. package/src/idl/token_faucet.json +0 -229
  157. package/src/idl/token_faucet.ts +0 -197
  158. package/src/idl/velocity.json +0 -23974
  159. package/src/idl/velocity.ts +0 -23980
  160. package/src/index.ts +0 -150
  161. package/src/indicative-quotes/indicativeQuotesSender.ts +0 -233
  162. package/src/isomorphic/README.md +0 -19
  163. package/src/isomorphic/anchor.browser.ts +0 -44
  164. package/src/isomorphic/anchor.node.ts +0 -1
  165. package/src/isomorphic/anchor.ts +0 -1
  166. package/src/isomorphic/anchor29.browser.ts +0 -24
  167. package/src/isomorphic/anchor29.node.ts +0 -1
  168. package/src/isomorphic/anchor29.ts +0 -1
  169. package/src/isomorphic/grpc.browser.ts +0 -4
  170. package/src/isomorphic/grpc.node.ts +0 -130
  171. package/src/isomorphic/grpc.ts +0 -1
  172. package/src/jupiter/jupiterClient.ts +0 -502
  173. package/src/keypair.ts +0 -32
  174. package/src/margin/README.md +0 -138
  175. package/src/marginCalculation.ts +0 -407
  176. package/src/marinade/idl/idl.json +0 -1962
  177. package/src/marinade/index.ts +0 -73
  178. package/src/marinade/types.ts +0 -3925
  179. package/src/math/amm.ts +0 -1758
  180. package/src/math/auction.ts +0 -480
  181. package/src/math/bankruptcy.ts +0 -138
  182. package/src/math/builder.ts +0 -130
  183. package/src/math/conversion.ts +0 -45
  184. package/src/math/exchangeStatus.ts +0 -261
  185. package/src/math/funding.ts +0 -498
  186. package/src/math/insurance.ts +0 -171
  187. package/src/math/liquidation.ts +0 -433
  188. package/src/math/margin.ts +0 -327
  189. package/src/math/market.ts +0 -487
  190. package/src/math/oracles.ts +0 -477
  191. package/src/math/orders.ts +0 -500
  192. package/src/math/position.ts +0 -381
  193. package/src/math/repeg.ts +0 -223
  194. package/src/math/spotBalance.ts +0 -996
  195. package/src/math/spotMarket.ts +0 -115
  196. package/src/math/spotPosition.ts +0 -263
  197. package/src/math/state.ts +0 -71
  198. package/src/math/superStake.ts +0 -602
  199. package/src/math/tiers.ts +0 -73
  200. package/src/math/trade.ts +0 -879
  201. package/src/math/utils.ts +0 -183
  202. package/src/memcmp.ts +0 -279
  203. package/src/oracles/oracleClientCache.ts +0 -41
  204. package/src/oracles/oracleId.ts +0 -99
  205. package/src/oracles/prelaunchOracleClient.ts +0 -63
  206. package/src/oracles/pythClient.ts +0 -125
  207. package/src/oracles/pythLazerClient.ts +0 -141
  208. package/src/oracles/quoteAssetOracleClient.ts +0 -43
  209. package/src/oracles/strictOraclePrice.ts +0 -40
  210. package/src/oracles/types.ts +0 -82
  211. package/src/oracles/utils.ts +0 -45
  212. package/src/orderParams.ts +0 -117
  213. package/src/orderSubscriber/OrderSubscriber.ts +0 -378
  214. package/src/orderSubscriber/PollingSubscription.ts +0 -50
  215. package/src/orderSubscriber/WebsocketSubscription.ts +0 -137
  216. package/src/orderSubscriber/grpcSubscription.ts +0 -155
  217. package/src/orderSubscriber/index.ts +0 -7
  218. package/src/orderSubscriber/types.ts +0 -64
  219. package/src/priorityFee/averageOverSlotsStrategy.ts +0 -17
  220. package/src/priorityFee/averageStrategy.ts +0 -13
  221. package/src/priorityFee/ewmaStrategy.ts +0 -51
  222. package/src/priorityFee/heliusPriorityFeeMethod.ts +0 -68
  223. package/src/priorityFee/index.ts +0 -16
  224. package/src/priorityFee/maxOverSlotsStrategy.ts +0 -18
  225. package/src/priorityFee/maxStrategy.ts +0 -8
  226. package/src/priorityFee/priorityFeeSubscriber.ts +0 -328
  227. package/src/priorityFee/priorityFeeSubscriberMap.ts +0 -134
  228. package/src/priorityFee/solanaPriorityFeeMethod.ts +0 -46
  229. package/src/priorityFee/types.ts +0 -82
  230. package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -53
  231. package/src/pyth/constants.ts +0 -9
  232. package/src/pyth/index.ts +0 -15
  233. package/src/pyth/pythLazerSubscriber.ts +0 -365
  234. package/src/pyth/types.ts +0 -4451
  235. package/src/pyth/utils.ts +0 -13
  236. package/src/slot/SlotSubscriber.ts +0 -126
  237. package/src/slot/SlothashSubscriber.ts +0 -163
  238. package/src/swap/UnifiedSwapClient.ts +0 -315
  239. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +0 -81
  240. package/src/swift/index.ts +0 -10
  241. package/src/swift/signedMsgUserAccountSubscriber.ts +0 -251
  242. package/src/swift/swiftOrderSubscriber.ts +0 -351
  243. package/src/testClient.ts +0 -42
  244. package/src/titan/titanClient.ts +0 -438
  245. package/src/token/index.ts +0 -13
  246. package/src/tokenFaucet.ts +0 -296
  247. package/src/tx/baseTxSender.ts +0 -651
  248. package/src/tx/blockhashFetcher/baseBlockhashFetcher.ts +0 -31
  249. package/src/tx/blockhashFetcher/cachedBlockhashFetcher.ts +0 -105
  250. package/src/tx/blockhashFetcher/types.ts +0 -9
  251. package/src/tx/fastSingleTxSender.ts +0 -200
  252. package/src/tx/forwardOnlyTxSender.ts +0 -193
  253. package/src/tx/priorityFeeCalculator.ts +0 -117
  254. package/src/tx/reportTransactionError.ts +0 -176
  255. package/src/tx/retryTxSender.ts +0 -177
  256. package/src/tx/txHandler.ts +0 -1009
  257. package/src/tx/txParamProcessor.ts +0 -225
  258. package/src/tx/types.ts +0 -117
  259. package/src/tx/utils.ts +0 -133
  260. package/src/tx/whileValidTxSender.ts +0 -377
  261. package/src/types.ts +0 -2575
  262. package/src/user.ts +0 -5316
  263. package/src/userConfig.ts +0 -38
  264. package/src/userMap/PollingSubscription.ts +0 -61
  265. package/src/userMap/WebsocketSubscription.ts +0 -93
  266. package/src/userMap/grpcSubscription.ts +0 -93
  267. package/src/userMap/referrerMap.ts +0 -360
  268. package/src/userMap/revenueShareEscrowMap.ts +0 -342
  269. package/src/userMap/userMap.ts +0 -784
  270. package/src/userMap/userMapConfig.ts +0 -82
  271. package/src/userMap/userStatsMap.ts +0 -393
  272. package/src/userName.ts +0 -37
  273. package/src/userStats.ts +0 -159
  274. package/src/userStatsConfig.ts +0 -35
  275. package/src/util/TransactionConfirmationManager.ts +0 -333
  276. package/src/util/chainClock.ts +0 -65
  277. package/src/util/computeUnits.ts +0 -101
  278. package/src/util/digest.ts +0 -33
  279. package/src/util/ed25519Utils.ts +0 -95
  280. package/src/util/promiseTimeout.ts +0 -23
  281. package/src/velocityClient.ts +0 -14802
  282. package/src/velocityClientConfig.ts +0 -119
  283. package/src/wallet.ts +0 -91
  284. package/tests/VelocityCore/builder_escrow.test.ts +0 -121
  285. package/tests/VelocityCore/decode.test.ts +0 -16
  286. package/tests/VelocityCore/fill_trigger.test.ts +0 -73
  287. package/tests/VelocityCore/instructions.test.ts +0 -46
  288. package/tests/VelocityCore/pdas.test.ts +0 -30
  289. package/tests/VelocityCore/perp_orders.test.ts +0 -205
  290. package/tests/VelocityCore/remainingAccounts.test.ts +0 -72
  291. package/tests/VelocityCore/settlement_liquidation.test.ts +0 -69
  292. package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +0 -211
  293. package/tests/amm/test.ts +0 -2402
  294. package/tests/auctions/test.ts +0 -81
  295. package/tests/bn/test.ts +0 -355
  296. package/tests/builder/builderFee.test.ts +0 -42
  297. package/tests/ci/verifyConstants.ts +0 -393
  298. package/tests/decode/test.ts +0 -262
  299. package/tests/decode/userAccountBufferStrings.ts +0 -102
  300. package/tests/dlob/helpers.ts +0 -748
  301. package/tests/dlob/test.ts +0 -6969
  302. package/tests/dlob/tickSizeStandardization.ts +0 -545
  303. package/tests/events/parseLogsForCuUsage.ts +0 -139
  304. package/tests/exchangeStatus/test.ts +0 -45
  305. package/tests/insurance/test.ts +0 -40
  306. package/tests/liquidation/test.ts +0 -125
  307. package/tests/oracles/mmOracleGate.test.ts +0 -379
  308. package/tests/oracles/pythPegSnap.test.ts +0 -76
  309. package/tests/sdkParity/enumParity.test.ts +0 -84
  310. package/tests/sdkParity/marginCategoryFill.test.ts +0 -143
  311. package/tests/sdkParity/memcmpOffsets.test.ts +0 -139
  312. package/tests/spot/test.ts +0 -281
  313. package/tests/tx/TransactionConfirmationManager.test.ts +0 -312
  314. package/tests/tx/cachedBlockhashFetcher.test.ts +0 -96
  315. package/tests/tx/priorityFeeCalculator.ts +0 -77
  316. package/tests/tx/priorityFeeStrategy.ts +0 -95
  317. package/tests/user/bankruptcy.ts +0 -165
  318. package/tests/user/feeAndWithdrawLimits.ts +0 -284
  319. package/tests/user/getMarginCalculation.ts +0 -586
  320. package/tests/user/helpers.ts +0 -184
  321. package/tests/user/liquidations.ts +0 -129
  322. package/tests/user/marginCalculations.test.ts +0 -321
  323. package/tests/user/test.ts +0 -833
  324. package/tsconfig.browser.json +0 -18
  325. package/tsconfig.json +0 -36
@@ -1,119 +0,0 @@
1
- /**
2
- * VelocityClientConfig — configuration types for constructing a {@link VelocityClient}.
3
- *
4
- * Key options: RPC connection, wallet/keypair, account subscription mode
5
- * (WebSocket vs polling), oracle client selection, transaction sender config,
6
- * and feature flags (activeSubAccountId, authority override).
7
- */
8
- import {
9
- Commitment,
10
- ConfirmOptions,
11
- Connection,
12
- PublicKey,
13
- TransactionVersion,
14
- } from '@solana/web3.js';
15
- import { IWallet, TxParams, UserAccount } from './types';
16
- import { OracleInfo } from './oracles/types';
17
- import { BulkAccountLoader } from './accounts/bulkAccountLoader';
18
- import { VelocityEnv } from './config';
19
- import { TxSender } from './tx/types';
20
- import { TxHandler, TxHandlerConfig } from './tx/txHandler';
21
- import {
22
- GrpcConfigs,
23
- ResubOpts,
24
- DelistedMarketSetting,
25
- } from './accounts/types';
26
- import { Coder, Program } from './isomorphic/anchor';
27
- import { WebSocketAccountSubscriber } from './accounts/webSocketAccountSubscriber';
28
- import { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscriberV2';
29
- import { grpcVelocityClientAccountSubscriberV2 } from './accounts/grpcVelocityClientAccountSubscriberV2';
30
- import { grpcVelocityClientAccountSubscriber } from './accounts/grpcVelocityClientAccountSubscriber';
31
- import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
32
- import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
33
- import { WebSocketVelocityClientAccountSubscriber } from './accounts/webSocketVelocityClientAccountSubscriber';
34
- import { WebSocketVelocityClientAccountSubscriberV2 } from './accounts/webSocketVelocityClientAccountSubscriberV2';
35
-
36
- export type VelocityClientConfig = {
37
- connection: Connection;
38
- wallet: IWallet;
39
- env?: VelocityEnv;
40
- programID?: PublicKey;
41
- accountSubscription?: VelocityClientSubscriptionConfig;
42
- opts?: ConfirmOptions;
43
- txSender?: TxSender;
44
- txHandler?: TxHandler;
45
- subAccountIds?: number[];
46
- activeSubAccountId?: number;
47
- perpMarketIndexes?: number[];
48
- spotMarketIndexes?: number[];
49
- /** @deprecated use marketLookupTables */
50
- marketLookupTable?: PublicKey;
51
- marketLookupTables?: PublicKey[];
52
- oracleInfos?: OracleInfo[];
53
- userStats?: boolean;
54
- authority?: PublicKey; // explicitly pass an authority if signer is delegate
55
- includeDelegates?: boolean; // flag for whether to load delegate accounts as well
56
- authoritySubAccountMap?: Map<string, number[]>; // if passed this will override subAccountIds and includeDelegates
57
- skipLoadUsers?: boolean; // if passed to constructor, no user accounts will be loaded. they will load if updateWallet is called afterwards.
58
- txVersion?: TransactionVersion; // which tx version to use
59
- txParams?: TxParams; // default tx params to use
60
- enableMetricsEvents?: boolean;
61
- txHandlerConfig?: TxHandlerConfig;
62
- delistedMarketSetting?: DelistedMarketSetting;
63
- useHotWalletAdmin?: boolean;
64
- coder?: Coder;
65
- };
66
-
67
- type GrpcVelocityClientAccountSubscriberCtor = new (
68
- grpcConfigs: GrpcConfigs,
69
- program: Program,
70
- perpMarketIndexes: number[],
71
- spotMarketIndexes: number[],
72
- oracleInfos: OracleInfo[],
73
- shouldFindAllMarketsAndOracles: boolean,
74
- delistedMarketSetting: DelistedMarketSetting
75
- ) =>
76
- | grpcVelocityClientAccountSubscriberV2
77
- | grpcVelocityClientAccountSubscriber;
78
-
79
- type WsVelocityClientAccountSubscriberCtor = new (
80
- program: Program,
81
- perpMarketIndexes: number[],
82
- spotMarketIndexes: number[],
83
- oracleInfos: OracleInfo[],
84
- shouldFindAllMarketsAndOracles: boolean,
85
- delistedMarketSetting: DelistedMarketSetting
86
- ) =>
87
- | WebSocketVelocityClientAccountSubscriber
88
- | WebSocketVelocityClientAccountSubscriberV2;
89
-
90
- export type VelocityClientSubscriptionConfig =
91
- | {
92
- type: 'grpc';
93
- grpcConfigs: GrpcConfigs;
94
- resubTimeoutMs?: number;
95
- logResubMessages?: boolean;
96
- velocityClientAccountSubscriber?: GrpcVelocityClientAccountSubscriberCtor;
97
- grpcMultiUserAccountSubscriber?: grpcMultiUserAccountSubscriber;
98
- }
99
- | {
100
- type: 'websocket';
101
- resubTimeoutMs?: number;
102
- logResubMessages?: boolean;
103
- commitment?: Commitment;
104
- programUserAccountSubscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
105
- perpMarketAccountSubscriber?: new (
106
- accountName: string,
107
- program: Program,
108
- accountPublicKey: PublicKey,
109
- decodeBuffer?: (buffer: Buffer) => any,
110
- resubOpts?: ResubOpts,
111
- commitment?: Commitment
112
- ) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
113
- /** If you use V2 here, whatever you pass for perpMarketAccountSubscriber will be ignored and it will use v2 under the hood regardless */
114
- velocityClientAccountSubscriber?: WsVelocityClientAccountSubscriberCtor;
115
- }
116
- | {
117
- type: 'polling';
118
- accountLoader: BulkAccountLoader;
119
- };
package/src/wallet.ts DELETED
@@ -1,91 +0,0 @@
1
- import {
2
- Keypair,
3
- PublicKey,
4
- Transaction,
5
- VersionedTransaction,
6
- } from '@solana/web3.js';
7
- import { IWallet, IVersionedWallet } from './types';
8
- import nacl from 'tweetnacl';
9
-
10
- /**
11
- * Local-keypair implementation of `IWallet`/`IVersionedWallet` that signs directly with an
12
- * in-memory `Keypair` (no external wallet/RPC round-trip). Suitable for keeper bots, scripts, and
13
- * tests; not for browser dapps holding user funds.
14
- */
15
- export class Wallet implements IWallet, IVersionedWallet {
16
- constructor(readonly payer: Keypair) {}
17
-
18
- /**
19
- * Partially signs a legacy `Transaction` with this wallet's keypair, leaving any other
20
- * required signatures untouched.
21
- * @param tx - Transaction to sign; mutated in place.
22
- * @returns The same transaction instance, now signed by `payer`.
23
- */
24
- async signTransaction(tx: Transaction): Promise<Transaction> {
25
- tx.partialSign(this.payer);
26
- return tx;
27
- }
28
-
29
- /**
30
- * Signs a `VersionedTransaction` with this wallet's keypair.
31
- * @param tx - Transaction to sign; mutated in place.
32
- * @returns The same transaction instance, now signed by `payer`.
33
- */
34
- async signVersionedTransaction(
35
- tx: VersionedTransaction
36
- ): Promise<VersionedTransaction> {
37
- tx.sign([this.payer]);
38
- return tx;
39
- }
40
-
41
- /**
42
- * Partially signs a batch of legacy `Transaction`s with this wallet's keypair.
43
- * @param txs - Transactions to sign; each is mutated in place.
44
- * @returns The same transaction instances, now signed by `payer`.
45
- */
46
- async signAllTransactions(txs: Transaction[]): Promise<Transaction[]> {
47
- return txs.map((t) => {
48
- t.partialSign(this.payer);
49
- return t;
50
- });
51
- }
52
-
53
- /**
54
- * Signs a batch of `VersionedTransaction`s with this wallet's keypair.
55
- * @param txs - Transactions to sign; each is mutated in place.
56
- * @returns The same transaction instances, now signed by `payer`.
57
- */
58
- async signAllVersionedTransactions(
59
- txs: VersionedTransaction[]
60
- ): Promise<VersionedTransaction[]> {
61
- return txs.map((t) => {
62
- t.sign([this.payer]);
63
- return t;
64
- });
65
- }
66
-
67
- /** The wallet's public key, i.e. `payer.publicKey`. */
68
- get publicKey(): PublicKey {
69
- return this.payer.publicKey;
70
- }
71
- }
72
-
73
- /**
74
- * `Wallet` variant that additionally supports raw message signing (`signMessage`), needed for
75
- * flows like swift/signed-message orders that sign an ed25519 payload outside of a transaction.
76
- */
77
- export class WalletV2 extends Wallet {
78
- constructor(readonly payer: Keypair) {
79
- super(payer);
80
- }
81
-
82
- /**
83
- * Signs an arbitrary message with this wallet's ed25519 secret key (detached signature, not a
84
- * transaction).
85
- * @param message - Raw bytes to sign.
86
- * @returns The 64-byte detached ed25519 signature.
87
- */
88
- async signMessage(message: Uint8Array): Promise<Uint8Array> {
89
- return Buffer.from(nacl.sign.detached(message, this.payer.secretKey));
90
- }
91
- }
@@ -1,121 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { Keypair, PublicKey } from '@solana/web3.js';
3
- import { VelocityClient } from '../../src/velocityClient';
4
- import { ReferrerMap } from '../../src/userMap/referrerMap';
5
- import { getRevenueShareEscrowAccountPublicKey } from '../../src/addresses/pda';
6
- import { RevenueShareEscrowAccount } from '../../src/types';
7
-
8
- // `getTakerEscrowAccountMeta` decides whether a perp fill must carry the taker's
9
- // RevenueShareEscrow account. It only reads `this.program.programId`, so we can
10
- // exercise the decision with a minimal `this` instead of a full client.
11
- // Regression guard for: a referred taker (escrow initialized with a referrer)
12
- // whose order carries no builder code must still get the escrow attached, else
13
- // the program rejects the fill with UnableToLoadRevenueShareAccount.
14
- const getTakerEscrowAccountMeta = (VelocityClient.prototype as any)
15
- .getTakerEscrowAccountMeta as (
16
- takerAuthority: PublicKey,
17
- orderHasBuilder: boolean,
18
- takerEscrow?: RevenueShareEscrowAccount,
19
- takerIsReferred?: boolean
20
- ) => { pubkey: PublicKey; isWritable: boolean; isSigner: boolean } | undefined;
21
-
22
- const programId = Keypair.generate().publicKey;
23
- const ctx = { program: { programId } };
24
- const escrow = (
25
- authority: PublicKey,
26
- referrer: PublicKey
27
- ): RevenueShareEscrowAccount =>
28
- ({ authority, referrer }) as unknown as RevenueShareEscrowAccount;
29
-
30
- describe('getTakerEscrowAccountMeta (fill escrow attachment)', () => {
31
- test('takerIsReferred, order without builder -> escrow attached', () => {
32
- const authority = Keypair.generate().publicKey;
33
- const meta = getTakerEscrowAccountMeta.call(
34
- ctx,
35
- authority,
36
- false,
37
- undefined,
38
- true
39
- );
40
- expect(meta).toBeDefined();
41
- expect(
42
- meta!.pubkey.equals(
43
- getRevenueShareEscrowAccountPublicKey(programId, authority)
44
- )
45
- ).toBe(true);
46
- expect(meta!.isWritable).toBe(true);
47
- });
48
-
49
- test('not referred, order without builder -> no escrow', () => {
50
- const authority = Keypair.generate().publicKey;
51
- expect(
52
- getTakerEscrowAccountMeta.call(ctx, authority, false, undefined, false)
53
- ).toBeUndefined();
54
- });
55
-
56
- test('builder-code order attaches escrow (no referral signal needed)', () => {
57
- const authority = Keypair.generate().publicKey;
58
- const meta = getTakerEscrowAccountMeta.call(
59
- ctx,
60
- authority,
61
- true,
62
- undefined
63
- );
64
- expect(meta).toBeDefined();
65
- expect(
66
- meta!.pubkey.equals(
67
- getRevenueShareEscrowAccountPublicKey(programId, authority)
68
- )
69
- ).toBe(true);
70
- });
71
-
72
- test('decoded escrow with a referrer still attaches (back-compat)', () => {
73
- const authority = Keypair.generate().publicKey;
74
- const meta = getTakerEscrowAccountMeta.call(
75
- ctx,
76
- authority,
77
- false,
78
- escrow(authority, Keypair.generate().publicKey)
79
- );
80
- expect(meta).toBeDefined();
81
- });
82
-
83
- test('escrow belonging to a different authority is rejected', () => {
84
- const authority = Keypair.generate().publicKey;
85
- const wrong = escrow(
86
- Keypair.generate().publicKey,
87
- Keypair.generate().publicKey
88
- );
89
- expect(() =>
90
- getTakerEscrowAccountMeta.call(ctx, authority, false, wrong)
91
- ).toThrow();
92
- });
93
- });
94
-
95
- // Guards the referral bit ReferrerMap reads out of the taker's UserStats — the
96
- // signal the fillers pass to getFillPerpOrderIx. Locks the `referrer_status`
97
- // byte offset (188) and the BuilderReferral bit (0b100).
98
- describe('ReferrerMap.mustGetIsBuilderReferral', () => {
99
- const REFERRER_STATUS_OFFSET = 188;
100
- const statsBuffer = (referrerStatus: number): Buffer => {
101
- const buf = Buffer.alloc(REFERRER_STATUS_OFFSET + 8);
102
- buf[REFERRER_STATUS_OFFSET] = referrerStatus;
103
- return buf;
104
- };
105
- const fakeClient = (buf: Buffer | null) =>
106
- ({
107
- program: { programId: Keypair.generate().publicKey },
108
- connection: { getAccountInfo: async () => (buf ? { data: buf } : null) },
109
- }) as any;
110
- const authority = () => Keypair.generate().publicKey.toBase58();
111
-
112
- test('BuilderReferral bit set -> true', async () => {
113
- const map = new ReferrerMap(fakeClient(statsBuffer(0b100)));
114
- expect(await map.mustGetIsBuilderReferral(authority())).toBe(true);
115
- });
116
-
117
- test('IsReferred without BuilderReferral -> false', async () => {
118
- const map = new ReferrerMap(fakeClient(statsBuffer(0b010)));
119
- expect(await map.mustGetIsBuilderReferral(authority())).toBe(false);
120
- });
121
- });
@@ -1,16 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { VelocityCore } from '../../src/core/VelocityCore';
3
- import { userAccountBufferStrings } from '../decode/userAccountBufferStrings';
4
-
5
- describe('VelocityCore decoding', () => {
6
- test('can decode User account from fixture buffer', () => {
7
- const s = userAccountBufferStrings[0];
8
- const buf = Buffer.from(s, 'base64');
9
- const decoded = VelocityCore.decodeUserAccount(buf);
10
-
11
- expect(decoded).toBeTruthy();
12
- expect(decoded.authority).toBeTruthy();
13
- expect(decoded.delegate).toBeTruthy();
14
- expect(decoded.name).toBeTruthy();
15
- });
16
- });
@@ -1,73 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { Keypair } from '@solana/web3.js';
3
- import { VelocityCore } from '../../src/core/VelocityCore';
4
-
5
- describe('VelocityCore fill/trigger builders', () => {
6
- test('buildFillPerpOrderInstruction wires accounts + args', async () => {
7
- const called: any[] = [];
8
- const fakeIx = {
9
- keys: [],
10
- programId: Keypair.generate().publicKey,
11
- data: Buffer.alloc(0),
12
- };
13
-
14
- const program = {
15
- instruction: {
16
- fillPerpOrder: async (...args: any[]) => {
17
- called.push(args);
18
- return fakeIx;
19
- },
20
- },
21
- };
22
- const pk = () => Keypair.generate().publicKey;
23
-
24
- const ix = await VelocityCore.buildFillPerpOrderInstruction({
25
- program,
26
- orderId: 7,
27
- state: pk(),
28
- filler: pk(),
29
- fillerStats: pk(),
30
- user: pk(),
31
- userStats: pk(),
32
- authority: pk(),
33
- remainingAccounts: [],
34
- });
35
-
36
- expect(ix).toBe(fakeIx as any);
37
- expect(called.length).toBe(1);
38
- expect(called[0][0]).toBe(7);
39
- });
40
-
41
- test('buildTriggerOrderInstruction wires accounts + args', async () => {
42
- const called: any[] = [];
43
- const fakeIx = {
44
- keys: [],
45
- programId: Keypair.generate().publicKey,
46
- data: Buffer.alloc(0),
47
- };
48
-
49
- const program = {
50
- instruction: {
51
- triggerOrder: async (...args: any[]) => {
52
- called.push(args);
53
- return fakeIx;
54
- },
55
- },
56
- };
57
- const pk = () => Keypair.generate().publicKey;
58
-
59
- const ix = await VelocityCore.buildTriggerOrderInstruction({
60
- program,
61
- orderId: 9,
62
- state: pk(),
63
- filler: pk(),
64
- user: pk(),
65
- authority: pk(),
66
- remainingAccounts: [],
67
- });
68
-
69
- expect(ix).toBe(fakeIx as any);
70
- expect(called.length).toBe(1);
71
- expect(called[0][0]).toBe(9);
72
- });
73
- });
@@ -1,46 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { VelocityCore } from '../../src/core/VelocityCore';
3
- import { Keypair } from '@solana/web3.js';
4
- import { BN } from '../../src/isomorphic/anchor';
5
-
6
- describe('VelocityCore instruction builders', () => {
7
- test('buildDepositInstruction calls underlying program.deposit', async () => {
8
- const called: any[] = [];
9
- const fakeIx = {
10
- keys: [],
11
- programId: Keypair.generate().publicKey,
12
- data: Buffer.alloc(0),
13
- };
14
-
15
- const program = {
16
- instruction: {
17
- deposit: async (...args: any[]) => {
18
- called.push(args);
19
- return fakeIx;
20
- },
21
- },
22
- };
23
-
24
- const pk = () => Keypair.generate().publicKey;
25
-
26
- const ix = await VelocityCore.buildDepositInstruction({
27
- program,
28
- marketIndex: 1,
29
- amount: new BN(123),
30
- reduceOnly: false,
31
- state: pk(),
32
- spotMarket: pk(),
33
- spotMarketVault: pk(),
34
- user: pk(),
35
- userStats: pk(),
36
- userTokenAccount: pk(),
37
- authority: pk(),
38
- tokenProgram: pk(),
39
- remainingAccounts: [],
40
- });
41
-
42
- expect(ix).toBe(fakeIx as any);
43
- expect(called.length).toBe(1);
44
- expect(called[0][0]).toBe(1);
45
- });
46
- });
@@ -1,30 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { Keypair, PublicKey } from '@solana/web3.js';
3
- import { VelocityCore } from '../../src/core/VelocityCore';
4
-
5
- describe('VelocityCore.pdas', () => {
6
- test('derives deterministic user/state PDAs', async () => {
7
- const programId = Keypair.generate().publicKey;
8
- const authority = Keypair.generate().publicKey;
9
-
10
- const [state] =
11
- await VelocityCore.pdas.getVelocityStateAccountPublicKeyAndNonce(
12
- programId
13
- );
14
- const user0 = await VelocityCore.pdas.getUserAccountPublicKey(
15
- programId,
16
- authority,
17
- 0
18
- );
19
- const user1 = await VelocityCore.pdas.getUserAccountPublicKey(
20
- programId,
21
- authority,
22
- 1
23
- );
24
-
25
- expect(state).toBeInstanceOf(PublicKey);
26
- expect(user0).toBeInstanceOf(PublicKey);
27
- expect(user1).toBeInstanceOf(PublicKey);
28
- expect(user0.toBase58()).not.toEqual(user1.toBase58());
29
- });
30
- });
@@ -1,205 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { Keypair } from '@solana/web3.js';
3
- import { VelocityCore } from '../../src/core/VelocityCore';
4
-
5
- describe('VelocityCore perp order instruction builders', () => {
6
- const pk = () => Keypair.generate().publicKey;
7
- const fakeIx = {
8
- keys: [],
9
- programId: Keypair.generate().publicKey,
10
- data: Buffer.alloc(0),
11
- };
12
-
13
- test('buildPlacePerpOrderInstruction', async () => {
14
- const called: any[] = [];
15
- const program = {
16
- instruction: {
17
- placePerpOrder: async (...args: any[]) => {
18
- called.push(args);
19
- return fakeIx;
20
- },
21
- },
22
- };
23
- const ix = await VelocityCore.buildPlacePerpOrderInstruction({
24
- program,
25
- orderParams: { x: 1 },
26
- state: pk(),
27
- user: pk(),
28
- userStats: pk(),
29
- authority: pk(),
30
- remainingAccounts: [],
31
- });
32
- expect(ix).toBe(fakeIx as any);
33
- expect(called[0][0]).toEqual({ x: 1 });
34
- });
35
-
36
- test('buildPlaceAndTakePerpOrderInstruction', async () => {
37
- const called: any[] = [];
38
- const program = {
39
- instruction: {
40
- placeAndTakePerpOrder: async (...args: any[]) => {
41
- called.push(args);
42
- return fakeIx;
43
- },
44
- },
45
- };
46
- const ix = await VelocityCore.buildPlaceAndTakePerpOrderInstruction({
47
- program,
48
- orderParams: { m: 0 },
49
- optionalParams: 256,
50
- state: pk(),
51
- user: pk(),
52
- userStats: pk(),
53
- authority: pk(),
54
- remainingAccounts: [],
55
- });
56
- expect(ix).toBe(fakeIx as any);
57
- expect(called[0][1]).toBe(256);
58
- });
59
-
60
- test('buildPlaceAndMakePerpOrderInstruction', async () => {
61
- const called: any[] = [];
62
- const program = {
63
- instruction: {
64
- placeAndMakePerpOrder: async (...args: any[]) => {
65
- called.push(args);
66
- return fakeIx;
67
- },
68
- },
69
- };
70
- const ix = await VelocityCore.buildPlaceAndMakePerpOrderInstruction({
71
- program,
72
- orderParams: {},
73
- takerOrderId: 7,
74
- state: pk(),
75
- user: pk(),
76
- userStats: pk(),
77
- taker: pk(),
78
- takerStats: pk(),
79
- authority: pk(),
80
- remainingAccounts: [],
81
- });
82
- expect(ix).toBe(fakeIx as any);
83
- expect(called[0][1]).toBe(7);
84
- });
85
-
86
- test('buildCancelOrderInstruction', async () => {
87
- const called: any[] = [];
88
- const program = {
89
- instruction: {
90
- cancelOrder: async (...args: any[]) => {
91
- called.push(args);
92
- return fakeIx;
93
- },
94
- },
95
- };
96
- const ix = await VelocityCore.buildCancelOrderInstruction({
97
- program,
98
- orderId: 3,
99
- state: pk(),
100
- user: pk(),
101
- authority: pk(),
102
- remainingAccounts: [],
103
- });
104
- expect(ix).toBe(fakeIx as any);
105
- expect(called[0][0]).toBe(3);
106
- });
107
-
108
- test('buildCancelOrderByUserIdInstruction', async () => {
109
- const called: any[] = [];
110
- const program = {
111
- instruction: {
112
- cancelOrderByUserId: async (...args: any[]) => {
113
- called.push(args);
114
- return fakeIx;
115
- },
116
- },
117
- };
118
- const ix = await VelocityCore.buildCancelOrderByUserIdInstruction({
119
- program,
120
- userOrderId: 9,
121
- state: pk(),
122
- user: pk(),
123
- authority: pk(),
124
- oracle: pk(),
125
- remainingAccounts: [],
126
- });
127
- expect(ix).toBe(fakeIx as any);
128
- expect(called[0][0]).toBe(9);
129
- });
130
-
131
- test('buildCancelOrdersByIdsInstruction', async () => {
132
- const called: any[] = [];
133
- const program = {
134
- instruction: {
135
- cancelOrdersByIds: async (...args: any[]) => {
136
- called.push(args);
137
- return fakeIx;
138
- },
139
- },
140
- };
141
- const ids = [1, 2];
142
- const ix = await VelocityCore.buildCancelOrdersByIdsInstruction({
143
- program,
144
- orderIds: ids,
145
- state: pk(),
146
- user: pk(),
147
- authority: pk(),
148
- remainingAccounts: [],
149
- });
150
- expect(ix).toBe(fakeIx as any);
151
- expect(called[0][0]).toBe(ids);
152
- });
153
-
154
- test('buildModifyOrderInstruction', async () => {
155
- const called: any[] = [];
156
- const program = {
157
- instruction: {
158
- modifyOrder: async (...args: any[]) => {
159
- called.push(args);
160
- return fakeIx;
161
- },
162
- },
163
- };
164
- const mp = { baseAssetAmount: null };
165
- const ix = await VelocityCore.buildModifyOrderInstruction({
166
- program,
167
- orderId: 4,
168
- modifyParams: mp,
169
- state: pk(),
170
- user: pk(),
171
- userStats: pk(),
172
- authority: pk(),
173
- remainingAccounts: [],
174
- });
175
- expect(ix).toBe(fakeIx as any);
176
- expect(called[0][0]).toBe(4);
177
- expect(called[0][1]).toBe(mp);
178
- });
179
-
180
- test('buildModifyOrderByUserIdInstruction', async () => {
181
- const called: any[] = [];
182
- const program = {
183
- instruction: {
184
- modifyOrderByUserId: async (...args: any[]) => {
185
- called.push(args);
186
- return fakeIx;
187
- },
188
- },
189
- };
190
- const mp = { reduceOnly: false };
191
- const ix = await VelocityCore.buildModifyOrderByUserIdInstruction({
192
- program,
193
- userOrderId: 11,
194
- modifyParams: mp,
195
- state: pk(),
196
- user: pk(),
197
- userStats: pk(),
198
- authority: pk(),
199
- remainingAccounts: [],
200
- });
201
- expect(ix).toBe(fakeIx as any);
202
- expect(called[0][0]).toBe(11);
203
- expect(called[0][1]).toBe(mp);
204
- });
205
- });