@velocity-exchange/sdk 0.0.5 → 0.2.0

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 (815) hide show
  1. package/.prettierignore +1 -1
  2. package/CHANGELOG.md +35 -0
  3. package/README.md +30 -30
  4. package/bun.lock +24 -2
  5. package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +5 -3
  6. package/lib/browser/accounts/basicUserAccountSubscriber.js +4 -3
  7. package/lib/browser/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
  8. package/lib/browser/accounts/basicUserStatsAccountSubscriber.js +4 -3
  9. package/lib/browser/accounts/bulkAccountLoader.d.ts +5 -5
  10. package/lib/browser/accounts/bulkAccountLoader.js +12 -1
  11. package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -1
  12. package/lib/browser/accounts/grpcAccountSubscriber.js +8 -2
  13. package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
  14. package/lib/browser/accounts/grpcMultiAccountSubscriber.js +13 -5
  15. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
  16. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +12 -8
  17. package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
  18. package/lib/browser/accounts/grpcProgramAccountSubscriber.js +9 -3
  19. package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
  20. package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
  21. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
  22. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
  23. package/lib/browser/accounts/laserProgramAccountSubscriber.js +4 -1
  24. package/lib/browser/accounts/oneShotUserAccountSubscriber.js +4 -3
  25. package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
  26. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  27. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
  28. package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
  29. package/lib/browser/accounts/pollingOracleAccountSubscriber.js +16 -5
  30. package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
  31. package/lib/browser/accounts/pollingTokenAccountSubscriber.js +16 -5
  32. package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +8 -4
  33. package/lib/browser/accounts/pollingUserAccountSubscriber.js +17 -11
  34. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
  35. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +6 -6
  36. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -5
  37. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
  38. package/lib/browser/accounts/types.d.ts +6 -12
  39. package/lib/browser/accounts/utils.d.ts +1 -0
  40. package/lib/browser/accounts/utils.js +10 -3
  41. package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +4 -2
  42. package/lib/browser/accounts/webSocketAccountSubscriber.js +17 -5
  43. package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
  44. package/lib/browser/accounts/webSocketAccountSubscriberV2.js +17 -6
  45. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  46. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
  47. package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
  48. package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +14 -3
  49. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
  50. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
  51. package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
  52. package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
  53. package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
  54. package/lib/browser/accounts/webSocketUserAccountSubscriber.js +9 -0
  55. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
  56. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
  57. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -8
  58. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
  59. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
  60. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
  61. package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
  62. package/lib/browser/accounts/websocketProgramUserAccountSubscriber.js +0 -3
  63. package/lib/browser/addresses/marketAddresses.js +3 -2
  64. package/lib/browser/addresses/pda.d.ts +1 -9
  65. package/lib/browser/addresses/pda.js +4 -23
  66. package/lib/browser/adminClient.d.ts +25 -29
  67. package/lib/browser/adminClient.js +168 -169
  68. package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +2 -4
  69. package/lib/browser/auctionSubscriber/auctionSubscriber.js +8 -10
  70. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
  71. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
  72. package/lib/browser/auctionSubscriber/types.d.ts +3 -2
  73. package/lib/browser/bankrun/bankrunConnection.d.ts +6 -4
  74. package/lib/browser/bankrun/bankrunConnection.js +69 -31
  75. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
  76. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +3 -2
  77. package/lib/browser/clock/clockSubscriber.d.ts +6 -6
  78. package/lib/browser/clock/clockSubscriber.js +4 -3
  79. package/lib/browser/config.d.ts +11 -20
  80. package/lib/browser/config.js +13 -36
  81. package/lib/browser/constants/index.d.ts +1 -2
  82. package/lib/browser/constants/index.js +1 -2
  83. package/lib/browser/constants/numericConstants.d.ts +1 -3
  84. package/lib/browser/constants/numericConstants.js +3 -5
  85. package/lib/browser/constituentMap/constituentMap.d.ts +0 -2
  86. package/lib/browser/constituentMap/constituentMap.js +10 -6
  87. package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
  88. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
  89. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
  90. package/lib/browser/core/VelocityCore.d.ts +9 -15
  91. package/lib/browser/core/VelocityCore.js +5 -7
  92. package/lib/browser/core/instructions/perpOrders.d.ts +14 -0
  93. package/lib/browser/core/instructions/perpOrders.js +14 -0
  94. package/lib/browser/core/instructions/withdraw.d.ts +1 -1
  95. package/lib/browser/core/instructions/withdraw.js +1 -1
  96. package/lib/browser/core/remainingAccounts.d.ts +2 -2
  97. package/lib/browser/core/remainingAccounts.js +5 -5
  98. package/lib/browser/decode/user.js +9 -1
  99. package/lib/browser/dlob/DLOB.d.ts +7 -2
  100. package/lib/browser/dlob/DLOB.js +205 -142
  101. package/lib/browser/dlob/DLOBNode.d.ts +5 -2
  102. package/lib/browser/dlob/DLOBNode.js +7 -0
  103. package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -2
  104. package/lib/browser/dlob/DLOBSubscriber.js +39 -39
  105. package/lib/browser/dlob/NodeList.js +8 -7
  106. package/lib/browser/dlob/orderBookLevels.js +24 -17
  107. package/lib/browser/dlob/types.d.ts +0 -2
  108. package/lib/browser/events/eventList.js +4 -1
  109. package/lib/browser/events/eventSubscriber.d.ts +6 -3
  110. package/lib/browser/events/eventSubscriber.js +75 -26
  111. package/lib/browser/events/eventsServerLogProvider.d.ts +1 -1
  112. package/lib/browser/events/eventsServerLogProvider.js +17 -10
  113. package/lib/browser/events/fetchLogs.d.ts +1 -1
  114. package/lib/browser/events/fetchLogs.js +4 -2
  115. package/lib/browser/events/parse.js +14 -14
  116. package/lib/browser/events/pollingLogProvider.d.ts +1 -1
  117. package/lib/browser/events/pollingLogProvider.js +1 -0
  118. package/lib/browser/events/txEventCache.js +6 -2
  119. package/lib/browser/events/types.d.ts +3 -7
  120. package/lib/browser/events/types.js +1 -3
  121. package/lib/browser/events/webSocketLogProvider.d.ts +1 -1
  122. package/lib/browser/events/webSocketLogProvider.js +5 -2
  123. package/lib/browser/factory/bigNum.js +1 -1
  124. package/lib/{node/idl/drift.d.ts → browser/idl/velocity.d.ts} +2412 -2481
  125. package/lib/browser/idl/{drift.json → velocity.json} +2265 -2333
  126. package/lib/browser/index.d.ts +1 -3
  127. package/lib/browser/index.js +1 -4
  128. package/lib/browser/jupiter/jupiterClient.d.ts +1 -1
  129. package/lib/browser/jupiter/jupiterClient.js +18 -8
  130. package/lib/browser/marginCalculation.js +1 -0
  131. package/lib/browser/math/amm.d.ts +31 -13
  132. package/lib/browser/math/amm.js +87 -31
  133. package/lib/browser/math/auction.js +16 -12
  134. package/lib/browser/math/bankruptcy.js +1 -1
  135. package/lib/browser/math/builder.d.ts +18 -1
  136. package/lib/browser/math/builder.js +32 -1
  137. package/lib/browser/math/funding.js +30 -30
  138. package/lib/browser/math/insurance.d.ts +1 -1
  139. package/lib/browser/math/insurance.js +4 -5
  140. package/lib/browser/math/margin.d.ts +3 -11
  141. package/lib/browser/math/margin.js +10 -69
  142. package/lib/browser/math/market.d.ts +4 -12
  143. package/lib/browser/math/market.js +12 -46
  144. package/lib/browser/math/oracles.d.ts +4 -7
  145. package/lib/browser/math/oracles.js +24 -37
  146. package/lib/browser/math/orders.d.ts +2 -7
  147. package/lib/browser/math/orders.js +9 -81
  148. package/lib/browser/math/position.d.ts +0 -4
  149. package/lib/browser/math/position.js +6 -11
  150. package/lib/browser/math/repeg.d.ts +0 -1
  151. package/lib/browser/math/repeg.js +1 -23
  152. package/lib/browser/math/spotBalance.d.ts +4 -4
  153. package/lib/browser/math/spotBalance.js +6 -6
  154. package/lib/browser/math/spotMarket.d.ts +0 -6
  155. package/lib/browser/math/spotMarket.js +1 -16
  156. package/lib/browser/math/spotPosition.d.ts +4 -4
  157. package/lib/browser/math/state.d.ts +0 -2
  158. package/lib/browser/math/state.js +1 -9
  159. package/lib/browser/math/superStake.d.ts +11 -63
  160. package/lib/browser/math/superStake.js +29 -28
  161. package/lib/browser/math/trade.js +7 -7
  162. package/lib/browser/math/utils.d.ts +1 -1
  163. package/lib/browser/math/utils.js +1 -1
  164. package/lib/browser/memcmp.d.ts +0 -1
  165. package/lib/browser/memcmp.js +1 -10
  166. package/lib/browser/oracles/prelaunchOracleClient.js +3 -2
  167. package/lib/browser/oracles/pythClient.js +9 -3
  168. package/lib/browser/oracles/pythLazerClient.js +5 -4
  169. package/lib/browser/oracles/utils.d.ts +4 -0
  170. package/lib/browser/oracles/utils.js +9 -1
  171. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -3
  172. package/lib/browser/orderSubscriber/OrderSubscriber.js +16 -14
  173. package/lib/browser/orderSubscriber/WebsocketSubscription.js +1 -1
  174. package/lib/browser/orderSubscriber/grpcSubscription.js +2 -2
  175. package/lib/browser/orderSubscriber/types.d.ts +0 -2
  176. package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
  177. package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +2 -6
  178. package/lib/browser/priorityFee/priorityFeeSubscriber.js +34 -18
  179. package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
  180. package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +3 -11
  181. package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
  182. package/lib/browser/priorityFee/types.d.ts +3 -8
  183. package/lib/browser/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
  184. package/lib/browser/priorityFee/velocityPriorityFeeMethod.js +1 -3
  185. package/lib/browser/pyth/pythLazerSubscriber.d.ts +1 -1
  186. package/lib/browser/pyth/pythLazerSubscriber.js +1 -1
  187. package/lib/browser/pyth/types.d.ts +0 -1
  188. package/lib/browser/slot/SlotSubscriber.d.ts +1 -1
  189. package/lib/browser/slot/SlotSubscriber.js +2 -1
  190. package/lib/browser/slot/SlothashSubscriber.d.ts +3 -2
  191. package/lib/browser/slot/SlothashSubscriber.js +11 -4
  192. package/lib/browser/swap/UnifiedSwapClient.js +1 -1
  193. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
  194. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
  195. package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +7 -7
  196. package/lib/browser/swift/signedMsgUserAccountSubscriber.js +14 -10
  197. package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -6
  198. package/lib/browser/swift/swiftOrderSubscriber.js +15 -16
  199. package/lib/browser/testClient.js +3 -2
  200. package/lib/browser/tokenFaucet.js +16 -2
  201. package/lib/browser/tx/baseTxSender.d.ts +4 -4
  202. package/lib/browser/tx/baseTxSender.js +5 -4
  203. package/lib/browser/tx/fastSingleTxSender.d.ts +3 -3
  204. package/lib/browser/tx/fastSingleTxSender.js +9 -5
  205. package/lib/browser/tx/reportTransactionError.d.ts +2 -2
  206. package/lib/browser/tx/reportTransactionError.js +5 -1
  207. package/lib/browser/tx/retryTxSender.d.ts +1 -1
  208. package/lib/browser/tx/retryTxSender.js +4 -2
  209. package/lib/browser/tx/txHandler.d.ts +7 -1
  210. package/lib/browser/tx/txHandler.js +54 -40
  211. package/lib/browser/tx/txParamProcessor.d.ts +4 -1
  212. package/lib/browser/tx/txParamProcessor.js +6 -0
  213. package/lib/browser/tx/types.d.ts +1 -1
  214. package/lib/browser/tx/whileValidTxSender.d.ts +1 -6
  215. package/lib/browser/tx/whileValidTxSender.js +35 -13
  216. package/lib/browser/types.d.ts +102 -157
  217. package/lib/browser/types.js +6 -2
  218. package/lib/browser/user.d.ts +22 -10
  219. package/lib/browser/user.js +174 -154
  220. package/lib/browser/userConfig.d.ts +3 -2
  221. package/lib/browser/userMap/WebsocketSubscription.d.ts +1 -1
  222. package/lib/browser/userMap/WebsocketSubscription.js +1 -1
  223. package/lib/browser/userMap/grpcSubscription.d.ts +1 -1
  224. package/lib/browser/userMap/grpcSubscription.js +1 -1
  225. package/lib/browser/userMap/referrerMap.d.ts +0 -2
  226. package/lib/browser/userMap/referrerMap.js +10 -7
  227. package/lib/browser/userMap/revenueShareEscrowMap.d.ts +0 -2
  228. package/lib/browser/userMap/revenueShareEscrowMap.js +4 -4
  229. package/lib/browser/userMap/userMap.d.ts +3 -5
  230. package/lib/browser/userMap/userMap.js +39 -30
  231. package/lib/browser/userMap/userMapConfig.d.ts +3 -2
  232. package/lib/browser/userMap/userStatsMap.d.ts +1 -3
  233. package/lib/browser/userMap/userStatsMap.js +18 -17
  234. package/lib/browser/userStats.d.ts +7 -4
  235. package/lib/browser/userStats.js +28 -18
  236. package/lib/browser/userStatsConfig.d.ts +3 -2
  237. package/lib/browser/util/TransactionConfirmationManager.js +4 -2
  238. package/lib/browser/util/chainClock.d.ts +1 -1
  239. package/lib/browser/util/computeUnits.d.ts +1 -1
  240. package/lib/browser/util/computeUnits.js +6 -1
  241. package/lib/browser/util/ed25519Utils.d.ts +1 -1
  242. package/lib/browser/util/ed25519Utils.js +1 -1
  243. package/lib/browser/velocityClient.d.ts +144 -71
  244. package/lib/browser/velocityClient.js +653 -457
  245. package/lib/browser/velocityClientConfig.d.ts +0 -8
  246. package/lib/node/accounts/basicUserAccountSubscriber.d.ts +5 -3
  247. package/lib/node/accounts/basicUserAccountSubscriber.d.ts.map +1 -1
  248. package/lib/node/accounts/basicUserAccountSubscriber.js +4 -3
  249. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
  250. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts.map +1 -1
  251. package/lib/node/accounts/basicUserStatsAccountSubscriber.js +4 -3
  252. package/lib/node/accounts/bulkAccountLoader.d.ts +5 -5
  253. package/lib/node/accounts/bulkAccountLoader.d.ts.map +1 -1
  254. package/lib/node/accounts/bulkAccountLoader.js +12 -1
  255. package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -1
  256. package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
  257. package/lib/node/accounts/grpcAccountSubscriber.js +8 -2
  258. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
  259. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  260. package/lib/node/accounts/grpcMultiAccountSubscriber.js +13 -5
  261. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
  262. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
  263. package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +12 -8
  264. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
  265. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
  266. package/lib/node/accounts/grpcProgramAccountSubscriber.js +9 -3
  267. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
  268. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
  269. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
  270. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
  271. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  272. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
  273. package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
  274. package/lib/node/accounts/laserProgramAccountSubscriber.js +4 -1
  275. package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
  276. package/lib/node/accounts/oneShotUserAccountSubscriber.js +4 -3
  277. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
  278. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
  279. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  280. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  281. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
  282. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
  283. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
  284. package/lib/node/accounts/pollingOracleAccountSubscriber.js +16 -5
  285. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
  286. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
  287. package/lib/node/accounts/pollingTokenAccountSubscriber.js +16 -5
  288. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +8 -4
  289. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts.map +1 -1
  290. package/lib/node/accounts/pollingUserAccountSubscriber.js +17 -11
  291. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
  292. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
  293. package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +6 -6
  294. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -5
  295. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
  296. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
  297. package/lib/node/accounts/types.d.ts +6 -12
  298. package/lib/node/accounts/types.d.ts.map +1 -1
  299. package/lib/node/accounts/utils.d.ts +1 -0
  300. package/lib/node/accounts/utils.d.ts.map +1 -1
  301. package/lib/node/accounts/utils.js +10 -3
  302. package/lib/node/accounts/webSocketAccountSubscriber.d.ts +4 -2
  303. package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
  304. package/lib/node/accounts/webSocketAccountSubscriber.js +17 -5
  305. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
  306. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
  307. package/lib/node/accounts/webSocketAccountSubscriberV2.js +17 -6
  308. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  309. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  310. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
  311. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
  312. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
  313. package/lib/node/accounts/webSocketProgramAccountSubscriber.js +14 -3
  314. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
  315. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
  316. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
  317. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
  318. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
  319. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
  320. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
  321. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
  322. package/lib/node/accounts/webSocketUserAccountSubscriber.js +9 -0
  323. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
  324. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
  325. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
  326. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -8
  327. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
  328. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
  329. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
  330. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  331. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
  332. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
  333. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
  334. package/lib/node/accounts/websocketProgramUserAccountSubscriber.js +0 -3
  335. package/lib/node/addresses/marketAddresses.d.ts.map +1 -1
  336. package/lib/node/addresses/marketAddresses.js +3 -2
  337. package/lib/node/addresses/pda.d.ts +1 -9
  338. package/lib/node/addresses/pda.d.ts.map +1 -1
  339. package/lib/node/addresses/pda.js +4 -23
  340. package/lib/node/adminClient.d.ts +25 -29
  341. package/lib/node/adminClient.d.ts.map +1 -1
  342. package/lib/node/adminClient.js +168 -169
  343. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +2 -4
  344. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
  345. package/lib/node/auctionSubscriber/auctionSubscriber.js +8 -10
  346. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
  347. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
  348. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
  349. package/lib/node/auctionSubscriber/types.d.ts +3 -2
  350. package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
  351. package/lib/node/bankrun/bankrunConnection.d.ts +6 -4
  352. package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
  353. package/lib/node/bankrun/bankrunConnection.js +69 -31
  354. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
  355. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts.map +1 -1
  356. package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +3 -2
  357. package/lib/node/clock/clockSubscriber.d.ts +6 -6
  358. package/lib/node/clock/clockSubscriber.d.ts.map +1 -1
  359. package/lib/node/clock/clockSubscriber.js +4 -3
  360. package/lib/node/config.d.ts +11 -20
  361. package/lib/node/config.d.ts.map +1 -1
  362. package/lib/node/config.js +13 -36
  363. package/lib/node/constants/index.d.ts +1 -2
  364. package/lib/node/constants/index.d.ts.map +1 -1
  365. package/lib/node/constants/index.js +1 -2
  366. package/lib/node/constants/numericConstants.d.ts +1 -3
  367. package/lib/node/constants/numericConstants.d.ts.map +1 -1
  368. package/lib/node/constants/numericConstants.js +3 -5
  369. package/lib/node/constituentMap/constituentMap.d.ts +0 -2
  370. package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
  371. package/lib/node/constituentMap/constituentMap.js +10 -6
  372. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -1
  373. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
  374. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
  375. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -1
  376. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
  377. package/lib/node/core/VelocityCore.d.ts +9 -15
  378. package/lib/node/core/VelocityCore.d.ts.map +1 -1
  379. package/lib/node/core/VelocityCore.js +5 -7
  380. package/lib/node/core/instructions/perpOrders.d.ts +14 -0
  381. package/lib/node/core/instructions/perpOrders.d.ts.map +1 -1
  382. package/lib/node/core/instructions/perpOrders.js +14 -0
  383. package/lib/node/core/instructions/withdraw.d.ts +1 -1
  384. package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
  385. package/lib/node/core/instructions/withdraw.js +1 -1
  386. package/lib/node/core/remainingAccounts.d.ts +2 -2
  387. package/lib/node/core/remainingAccounts.d.ts.map +1 -1
  388. package/lib/node/core/remainingAccounts.js +5 -5
  389. package/lib/node/decode/user.d.ts.map +1 -1
  390. package/lib/node/decode/user.js +9 -1
  391. package/lib/node/dlob/DLOB.d.ts +7 -2
  392. package/lib/node/dlob/DLOB.d.ts.map +1 -1
  393. package/lib/node/dlob/DLOB.js +205 -142
  394. package/lib/node/dlob/DLOBNode.d.ts +5 -2
  395. package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
  396. package/lib/node/dlob/DLOBNode.js +7 -0
  397. package/lib/node/dlob/DLOBSubscriber.d.ts +0 -2
  398. package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
  399. package/lib/node/dlob/DLOBSubscriber.js +39 -39
  400. package/lib/node/dlob/NodeList.d.ts.map +1 -1
  401. package/lib/node/dlob/NodeList.js +8 -7
  402. package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
  403. package/lib/node/dlob/orderBookLevels.js +24 -17
  404. package/lib/node/dlob/types.d.ts +0 -2
  405. package/lib/node/dlob/types.d.ts.map +1 -1
  406. package/lib/node/events/eventList.d.ts +3 -3
  407. package/lib/node/events/eventList.d.ts.map +1 -1
  408. package/lib/node/events/eventList.js +4 -1
  409. package/lib/node/events/eventSubscriber.d.ts +6 -3
  410. package/lib/node/events/eventSubscriber.d.ts.map +1 -1
  411. package/lib/node/events/eventSubscriber.js +75 -26
  412. package/lib/node/events/eventsServerLogProvider.d.ts +2 -2
  413. package/lib/node/events/eventsServerLogProvider.d.ts.map +1 -1
  414. package/lib/node/events/eventsServerLogProvider.js +17 -10
  415. package/lib/node/events/fetchLogs.d.ts +1 -1
  416. package/lib/node/events/fetchLogs.d.ts.map +1 -1
  417. package/lib/node/events/fetchLogs.js +4 -2
  418. package/lib/node/events/parse.d.ts.map +1 -1
  419. package/lib/node/events/parse.js +14 -14
  420. package/lib/node/events/pollingLogProvider.d.ts +2 -2
  421. package/lib/node/events/pollingLogProvider.d.ts.map +1 -1
  422. package/lib/node/events/pollingLogProvider.js +1 -0
  423. package/lib/node/events/txEventCache.d.ts +3 -3
  424. package/lib/node/events/txEventCache.d.ts.map +1 -1
  425. package/lib/node/events/txEventCache.js +6 -2
  426. package/lib/node/events/types.d.ts +3 -7
  427. package/lib/node/events/types.d.ts.map +1 -1
  428. package/lib/node/events/types.js +1 -3
  429. package/lib/node/events/webSocketLogProvider.d.ts +2 -2
  430. package/lib/node/events/webSocketLogProvider.d.ts.map +1 -1
  431. package/lib/node/events/webSocketLogProvider.js +5 -2
  432. package/lib/node/factory/bigNum.js +1 -1
  433. package/lib/{browser/idl/drift.d.ts → node/idl/velocity.d.ts} +2413 -2480
  434. package/lib/node/idl/velocity.d.ts.map +1 -0
  435. package/lib/node/idl/{drift.json → velocity.json} +2265 -2333
  436. package/lib/node/index.d.ts +1 -3
  437. package/lib/node/index.d.ts.map +1 -1
  438. package/lib/node/index.js +1 -4
  439. package/lib/node/jupiter/jupiterClient.d.ts +1 -1
  440. package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
  441. package/lib/node/jupiter/jupiterClient.js +18 -8
  442. package/lib/node/marginCalculation.d.ts.map +1 -1
  443. package/lib/node/marginCalculation.js +1 -0
  444. package/lib/node/math/amm.d.ts +31 -13
  445. package/lib/node/math/amm.d.ts.map +1 -1
  446. package/lib/node/math/amm.js +87 -31
  447. package/lib/node/math/auction.d.ts.map +1 -1
  448. package/lib/node/math/auction.js +16 -12
  449. package/lib/node/math/bankruptcy.js +1 -1
  450. package/lib/node/math/builder.d.ts +18 -1
  451. package/lib/node/math/builder.d.ts.map +1 -1
  452. package/lib/node/math/builder.js +32 -1
  453. package/lib/node/math/funding.d.ts.map +1 -1
  454. package/lib/node/math/funding.js +30 -30
  455. package/lib/node/math/insurance.d.ts +1 -1
  456. package/lib/node/math/insurance.d.ts.map +1 -1
  457. package/lib/node/math/insurance.js +4 -5
  458. package/lib/node/math/margin.d.ts +3 -11
  459. package/lib/node/math/margin.d.ts.map +1 -1
  460. package/lib/node/math/margin.js +10 -69
  461. package/lib/node/math/market.d.ts +4 -12
  462. package/lib/node/math/market.d.ts.map +1 -1
  463. package/lib/node/math/market.js +12 -46
  464. package/lib/node/math/oracles.d.ts +4 -7
  465. package/lib/node/math/oracles.d.ts.map +1 -1
  466. package/lib/node/math/oracles.js +24 -37
  467. package/lib/node/math/orders.d.ts +2 -7
  468. package/lib/node/math/orders.d.ts.map +1 -1
  469. package/lib/node/math/orders.js +9 -81
  470. package/lib/node/math/position.d.ts +1 -5
  471. package/lib/node/math/position.d.ts.map +1 -1
  472. package/lib/node/math/position.js +6 -11
  473. package/lib/node/math/repeg.d.ts +0 -1
  474. package/lib/node/math/repeg.d.ts.map +1 -1
  475. package/lib/node/math/repeg.js +1 -23
  476. package/lib/node/math/spotBalance.d.ts +4 -4
  477. package/lib/node/math/spotBalance.d.ts.map +1 -1
  478. package/lib/node/math/spotBalance.js +6 -6
  479. package/lib/node/math/spotMarket.d.ts +0 -6
  480. package/lib/node/math/spotMarket.d.ts.map +1 -1
  481. package/lib/node/math/spotMarket.js +1 -16
  482. package/lib/node/math/spotPosition.d.ts +4 -4
  483. package/lib/node/math/spotPosition.d.ts.map +1 -1
  484. package/lib/node/math/state.d.ts +0 -2
  485. package/lib/node/math/state.d.ts.map +1 -1
  486. package/lib/node/math/state.js +1 -9
  487. package/lib/node/math/superStake.d.ts +11 -63
  488. package/lib/node/math/superStake.d.ts.map +1 -1
  489. package/lib/node/math/superStake.js +29 -28
  490. package/lib/node/math/trade.d.ts +2 -2
  491. package/lib/node/math/trade.d.ts.map +1 -1
  492. package/lib/node/math/trade.js +7 -7
  493. package/lib/node/math/utils.d.ts +1 -1
  494. package/lib/node/math/utils.js +1 -1
  495. package/lib/node/memcmp.d.ts +0 -1
  496. package/lib/node/memcmp.d.ts.map +1 -1
  497. package/lib/node/memcmp.js +1 -10
  498. package/lib/node/oracles/oracleClientCache.d.ts +1 -1
  499. package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
  500. package/lib/node/oracles/prelaunchOracleClient.js +3 -2
  501. package/lib/node/oracles/pythClient.d.ts.map +1 -1
  502. package/lib/node/oracles/pythClient.js +9 -3
  503. package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
  504. package/lib/node/oracles/pythLazerClient.js +5 -4
  505. package/lib/node/oracles/utils.d.ts +4 -0
  506. package/lib/node/oracles/utils.d.ts.map +1 -1
  507. package/lib/node/oracles/utils.js +9 -1
  508. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -3
  509. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  510. package/lib/node/orderSubscriber/OrderSubscriber.js +16 -14
  511. package/lib/node/orderSubscriber/WebsocketSubscription.js +1 -1
  512. package/lib/node/orderSubscriber/grpcSubscription.js +2 -2
  513. package/lib/node/orderSubscriber/types.d.ts +0 -2
  514. package/lib/node/orderSubscriber/types.d.ts.map +1 -1
  515. package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
  516. package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts.map +1 -1
  517. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +2 -6
  518. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
  519. package/lib/node/priorityFee/priorityFeeSubscriber.js +34 -18
  520. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
  521. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
  522. package/lib/node/priorityFee/priorityFeeSubscriberMap.js +3 -11
  523. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
  524. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
  525. package/lib/node/priorityFee/types.d.ts +3 -8
  526. package/lib/node/priorityFee/types.d.ts.map +1 -1
  527. package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
  528. package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts.map +1 -1
  529. package/lib/node/priorityFee/velocityPriorityFeeMethod.js +1 -3
  530. package/lib/node/pyth/pythLazerSubscriber.d.ts +1 -1
  531. package/lib/node/pyth/pythLazerSubscriber.js +1 -1
  532. package/lib/node/pyth/types.d.ts +0 -1
  533. package/lib/node/pyth/types.d.ts.map +1 -1
  534. package/lib/node/slot/SlotSubscriber.d.ts +1 -1
  535. package/lib/node/slot/SlotSubscriber.d.ts.map +1 -1
  536. package/lib/node/slot/SlotSubscriber.js +2 -1
  537. package/lib/node/slot/SlothashSubscriber.d.ts +3 -2
  538. package/lib/node/slot/SlothashSubscriber.d.ts.map +1 -1
  539. package/lib/node/slot/SlothashSubscriber.js +11 -4
  540. package/lib/node/swap/UnifiedSwapClient.js +1 -1
  541. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
  542. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
  543. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
  544. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +7 -7
  545. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
  546. package/lib/node/swift/signedMsgUserAccountSubscriber.js +14 -10
  547. package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -6
  548. package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
  549. package/lib/node/swift/swiftOrderSubscriber.js +15 -16
  550. package/lib/node/testClient.js +3 -2
  551. package/lib/node/tokenFaucet.d.ts.map +1 -1
  552. package/lib/node/tokenFaucet.js +16 -2
  553. package/lib/node/tx/baseTxSender.d.ts +4 -4
  554. package/lib/node/tx/baseTxSender.d.ts.map +1 -1
  555. package/lib/node/tx/baseTxSender.js +5 -4
  556. package/lib/node/tx/fastSingleTxSender.d.ts +3 -3
  557. package/lib/node/tx/fastSingleTxSender.d.ts.map +1 -1
  558. package/lib/node/tx/fastSingleTxSender.js +9 -5
  559. package/lib/node/tx/reportTransactionError.d.ts +2 -2
  560. package/lib/node/tx/reportTransactionError.d.ts.map +1 -1
  561. package/lib/node/tx/reportTransactionError.js +5 -1
  562. package/lib/node/tx/retryTxSender.d.ts +1 -1
  563. package/lib/node/tx/retryTxSender.d.ts.map +1 -1
  564. package/lib/node/tx/retryTxSender.js +4 -2
  565. package/lib/node/tx/txHandler.d.ts +9 -3
  566. package/lib/node/tx/txHandler.d.ts.map +1 -1
  567. package/lib/node/tx/txHandler.js +54 -40
  568. package/lib/node/tx/txParamProcessor.d.ts +4 -1
  569. package/lib/node/tx/txParamProcessor.d.ts.map +1 -1
  570. package/lib/node/tx/txParamProcessor.js +6 -0
  571. package/lib/node/tx/types.d.ts +1 -1
  572. package/lib/node/tx/types.d.ts.map +1 -1
  573. package/lib/node/tx/whileValidTxSender.d.ts +1 -6
  574. package/lib/node/tx/whileValidTxSender.d.ts.map +1 -1
  575. package/lib/node/tx/whileValidTxSender.js +35 -13
  576. package/lib/node/types.d.ts +100 -155
  577. package/lib/node/types.d.ts.map +1 -1
  578. package/lib/node/types.js +6 -2
  579. package/lib/node/user.d.ts +22 -10
  580. package/lib/node/user.d.ts.map +1 -1
  581. package/lib/node/user.js +174 -154
  582. package/lib/node/userConfig.d.ts +3 -2
  583. package/lib/node/userConfig.d.ts.map +1 -1
  584. package/lib/node/userMap/WebsocketSubscription.d.ts +1 -1
  585. package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
  586. package/lib/node/userMap/WebsocketSubscription.js +1 -1
  587. package/lib/node/userMap/grpcSubscription.d.ts +1 -1
  588. package/lib/node/userMap/grpcSubscription.d.ts.map +1 -1
  589. package/lib/node/userMap/grpcSubscription.js +1 -1
  590. package/lib/node/userMap/referrerMap.d.ts +0 -2
  591. package/lib/node/userMap/referrerMap.d.ts.map +1 -1
  592. package/lib/node/userMap/referrerMap.js +10 -7
  593. package/lib/node/userMap/revenueShareEscrowMap.d.ts +0 -2
  594. package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
  595. package/lib/node/userMap/revenueShareEscrowMap.js +4 -4
  596. package/lib/node/userMap/userMap.d.ts +3 -5
  597. package/lib/node/userMap/userMap.d.ts.map +1 -1
  598. package/lib/node/userMap/userMap.js +39 -30
  599. package/lib/node/userMap/userMapConfig.d.ts +3 -2
  600. package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
  601. package/lib/node/userMap/userStatsMap.d.ts +1 -3
  602. package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
  603. package/lib/node/userMap/userStatsMap.js +18 -17
  604. package/lib/node/userStats.d.ts +7 -4
  605. package/lib/node/userStats.d.ts.map +1 -1
  606. package/lib/node/userStats.js +28 -18
  607. package/lib/node/userStatsConfig.d.ts +3 -2
  608. package/lib/node/userStatsConfig.d.ts.map +1 -1
  609. package/lib/node/util/TransactionConfirmationManager.d.ts.map +1 -1
  610. package/lib/node/util/TransactionConfirmationManager.js +4 -2
  611. package/lib/node/util/chainClock.d.ts +1 -1
  612. package/lib/node/util/chainClock.d.ts.map +1 -1
  613. package/lib/node/util/computeUnits.d.ts +1 -1
  614. package/lib/node/util/computeUnits.d.ts.map +1 -1
  615. package/lib/node/util/computeUnits.js +6 -1
  616. package/lib/node/util/ed25519Utils.d.ts +1 -1
  617. package/lib/node/util/ed25519Utils.js +1 -1
  618. package/lib/node/velocityClient.d.ts +145 -72
  619. package/lib/node/velocityClient.d.ts.map +1 -1
  620. package/lib/node/velocityClient.js +653 -457
  621. package/lib/node/velocityClientConfig.d.ts +0 -8
  622. package/lib/node/velocityClientConfig.d.ts.map +1 -1
  623. package/package.json +10 -9
  624. package/scripts/deposit-isolated-positions.ts +2 -2
  625. package/scripts/find-flagged-users.ts +1 -1
  626. package/scripts/grpc-client-test-comparison.ts +4 -4
  627. package/scripts/grpc-multiuser-client-test-comparison.ts +2 -2
  628. package/scripts/single-grpc-client-test.ts +3 -3
  629. package/scripts/updateVersion.js +4 -4
  630. package/scripts/withdraw-isolated-positions.ts +2 -2
  631. package/src/accounts/basicUserAccountSubscriber.ts +7 -5
  632. package/src/accounts/basicUserStatsAccountSubscriber.ts +9 -5
  633. package/src/accounts/bulkAccountLoader.ts +20 -7
  634. package/src/accounts/grpcAccountSubscriber.ts +11 -3
  635. package/src/accounts/grpcMultiAccountSubscriber.ts +24 -9
  636. package/src/accounts/grpcMultiUserAccountSubscriber.ts +16 -12
  637. package/src/accounts/grpcProgramAccountSubscriber.ts +12 -4
  638. package/src/accounts/grpcVelocityClientAccountSubscriber.ts +17 -14
  639. package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +69 -49
  640. package/src/accounts/laserProgramAccountSubscriber.ts +4 -1
  641. package/src/accounts/oneShotUserAccountSubscriber.ts +5 -3
  642. package/src/accounts/oneShotUserStatsAccountSubscriber.ts +8 -3
  643. package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +11 -5
  644. package/src/accounts/pollingOracleAccountSubscriber.ts +17 -10
  645. package/src/accounts/pollingTokenAccountSubscriber.ts +17 -10
  646. package/src/accounts/pollingUserAccountSubscriber.ts +26 -20
  647. package/src/accounts/pollingUserStatsAccountSubscriber.ts +12 -10
  648. package/src/accounts/pollingVelocityClientAccountSubscriber.ts +80 -41
  649. package/src/accounts/types.ts +8 -13
  650. package/src/accounts/utils.ts +12 -2
  651. package/src/accounts/webSocketAccountSubscriber.ts +23 -10
  652. package/src/accounts/webSocketAccountSubscriberV2.ts +23 -8
  653. package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +17 -2
  654. package/src/accounts/webSocketProgramAccountSubscriber.ts +29 -4
  655. package/src/accounts/webSocketProgramAccountSubscriberV2.ts +30 -4
  656. package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +29 -4
  657. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -2
  658. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +15 -2
  659. package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +79 -58
  660. package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +77 -45
  661. package/src/accounts/websocketProgramUserAccountSubscriber.ts +1 -6
  662. package/src/addresses/marketAddresses.ts +3 -2
  663. package/src/addresses/pda.ts +3 -38
  664. package/src/adminClient.ts +285 -315
  665. package/src/auctionSubscriber/auctionSubscriber.ts +8 -11
  666. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +13 -11
  667. package/src/auctionSubscriber/types.ts +3 -3
  668. package/src/bankrun/bankrunConnection.ts +83 -39
  669. package/src/blockhashSubscriber/BlockhashSubscriber.ts +5 -4
  670. package/src/clock/clockSubscriber.ts +10 -9
  671. package/src/config.ts +16 -70
  672. package/src/constants/index.ts +1 -2
  673. package/src/constants/numericConstants.ts +3 -3
  674. package/src/constituentMap/constituentMap.ts +10 -7
  675. package/src/constituentMap/pollingConstituentAccountSubscriber.ts +4 -2
  676. package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +13 -4
  677. package/src/core/VelocityCore.ts +11 -20
  678. package/src/core/instructions/perpOrders.ts +14 -0
  679. package/src/core/instructions/withdraw.ts +2 -2
  680. package/src/core/remainingAccounts.ts +7 -7
  681. package/src/decode/user.ts +8 -1
  682. package/src/dlob/DLOB.ts +300 -176
  683. package/src/dlob/DLOBNode.ts +23 -3
  684. package/src/dlob/DLOBSubscriber.ts +53 -42
  685. package/src/dlob/NodeList.ts +8 -7
  686. package/src/dlob/orderBookLevels.ts +51 -25
  687. package/src/dlob/types.ts +0 -2
  688. package/src/events/eventList.ts +4 -1
  689. package/src/events/eventSubscriber.ts +108 -50
  690. package/src/events/eventsServerLogProvider.ts +24 -15
  691. package/src/events/fetchLogs.ts +3 -3
  692. package/src/events/parse.ts +14 -14
  693. package/src/events/pollingLogProvider.ts +2 -2
  694. package/src/events/txEventCache.ts +8 -2
  695. package/src/events/types.ts +4 -15
  696. package/src/events/webSocketLogProvider.ts +5 -3
  697. package/src/factory/bigNum.ts +2 -2
  698. package/src/idl/{drift.json → velocity.json} +2265 -2333
  699. package/src/idl/{drift.ts → velocity.ts} +2267 -2335
  700. package/src/index.ts +1 -6
  701. package/src/jupiter/jupiterClient.ts +30 -10
  702. package/src/margin/README.md +2 -2
  703. package/src/marginCalculation.ts +1 -0
  704. package/src/math/amm.ts +217 -40
  705. package/src/math/auction.ts +16 -12
  706. package/src/math/bankruptcy.ts +1 -1
  707. package/src/math/builder.ts +45 -1
  708. package/src/math/funding.ts +51 -47
  709. package/src/math/insurance.ts +6 -8
  710. package/src/math/margin.ts +12 -119
  711. package/src/math/market.ts +16 -98
  712. package/src/math/oracles.ts +29 -43
  713. package/src/math/orders.ts +13 -109
  714. package/src/math/position.ts +6 -12
  715. package/src/math/repeg.ts +0 -29
  716. package/src/math/spotBalance.ts +14 -10
  717. package/src/math/spotMarket.ts +2 -28
  718. package/src/math/spotPosition.ts +4 -4
  719. package/src/math/state.ts +0 -8
  720. package/src/math/superStake.ts +36 -85
  721. package/src/math/trade.ts +7 -3
  722. package/src/math/utils.ts +1 -1
  723. package/src/memcmp.ts +0 -9
  724. package/src/oracles/prelaunchOracleClient.ts +7 -2
  725. package/src/oracles/pythClient.ts +12 -3
  726. package/src/oracles/pythLazerClient.ts +10 -5
  727. package/src/oracles/utils.ts +15 -0
  728. package/src/orderSubscriber/OrderSubscriber.ts +12 -12
  729. package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
  730. package/src/orderSubscriber/grpcSubscription.ts +2 -2
  731. package/src/orderSubscriber/types.ts +0 -2
  732. package/src/priorityFee/heliusPriorityFeeMethod.ts +1 -1
  733. package/src/priorityFee/priorityFeeSubscriber.ts +50 -21
  734. package/src/priorityFee/priorityFeeSubscriberMap.ts +2 -10
  735. package/src/priorityFee/solanaPriorityFeeMethod.ts +1 -1
  736. package/src/priorityFee/types.ts +3 -13
  737. package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -12
  738. package/src/pyth/pythLazerSubscriber.ts +1 -1
  739. package/src/pyth/types.ts +0 -2
  740. package/src/slot/SlotSubscriber.ts +3 -3
  741. package/src/slot/SlothashSubscriber.ts +17 -6
  742. package/src/swap/UnifiedSwapClient.ts +1 -1
  743. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +5 -6
  744. package/src/swift/signedMsgUserAccountSubscriber.ts +18 -16
  745. package/src/swift/swiftOrderSubscriber.ts +17 -21
  746. package/src/testClient.ts +2 -2
  747. package/src/tokenFaucet.ts +22 -3
  748. package/src/tx/baseTxSender.ts +10 -10
  749. package/src/tx/fastSingleTxSender.ts +12 -8
  750. package/src/tx/reportTransactionError.ts +12 -7
  751. package/src/tx/retryTxSender.ts +6 -4
  752. package/src/tx/txHandler.ts +88 -43
  753. package/src/tx/txParamProcessor.ts +18 -3
  754. package/src/tx/types.ts +1 -1
  755. package/src/tx/whileValidTxSender.ts +51 -22
  756. package/src/types.ts +119 -173
  757. package/src/user.ts +208 -165
  758. package/src/userConfig.ts +1 -3
  759. package/src/userMap/WebsocketSubscription.ts +2 -2
  760. package/src/userMap/grpcSubscription.ts +2 -2
  761. package/src/userMap/referrerMap.ts +13 -13
  762. package/src/userMap/revenueShareEscrowMap.ts +6 -5
  763. package/src/userMap/userMap.ts +46 -32
  764. package/src/userMap/userMapConfig.ts +3 -3
  765. package/src/userMap/userStatsMap.ts +32 -23
  766. package/src/userStats.ts +22 -13
  767. package/src/userStatsConfig.ts +3 -3
  768. package/src/util/TransactionConfirmationManager.ts +10 -2
  769. package/src/util/chainClock.ts +1 -1
  770. package/src/util/computeUnits.ts +7 -3
  771. package/src/util/ed25519Utils.ts +1 -1
  772. package/src/velocityClient.ts +867 -600
  773. package/src/velocityClientConfig.ts +0 -10
  774. package/tests/{DriftCore → VelocityCore}/decode.test.ts +1 -1
  775. package/tests/{DriftCore → VelocityCore}/fill_trigger.test.ts +1 -1
  776. package/tests/{DriftCore → VelocityCore}/instructions.test.ts +1 -1
  777. package/tests/{DriftCore → VelocityCore}/pdas.test.ts +4 -2
  778. package/tests/amm/test.ts +138 -0
  779. package/tests/ci/verifyConstants.ts +24 -27
  780. package/tests/decode/test.ts +2 -2
  781. package/tests/dlob/helpers.ts +11 -10
  782. package/tests/events/parseLogsForCuUsage.ts +15 -15
  783. package/tests/user/helpers.ts +9 -9
  784. package/tests/user/test.ts +13 -10
  785. package/tsconfig.json +1 -0
  786. package/lib/browser/constants/insuranceFund.d.ts +0 -5
  787. package/lib/browser/constants/insuranceFund.js +0 -9
  788. package/lib/browser/tx/forwardOnlyTxSender.d.ts +0 -37
  789. package/lib/browser/tx/forwardOnlyTxSender.js +0 -92
  790. package/lib/browser/util/deprecatedAlias.d.ts +0 -26
  791. package/lib/browser/util/deprecatedAlias.js +0 -10
  792. package/lib/browser/util/tps.d.ts +0 -2
  793. package/lib/browser/util/tps.js +0 -16
  794. package/lib/node/constants/insuranceFund.d.ts +0 -6
  795. package/lib/node/constants/insuranceFund.d.ts.map +0 -1
  796. package/lib/node/constants/insuranceFund.js +0 -9
  797. package/lib/node/idl/drift.d.ts.map +0 -1
  798. package/lib/node/tx/forwardOnlyTxSender.d.ts +0 -38
  799. package/lib/node/tx/forwardOnlyTxSender.d.ts.map +0 -1
  800. package/lib/node/tx/forwardOnlyTxSender.js +0 -92
  801. package/lib/node/util/deprecatedAlias.d.ts +0 -27
  802. package/lib/node/util/deprecatedAlias.d.ts.map +0 -1
  803. package/lib/node/util/deprecatedAlias.js +0 -10
  804. package/lib/node/util/tps.d.ts +0 -3
  805. package/lib/node/util/tps.d.ts.map +0 -1
  806. package/lib/node/util/tps.js +0 -16
  807. package/src/constants/insuranceFund.ts +0 -8
  808. package/src/tx/forwardOnlyTxSender.ts +0 -145
  809. package/src/util/deprecatedAlias.ts +0 -21
  810. package/src/util/tps.ts +0 -27
  811. /package/lib/browser/idl/{drift.js → velocity.js} +0 -0
  812. /package/lib/node/idl/{drift.js → velocity.js} +0 -0
  813. /package/tests/{DriftCore → VelocityCore}/perp_orders.test.ts +0 -0
  814. /package/tests/{DriftCore → VelocityCore}/remainingAccounts.test.ts +0 -0
  815. /package/tests/{DriftCore → VelocityCore}/settlement_liquidation.test.ts +0 -0
package/src/dlob/DLOB.ts CHANGED
@@ -116,6 +116,20 @@ const SUPPORTED_ORDER_TYPES = [
116
116
  'oracle',
117
117
  ];
118
118
 
119
+ function getOrderOrThrow(node: DLOBNode): Order {
120
+ if (!node.order) {
121
+ throw new Error('DLOBNode must have an order');
122
+ }
123
+ return node.order;
124
+ }
125
+
126
+ function getUserAccountOrThrow(node: DLOBNode): string {
127
+ if (node.userAccount === undefined) {
128
+ throw new Error('DLOBNode must have a userAccount');
129
+ }
130
+ return node.userAccount;
131
+ }
132
+
119
133
  export class DLOB {
120
134
  openOrders = new Map<MarketTypeStr, Set<string>>();
121
135
  orderLists = new Map<MarketTypeStr, Map<number, MarketNodeLists>>();
@@ -134,20 +148,64 @@ export class DLOB {
134
148
  this.orderLists.set('spot', new Map<number, MarketNodeLists>());
135
149
  }
136
150
 
151
+ private getOpenOrdersForMarketType(
152
+ marketTypeStr: MarketTypeStr
153
+ ): Set<string> {
154
+ const openOrders = this.openOrders.get(marketTypeStr);
155
+ if (!openOrders) {
156
+ throw new Error(
157
+ `DLOB has no open orders set for market type ${marketTypeStr}`
158
+ );
159
+ }
160
+ return openOrders;
161
+ }
162
+
163
+ private getOrderListsForMarketType(
164
+ marketTypeStr: MarketTypeStr
165
+ ): Map<number, MarketNodeLists> {
166
+ const orderLists = this.orderLists.get(marketTypeStr);
167
+ if (!orderLists) {
168
+ throw new Error(
169
+ `DLOB has no order lists for market type ${marketTypeStr}`
170
+ );
171
+ }
172
+ return orderLists;
173
+ }
174
+
175
+ private tryGetMarketNodeLists(
176
+ marketTypeStr: MarketTypeStr,
177
+ marketIndex: number
178
+ ): MarketNodeLists | undefined {
179
+ return this.orderLists.get(marketTypeStr)?.get(marketIndex);
180
+ }
181
+
182
+ private getMarketNodeLists(
183
+ marketTypeStr: MarketTypeStr,
184
+ marketIndex: number
185
+ ): MarketNodeLists {
186
+ const marketNodeLists = this.tryGetMarketNodeLists(
187
+ marketTypeStr,
188
+ marketIndex
189
+ );
190
+ if (!marketNodeLists) {
191
+ throw new Error(
192
+ `DLOB has no order lists for market type ${marketTypeStr} and market index ${marketIndex}`
193
+ );
194
+ }
195
+ return marketNodeLists;
196
+ }
197
+
137
198
  public clear() {
138
- for (const marketType of this.openOrders.keys()) {
139
- this.openOrders.get(marketType).clear();
199
+ for (const openOrders of this.openOrders.values()) {
200
+ openOrders.clear();
140
201
  }
141
202
  this.openOrders.clear();
142
203
 
143
- for (const marketType of this.orderLists.keys()) {
144
- for (const marketIndex of this.orderLists.get(marketType).keys()) {
145
- const marketNodeLists = this.orderLists
146
- .get(marketType)
147
- .get(marketIndex);
148
- for (const side of Object.keys(marketNodeLists)) {
149
- for (const orderType of Object.keys(marketNodeLists[side])) {
150
- marketNodeLists[side][orderType].clear();
204
+ for (const marketNodeListsMap of this.orderLists.values()) {
205
+ for (const marketNodeLists of marketNodeListsMap.values()) {
206
+ for (const side of Object.values(marketNodeLists)) {
207
+ for (const nodeList of Object.values(side)) {
208
+ nodeList.clear();
151
209
  }
152
210
  }
153
211
  }
@@ -174,7 +232,7 @@ export class DLOB {
174
232
 
175
233
  // initialize the dlob with the user map
176
234
  for (const user of userMap.values()) {
177
- const userAccount = user.getUserAccount();
235
+ const userAccount = user.getUserAccountOrThrow();
178
236
  const userAccountPubkey = user.getUserAccountPublicKey();
179
237
  const userAccountPubkeyString = userAccountPubkey.toString();
180
238
 
@@ -217,14 +275,14 @@ export class DLOB {
217
275
 
218
276
  const marketType = getVariant(order.marketType) as MarketTypeStr;
219
277
 
220
- if (!this.orderLists.get(marketType).has(order.marketIndex)) {
278
+ if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
221
279
  this.addOrderList(marketType, order.marketIndex);
222
280
  }
223
281
 
224
282
  if (isVariant(order.status, 'open')) {
225
- this.openOrders
226
- .get(marketType)
227
- .add(getOrderSignature(order.orderId, userAccount));
283
+ this.getOpenOrdersForMarketType(marketType).add(
284
+ getOrderSignature(order.orderId, userAccount)
285
+ );
228
286
  }
229
287
 
230
288
  this.getListForOnChainOrder(order, slot)?.insert(
@@ -248,28 +306,25 @@ export class DLOB {
248
306
  const marketType = getVariant(order.marketType) as MarketTypeStr;
249
307
  const marketIndex = order.marketIndex;
250
308
  const bidOrAsk = isVariant(order.direction, 'long') ? 'bid' : 'ask';
251
- if (!this.orderLists.get(marketType).has(order.marketIndex)) {
309
+ if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
252
310
  this.addOrderList(marketType, order.marketIndex);
253
311
  }
254
- this.openOrders
255
- .get(marketType)
256
- .add(getOrderSignature(order.orderId, userAccount));
257
- this.orderLists
258
- .get(marketType)
259
- .get(marketIndex)
260
- .signedMsg[bidOrAsk].insert(
261
- order,
262
- marketType,
263
- userAccount,
264
- baseAssetAmount
265
- );
312
+ this.getOpenOrdersForMarketType(marketType).add(
313
+ getOrderSignature(order.orderId, userAccount)
314
+ );
315
+ this.getMarketNodeLists(marketType, marketIndex).signedMsg[bidOrAsk].insert(
316
+ order,
317
+ marketType,
318
+ userAccount,
319
+ baseAssetAmount
320
+ );
266
321
  if (onInsert) {
267
322
  onInsert();
268
323
  }
269
324
  }
270
325
 
271
326
  addOrderList(marketType: MarketTypeStr, marketIndex: number): void {
272
- this.orderLists.get(marketType).set(marketIndex, {
327
+ this.getOrderListsForMarketType(marketType).set(marketIndex, {
273
328
  restingLimit: {
274
329
  ask: new NodeList('restingLimit', 'asc'),
275
330
  bid: new NodeList('restingLimit', 'desc'),
@@ -326,36 +381,49 @@ export class DLOB {
326
381
  const isInactiveTriggerOrder =
327
382
  mustBeTriggered(order) && !isTriggered(order);
328
383
 
329
- let type: DLOBNodeType;
384
+ const marketType = getVariant(order.marketType) as MarketTypeStr;
385
+
386
+ const marketNodeLists = this.tryGetMarketNodeLists(
387
+ marketType,
388
+ order.marketIndex
389
+ );
390
+ if (!marketNodeLists) {
391
+ return undefined;
392
+ }
393
+
330
394
  if (isInactiveTriggerOrder) {
331
- type = 'trigger';
332
- } else if (
395
+ const subType = isVariant(order.triggerCondition, 'above')
396
+ ? 'above'
397
+ : 'below';
398
+ return marketNodeLists.trigger[subType];
399
+ }
400
+
401
+ const subType = isVariant(order.direction, 'long') ? 'bid' : 'ask';
402
+ if (
333
403
  isOneOfVariant(order.orderType, ['market', 'triggerMarket', 'oracle'])
334
404
  ) {
335
- type = 'market';
405
+ return marketNodeLists.market[subType];
336
406
  } else if (!order.oraclePriceOffset.eq(ZERO)) {
337
- type = 'floatingLimit';
407
+ return marketNodeLists.floatingLimit[subType];
338
408
  } else {
339
409
  const isResting = isRestingLimitOrder(order, slot);
340
- type = isResting ? 'restingLimit' : 'takingLimit';
410
+ return isResting
411
+ ? marketNodeLists.restingLimit[subType]
412
+ : marketNodeLists.takingLimit[subType];
341
413
  }
414
+ }
342
415
 
343
- let subType: string;
344
- if (isInactiveTriggerOrder) {
345
- subType = isVariant(order.triggerCondition, 'above') ? 'above' : 'below';
346
- } else {
347
- subType = isVariant(order.direction, 'long') ? 'bid' : 'ask';
348
- }
349
-
350
- const marketType = getVariant(order.marketType) as MarketTypeStr;
351
-
352
- if (!this.orderLists.has(marketType)) {
353
- return undefined;
416
+ private getListForOnChainOrderOrThrow(
417
+ order: Order,
418
+ slot: number
419
+ ): NodeList<any> {
420
+ const list = this.getListForOnChainOrder(order, slot);
421
+ if (!list) {
422
+ throw new Error(
423
+ `No order list found for order ${order.orderId} in market ${order.marketIndex}`
424
+ );
354
425
  }
355
-
356
- return this.orderLists.get(marketType).get(order.marketIndex)[type][
357
- subType
358
- ];
426
+ return list;
359
427
  }
360
428
 
361
429
  public updateRestingLimitOrders(slot: number): void {
@@ -374,10 +442,12 @@ export class DLOB {
374
442
  slot: number,
375
443
  marketTypeStr: MarketTypeStr
376
444
  ): void {
377
- for (const [_, nodeLists] of this.orderLists.get(marketTypeStr)) {
378
- const nodesToUpdate = [];
445
+ for (const [_, nodeLists] of this.getOrderListsForMarketType(
446
+ marketTypeStr
447
+ )) {
448
+ const nodesToUpdate: Array<{ side: 'ask' | 'bid'; node: DLOBNode }> = [];
379
449
  for (const node of nodeLists.takingLimit.ask.getGenerator()) {
380
- if (!isRestingLimitOrder(node.order, slot)) {
450
+ if (!isRestingLimitOrder(getOrderOrThrow(node), slot)) {
381
451
  continue;
382
452
  }
383
453
 
@@ -388,7 +458,7 @@ export class DLOB {
388
458
  }
389
459
 
390
460
  for (const node of nodeLists.takingLimit.bid.getGenerator()) {
391
- if (!isRestingLimitOrder(node.order, slot)) {
461
+ if (!isRestingLimitOrder(getOrderOrThrow(node), slot)) {
392
462
  continue;
393
463
  }
394
464
 
@@ -400,12 +470,10 @@ export class DLOB {
400
470
 
401
471
  for (const nodeToUpdate of nodesToUpdate) {
402
472
  const { side, node } = nodeToUpdate;
403
- nodeLists.takingLimit[side].remove(node.order, node.userAccount);
404
- nodeLists.restingLimit[side].insert(
405
- node.order,
406
- marketTypeStr,
407
- node.userAccount
408
- );
473
+ const order = getOrderOrThrow(node);
474
+ const userAccount = getUserAccountOrThrow(node);
475
+ nodeLists.takingLimit[side].remove(order, userAccount);
476
+ nodeLists.restingLimit[side].insert(order, marketTypeStr, userAccount);
409
477
  }
410
478
  }
411
479
  }
@@ -483,7 +551,7 @@ export class DLOB {
483
551
  );
484
552
 
485
553
  const stepSize = isVariant(marketType, 'perp')
486
- ? (marketAccount as PerpMarketAccount).amm.orderStepSize
554
+ ? (marketAccount as PerpMarketAccount).orderStepSize
487
555
  : (marketAccount as SpotMarketAccount).orderStepSize;
488
556
 
489
557
  const cancelReduceOnlyNodesToFill =
@@ -538,21 +606,21 @@ export class DLOB {
538
606
  const mergeNodesToFillHelper = (nodesToFillArray: NodeToFill[]) => {
539
607
  nodesToFillArray.forEach((nodeToFill) => {
540
608
  const nodeSignature = getOrderSignature(
541
- nodeToFill.node.order.orderId,
542
- nodeToFill.node.userAccount
609
+ getOrderOrThrow(nodeToFill.node).orderId,
610
+ getUserAccountOrThrow(nodeToFill.node)
543
611
  );
544
612
 
545
- if (!mergedNodesToFill.has(nodeSignature)) {
546
- mergedNodesToFill.set(nodeSignature, {
613
+ let mergedNodeToFill = mergedNodesToFill.get(nodeSignature);
614
+ if (!mergedNodeToFill) {
615
+ mergedNodeToFill = {
547
616
  node: nodeToFill.node,
548
617
  makerNodes: [],
549
- });
618
+ };
619
+ mergedNodesToFill.set(nodeSignature, mergedNodeToFill);
550
620
  }
551
621
 
552
622
  if (nodeToFill.makerNodes) {
553
- mergedNodesToFill
554
- .get(nodeSignature)
555
- .makerNodes.push(...nodeToFill.makerNodes);
623
+ mergedNodeToFill.makerNodes.push(...nodeToFill.makerNodes);
556
624
  }
557
625
  });
558
626
  };
@@ -611,6 +679,9 @@ export class DLOB {
611
679
  oraclePriceData,
612
680
  askGenerator,
613
681
  (askPrice) => {
682
+ if (askPrice === undefined) {
683
+ throw new Error('Resting limit ask must have a limit price');
684
+ }
614
685
  return askPrice.lte(fallbackBidWithBuffer);
615
686
  },
616
687
  stateAccount,
@@ -640,6 +711,9 @@ export class DLOB {
640
711
  oraclePriceData,
641
712
  bidGenerator,
642
713
  (bidPrice) => {
714
+ if (bidPrice === undefined) {
715
+ throw new Error('Resting limit bid must have a limit price');
716
+ }
643
717
  return bidPrice.gte(fallbackAskWithBuffer);
644
718
  },
645
719
  stateAccount,
@@ -798,7 +872,7 @@ export class DLOB {
798
872
  makerNodeGeneratorFn: (
799
873
  marketIndex: number,
800
874
  slot: number,
801
- marketType: MarketType,
875
+ marketType: T,
802
876
  oraclePriceData: T extends { spot: unknown }
803
877
  ? OraclePriceData
804
878
  : MMOraclePriceData
@@ -822,7 +896,7 @@ export class DLOB {
822
896
  continue;
823
897
  }
824
898
 
825
- const makerPrice = makerNode.getPrice(oraclePriceData, slot);
899
+ const makerPrice = makerNode.getPriceOrThrow(oraclePriceData, slot);
826
900
  const takerPrice = takerNode.getPrice(oraclePriceData, slot);
827
901
 
828
902
  const ordersCross = doesCross(takerPrice, makerPrice);
@@ -837,8 +911,8 @@ export class DLOB {
837
911
  makerNodes: [makerNode],
838
912
  });
839
913
 
840
- const makerOrder = makerNode.order;
841
- const takerOrder = takerNode.order;
914
+ const makerOrder = getOrderOrThrow(makerNode);
915
+ const takerOrder = getOrderOrThrow(takerNode);
842
916
 
843
917
  const makerBaseRemaining = makerOrder.baseAssetAmount.sub(
844
918
  makerOrder.baseAssetAmountFilled
@@ -852,9 +926,9 @@ export class DLOB {
852
926
  const newMakerOrder = { ...makerOrder };
853
927
  newMakerOrder.baseAssetAmountFilled =
854
928
  makerOrder.baseAssetAmountFilled.add(baseFilled);
855
- this.getListForOnChainOrder(newMakerOrder, slot).update(
929
+ this.getListForOnChainOrderOrThrow(newMakerOrder, slot).update(
856
930
  newMakerOrder,
857
- makerNode.userAccount
931
+ getUserAccountOrThrow(makerNode)
858
932
  );
859
933
 
860
934
  const newTakerOrder = { ...takerOrder };
@@ -863,14 +937,18 @@ export class DLOB {
863
937
 
864
938
  if (takerNode.isSignedMsg) {
865
939
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
940
+ const marketNodeLists = this.getMarketNodeLists(
941
+ marketTypeStr,
942
+ marketIndex
943
+ );
866
944
  const orderList = isVariant(takerOrder.direction, 'long')
867
- ? this.orderLists.get(marketTypeStr).get(marketIndex).signedMsg.bid
868
- : this.orderLists.get(marketTypeStr).get(marketIndex).signedMsg.ask;
869
- orderList.update(newTakerOrder, takerNode.userAccount);
945
+ ? marketNodeLists.signedMsg.bid
946
+ : marketNodeLists.signedMsg.ask;
947
+ orderList.update(newTakerOrder, getUserAccountOrThrow(takerNode));
870
948
  } else {
871
- this.getListForOnChainOrder(newTakerOrder, slot).update(
949
+ this.getListForOnChainOrderOrThrow(newTakerOrder, slot).update(
872
950
  newTakerOrder,
873
- takerNode.userAccount
951
+ getUserAccountOrThrow(takerNode)
874
952
  );
875
953
  }
876
954
 
@@ -908,8 +986,8 @@ export class DLOB {
908
986
  nextNode = nodeGenerator.next();
909
987
  continue;
910
988
  }
911
-
912
- const nodePrice = getLimitPrice(node.order, oraclePriceData, slot);
989
+ const nodeOrder = getOrderOrThrow(node);
990
+ const nodePrice = getLimitPrice(nodeOrder, oraclePriceData, slot);
913
991
 
914
992
  // order crosses if there is no limit price or it crosses fallback price
915
993
  const crosses = doesCross(nodePrice);
@@ -918,7 +996,7 @@ export class DLOB {
918
996
  const fallbackAvailable =
919
997
  isVariant(marketType, 'spot') ||
920
998
  isFallbackAvailableLiquiditySource(
921
- node.order,
999
+ nodeOrder,
922
1000
  oraclePriceData as MMOraclePriceData,
923
1001
  slot,
924
1002
  state,
@@ -947,7 +1025,7 @@ export class DLOB {
947
1025
  const nodesToFill = new Array<NodeToFill>();
948
1026
 
949
1027
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
950
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1028
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
951
1029
 
952
1030
  if (!nodeLists) {
953
1031
  return nodesToFill;
@@ -972,15 +1050,22 @@ export class DLOB {
972
1050
 
973
1051
  for (const bidGenerator of bidGenerators) {
974
1052
  for (const bid of bidGenerator) {
975
- if (
976
- bid.isSignedMsg &&
977
- slot.gt(bid.order.slot.addn(bid.order.auctionDuration))
978
- ) {
979
- this.orderLists
980
- .get(marketTypeStr)
981
- .get(marketIndex)
982
- .signedMsg.bid.remove(bid.order, bid.userAccount);
983
- } else if (isOrderExpired(bid.order, ts, true, 25)) {
1053
+ const bidOrder = getOrderOrThrow(bid);
1054
+ if (bid.isSignedMsg) {
1055
+ if (slot === undefined) {
1056
+ throw new Error(
1057
+ 'Must provide slot to findExpiredNodesToFill to expire signedMsg orders'
1058
+ );
1059
+ }
1060
+ if (slot.gt(bidOrder.slot.addn(bidOrder.auctionDuration))) {
1061
+ nodeLists.signedMsg.bid.remove(
1062
+ bidOrder,
1063
+ getUserAccountOrThrow(bid)
1064
+ );
1065
+ continue;
1066
+ }
1067
+ }
1068
+ if (isOrderExpired(bidOrder, ts, true, 25)) {
984
1069
  nodesToFill.push({
985
1070
  node: bid,
986
1071
  makerNodes: [],
@@ -991,15 +1076,22 @@ export class DLOB {
991
1076
 
992
1077
  for (const askGenerator of askGenerators) {
993
1078
  for (const ask of askGenerator) {
994
- if (
995
- ask.isSignedMsg &&
996
- slot.gt(ask.order.slot.addn(ask.order.auctionDuration))
997
- ) {
998
- this.orderLists
999
- .get(marketTypeStr)
1000
- .get(marketIndex)
1001
- .signedMsg.ask.remove(ask.order, ask.userAccount);
1002
- } else if (isOrderExpired(ask.order, ts, true, 25)) {
1079
+ const askOrder = getOrderOrThrow(ask);
1080
+ if (ask.isSignedMsg) {
1081
+ if (slot === undefined) {
1082
+ throw new Error(
1083
+ 'Must provide slot to findExpiredNodesToFill to expire signedMsg orders'
1084
+ );
1085
+ }
1086
+ if (slot.gt(askOrder.slot.addn(askOrder.auctionDuration))) {
1087
+ nodeLists.signedMsg.ask.remove(
1088
+ askOrder,
1089
+ getUserAccountOrThrow(ask)
1090
+ );
1091
+ continue;
1092
+ }
1093
+ }
1094
+ if (isOrderExpired(askOrder, ts, true, 25)) {
1003
1095
  nodesToFill.push({
1004
1096
  node: ask,
1005
1097
  makerNodes: [],
@@ -1019,7 +1111,7 @@ export class DLOB {
1019
1111
  const nodesToFill = new Array<NodeToFill>();
1020
1112
 
1021
1113
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1022
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1114
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
1023
1115
 
1024
1116
  if (!nodeLists) {
1025
1117
  return nodesToFill;
@@ -1042,7 +1134,7 @@ export class DLOB {
1042
1134
 
1043
1135
  for (const generator of generators) {
1044
1136
  for (const node of generator) {
1045
- if (!node.order.reduceOnly) {
1137
+ if (!getOrderOrThrow(node).reduceOnly) {
1046
1138
  continue;
1047
1139
  }
1048
1140
 
@@ -1067,7 +1159,7 @@ export class DLOB {
1067
1159
  filterFcn?: DLOBFilterFcn
1068
1160
  ): Generator<DLOBNode> {
1069
1161
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1070
- const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1162
+ const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
1071
1163
  if (!orderLists) {
1072
1164
  return;
1073
1165
  }
@@ -1079,7 +1171,7 @@ export class DLOB {
1079
1171
  orderLists.takingLimit.bid.getGenerator(),
1080
1172
  this.signedMsgGenerator(
1081
1173
  orderLists.signedMsg.bid,
1082
- (x: DLOBNode) => !isRestingLimitOrder(x.order, slot)
1174
+ (x: DLOBNode) => !isRestingLimitOrder(getOrderOrThrow(x), slot)
1083
1175
  ),
1084
1176
  ];
1085
1177
 
@@ -1088,7 +1180,9 @@ export class DLOB {
1088
1180
  oraclePriceData,
1089
1181
  slot,
1090
1182
  (bestNode, currentNode) => {
1091
- return bestNode.order.slot.lt(currentNode.order.slot);
1183
+ return getOrderOrThrow(bestNode).slot.lt(
1184
+ getOrderOrThrow(currentNode).slot
1185
+ );
1092
1186
  },
1093
1187
  filterFcn
1094
1188
  );
@@ -1104,7 +1198,7 @@ export class DLOB {
1104
1198
  filterFcn?: DLOBFilterFcn
1105
1199
  ): Generator<DLOBNode> {
1106
1200
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1107
- const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1201
+ const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
1108
1202
  if (!orderLists) {
1109
1203
  return;
1110
1204
  }
@@ -1116,7 +1210,7 @@ export class DLOB {
1116
1210
  orderLists.takingLimit.ask.getGenerator(),
1117
1211
  this.signedMsgGenerator(
1118
1212
  orderLists.signedMsg.ask,
1119
- (x: DLOBNode) => !isRestingLimitOrder(x.order, slot)
1213
+ (x: DLOBNode) => !isRestingLimitOrder(getOrderOrThrow(x), slot)
1120
1214
  ),
1121
1215
  ];
1122
1216
 
@@ -1125,7 +1219,9 @@ export class DLOB {
1125
1219
  oraclePriceData,
1126
1220
  slot,
1127
1221
  (bestNode, currentNode) => {
1128
- return bestNode.order.slot.lt(currentNode.order.slot);
1222
+ return getOrderOrThrow(bestNode).slot.lt(
1223
+ getOrderOrThrow(currentNode).slot
1224
+ );
1129
1225
  },
1130
1226
  filterFcn
1131
1227
  );
@@ -1218,7 +1314,7 @@ export class DLOB {
1218
1314
  this.updateRestingLimitOrders(slot);
1219
1315
 
1220
1316
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1221
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1317
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
1222
1318
 
1223
1319
  if (!nodeLists) {
1224
1320
  return;
@@ -1228,7 +1324,7 @@ export class DLOB {
1228
1324
  nodeLists.restingLimit.ask.getGenerator(),
1229
1325
  nodeLists.floatingLimit.ask.getGenerator(),
1230
1326
  this.signedMsgGenerator(nodeLists.signedMsg.ask, (x: DLOBNode) =>
1231
- isRestingLimitOrder(x.order, slot)
1327
+ isRestingLimitOrder(getOrderOrThrow(x), slot)
1232
1328
  ),
1233
1329
  ];
1234
1330
 
@@ -1238,8 +1334,8 @@ export class DLOB {
1238
1334
  slot,
1239
1335
  (bestNode, currentNode, slot, oraclePriceData) => {
1240
1336
  return bestNode
1241
- .getPrice(oraclePriceData, slot)
1242
- .lt(currentNode.getPrice(oraclePriceData, slot));
1337
+ .getPriceOrThrow(oraclePriceData, slot)
1338
+ .lt(currentNode.getPriceOrThrow(oraclePriceData, slot));
1243
1339
  },
1244
1340
  filterFcn
1245
1341
  );
@@ -1261,7 +1357,7 @@ export class DLOB {
1261
1357
  this.updateRestingLimitOrders(slot);
1262
1358
 
1263
1359
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1264
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1360
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
1265
1361
 
1266
1362
  if (!nodeLists) {
1267
1363
  return;
@@ -1271,7 +1367,7 @@ export class DLOB {
1271
1367
  nodeLists.restingLimit.bid.getGenerator(),
1272
1368
  nodeLists.floatingLimit.bid.getGenerator(),
1273
1369
  this.signedMsgGenerator(nodeLists.signedMsg.bid, (x: DLOBNode) =>
1274
- isRestingLimitOrder(x.order, slot)
1370
+ isRestingLimitOrder(getOrderOrThrow(x), slot)
1275
1371
  ),
1276
1372
  ];
1277
1373
 
@@ -1281,8 +1377,8 @@ export class DLOB {
1281
1377
  slot,
1282
1378
  (bestNode, currentNode, slot, oraclePriceData) => {
1283
1379
  return bestNode
1284
- .getPrice(oraclePriceData, slot)
1285
- .gt(currentNode.getPrice(oraclePriceData, slot));
1380
+ .getPriceOrThrow(oraclePriceData, slot)
1381
+ .gt(currentNode.getPriceOrThrow(oraclePriceData, slot));
1286
1382
  },
1287
1383
  filterFcn
1288
1384
  );
@@ -1326,7 +1422,9 @@ export class DLOB {
1326
1422
  currentNode.getPrice(oraclePriceData, slot) ?? ZERO;
1327
1423
 
1328
1424
  if (bestNodePrice.eq(currentNodePrice)) {
1329
- return bestNode.order.slot.lt(currentNode.order.slot);
1425
+ return getOrderOrThrow(bestNode).slot.lt(
1426
+ getOrderOrThrow(currentNode).slot
1427
+ );
1330
1428
  }
1331
1429
 
1332
1430
  return bestNodePrice.lt(currentNodePrice);
@@ -1374,7 +1472,9 @@ export class DLOB {
1374
1472
  currentNode.getPrice(oraclePriceData, slot) ?? BN_MAX;
1375
1473
 
1376
1474
  if (bestNodePrice.eq(currentNodePrice)) {
1377
- return bestNode.order.slot.lt(currentNode.order.slot);
1475
+ return getOrderOrThrow(bestNode).slot.lt(
1476
+ getOrderOrThrow(currentNode).slot
1477
+ );
1378
1478
  }
1379
1479
 
1380
1480
  return bestNodePrice.gt(currentNodePrice);
@@ -1407,16 +1507,16 @@ export class DLOB {
1407
1507
  );
1408
1508
 
1409
1509
  for (const bidNode of bidGenerator) {
1410
- const bidPrice = bidNode.getPrice(oraclePriceData, slot);
1411
- const askPrice = askNode.getPrice(oraclePriceData, slot);
1510
+ const bidPrice = bidNode.getPriceOrThrow(oraclePriceData, slot);
1511
+ const askPrice = askNode.getPriceOrThrow(oraclePriceData, slot);
1412
1512
 
1413
1513
  // orders don't cross
1414
1514
  if (bidPrice.lt(askPrice)) {
1415
1515
  break;
1416
1516
  }
1417
1517
 
1418
- const bidOrder = bidNode.order;
1419
- const askOrder = askNode.order;
1518
+ const bidOrder = getOrderOrThrow(bidNode);
1519
+ const askOrder = getOrderOrThrow(askNode);
1420
1520
 
1421
1521
  // Can't match orders from the same user
1422
1522
  const sameUser = bidNode.userAccount === askNode.userAccount;
@@ -1445,18 +1545,18 @@ export class DLOB {
1445
1545
  const newBidOrder = { ...bidOrder };
1446
1546
  newBidOrder.baseAssetAmountFilled =
1447
1547
  bidOrder.baseAssetAmountFilled.add(baseFilled);
1448
- this.getListForOnChainOrder(newBidOrder, slot).update(
1548
+ this.getListForOnChainOrderOrThrow(newBidOrder, slot).update(
1449
1549
  newBidOrder,
1450
- bidNode.userAccount
1550
+ getUserAccountOrThrow(bidNode)
1451
1551
  );
1452
1552
 
1453
1553
  // ask completely filled
1454
1554
  const newAskOrder = { ...askOrder };
1455
1555
  newAskOrder.baseAssetAmountFilled =
1456
1556
  askOrder.baseAssetAmountFilled.add(baseFilled);
1457
- this.getListForOnChainOrder(newAskOrder, slot).update(
1557
+ this.getListForOnChainOrderOrThrow(newAskOrder, slot).update(
1458
1558
  newAskOrder,
1459
- askNode.userAccount
1559
+ getUserAccountOrThrow(askNode)
1460
1560
  );
1461
1561
 
1462
1562
  nodesToFill.push({
@@ -1477,21 +1577,19 @@ export class DLOB {
1477
1577
  askNode: DLOBNode,
1478
1578
  bidNode: DLOBNode
1479
1579
  ): { takerNode: DLOBNode; makerNode: DLOBNode } | undefined {
1480
- const askSlot = askNode.order.slot.add(
1481
- new BN(askNode.order.auctionDuration)
1482
- );
1483
- const bidSlot = bidNode.order.slot.add(
1484
- new BN(bidNode.order.auctionDuration)
1485
- );
1580
+ const askOrder = getOrderOrThrow(askNode);
1581
+ const bidOrder = getOrderOrThrow(bidNode);
1582
+ const askSlot = askOrder.slot.add(new BN(askOrder.auctionDuration));
1583
+ const bidSlot = bidOrder.slot.add(new BN(bidOrder.auctionDuration));
1486
1584
 
1487
- if (bidNode.order.postOnly && askNode.order.postOnly) {
1585
+ if (bidOrder.postOnly && askOrder.postOnly) {
1488
1586
  return undefined;
1489
- } else if (bidNode.order.postOnly) {
1587
+ } else if (bidOrder.postOnly) {
1490
1588
  return {
1491
1589
  takerNode: askNode,
1492
1590
  makerNode: bidNode,
1493
1591
  };
1494
- } else if (askNode.order.postOnly) {
1592
+ } else if (askOrder.postOnly) {
1495
1593
  return {
1496
1594
  takerNode: bidNode,
1497
1595
  makerNode: askNode,
@@ -1557,17 +1655,17 @@ export class DLOB {
1557
1655
  direction: PositionDirection
1558
1656
  ): Generator<DLOBNode> {
1559
1657
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1560
- const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1658
+ const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
1561
1659
 
1562
1660
  if (isVariant(direction, 'long') && marketNodeLists.trigger.below) {
1563
1661
  for (const node of marketNodeLists.trigger.below.getGenerator()) {
1564
- if (isVariant(node.order.direction, 'short')) {
1662
+ if (isVariant(getOrderOrThrow(node).direction, 'short')) {
1565
1663
  yield node;
1566
1664
  }
1567
1665
  }
1568
1666
  } else if (isVariant(direction, 'short') && marketNodeLists.trigger.above) {
1569
1667
  for (const node of marketNodeLists.trigger.above.getGenerator()) {
1570
- if (isVariant(node.order.direction, 'long')) {
1668
+ if (isVariant(getOrderOrThrow(node).direction, 'long')) {
1571
1669
  yield node;
1572
1670
  }
1573
1671
  }
@@ -1580,7 +1678,7 @@ export class DLOB {
1580
1678
  direction: PositionDirection
1581
1679
  ): Generator<DLOBNode> {
1582
1680
  for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
1583
- if (isVariant(node.order.orderType, 'triggerMarket')) {
1681
+ if (isVariant(getOrderOrThrow(node).orderType, 'triggerMarket')) {
1584
1682
  yield node;
1585
1683
  }
1586
1684
  }
@@ -1592,7 +1690,7 @@ export class DLOB {
1592
1690
  direction: PositionDirection
1593
1691
  ): Generator<DLOBNode> {
1594
1692
  for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
1595
- if (isVariant(node.order.orderType, 'triggerLimit')) {
1693
+ if (isVariant(getOrderOrThrow(node).orderType, 'triggerLimit')) {
1596
1694
  yield node;
1597
1695
  }
1598
1696
  }
@@ -1604,17 +1702,17 @@ export class DLOB {
1604
1702
  direction: PositionDirection
1605
1703
  ): Generator<DLOBNode> {
1606
1704
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1607
- const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1705
+ const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
1608
1706
 
1609
1707
  if (isVariant(direction, 'long') && marketNodeLists.trigger.above) {
1610
1708
  for (const node of marketNodeLists.trigger.above.getGenerator()) {
1611
- if (isVariant(node.order.direction, 'short')) {
1709
+ if (isVariant(getOrderOrThrow(node).direction, 'short')) {
1612
1710
  yield node;
1613
1711
  }
1614
1712
  }
1615
1713
  } else if (isVariant(direction, 'short') && marketNodeLists.trigger.below) {
1616
1714
  for (const node of marketNodeLists.trigger.below.getGenerator()) {
1617
- if (isVariant(node.order.direction, 'long')) {
1715
+ if (isVariant(getOrderOrThrow(node).direction, 'long')) {
1618
1716
  yield node;
1619
1717
  }
1620
1718
  }
@@ -1631,7 +1729,7 @@ export class DLOB {
1631
1729
  marketType,
1632
1730
  direction
1633
1731
  )) {
1634
- if (isVariant(node.order.orderType, 'triggerMarket')) {
1732
+ if (isVariant(getOrderOrThrow(node).orderType, 'triggerMarket')) {
1635
1733
  yield node;
1636
1734
  }
1637
1735
  }
@@ -1647,7 +1745,7 @@ export class DLOB {
1647
1745
  marketType,
1648
1746
  direction
1649
1747
  )) {
1650
- if (isVariant(node.order.orderType, 'triggerLimit')) {
1748
+ if (isVariant(getOrderOrThrow(node).orderType, 'triggerLimit')) {
1651
1749
  yield node;
1652
1750
  }
1653
1751
  }
@@ -1664,15 +1762,21 @@ export class DLOB {
1664
1762
  return [];
1665
1763
  }
1666
1764
 
1667
- const nodesToTrigger = [];
1765
+ const nodesToTrigger: NodeToTrigger[] = [];
1668
1766
  const marketTypeStr = getVariant(marketType) as MarketTypeStr;
1669
- const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
1767
+ const marketNodeLists = this.orderLists
1768
+ .get(marketTypeStr)
1769
+ ?.get(marketIndex);
1670
1770
 
1671
1771
  const triggerAboveList = marketNodeLists
1672
1772
  ? marketNodeLists.trigger.above
1673
1773
  : undefined;
1674
1774
  if (triggerAboveList) {
1675
- for (const node of triggerAboveList.getGenerator()) {
1775
+ for (
1776
+ let node = triggerAboveList.head;
1777
+ node !== undefined;
1778
+ node = node.next
1779
+ ) {
1676
1780
  if (triggerPrice.gt(node.order.triggerPrice)) {
1677
1781
  nodesToTrigger.push({
1678
1782
  node: node,
@@ -1687,7 +1791,11 @@ export class DLOB {
1687
1791
  ? marketNodeLists.trigger.below
1688
1792
  : undefined;
1689
1793
  if (triggerBelowList) {
1690
- for (const node of triggerBelowList.getGenerator()) {
1794
+ for (
1795
+ let node = triggerBelowList.head;
1796
+ node !== undefined;
1797
+ node = node.next
1798
+ ) {
1691
1799
  if (triggerPrice.lt(node.order.triggerPrice)) {
1692
1800
  nodesToTrigger.push({
1693
1801
  node: node,
@@ -1702,7 +1810,7 @@ export class DLOB {
1702
1810
  }
1703
1811
 
1704
1812
  public printTop(
1705
- driftClient: VelocityClient,
1813
+ velocityClient: VelocityClient,
1706
1814
  slotSubscriber: SlotSubscriber,
1707
1815
  marketIndex: number,
1708
1816
  marketType: MarketType
@@ -1710,7 +1818,7 @@ export class DLOB {
1710
1818
  if (isVariant(marketType, 'perp')) {
1711
1819
  const slot = slotSubscriber.getSlot();
1712
1820
  const oraclePriceData =
1713
- driftClient.getMMOracleDataForPerpMarket(marketIndex);
1821
+ velocityClient.getMMOracleDataForPerpMarket(marketIndex);
1714
1822
 
1715
1823
  const bestAsk = this.getBestAsk(
1716
1824
  marketIndex,
@@ -1724,6 +1832,11 @@ export class DLOB {
1724
1832
  marketType,
1725
1833
  oraclePriceData
1726
1834
  );
1835
+ if (bestAsk === undefined || bestBid === undefined) {
1836
+ throw new Error(
1837
+ `printTop requires both a best ask and best bid for market ${marketIndex}`
1838
+ );
1839
+ }
1727
1840
  const mid = bestAsk.add(bestBid).div(new BN(2));
1728
1841
 
1729
1842
  const bidSpread =
@@ -1738,7 +1851,7 @@ export class DLOB {
1738
1851
  100.0;
1739
1852
 
1740
1853
  const name = decodeName(
1741
- driftClient.getPerpMarketAccount(marketIndex).name
1854
+ velocityClient.getPerpMarketAccountOrThrow(marketIndex).name
1742
1855
  );
1743
1856
  console.log(`Market ${name} Orders`);
1744
1857
  console.log(
@@ -1755,7 +1868,7 @@ export class DLOB {
1755
1868
  } else if (isVariant(marketType, 'spot')) {
1756
1869
  const slot = slotSubscriber.getSlot();
1757
1870
  const oraclePriceData =
1758
- driftClient.getOracleDataForSpotMarket(marketIndex);
1871
+ velocityClient.getOracleDataForSpotMarket(marketIndex);
1759
1872
 
1760
1873
  const bestAsk = this.getBestAsk(
1761
1874
  marketIndex,
@@ -1769,6 +1882,11 @@ export class DLOB {
1769
1882
  MarketType.SPOT,
1770
1883
  oraclePriceData
1771
1884
  );
1885
+ if (bestAsk === undefined || bestBid === undefined) {
1886
+ throw new Error(
1887
+ `printTop requires both a best ask and best bid for market ${marketIndex}`
1888
+ );
1889
+ }
1772
1890
  const mid = bestAsk.add(bestBid).div(new BN(2));
1773
1891
 
1774
1892
  const bidSpread =
@@ -1783,7 +1901,7 @@ export class DLOB {
1783
1901
  100.0;
1784
1902
 
1785
1903
  const name = decodeName(
1786
- driftClient.getSpotMarketAccount(marketIndex).name
1904
+ velocityClient.getSpotMarketAccountOrThrow(marketIndex).name
1787
1905
  );
1788
1906
  console.log(`Market ${name} Orders`);
1789
1907
  console.log(
@@ -1806,8 +1924,8 @@ export class DLOB {
1806
1924
  for (const nodeList of this.getNodeLists()) {
1807
1925
  for (const node of nodeList.getGenerator()) {
1808
1926
  dlobOrders.push({
1809
- user: new PublicKey(node.userAccount),
1810
- order: node.order,
1927
+ user: new PublicKey(getUserAccountOrThrow(node)),
1928
+ order: getOrderOrThrow(node),
1811
1929
  });
1812
1930
  }
1813
1931
  }
@@ -1816,7 +1934,7 @@ export class DLOB {
1816
1934
  }
1817
1935
 
1818
1936
  *getNodeLists(): Generator<NodeList<DLOBNodeType>> {
1819
- for (const [_, nodeLists] of this.orderLists.get('perp')) {
1937
+ for (const [_, nodeLists] of this.getOrderListsForMarketType('perp')) {
1820
1938
  yield nodeLists.restingLimit.bid;
1821
1939
  yield nodeLists.restingLimit.ask;
1822
1940
  yield nodeLists.takingLimit.bid;
@@ -1829,7 +1947,7 @@ export class DLOB {
1829
1947
  yield nodeLists.trigger.below;
1830
1948
  }
1831
1949
 
1832
- for (const [_, nodeLists] of this.orderLists.get('spot')) {
1950
+ for (const [_, nodeLists] of this.getOrderListsForMarketType('spot')) {
1833
1951
  yield nodeLists.restingLimit.bid;
1834
1952
  yield nodeLists.restingLimit.ask;
1835
1953
  yield nodeLists.takingLimit.bid;
@@ -1949,11 +2067,12 @@ export class DLOB {
1949
2067
  );
1950
2068
 
1951
2069
  for (const ask of restingAsks) {
2070
+ const askOrder = getOrderOrThrow(ask);
1952
2071
  asks.push({
1953
- price: ask.getPrice(oraclePriceData, slot),
1954
- size: ask.order.baseAssetAmount.sub(ask.order.baseAssetAmountFilled),
1955
- maker: new PublicKey(ask.userAccount),
1956
- orderId: ask.order.orderId,
2072
+ price: ask.getPriceOrThrow(oraclePriceData, slot),
2073
+ size: askOrder.baseAssetAmount.sub(askOrder.baseAssetAmountFilled),
2074
+ maker: new PublicKey(getUserAccountOrThrow(ask)),
2075
+ orderId: askOrder.orderId,
1957
2076
  });
1958
2077
  }
1959
2078
 
@@ -1965,11 +2084,12 @@ export class DLOB {
1965
2084
  );
1966
2085
 
1967
2086
  for (const bid of restingBids) {
2087
+ const bidOrder = getOrderOrThrow(bid);
1968
2088
  bids.push({
1969
- price: bid.getPrice(oraclePriceData, slot),
1970
- size: bid.order.baseAssetAmount.sub(bid.order.baseAssetAmountFilled),
1971
- maker: new PublicKey(bid.userAccount),
1972
- orderId: bid.order.orderId,
2089
+ price: bid.getPriceOrThrow(oraclePriceData, slot),
2090
+ size: bidOrder.baseAssetAmount.sub(bidOrder.baseAssetAmountFilled),
2091
+ maker: new PublicKey(getUserAccountOrThrow(bid)),
2092
+ orderId: bidOrder.orderId,
1973
2093
  });
1974
2094
  }
1975
2095
 
@@ -1989,9 +2109,10 @@ export class DLOB {
1989
2109
  let runningSumQuote = ZERO;
1990
2110
  let runningSumBase = ZERO;
1991
2111
  for (const side of dlobSide) {
1992
- const price = side.getPrice(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
1993
- const baseAmountRemaining = side.order.baseAssetAmount.sub(
1994
- side.order.baseAssetAmountFilled
2112
+ const price = side.getPriceOrThrow(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
2113
+ const sideOrder = getOrderOrThrow(side);
2114
+ const baseAmountRemaining = sideOrder.baseAssetAmount.sub(
2115
+ sideOrder.baseAssetAmountFilled
1995
2116
  );
1996
2117
  if (runningSumBase.add(baseAmountRemaining).gt(baseAmountIn)) {
1997
2118
  const remainingBase = baseAmountIn.sub(runningSumBase);
@@ -2051,6 +2172,11 @@ export class DLOB {
2051
2172
  this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
2052
2173
  );
2053
2174
  }
2175
+ throw new Error(
2176
+ `Invalid order direction ${getVariant(
2177
+ orderDirection
2178
+ )}: must be long or short`
2179
+ );
2054
2180
  }
2055
2181
 
2056
2182
  public getBestMakers<T extends MarketType>({
@@ -2081,11 +2207,9 @@ export class DLOB {
2081
2207
  );
2082
2208
 
2083
2209
  for (const node of generator) {
2084
- if (!makers.has(node.userAccount.toString())) {
2085
- makers.set(
2086
- node.userAccount.toString(),
2087
- new PublicKey(node.userAccount)
2088
- );
2210
+ const userAccount = getUserAccountOrThrow(node);
2211
+ if (!makers.has(userAccount)) {
2212
+ makers.set(userAccount, new PublicKey(userAccount));
2089
2213
  }
2090
2214
 
2091
2215
  if (makers.size === numMakers) {