@velocity-exchange/sdk 0.1.0 → 0.2.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 (761) hide show
  1. package/CHANGELOG.md +4 -32
  2. package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +5 -3
  3. package/lib/browser/accounts/basicUserAccountSubscriber.js +4 -3
  4. package/lib/browser/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
  5. package/lib/browser/accounts/basicUserStatsAccountSubscriber.js +4 -3
  6. package/lib/browser/accounts/bulkAccountLoader.d.ts +5 -5
  7. package/lib/browser/accounts/bulkAccountLoader.js +12 -1
  8. package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -1
  9. package/lib/browser/accounts/grpcAccountSubscriber.js +8 -2
  10. package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
  11. package/lib/browser/accounts/grpcMultiAccountSubscriber.js +13 -5
  12. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
  13. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +12 -8
  14. package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
  15. package/lib/browser/accounts/grpcProgramAccountSubscriber.js +8 -2
  16. package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +18 -3
  17. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -1
  18. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +40 -17
  19. package/lib/browser/accounts/laserProgramAccountSubscriber.js +3 -0
  20. package/lib/browser/accounts/oneShotUserAccountSubscriber.js +4 -3
  21. package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
  22. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  23. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
  24. package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
  25. package/lib/browser/accounts/pollingOracleAccountSubscriber.js +16 -5
  26. package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
  27. package/lib/browser/accounts/pollingTokenAccountSubscriber.js +16 -5
  28. package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +8 -4
  29. package/lib/browser/accounts/pollingUserAccountSubscriber.js +17 -11
  30. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
  31. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +6 -6
  32. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -1
  33. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +64 -28
  34. package/lib/browser/accounts/types.d.ts +4 -4
  35. package/lib/browser/accounts/utils.d.ts +1 -0
  36. package/lib/browser/accounts/utils.js +8 -1
  37. package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +4 -2
  38. package/lib/browser/accounts/webSocketAccountSubscriber.js +17 -5
  39. package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
  40. package/lib/browser/accounts/webSocketAccountSubscriberV2.js +17 -6
  41. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  42. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
  43. package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
  44. package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +14 -3
  45. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
  46. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
  47. package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
  48. package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
  49. package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
  50. package/lib/browser/accounts/webSocketUserAccountSubscriber.js +9 -0
  51. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
  52. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
  53. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -4
  54. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +48 -20
  55. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -3
  56. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +45 -14
  57. package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
  58. package/lib/browser/accounts/websocketProgramUserAccountSubscriber.js +0 -3
  59. package/lib/browser/addresses/marketAddresses.js +3 -2
  60. package/lib/browser/addresses/pda.d.ts +0 -2
  61. package/lib/browser/addresses/pda.js +1 -14
  62. package/lib/browser/adminClient.d.ts +24 -29
  63. package/lib/browser/adminClient.js +156 -157
  64. package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +1 -1
  65. package/lib/browser/auctionSubscriber/auctionSubscriber.js +6 -4
  66. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -1
  67. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
  68. package/lib/browser/bankrun/bankrunConnection.d.ts +8 -5
  69. package/lib/browser/bankrun/bankrunConnection.js +92 -32
  70. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
  71. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +3 -2
  72. package/lib/browser/clock/clockSubscriber.d.ts +6 -6
  73. package/lib/browser/clock/clockSubscriber.js +4 -3
  74. package/lib/browser/config.d.ts +1 -1
  75. package/lib/browser/config.js +8 -4
  76. package/lib/browser/constants/index.d.ts +1 -2
  77. package/lib/browser/constants/index.js +1 -2
  78. package/lib/browser/constants/numericConstants.d.ts +1 -2
  79. package/lib/browser/constants/numericConstants.js +7 -5
  80. package/lib/browser/constants/spotMarkets.d.ts +0 -1
  81. package/lib/browser/constituentMap/constituentMap.js +5 -1
  82. package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
  83. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
  84. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
  85. package/lib/browser/core/VelocityCore.d.ts +0 -1
  86. package/lib/browser/core/instructions/deposit.d.ts +0 -1
  87. package/lib/browser/core/instructions/perpOrders.d.ts +14 -0
  88. package/lib/browser/core/instructions/perpOrders.js +14 -0
  89. package/lib/browser/core/instructions/withdraw.d.ts +0 -1
  90. package/lib/browser/core/remainingAccounts.d.ts +2 -2
  91. package/lib/browser/core/remainingAccounts.js +2 -2
  92. package/lib/browser/decode/user.js +9 -1
  93. package/lib/browser/dlob/DLOB.d.ts +6 -2
  94. package/lib/browser/dlob/DLOB.js +201 -138
  95. package/lib/browser/dlob/DLOBNode.d.ts +5 -3
  96. package/lib/browser/dlob/DLOBNode.js +7 -0
  97. package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -1
  98. package/lib/browser/dlob/DLOBSubscriber.js +37 -32
  99. package/lib/browser/dlob/NodeList.d.ts +0 -1
  100. package/lib/browser/dlob/NodeList.js +8 -7
  101. package/lib/browser/dlob/orderBookLevels.d.ts +0 -1
  102. package/lib/browser/dlob/orderBookLevels.js +19 -12
  103. package/lib/browser/events/eventList.d.ts +3 -3
  104. package/lib/browser/events/eventList.js +4 -1
  105. package/lib/browser/events/eventSubscriber.d.ts +5 -2
  106. package/lib/browser/events/eventSubscriber.js +75 -26
  107. package/lib/browser/events/eventsServerLogProvider.d.ts +2 -2
  108. package/lib/browser/events/eventsServerLogProvider.js +15 -8
  109. package/lib/browser/events/fetchLogs.d.ts +1 -1
  110. package/lib/browser/events/fetchLogs.js +4 -2
  111. package/lib/browser/events/pollingLogProvider.d.ts +2 -2
  112. package/lib/browser/events/pollingLogProvider.js +1 -0
  113. package/lib/browser/events/txEventCache.d.ts +3 -3
  114. package/lib/browser/events/txEventCache.js +6 -2
  115. package/lib/browser/events/types.d.ts +2 -4
  116. package/lib/browser/events/types.js +0 -2
  117. package/lib/browser/events/webSocketLogProvider.d.ts +2 -2
  118. package/lib/browser/events/webSocketLogProvider.js +5 -2
  119. package/lib/browser/factory/bigNum.d.ts +0 -1
  120. package/lib/browser/factory/bigNum.js +1 -1
  121. package/lib/browser/idl/velocity.d.ts +1243 -1586
  122. package/lib/browser/idl/velocity.json +1234 -1577
  123. package/lib/browser/index.d.ts +0 -2
  124. package/lib/browser/index.js +0 -2
  125. package/lib/browser/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
  126. package/lib/browser/jupiter/jupiterClient.d.ts +1 -2
  127. package/lib/browser/jupiter/jupiterClient.js +18 -8
  128. package/lib/browser/marginCalculation.d.ts +0 -1
  129. package/lib/browser/marginCalculation.js +1 -0
  130. package/lib/browser/marinade/index.d.ts +2 -3
  131. package/lib/browser/marinade/index.js +5 -0
  132. package/lib/browser/math/amm.d.ts +31 -14
  133. package/lib/browser/math/amm.js +77 -22
  134. package/lib/browser/math/auction.d.ts +0 -1
  135. package/lib/browser/math/bankruptcy.js +1 -1
  136. package/lib/browser/math/conversion.d.ts +0 -1
  137. package/lib/browser/math/funding.d.ts +0 -1
  138. package/lib/browser/math/funding.js +6 -6
  139. package/lib/browser/math/insurance.d.ts +1 -2
  140. package/lib/browser/math/insurance.js +4 -5
  141. package/lib/browser/math/liquidation.d.ts +0 -1
  142. package/lib/browser/math/margin.d.ts +1 -10
  143. package/lib/browser/math/margin.js +3 -62
  144. package/lib/browser/math/market.d.ts +4 -13
  145. package/lib/browser/math/market.js +6 -40
  146. package/lib/browser/math/oracles.d.ts +0 -4
  147. package/lib/browser/math/oracles.js +1 -14
  148. package/lib/browser/math/orders.d.ts +0 -6
  149. package/lib/browser/math/orders.js +2 -74
  150. package/lib/browser/math/position.d.ts +1 -6
  151. package/lib/browser/math/position.js +5 -10
  152. package/lib/browser/math/repeg.d.ts +0 -2
  153. package/lib/browser/math/repeg.js +1 -23
  154. package/lib/browser/math/spotBalance.d.ts +4 -5
  155. package/lib/browser/math/spotBalance.js +6 -6
  156. package/lib/browser/math/spotMarket.d.ts +0 -7
  157. package/lib/browser/math/spotMarket.js +1 -16
  158. package/lib/browser/math/spotPosition.d.ts +4 -5
  159. package/lib/browser/math/state.d.ts +0 -3
  160. package/lib/browser/math/state.js +1 -9
  161. package/lib/browser/math/superStake.d.ts +3 -54
  162. package/lib/browser/math/superStake.js +16 -13
  163. package/lib/browser/math/trade.d.ts +2 -3
  164. package/lib/browser/math/trade.js +6 -6
  165. package/lib/browser/math/utils.d.ts +0 -1
  166. package/lib/browser/memcmp.d.ts +0 -1
  167. package/lib/browser/memcmp.js +1 -10
  168. package/lib/browser/oracles/oracleClientCache.d.ts +1 -1
  169. package/lib/browser/oracles/prelaunchOracleClient.js +3 -2
  170. package/lib/browser/oracles/pythClient.d.ts +0 -1
  171. package/lib/browser/oracles/pythClient.js +9 -3
  172. package/lib/browser/oracles/pythLazerClient.d.ts +0 -1
  173. package/lib/browser/oracles/pythLazerClient.js +3 -2
  174. package/lib/browser/oracles/strictOraclePrice.d.ts +0 -1
  175. package/lib/browser/oracles/types.d.ts +0 -1
  176. package/lib/browser/oracles/utils.d.ts +4 -1
  177. package/lib/browser/oracles/utils.js +9 -1
  178. package/lib/browser/orderParams.d.ts +0 -1
  179. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -1
  180. package/lib/browser/orderSubscriber/OrderSubscriber.js +8 -2
  181. package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
  182. package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +1 -1
  183. package/lib/browser/priorityFee/priorityFeeSubscriber.js +32 -8
  184. package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
  185. package/lib/browser/pyth/types.d.ts +0 -1
  186. package/lib/browser/slot/SlotSubscriber.d.ts +1 -1
  187. package/lib/browser/slot/SlotSubscriber.js +2 -1
  188. package/lib/browser/slot/SlothashSubscriber.d.ts +3 -2
  189. package/lib/browser/slot/SlothashSubscriber.js +11 -4
  190. package/lib/browser/swap/UnifiedSwapClient.d.ts +0 -1
  191. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
  192. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
  193. package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +3 -2
  194. package/lib/browser/swift/signedMsgUserAccountSubscriber.js +13 -5
  195. package/lib/browser/swift/swiftOrderSubscriber.d.ts +1 -1
  196. package/lib/browser/swift/swiftOrderSubscriber.js +10 -5
  197. package/lib/browser/testClient.js +3 -2
  198. package/lib/browser/titan/titanClient.d.ts +0 -1
  199. package/lib/browser/tokenFaucet.d.ts +0 -1
  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 +9 -3
  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 +25 -69
  217. package/lib/browser/types.js +2 -2
  218. package/lib/browser/user.d.ts +21 -8
  219. package/lib/browser/user.js +156 -132
  220. package/lib/browser/userMap/WebsocketSubscription.d.ts +1 -1
  221. package/lib/browser/userMap/grpcSubscription.d.ts +1 -1
  222. package/lib/browser/userMap/referrerMap.js +10 -3
  223. package/lib/browser/userMap/revenueShareEscrowMap.js +4 -0
  224. package/lib/browser/userMap/userMap.d.ts +1 -1
  225. package/lib/browser/userMap/userMap.js +36 -23
  226. package/lib/browser/userMap/userStatsMap.d.ts +1 -1
  227. package/lib/browser/userMap/userStatsMap.js +18 -13
  228. package/lib/browser/userStats.d.ts +7 -2
  229. package/lib/browser/userStats.js +18 -4
  230. package/lib/browser/util/TransactionConfirmationManager.js +4 -2
  231. package/lib/browser/util/chainClock.d.ts +1 -1
  232. package/lib/browser/util/computeUnits.d.ts +1 -1
  233. package/lib/browser/util/computeUnits.js +6 -1
  234. package/lib/browser/velocityClient.d.ts +93 -36
  235. package/lib/browser/velocityClient.js +414 -280
  236. package/lib/node/accounts/basicUserAccountSubscriber.d.ts +5 -3
  237. package/lib/node/accounts/basicUserAccountSubscriber.d.ts.map +1 -1
  238. package/lib/node/accounts/basicUserAccountSubscriber.js +4 -3
  239. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
  240. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts.map +1 -1
  241. package/lib/node/accounts/basicUserStatsAccountSubscriber.js +4 -3
  242. package/lib/node/accounts/bulkAccountLoader.d.ts +5 -5
  243. package/lib/node/accounts/bulkAccountLoader.d.ts.map +1 -1
  244. package/lib/node/accounts/bulkAccountLoader.js +12 -1
  245. package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -1
  246. package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
  247. package/lib/node/accounts/grpcAccountSubscriber.js +8 -2
  248. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
  249. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  250. package/lib/node/accounts/grpcMultiAccountSubscriber.js +13 -5
  251. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
  252. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
  253. package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +12 -8
  254. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
  255. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
  256. package/lib/node/accounts/grpcProgramAccountSubscriber.js +8 -2
  257. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
  258. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +18 -3
  259. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -1
  260. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  261. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +40 -17
  262. package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
  263. package/lib/node/accounts/laserProgramAccountSubscriber.js +3 -0
  264. package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
  265. package/lib/node/accounts/oneShotUserAccountSubscriber.js +4 -3
  266. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
  267. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
  268. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  269. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  270. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
  271. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
  272. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
  273. package/lib/node/accounts/pollingOracleAccountSubscriber.js +16 -5
  274. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
  275. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
  276. package/lib/node/accounts/pollingTokenAccountSubscriber.js +16 -5
  277. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +8 -4
  278. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts.map +1 -1
  279. package/lib/node/accounts/pollingUserAccountSubscriber.js +17 -11
  280. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
  281. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
  282. package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +6 -6
  283. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -1
  284. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
  285. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +64 -28
  286. package/lib/node/accounts/types.d.ts +4 -4
  287. package/lib/node/accounts/types.d.ts.map +1 -1
  288. package/lib/node/accounts/utils.d.ts +1 -0
  289. package/lib/node/accounts/utils.d.ts.map +1 -1
  290. package/lib/node/accounts/utils.js +8 -1
  291. package/lib/node/accounts/webSocketAccountSubscriber.d.ts +4 -2
  292. package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
  293. package/lib/node/accounts/webSocketAccountSubscriber.js +17 -5
  294. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
  295. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
  296. package/lib/node/accounts/webSocketAccountSubscriberV2.js +17 -6
  297. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  298. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  299. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
  300. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
  301. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
  302. package/lib/node/accounts/webSocketProgramAccountSubscriber.js +14 -3
  303. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
  304. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
  305. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
  306. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
  307. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
  308. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
  309. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
  310. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
  311. package/lib/node/accounts/webSocketUserAccountSubscriber.js +9 -0
  312. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
  313. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
  314. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
  315. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -4
  316. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
  317. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +48 -20
  318. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -3
  319. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  320. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +45 -14
  321. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
  322. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
  323. package/lib/node/accounts/websocketProgramUserAccountSubscriber.js +0 -3
  324. package/lib/node/addresses/marketAddresses.d.ts.map +1 -1
  325. package/lib/node/addresses/marketAddresses.js +3 -2
  326. package/lib/node/addresses/pda.d.ts +0 -2
  327. package/lib/node/addresses/pda.d.ts.map +1 -1
  328. package/lib/node/addresses/pda.js +1 -14
  329. package/lib/node/adminClient.d.ts +24 -29
  330. package/lib/node/adminClient.d.ts.map +1 -1
  331. package/lib/node/adminClient.js +156 -157
  332. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +1 -1
  333. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
  334. package/lib/node/auctionSubscriber/auctionSubscriber.js +6 -4
  335. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -1
  336. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
  337. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
  338. package/lib/node/bankrun/bankrunConnection.d.ts +8 -5
  339. package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
  340. package/lib/node/bankrun/bankrunConnection.js +92 -32
  341. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
  342. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts.map +1 -1
  343. package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +3 -2
  344. package/lib/node/clock/clockSubscriber.d.ts +6 -6
  345. package/lib/node/clock/clockSubscriber.d.ts.map +1 -1
  346. package/lib/node/clock/clockSubscriber.js +4 -3
  347. package/lib/node/config.d.ts +1 -1
  348. package/lib/node/config.d.ts.map +1 -1
  349. package/lib/node/config.js +8 -4
  350. package/lib/node/constants/index.d.ts +1 -2
  351. package/lib/node/constants/index.d.ts.map +1 -1
  352. package/lib/node/constants/index.js +1 -2
  353. package/lib/node/constants/numericConstants.d.ts +1 -2
  354. package/lib/node/constants/numericConstants.d.ts.map +1 -1
  355. package/lib/node/constants/numericConstants.js +7 -5
  356. package/lib/node/constants/spotMarkets.d.ts +0 -1
  357. package/lib/node/constants/spotMarkets.d.ts.map +1 -1
  358. package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
  359. package/lib/node/constituentMap/constituentMap.js +5 -1
  360. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -1
  361. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
  362. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
  363. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -1
  364. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
  365. package/lib/node/core/VelocityCore.d.ts +0 -1
  366. package/lib/node/core/VelocityCore.d.ts.map +1 -1
  367. package/lib/node/core/instructions/deposit.d.ts +0 -1
  368. package/lib/node/core/instructions/deposit.d.ts.map +1 -1
  369. package/lib/node/core/instructions/perpOrders.d.ts +14 -0
  370. package/lib/node/core/instructions/perpOrders.d.ts.map +1 -1
  371. package/lib/node/core/instructions/perpOrders.js +14 -0
  372. package/lib/node/core/instructions/withdraw.d.ts +0 -1
  373. package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
  374. package/lib/node/core/remainingAccounts.d.ts +2 -2
  375. package/lib/node/core/remainingAccounts.d.ts.map +1 -1
  376. package/lib/node/core/remainingAccounts.js +2 -2
  377. package/lib/node/decode/user.d.ts.map +1 -1
  378. package/lib/node/decode/user.js +9 -1
  379. package/lib/node/dlob/DLOB.d.ts +6 -2
  380. package/lib/node/dlob/DLOB.d.ts.map +1 -1
  381. package/lib/node/dlob/DLOB.js +201 -138
  382. package/lib/node/dlob/DLOBNode.d.ts +5 -3
  383. package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
  384. package/lib/node/dlob/DLOBNode.js +7 -0
  385. package/lib/node/dlob/DLOBSubscriber.d.ts +0 -1
  386. package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
  387. package/lib/node/dlob/DLOBSubscriber.js +37 -32
  388. package/lib/node/dlob/NodeList.d.ts +0 -1
  389. package/lib/node/dlob/NodeList.d.ts.map +1 -1
  390. package/lib/node/dlob/NodeList.js +8 -7
  391. package/lib/node/dlob/orderBookLevels.d.ts +0 -1
  392. package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
  393. package/lib/node/dlob/orderBookLevels.js +19 -12
  394. package/lib/node/events/eventList.d.ts +3 -3
  395. package/lib/node/events/eventList.d.ts.map +1 -1
  396. package/lib/node/events/eventList.js +4 -1
  397. package/lib/node/events/eventSubscriber.d.ts +5 -2
  398. package/lib/node/events/eventSubscriber.d.ts.map +1 -1
  399. package/lib/node/events/eventSubscriber.js +75 -26
  400. package/lib/node/events/eventsServerLogProvider.d.ts +2 -2
  401. package/lib/node/events/eventsServerLogProvider.d.ts.map +1 -1
  402. package/lib/node/events/eventsServerLogProvider.js +15 -8
  403. package/lib/node/events/fetchLogs.d.ts +1 -1
  404. package/lib/node/events/fetchLogs.d.ts.map +1 -1
  405. package/lib/node/events/fetchLogs.js +4 -2
  406. package/lib/node/events/pollingLogProvider.d.ts +2 -2
  407. package/lib/node/events/pollingLogProvider.d.ts.map +1 -1
  408. package/lib/node/events/pollingLogProvider.js +1 -0
  409. package/lib/node/events/txEventCache.d.ts +3 -3
  410. package/lib/node/events/txEventCache.d.ts.map +1 -1
  411. package/lib/node/events/txEventCache.js +6 -2
  412. package/lib/node/events/types.d.ts +2 -4
  413. package/lib/node/events/types.d.ts.map +1 -1
  414. package/lib/node/events/types.js +0 -2
  415. package/lib/node/events/webSocketLogProvider.d.ts +2 -2
  416. package/lib/node/events/webSocketLogProvider.d.ts.map +1 -1
  417. package/lib/node/events/webSocketLogProvider.js +5 -2
  418. package/lib/node/factory/bigNum.d.ts +0 -1
  419. package/lib/node/factory/bigNum.d.ts.map +1 -1
  420. package/lib/node/factory/bigNum.js +1 -1
  421. package/lib/node/idl/velocity.d.ts +1243 -1586
  422. package/lib/node/idl/velocity.d.ts.map +1 -1
  423. package/lib/node/idl/velocity.json +1234 -1577
  424. package/lib/node/index.d.ts +0 -2
  425. package/lib/node/index.d.ts.map +1 -1
  426. package/lib/node/index.js +0 -2
  427. package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts +0 -1
  428. package/lib/node/indicative-quotes/indicativeQuotesSender.d.ts.map +1 -1
  429. package/lib/node/jupiter/jupiterClient.d.ts +1 -2
  430. package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
  431. package/lib/node/jupiter/jupiterClient.js +18 -8
  432. package/lib/node/marginCalculation.d.ts +0 -1
  433. package/lib/node/marginCalculation.d.ts.map +1 -1
  434. package/lib/node/marginCalculation.js +1 -0
  435. package/lib/node/marinade/index.d.ts +2 -3
  436. package/lib/node/marinade/index.d.ts.map +1 -1
  437. package/lib/node/marinade/index.js +5 -0
  438. package/lib/node/math/amm.d.ts +31 -14
  439. package/lib/node/math/amm.d.ts.map +1 -1
  440. package/lib/node/math/amm.js +77 -22
  441. package/lib/node/math/auction.d.ts +0 -1
  442. package/lib/node/math/auction.d.ts.map +1 -1
  443. package/lib/node/math/bankruptcy.js +1 -1
  444. package/lib/node/math/conversion.d.ts +0 -1
  445. package/lib/node/math/conversion.d.ts.map +1 -1
  446. package/lib/node/math/funding.d.ts +0 -1
  447. package/lib/node/math/funding.d.ts.map +1 -1
  448. package/lib/node/math/funding.js +6 -6
  449. package/lib/node/math/insurance.d.ts +1 -2
  450. package/lib/node/math/insurance.d.ts.map +1 -1
  451. package/lib/node/math/insurance.js +4 -5
  452. package/lib/node/math/liquidation.d.ts +0 -1
  453. package/lib/node/math/liquidation.d.ts.map +1 -1
  454. package/lib/node/math/margin.d.ts +1 -10
  455. package/lib/node/math/margin.d.ts.map +1 -1
  456. package/lib/node/math/margin.js +3 -62
  457. package/lib/node/math/market.d.ts +4 -13
  458. package/lib/node/math/market.d.ts.map +1 -1
  459. package/lib/node/math/market.js +6 -40
  460. package/lib/node/math/oracles.d.ts +0 -4
  461. package/lib/node/math/oracles.d.ts.map +1 -1
  462. package/lib/node/math/oracles.js +1 -14
  463. package/lib/node/math/orders.d.ts +0 -6
  464. package/lib/node/math/orders.d.ts.map +1 -1
  465. package/lib/node/math/orders.js +2 -74
  466. package/lib/node/math/position.d.ts +1 -6
  467. package/lib/node/math/position.d.ts.map +1 -1
  468. package/lib/node/math/position.js +5 -10
  469. package/lib/node/math/repeg.d.ts +0 -2
  470. package/lib/node/math/repeg.d.ts.map +1 -1
  471. package/lib/node/math/repeg.js +1 -23
  472. package/lib/node/math/spotBalance.d.ts +4 -5
  473. package/lib/node/math/spotBalance.d.ts.map +1 -1
  474. package/lib/node/math/spotBalance.js +6 -6
  475. package/lib/node/math/spotMarket.d.ts +0 -7
  476. package/lib/node/math/spotMarket.d.ts.map +1 -1
  477. package/lib/node/math/spotMarket.js +1 -16
  478. package/lib/node/math/spotPosition.d.ts +4 -5
  479. package/lib/node/math/spotPosition.d.ts.map +1 -1
  480. package/lib/node/math/state.d.ts +0 -3
  481. package/lib/node/math/state.d.ts.map +1 -1
  482. package/lib/node/math/state.js +1 -9
  483. package/lib/node/math/superStake.d.ts +3 -54
  484. package/lib/node/math/superStake.d.ts.map +1 -1
  485. package/lib/node/math/superStake.js +16 -13
  486. package/lib/node/math/trade.d.ts +2 -3
  487. package/lib/node/math/trade.d.ts.map +1 -1
  488. package/lib/node/math/trade.js +6 -6
  489. package/lib/node/math/utils.d.ts +0 -1
  490. package/lib/node/math/utils.d.ts.map +1 -1
  491. package/lib/node/memcmp.d.ts +0 -1
  492. package/lib/node/memcmp.d.ts.map +1 -1
  493. package/lib/node/memcmp.js +1 -10
  494. package/lib/node/oracles/oracleClientCache.d.ts +1 -1
  495. package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
  496. package/lib/node/oracles/prelaunchOracleClient.js +3 -2
  497. package/lib/node/oracles/pythClient.d.ts +0 -1
  498. package/lib/node/oracles/pythClient.d.ts.map +1 -1
  499. package/lib/node/oracles/pythClient.js +9 -3
  500. package/lib/node/oracles/pythLazerClient.d.ts +0 -1
  501. package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
  502. package/lib/node/oracles/pythLazerClient.js +3 -2
  503. package/lib/node/oracles/strictOraclePrice.d.ts +0 -1
  504. package/lib/node/oracles/strictOraclePrice.d.ts.map +1 -1
  505. package/lib/node/oracles/types.d.ts +0 -1
  506. package/lib/node/oracles/types.d.ts.map +1 -1
  507. package/lib/node/oracles/utils.d.ts +4 -1
  508. package/lib/node/oracles/utils.d.ts.map +1 -1
  509. package/lib/node/oracles/utils.js +9 -1
  510. package/lib/node/orderParams.d.ts +0 -1
  511. package/lib/node/orderParams.d.ts.map +1 -1
  512. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -1
  513. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  514. package/lib/node/orderSubscriber/OrderSubscriber.js +8 -2
  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 +1 -1
  518. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
  519. package/lib/node/priorityFee/priorityFeeSubscriber.js +32 -8
  520. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
  521. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
  522. package/lib/node/pyth/types.d.ts +0 -1
  523. package/lib/node/pyth/types.d.ts.map +1 -1
  524. package/lib/node/slot/SlotSubscriber.d.ts +1 -1
  525. package/lib/node/slot/SlotSubscriber.d.ts.map +1 -1
  526. package/lib/node/slot/SlotSubscriber.js +2 -1
  527. package/lib/node/slot/SlothashSubscriber.d.ts +3 -2
  528. package/lib/node/slot/SlothashSubscriber.d.ts.map +1 -1
  529. package/lib/node/slot/SlothashSubscriber.js +11 -4
  530. package/lib/node/swap/UnifiedSwapClient.d.ts +0 -1
  531. package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
  532. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
  533. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
  534. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
  535. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +3 -2
  536. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
  537. package/lib/node/swift/signedMsgUserAccountSubscriber.js +13 -5
  538. package/lib/node/swift/swiftOrderSubscriber.d.ts +1 -1
  539. package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
  540. package/lib/node/swift/swiftOrderSubscriber.js +10 -5
  541. package/lib/node/testClient.js +3 -2
  542. package/lib/node/titan/titanClient.d.ts +0 -1
  543. package/lib/node/titan/titanClient.d.ts.map +1 -1
  544. package/lib/node/tokenFaucet.d.ts +0 -1
  545. package/lib/node/tokenFaucet.d.ts.map +1 -1
  546. package/lib/node/tokenFaucet.js +16 -2
  547. package/lib/node/tx/baseTxSender.d.ts +4 -4
  548. package/lib/node/tx/baseTxSender.d.ts.map +1 -1
  549. package/lib/node/tx/baseTxSender.js +5 -4
  550. package/lib/node/tx/fastSingleTxSender.d.ts +3 -3
  551. package/lib/node/tx/fastSingleTxSender.d.ts.map +1 -1
  552. package/lib/node/tx/fastSingleTxSender.js +9 -5
  553. package/lib/node/tx/reportTransactionError.d.ts +2 -2
  554. package/lib/node/tx/reportTransactionError.d.ts.map +1 -1
  555. package/lib/node/tx/reportTransactionError.js +5 -1
  556. package/lib/node/tx/retryTxSender.d.ts +1 -1
  557. package/lib/node/tx/retryTxSender.d.ts.map +1 -1
  558. package/lib/node/tx/retryTxSender.js +4 -2
  559. package/lib/node/tx/txHandler.d.ts +9 -3
  560. package/lib/node/tx/txHandler.d.ts.map +1 -1
  561. package/lib/node/tx/txHandler.js +54 -40
  562. package/lib/node/tx/txParamProcessor.d.ts +4 -1
  563. package/lib/node/tx/txParamProcessor.d.ts.map +1 -1
  564. package/lib/node/tx/txParamProcessor.js +6 -0
  565. package/lib/node/tx/types.d.ts +1 -1
  566. package/lib/node/tx/types.d.ts.map +1 -1
  567. package/lib/node/tx/whileValidTxSender.d.ts +1 -6
  568. package/lib/node/tx/whileValidTxSender.d.ts.map +1 -1
  569. package/lib/node/tx/whileValidTxSender.js +35 -13
  570. package/lib/node/types.d.ts +25 -69
  571. package/lib/node/types.d.ts.map +1 -1
  572. package/lib/node/types.js +2 -2
  573. package/lib/node/user.d.ts +21 -8
  574. package/lib/node/user.d.ts.map +1 -1
  575. package/lib/node/user.js +156 -132
  576. package/lib/node/userMap/WebsocketSubscription.d.ts +1 -1
  577. package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
  578. package/lib/node/userMap/grpcSubscription.d.ts +1 -1
  579. package/lib/node/userMap/grpcSubscription.d.ts.map +1 -1
  580. package/lib/node/userMap/referrerMap.d.ts.map +1 -1
  581. package/lib/node/userMap/referrerMap.js +10 -3
  582. package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
  583. package/lib/node/userMap/revenueShareEscrowMap.js +4 -0
  584. package/lib/node/userMap/userMap.d.ts +1 -1
  585. package/lib/node/userMap/userMap.d.ts.map +1 -1
  586. package/lib/node/userMap/userMap.js +36 -23
  587. package/lib/node/userMap/userStatsMap.d.ts +1 -1
  588. package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
  589. package/lib/node/userMap/userStatsMap.js +18 -13
  590. package/lib/node/userStats.d.ts +7 -2
  591. package/lib/node/userStats.d.ts.map +1 -1
  592. package/lib/node/userStats.js +18 -4
  593. package/lib/node/util/TransactionConfirmationManager.d.ts.map +1 -1
  594. package/lib/node/util/TransactionConfirmationManager.js +4 -2
  595. package/lib/node/util/chainClock.d.ts +1 -1
  596. package/lib/node/util/chainClock.d.ts.map +1 -1
  597. package/lib/node/util/computeUnits.d.ts +1 -1
  598. package/lib/node/util/computeUnits.d.ts.map +1 -1
  599. package/lib/node/util/computeUnits.js +6 -1
  600. package/lib/node/velocityClient.d.ts +93 -36
  601. package/lib/node/velocityClient.d.ts.map +1 -1
  602. package/lib/node/velocityClient.js +414 -280
  603. package/package.json +15 -8
  604. package/src/accounts/basicUserAccountSubscriber.ts +7 -5
  605. package/src/accounts/basicUserStatsAccountSubscriber.ts +9 -5
  606. package/src/accounts/bulkAccountLoader.ts +20 -7
  607. package/src/accounts/grpcAccountSubscriber.ts +11 -3
  608. package/src/accounts/grpcMultiAccountSubscriber.ts +24 -9
  609. package/src/accounts/grpcMultiUserAccountSubscriber.ts +16 -12
  610. package/src/accounts/grpcProgramAccountSubscriber.ts +11 -3
  611. package/src/accounts/grpcVelocityClientAccountSubscriber.ts +17 -7
  612. package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +66 -39
  613. package/src/accounts/laserProgramAccountSubscriber.ts +3 -0
  614. package/src/accounts/oneShotUserAccountSubscriber.ts +5 -3
  615. package/src/accounts/oneShotUserStatsAccountSubscriber.ts +8 -3
  616. package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +11 -5
  617. package/src/accounts/pollingOracleAccountSubscriber.ts +17 -10
  618. package/src/accounts/pollingTokenAccountSubscriber.ts +17 -10
  619. package/src/accounts/pollingUserAccountSubscriber.ts +26 -20
  620. package/src/accounts/pollingUserStatsAccountSubscriber.ts +12 -10
  621. package/src/accounts/pollingVelocityClientAccountSubscriber.ts +76 -30
  622. package/src/accounts/types.ts +6 -4
  623. package/src/accounts/utils.ts +10 -0
  624. package/src/accounts/webSocketAccountSubscriber.ts +23 -10
  625. package/src/accounts/webSocketAccountSubscriberV2.ts +23 -8
  626. package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +17 -2
  627. package/src/accounts/webSocketProgramAccountSubscriber.ts +29 -4
  628. package/src/accounts/webSocketProgramAccountSubscriberV2.ts +30 -4
  629. package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +29 -4
  630. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -2
  631. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +15 -2
  632. package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +76 -48
  633. package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +74 -35
  634. package/src/accounts/websocketProgramUserAccountSubscriber.ts +1 -6
  635. package/src/addresses/marketAddresses.ts +3 -2
  636. package/src/addresses/pda.ts +0 -25
  637. package/src/adminClient.ts +273 -303
  638. package/src/auctionSubscriber/auctionSubscriber.ts +7 -5
  639. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -5
  640. package/src/bankrun/bankrunConnection.ts +110 -40
  641. package/src/blockhashSubscriber/BlockhashSubscriber.ts +5 -4
  642. package/src/clock/clockSubscriber.ts +10 -9
  643. package/src/config.ts +8 -3
  644. package/src/constants/index.ts +1 -2
  645. package/src/constants/numericConstants.ts +8 -4
  646. package/src/constituentMap/constituentMap.ts +8 -1
  647. package/src/constituentMap/pollingConstituentAccountSubscriber.ts +4 -2
  648. package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +13 -4
  649. package/src/core/instructions/perpOrders.ts +14 -0
  650. package/src/core/remainingAccounts.ts +4 -4
  651. package/src/decode/user.ts +8 -1
  652. package/src/dlob/DLOB.ts +296 -172
  653. package/src/dlob/DLOBNode.ts +23 -3
  654. package/src/dlob/DLOBSubscriber.ts +51 -34
  655. package/src/dlob/NodeList.ts +8 -7
  656. package/src/dlob/orderBookLevels.ts +45 -25
  657. package/src/events/eventList.ts +4 -1
  658. package/src/events/eventSubscriber.ts +107 -49
  659. package/src/events/eventsServerLogProvider.ts +22 -13
  660. package/src/events/fetchLogs.ts +3 -3
  661. package/src/events/pollingLogProvider.ts +2 -2
  662. package/src/events/txEventCache.ts +8 -2
  663. package/src/events/types.ts +0 -8
  664. package/src/events/webSocketLogProvider.ts +5 -3
  665. package/src/factory/bigNum.ts +2 -2
  666. package/src/idl/velocity.json +1234 -1577
  667. package/src/idl/velocity.ts +1234 -1577
  668. package/src/index.ts +0 -2
  669. package/src/jupiter/jupiterClient.ts +30 -10
  670. package/src/marginCalculation.ts +1 -0
  671. package/src/marinade/index.ts +11 -2
  672. package/src/math/amm.ts +188 -33
  673. package/src/math/bankruptcy.ts +1 -1
  674. package/src/math/funding.ts +7 -6
  675. package/src/math/insurance.ts +6 -8
  676. package/src/math/margin.ts +5 -112
  677. package/src/math/market.ts +6 -96
  678. package/src/math/oracles.ts +0 -17
  679. package/src/math/orders.ts +1 -110
  680. package/src/math/position.ts +4 -16
  681. package/src/math/repeg.ts +0 -29
  682. package/src/math/spotBalance.ts +14 -10
  683. package/src/math/spotMarket.ts +2 -28
  684. package/src/math/spotPosition.ts +4 -4
  685. package/src/math/state.ts +0 -8
  686. package/src/math/superStake.ts +19 -65
  687. package/src/math/trade.ts +2 -6
  688. package/src/memcmp.ts +0 -9
  689. package/src/oracles/prelaunchOracleClient.ts +7 -2
  690. package/src/oracles/pythClient.ts +12 -3
  691. package/src/oracles/pythLazerClient.ts +7 -2
  692. package/src/oracles/utils.ts +15 -0
  693. package/src/orderSubscriber/OrderSubscriber.ts +10 -4
  694. package/src/priorityFee/heliusPriorityFeeMethod.ts +1 -1
  695. package/src/priorityFee/priorityFeeSubscriber.ts +45 -9
  696. package/src/priorityFee/solanaPriorityFeeMethod.ts +1 -1
  697. package/src/pyth/types.ts +0 -2
  698. package/src/slot/SlotSubscriber.ts +3 -3
  699. package/src/slot/SlothashSubscriber.ts +17 -6
  700. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +5 -6
  701. package/src/swift/signedMsgUserAccountSubscriber.ts +16 -8
  702. package/src/swift/swiftOrderSubscriber.ts +10 -9
  703. package/src/testClient.ts +2 -2
  704. package/src/tokenFaucet.ts +22 -3
  705. package/src/tx/baseTxSender.ts +10 -10
  706. package/src/tx/fastSingleTxSender.ts +12 -8
  707. package/src/tx/reportTransactionError.ts +12 -7
  708. package/src/tx/retryTxSender.ts +6 -4
  709. package/src/tx/txHandler.ts +88 -43
  710. package/src/tx/txParamProcessor.ts +18 -3
  711. package/src/tx/types.ts +1 -1
  712. package/src/tx/whileValidTxSender.ts +51 -22
  713. package/src/types.ts +39 -75
  714. package/src/user.ts +200 -152
  715. package/src/userMap/WebsocketSubscription.ts +1 -1
  716. package/src/userMap/grpcSubscription.ts +1 -1
  717. package/src/userMap/referrerMap.ts +14 -10
  718. package/src/userMap/revenueShareEscrowMap.ts +8 -3
  719. package/src/userMap/userMap.ts +43 -25
  720. package/src/userMap/userStatsMap.ts +32 -19
  721. package/src/userStats.ts +21 -8
  722. package/src/util/TransactionConfirmationManager.ts +10 -2
  723. package/src/util/chainClock.ts +1 -1
  724. package/src/util/computeUnits.ts +7 -3
  725. package/src/velocityClient.ts +536 -383
  726. package/tests/VelocityCore/remainingAccounts.test.ts +4 -5
  727. package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +19 -11
  728. package/tests/amm/test.ts +300 -95
  729. package/tests/decode/userAccountBufferStrings.ts +100 -100
  730. package/tests/dlob/helpers.ts +162 -173
  731. package/tests/dlob/test.ts +155 -106
  732. package/tests/tx/TransactionConfirmationManager.test.ts +9 -2
  733. package/tests/user/getMarginCalculation.ts +1 -1
  734. package/tests/user/helpers.ts +3 -4
  735. package/tests/user/marginCalculations.test.ts +2 -2
  736. package/tests/user/test.ts +3 -3
  737. package/tsconfig.browser.json +3 -1
  738. package/tsconfig.json +21 -2
  739. package/.yarn/install-state.gz +0 -0
  740. package/VERSION +0 -1
  741. package/bun.lock +0 -1885
  742. package/lib/browser/constants/insuranceFund.d.ts +0 -5
  743. package/lib/browser/constants/insuranceFund.js +0 -9
  744. package/lib/browser/tx/forwardOnlyTxSender.d.ts +0 -37
  745. package/lib/browser/tx/forwardOnlyTxSender.js +0 -92
  746. package/lib/browser/util/tps.d.ts +0 -2
  747. package/lib/browser/util/tps.js +0 -16
  748. package/lib/node/constants/insuranceFund.d.ts +0 -6
  749. package/lib/node/constants/insuranceFund.d.ts.map +0 -1
  750. package/lib/node/constants/insuranceFund.js +0 -9
  751. package/lib/node/tx/forwardOnlyTxSender.d.ts +0 -38
  752. package/lib/node/tx/forwardOnlyTxSender.d.ts.map +0 -1
  753. package/lib/node/tx/forwardOnlyTxSender.js +0 -92
  754. package/lib/node/util/tps.d.ts +0 -3
  755. package/lib/node/util/tps.d.ts.map +0 -1
  756. package/lib/node/util/tps.js +0 -16
  757. package/scripts/updateVersion.js +0 -28
  758. package/src/constants/insuranceFund.ts +0 -8
  759. package/src/tx/forwardOnlyTxSender.ts +0 -145
  760. package/src/util/tps.ts +0 -27
  761. package/tests/decode/phoenix.ts +0 -71
@@ -31,6 +31,18 @@ const SUPPORTED_ORDER_TYPES = [
31
31
  'triggerLimit',
32
32
  'oracle',
33
33
  ];
34
+ function getOrderOrThrow(node) {
35
+ if (!node.order) {
36
+ throw new Error('DLOBNode must have an order');
37
+ }
38
+ return node.order;
39
+ }
40
+ function getUserAccountOrThrow(node) {
41
+ if (node.userAccount === undefined) {
42
+ throw new Error('DLOBNode must have a userAccount');
43
+ }
44
+ return node.userAccount;
45
+ }
34
46
  class DLOB {
35
47
  constructor() {
36
48
  this.openOrders = new Map();
@@ -45,19 +57,41 @@ class DLOB {
45
57
  this.orderLists.set('perp', new Map());
46
58
  this.orderLists.set('spot', new Map());
47
59
  }
60
+ getOpenOrdersForMarketType(marketTypeStr) {
61
+ const openOrders = this.openOrders.get(marketTypeStr);
62
+ if (!openOrders) {
63
+ throw new Error(`DLOB has no open orders set for market type ${marketTypeStr}`);
64
+ }
65
+ return openOrders;
66
+ }
67
+ getOrderListsForMarketType(marketTypeStr) {
68
+ const orderLists = this.orderLists.get(marketTypeStr);
69
+ if (!orderLists) {
70
+ throw new Error(`DLOB has no order lists for market type ${marketTypeStr}`);
71
+ }
72
+ return orderLists;
73
+ }
74
+ tryGetMarketNodeLists(marketTypeStr, marketIndex) {
75
+ var _a;
76
+ return (_a = this.orderLists.get(marketTypeStr)) === null || _a === void 0 ? void 0 : _a.get(marketIndex);
77
+ }
78
+ getMarketNodeLists(marketTypeStr, marketIndex) {
79
+ const marketNodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
80
+ if (!marketNodeLists) {
81
+ throw new Error(`DLOB has no order lists for market type ${marketTypeStr} and market index ${marketIndex}`);
82
+ }
83
+ return marketNodeLists;
84
+ }
48
85
  clear() {
49
- for (const marketType of this.openOrders.keys()) {
50
- this.openOrders.get(marketType).clear();
86
+ for (const openOrders of this.openOrders.values()) {
87
+ openOrders.clear();
51
88
  }
52
89
  this.openOrders.clear();
53
- for (const marketType of this.orderLists.keys()) {
54
- for (const marketIndex of this.orderLists.get(marketType).keys()) {
55
- const marketNodeLists = this.orderLists
56
- .get(marketType)
57
- .get(marketIndex);
58
- for (const side of Object.keys(marketNodeLists)) {
59
- for (const orderType of Object.keys(marketNodeLists[side])) {
60
- marketNodeLists[side][orderType].clear();
90
+ for (const marketNodeListsMap of this.orderLists.values()) {
91
+ for (const marketNodeLists of marketNodeListsMap.values()) {
92
+ for (const side of Object.values(marketNodeLists)) {
93
+ for (const nodeList of Object.values(side)) {
94
+ nodeList.clear();
61
95
  }
62
96
  }
63
97
  }
@@ -78,7 +112,7 @@ class DLOB {
78
112
  }
79
113
  // initialize the dlob with the user map
80
114
  for (const user of userMap.values()) {
81
- const userAccount = user.getUserAccount();
115
+ const userAccount = user.getUserAccountOrThrow();
82
116
  const userAccountPubkey = user.getUserAccountPublicKey();
83
117
  const userAccountPubkeyString = userAccountPubkey.toString();
84
118
  for (const order of userAccount.orders) {
@@ -102,13 +136,11 @@ class DLOB {
102
136
  return;
103
137
  }
104
138
  const marketType = (0, types_1.getVariant)(order.marketType);
105
- if (!this.orderLists.get(marketType).has(order.marketIndex)) {
139
+ if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
106
140
  this.addOrderList(marketType, order.marketIndex);
107
141
  }
108
142
  if ((0, types_1.isVariant)(order.status, 'open')) {
109
- this.openOrders
110
- .get(marketType)
111
- .add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
143
+ this.getOpenOrdersForMarketType(marketType).add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
112
144
  }
113
145
  (_a = this.getListForOnChainOrder(order, slot)) === null || _a === void 0 ? void 0 : _a.insert(order, marketType, userAccount, baseAssetAmount);
114
146
  if (onInsert) {
@@ -119,22 +151,17 @@ class DLOB {
119
151
  const marketType = (0, types_1.getVariant)(order.marketType);
120
152
  const marketIndex = order.marketIndex;
121
153
  const bidOrAsk = (0, types_1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
122
- if (!this.orderLists.get(marketType).has(order.marketIndex)) {
154
+ if (!this.getOrderListsForMarketType(marketType).has(order.marketIndex)) {
123
155
  this.addOrderList(marketType, order.marketIndex);
124
156
  }
125
- this.openOrders
126
- .get(marketType)
127
- .add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
128
- this.orderLists
129
- .get(marketType)
130
- .get(marketIndex)
131
- .signedMsg[bidOrAsk].insert(order, marketType, userAccount, baseAssetAmount);
157
+ this.getOpenOrdersForMarketType(marketType).add((0, NodeList_1.getOrderSignature)(order.orderId, userAccount));
158
+ this.getMarketNodeLists(marketType, marketIndex).signedMsg[bidOrAsk].insert(order, marketType, userAccount, baseAssetAmount);
132
159
  if (onInsert) {
133
160
  onInsert();
134
161
  }
135
162
  }
136
163
  addOrderList(marketType, marketIndex) {
137
- this.orderLists.get(marketType).set(marketIndex, {
164
+ this.getOrderListsForMarketType(marketType).set(marketIndex, {
138
165
  restingLimit: {
139
166
  ask: new NodeList_1.NodeList('restingLimit', 'asc'),
140
167
  bid: new NodeList_1.NodeList('restingLimit', 'desc'),
@@ -174,32 +201,37 @@ class DLOB {
174
201
  }
175
202
  getListForOnChainOrder(order, slot) {
176
203
  const isInactiveTriggerOrder = (0, orders_1.mustBeTriggered)(order) && !(0, orders_1.isTriggered)(order);
177
- let type;
204
+ const marketType = (0, types_1.getVariant)(order.marketType);
205
+ const marketNodeLists = this.tryGetMarketNodeLists(marketType, order.marketIndex);
206
+ if (!marketNodeLists) {
207
+ return undefined;
208
+ }
178
209
  if (isInactiveTriggerOrder) {
179
- type = 'trigger';
210
+ const subType = (0, types_1.isVariant)(order.triggerCondition, 'above')
211
+ ? 'above'
212
+ : 'below';
213
+ return marketNodeLists.trigger[subType];
180
214
  }
181
- else if ((0, types_1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket', 'oracle'])) {
182
- type = 'market';
215
+ const subType = (0, types_1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
216
+ if ((0, types_1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket', 'oracle'])) {
217
+ return marketNodeLists.market[subType];
183
218
  }
184
219
  else if (!order.oraclePriceOffset.eq(numericConstants_1.ZERO)) {
185
- type = 'floatingLimit';
220
+ return marketNodeLists.floatingLimit[subType];
186
221
  }
187
222
  else {
188
223
  const isResting = (0, orders_1.isRestingLimitOrder)(order, slot);
189
- type = isResting ? 'restingLimit' : 'takingLimit';
224
+ return isResting
225
+ ? marketNodeLists.restingLimit[subType]
226
+ : marketNodeLists.takingLimit[subType];
190
227
  }
191
- let subType;
192
- if (isInactiveTriggerOrder) {
193
- subType = (0, types_1.isVariant)(order.triggerCondition, 'above') ? 'above' : 'below';
194
- }
195
- else {
196
- subType = (0, types_1.isVariant)(order.direction, 'long') ? 'bid' : 'ask';
197
- }
198
- const marketType = (0, types_1.getVariant)(order.marketType);
199
- if (!this.orderLists.has(marketType)) {
200
- return undefined;
228
+ }
229
+ getListForOnChainOrderOrThrow(order, slot) {
230
+ const list = this.getListForOnChainOrder(order, slot);
231
+ if (!list) {
232
+ throw new Error(`No order list found for order ${order.orderId} in market ${order.marketIndex}`);
201
233
  }
202
- return this.orderLists.get(marketType).get(order.marketIndex)[type][subType];
234
+ return list;
203
235
  }
204
236
  updateRestingLimitOrders(slot) {
205
237
  if (slot <= this.maxSlotForRestingLimitOrders) {
@@ -210,10 +242,10 @@ class DLOB {
210
242
  this.updateRestingLimitOrdersForMarketType(slot, 'spot');
211
243
  }
212
244
  updateRestingLimitOrdersForMarketType(slot, marketTypeStr) {
213
- for (const [_, nodeLists] of this.orderLists.get(marketTypeStr)) {
245
+ for (const [_, nodeLists] of this.getOrderListsForMarketType(marketTypeStr)) {
214
246
  const nodesToUpdate = [];
215
247
  for (const node of nodeLists.takingLimit.ask.getGenerator()) {
216
- if (!(0, orders_1.isRestingLimitOrder)(node.order, slot)) {
248
+ if (!(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(node), slot)) {
217
249
  continue;
218
250
  }
219
251
  nodesToUpdate.push({
@@ -222,7 +254,7 @@ class DLOB {
222
254
  });
223
255
  }
224
256
  for (const node of nodeLists.takingLimit.bid.getGenerator()) {
225
- if (!(0, orders_1.isRestingLimitOrder)(node.order, slot)) {
257
+ if (!(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(node), slot)) {
226
258
  continue;
227
259
  }
228
260
  nodesToUpdate.push({
@@ -232,8 +264,10 @@ class DLOB {
232
264
  }
233
265
  for (const nodeToUpdate of nodesToUpdate) {
234
266
  const { side, node } = nodeToUpdate;
235
- nodeLists.takingLimit[side].remove(node.order, node.userAccount);
236
- nodeLists.restingLimit[side].insert(node.order, marketTypeStr, node.userAccount);
267
+ const order = getOrderOrThrow(node);
268
+ const userAccount = getUserAccountOrThrow(node);
269
+ nodeLists.takingLimit[side].remove(order, userAccount);
270
+ nodeLists.restingLimit[side].insert(order, marketTypeStr, userAccount);
237
271
  }
238
272
  }
239
273
  }
@@ -291,17 +325,17 @@ class DLOB {
291
325
  const mergedNodesToFill = new Map();
292
326
  const mergeNodesToFillHelper = (nodesToFillArray) => {
293
327
  nodesToFillArray.forEach((nodeToFill) => {
294
- const nodeSignature = (0, NodeList_1.getOrderSignature)(nodeToFill.node.order.orderId, nodeToFill.node.userAccount);
295
- if (!mergedNodesToFill.has(nodeSignature)) {
296
- mergedNodesToFill.set(nodeSignature, {
328
+ const nodeSignature = (0, NodeList_1.getOrderSignature)(getOrderOrThrow(nodeToFill.node).orderId, getUserAccountOrThrow(nodeToFill.node));
329
+ let mergedNodeToFill = mergedNodesToFill.get(nodeSignature);
330
+ if (!mergedNodeToFill) {
331
+ mergedNodeToFill = {
297
332
  node: nodeToFill.node,
298
333
  makerNodes: [],
299
- });
334
+ };
335
+ mergedNodesToFill.set(nodeSignature, mergedNodeToFill);
300
336
  }
301
337
  if (nodeToFill.makerNodes) {
302
- mergedNodesToFill
303
- .get(nodeSignature)
304
- .makerNodes.push(...nodeToFill.makerNodes);
338
+ mergedNodeToFill.makerNodes.push(...nodeToFill.makerNodes);
305
339
  }
306
340
  });
307
341
  };
@@ -319,6 +353,9 @@ class DLOB {
319
353
  const askGenerator = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
320
354
  const fallbackBidWithBuffer = fallbackBid.sub(fallbackBid.muln(makerRebateNumerator).divn(makerRebateDenominator));
321
355
  const asksCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, askGenerator, (askPrice) => {
356
+ if (askPrice === undefined) {
357
+ throw new Error('Resting limit ask must have a limit price');
358
+ }
322
359
  return askPrice.lte(fallbackBidWithBuffer);
323
360
  }, stateAccount, marketAccount);
324
361
  for (const askCrossingFallback of asksCrossingFallback) {
@@ -329,6 +366,9 @@ class DLOB {
329
366
  const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
330
367
  const fallbackAskWithBuffer = fallbackAsk.add(fallbackAsk.muln(makerRebateNumerator).divn(makerRebateDenominator));
331
368
  const bidsCrossingFallback = this.findNodesCrossingFallbackLiquidity(marketType, slot, oraclePriceData, bidGenerator, (bidPrice) => {
369
+ if (bidPrice === undefined) {
370
+ throw new Error('Resting limit bid must have a limit price');
371
+ }
332
372
  return bidPrice.gte(fallbackAskWithBuffer);
333
373
  }, stateAccount, marketAccount);
334
374
  for (const bidCrossingFallback of bidsCrossingFallback) {
@@ -399,7 +439,7 @@ class DLOB {
399
439
  if (sameUser) {
400
440
  continue;
401
441
  }
402
- const makerPrice = makerNode.getPrice(oraclePriceData, slot);
442
+ const makerPrice = makerNode.getPriceOrThrow(oraclePriceData, slot);
403
443
  const takerPrice = takerNode.getPrice(oraclePriceData, slot);
404
444
  const ordersCross = doesCross(takerPrice, makerPrice);
405
445
  if (!ordersCross) {
@@ -411,27 +451,28 @@ class DLOB {
411
451
  node: takerNode,
412
452
  makerNodes: [makerNode],
413
453
  });
414
- const makerOrder = makerNode.order;
415
- const takerOrder = takerNode.order;
454
+ const makerOrder = getOrderOrThrow(makerNode);
455
+ const takerOrder = getOrderOrThrow(takerNode);
416
456
  const makerBaseRemaining = makerOrder.baseAssetAmount.sub(makerOrder.baseAssetAmountFilled);
417
457
  const takerBaseRemaining = takerOrder.baseAssetAmount.sub(takerOrder.baseAssetAmountFilled);
418
458
  const baseFilled = anchor_1.BN.min(makerBaseRemaining, takerBaseRemaining);
419
459
  const newMakerOrder = { ...makerOrder };
420
460
  newMakerOrder.baseAssetAmountFilled =
421
461
  makerOrder.baseAssetAmountFilled.add(baseFilled);
422
- this.getListForOnChainOrder(newMakerOrder, slot).update(newMakerOrder, makerNode.userAccount);
462
+ this.getListForOnChainOrderOrThrow(newMakerOrder, slot).update(newMakerOrder, getUserAccountOrThrow(makerNode));
423
463
  const newTakerOrder = { ...takerOrder };
424
464
  newTakerOrder.baseAssetAmountFilled =
425
465
  takerOrder.baseAssetAmountFilled.add(baseFilled);
426
466
  if (takerNode.isSignedMsg) {
427
467
  const marketTypeStr = (0, types_1.getVariant)(marketType);
468
+ const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
428
469
  const orderList = (0, types_1.isVariant)(takerOrder.direction, 'long')
429
- ? this.orderLists.get(marketTypeStr).get(marketIndex).signedMsg.bid
430
- : this.orderLists.get(marketTypeStr).get(marketIndex).signedMsg.ask;
431
- orderList.update(newTakerOrder, takerNode.userAccount);
470
+ ? marketNodeLists.signedMsg.bid
471
+ : marketNodeLists.signedMsg.ask;
472
+ orderList.update(newTakerOrder, getUserAccountOrThrow(takerNode));
432
473
  }
433
474
  else {
434
- this.getListForOnChainOrder(newTakerOrder, slot).update(newTakerOrder, takerNode.userAccount);
475
+ this.getListForOnChainOrderOrThrow(newTakerOrder, slot).update(newTakerOrder, getUserAccountOrThrow(takerNode));
435
476
  }
436
477
  if (newTakerOrder.baseAssetAmountFilled.eq(takerOrder.baseAssetAmount)) {
437
478
  break;
@@ -450,12 +491,13 @@ class DLOB {
450
491
  nextNode = nodeGenerator.next();
451
492
  continue;
452
493
  }
453
- const nodePrice = (0, orders_1.getLimitPrice)(node.order, oraclePriceData, slot);
494
+ const nodeOrder = getOrderOrThrow(node);
495
+ const nodePrice = (0, orders_1.getLimitPrice)(nodeOrder, oraclePriceData, slot);
454
496
  // order crosses if there is no limit price or it crosses fallback price
455
497
  const crosses = doesCross(nodePrice);
456
498
  // fallback is available if auction is complete or it's a spot order
457
499
  const fallbackAvailable = (0, types_1.isVariant)(marketType, 'spot') ||
458
- (0, auction_1.isFallbackAvailableLiquiditySource)(node.order, oraclePriceData, slot, state, marketAccount);
500
+ (0, auction_1.isFallbackAvailableLiquiditySource)(nodeOrder, oraclePriceData, slot, state, marketAccount);
459
501
  if (crosses && fallbackAvailable) {
460
502
  nodesToFill.push({
461
503
  node: node,
@@ -469,7 +511,7 @@ class DLOB {
469
511
  findExpiredNodesToFill(marketIndex, ts, marketType, slot) {
470
512
  const nodesToFill = new Array();
471
513
  const marketTypeStr = (0, types_1.getVariant)(marketType);
472
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
514
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
473
515
  if (!nodeLists) {
474
516
  return nodesToFill;
475
517
  }
@@ -491,14 +533,17 @@ class DLOB {
491
533
  ];
492
534
  for (const bidGenerator of bidGenerators) {
493
535
  for (const bid of bidGenerator) {
494
- if (bid.isSignedMsg &&
495
- slot.gt(bid.order.slot.addn(bid.order.auctionDuration))) {
496
- this.orderLists
497
- .get(marketTypeStr)
498
- .get(marketIndex)
499
- .signedMsg.bid.remove(bid.order, bid.userAccount);
536
+ const bidOrder = getOrderOrThrow(bid);
537
+ if (bid.isSignedMsg) {
538
+ if (slot === undefined) {
539
+ throw new Error('Must provide slot to findExpiredNodesToFill to expire signedMsg orders');
540
+ }
541
+ if (slot.gt(bidOrder.slot.addn(bidOrder.auctionDuration))) {
542
+ nodeLists.signedMsg.bid.remove(bidOrder, getUserAccountOrThrow(bid));
543
+ continue;
544
+ }
500
545
  }
501
- else if ((0, orders_1.isOrderExpired)(bid.order, ts, true, 25)) {
546
+ if ((0, orders_1.isOrderExpired)(bidOrder, ts, true, 25)) {
502
547
  nodesToFill.push({
503
548
  node: bid,
504
549
  makerNodes: [],
@@ -508,14 +553,17 @@ class DLOB {
508
553
  }
509
554
  for (const askGenerator of askGenerators) {
510
555
  for (const ask of askGenerator) {
511
- if (ask.isSignedMsg &&
512
- slot.gt(ask.order.slot.addn(ask.order.auctionDuration))) {
513
- this.orderLists
514
- .get(marketTypeStr)
515
- .get(marketIndex)
516
- .signedMsg.ask.remove(ask.order, ask.userAccount);
556
+ const askOrder = getOrderOrThrow(ask);
557
+ if (ask.isSignedMsg) {
558
+ if (slot === undefined) {
559
+ throw new Error('Must provide slot to findExpiredNodesToFill to expire signedMsg orders');
560
+ }
561
+ if (slot.gt(askOrder.slot.addn(askOrder.auctionDuration))) {
562
+ nodeLists.signedMsg.ask.remove(askOrder, getUserAccountOrThrow(ask));
563
+ continue;
564
+ }
517
565
  }
518
- else if ((0, orders_1.isOrderExpired)(ask.order, ts, true, 25)) {
566
+ if ((0, orders_1.isOrderExpired)(askOrder, ts, true, 25)) {
519
567
  nodesToFill.push({
520
568
  node: ask,
521
569
  makerNodes: [],
@@ -528,7 +576,7 @@ class DLOB {
528
576
  findUnfillableReduceOnlyOrdersToCancel(marketIndex, marketType, stepSize) {
529
577
  const nodesToFill = new Array();
530
578
  const marketTypeStr = (0, types_1.getVariant)(marketType);
531
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
579
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
532
580
  if (!nodeLists) {
533
581
  return nodesToFill;
534
582
  }
@@ -548,7 +596,7 @@ class DLOB {
548
596
  ];
549
597
  for (const generator of generators) {
550
598
  for (const node of generator) {
551
- if (!node.order.reduceOnly) {
599
+ if (!getOrderOrThrow(node).reduceOnly) {
552
600
  continue;
553
601
  }
554
602
  if (node.baseAssetAmount.lt(stepSize)) {
@@ -563,7 +611,7 @@ class DLOB {
563
611
  }
564
612
  *getTakingBids(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
565
613
  const marketTypeStr = (0, types_1.getVariant)(marketType);
566
- const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
614
+ const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
567
615
  if (!orderLists) {
568
616
  return;
569
617
  }
@@ -571,15 +619,15 @@ class DLOB {
571
619
  const generatorList = [
572
620
  orderLists.market.bid.getGenerator(),
573
621
  orderLists.takingLimit.bid.getGenerator(),
574
- this.signedMsgGenerator(orderLists.signedMsg.bid, (x) => !(0, orders_1.isRestingLimitOrder)(x.order, slot)),
622
+ this.signedMsgGenerator(orderLists.signedMsg.bid, (x) => !(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
575
623
  ];
576
624
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
577
- return bestNode.order.slot.lt(currentNode.order.slot);
625
+ return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
578
626
  }, filterFcn);
579
627
  }
580
628
  *getTakingAsks(marketIndex, marketType, slot, oraclePriceData, filterFcn) {
581
629
  const marketTypeStr = (0, types_1.getVariant)(marketType);
582
- const orderLists = this.orderLists.get(marketTypeStr).get(marketIndex);
630
+ const orderLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
583
631
  if (!orderLists) {
584
632
  return;
585
633
  }
@@ -587,10 +635,10 @@ class DLOB {
587
635
  const generatorList = [
588
636
  orderLists.market.ask.getGenerator(),
589
637
  orderLists.takingLimit.ask.getGenerator(),
590
- this.signedMsgGenerator(orderLists.signedMsg.ask, (x) => !(0, orders_1.isRestingLimitOrder)(x.order, slot)),
638
+ this.signedMsgGenerator(orderLists.signedMsg.ask, (x) => !(0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
591
639
  ];
592
640
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode) => {
593
- return bestNode.order.slot.lt(currentNode.order.slot);
641
+ return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
594
642
  }, filterFcn);
595
643
  }
596
644
  *signedMsgGenerator(signedMsgOrderList, filter) {
@@ -646,19 +694,19 @@ class DLOB {
646
694
  }
647
695
  this.updateRestingLimitOrders(slot);
648
696
  const marketTypeStr = (0, types_1.getVariant)(marketType);
649
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
697
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
650
698
  if (!nodeLists) {
651
699
  return;
652
700
  }
653
701
  const generatorList = [
654
702
  nodeLists.restingLimit.ask.getGenerator(),
655
703
  nodeLists.floatingLimit.ask.getGenerator(),
656
- this.signedMsgGenerator(nodeLists.signedMsg.ask, (x) => (0, orders_1.isRestingLimitOrder)(x.order, slot)),
704
+ this.signedMsgGenerator(nodeLists.signedMsg.ask, (x) => (0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
657
705
  ];
658
706
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
659
707
  return bestNode
660
- .getPrice(oraclePriceData, slot)
661
- .lt(currentNode.getPrice(oraclePriceData, slot));
708
+ .getPriceOrThrow(oraclePriceData, slot)
709
+ .lt(currentNode.getPriceOrThrow(oraclePriceData, slot));
662
710
  }, filterFcn);
663
711
  }
664
712
  *getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData, filterFcn) {
@@ -667,19 +715,19 @@ class DLOB {
667
715
  }
668
716
  this.updateRestingLimitOrders(slot);
669
717
  const marketTypeStr = (0, types_1.getVariant)(marketType);
670
- const nodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
718
+ const nodeLists = this.tryGetMarketNodeLists(marketTypeStr, marketIndex);
671
719
  if (!nodeLists) {
672
720
  return;
673
721
  }
674
722
  const generatorList = [
675
723
  nodeLists.restingLimit.bid.getGenerator(),
676
724
  nodeLists.floatingLimit.bid.getGenerator(),
677
- this.signedMsgGenerator(nodeLists.signedMsg.bid, (x) => (0, orders_1.isRestingLimitOrder)(x.order, slot)),
725
+ this.signedMsgGenerator(nodeLists.signedMsg.bid, (x) => (0, orders_1.isRestingLimitOrder)(getOrderOrThrow(x), slot)),
678
726
  ];
679
727
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
680
728
  return bestNode
681
- .getPrice(oraclePriceData, slot)
682
- .gt(currentNode.getPrice(oraclePriceData, slot));
729
+ .getPriceOrThrow(oraclePriceData, slot)
730
+ .gt(currentNode.getPriceOrThrow(oraclePriceData, slot));
683
731
  }, filterFcn);
684
732
  }
685
733
  /**
@@ -704,7 +752,7 @@ class DLOB {
704
752
  const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : numericConstants_1.ZERO;
705
753
  const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : numericConstants_1.ZERO;
706
754
  if (bestNodePrice.eq(currentNodePrice)) {
707
- return bestNode.order.slot.lt(currentNode.order.slot);
755
+ return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
708
756
  }
709
757
  return bestNodePrice.lt(currentNodePrice);
710
758
  }, filterFcn);
@@ -731,7 +779,7 @@ class DLOB {
731
779
  const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : numericConstants_1.BN_MAX;
732
780
  const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : numericConstants_1.BN_MAX;
733
781
  if (bestNodePrice.eq(currentNodePrice)) {
734
- return bestNode.order.slot.lt(currentNode.order.slot);
782
+ return getOrderOrThrow(bestNode).slot.lt(getOrderOrThrow(currentNode).slot);
735
783
  }
736
784
  return bestNodePrice.gt(currentNodePrice);
737
785
  }, filterFcn);
@@ -741,14 +789,14 @@ class DLOB {
741
789
  for (const askNode of this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData)) {
742
790
  const bidGenerator = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
743
791
  for (const bidNode of bidGenerator) {
744
- const bidPrice = bidNode.getPrice(oraclePriceData, slot);
745
- const askPrice = askNode.getPrice(oraclePriceData, slot);
792
+ const bidPrice = bidNode.getPriceOrThrow(oraclePriceData, slot);
793
+ const askPrice = askNode.getPriceOrThrow(oraclePriceData, slot);
746
794
  // orders don't cross
747
795
  if (bidPrice.lt(askPrice)) {
748
796
  break;
749
797
  }
750
- const bidOrder = bidNode.order;
751
- const askOrder = askNode.order;
798
+ const bidOrder = getOrderOrThrow(bidNode);
799
+ const askOrder = getOrderOrThrow(askNode);
752
800
  // Can't match orders from the same user
753
801
  const sameUser = bidNode.userAccount === askNode.userAccount;
754
802
  if (sameUser) {
@@ -766,12 +814,12 @@ class DLOB {
766
814
  const newBidOrder = { ...bidOrder };
767
815
  newBidOrder.baseAssetAmountFilled =
768
816
  bidOrder.baseAssetAmountFilled.add(baseFilled);
769
- this.getListForOnChainOrder(newBidOrder, slot).update(newBidOrder, bidNode.userAccount);
817
+ this.getListForOnChainOrderOrThrow(newBidOrder, slot).update(newBidOrder, getUserAccountOrThrow(bidNode));
770
818
  // ask completely filled
771
819
  const newAskOrder = { ...askOrder };
772
820
  newAskOrder.baseAssetAmountFilled =
773
821
  askOrder.baseAssetAmountFilled.add(baseFilled);
774
- this.getListForOnChainOrder(newAskOrder, slot).update(newAskOrder, askNode.userAccount);
822
+ this.getListForOnChainOrderOrThrow(newAskOrder, slot).update(newAskOrder, getUserAccountOrThrow(askNode));
775
823
  nodesToFill.push({
776
824
  node: takerNode,
777
825
  makerNodes: [makerNode],
@@ -784,18 +832,20 @@ class DLOB {
784
832
  return nodesToFill;
785
833
  }
786
834
  determineMakerAndTaker(askNode, bidNode) {
787
- const askSlot = askNode.order.slot.add(new anchor_1.BN(askNode.order.auctionDuration));
788
- const bidSlot = bidNode.order.slot.add(new anchor_1.BN(bidNode.order.auctionDuration));
789
- if (bidNode.order.postOnly && askNode.order.postOnly) {
835
+ const askOrder = getOrderOrThrow(askNode);
836
+ const bidOrder = getOrderOrThrow(bidNode);
837
+ const askSlot = askOrder.slot.add(new anchor_1.BN(askOrder.auctionDuration));
838
+ const bidSlot = bidOrder.slot.add(new anchor_1.BN(bidOrder.auctionDuration));
839
+ if (bidOrder.postOnly && askOrder.postOnly) {
790
840
  return undefined;
791
841
  }
792
- else if (bidNode.order.postOnly) {
842
+ else if (bidOrder.postOnly) {
793
843
  return {
794
844
  takerNode: askNode,
795
845
  makerNode: bidNode,
796
846
  };
797
847
  }
798
- else if (askNode.order.postOnly) {
848
+ else if (askOrder.postOnly) {
799
849
  return {
800
850
  takerNode: bidNode,
801
851
  makerNode: askNode,
@@ -830,17 +880,17 @@ class DLOB {
830
880
  }
831
881
  *getStopLosses(marketIndex, marketType, direction) {
832
882
  const marketTypeStr = (0, types_1.getVariant)(marketType);
833
- const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
883
+ const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
834
884
  if ((0, types_1.isVariant)(direction, 'long') && marketNodeLists.trigger.below) {
835
885
  for (const node of marketNodeLists.trigger.below.getGenerator()) {
836
- if ((0, types_1.isVariant)(node.order.direction, 'short')) {
886
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'short')) {
837
887
  yield node;
838
888
  }
839
889
  }
840
890
  }
841
891
  else if ((0, types_1.isVariant)(direction, 'short') && marketNodeLists.trigger.above) {
842
892
  for (const node of marketNodeLists.trigger.above.getGenerator()) {
843
- if ((0, types_1.isVariant)(node.order.direction, 'long')) {
893
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'long')) {
844
894
  yield node;
845
895
  }
846
896
  }
@@ -848,31 +898,31 @@ class DLOB {
848
898
  }
849
899
  *getStopLossMarkets(marketIndex, marketType, direction) {
850
900
  for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
851
- if ((0, types_1.isVariant)(node.order.orderType, 'triggerMarket')) {
901
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerMarket')) {
852
902
  yield node;
853
903
  }
854
904
  }
855
905
  }
856
906
  *getStopLossLimits(marketIndex, marketType, direction) {
857
907
  for (const node of this.getStopLosses(marketIndex, marketType, direction)) {
858
- if ((0, types_1.isVariant)(node.order.orderType, 'triggerLimit')) {
908
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerLimit')) {
859
909
  yield node;
860
910
  }
861
911
  }
862
912
  }
863
913
  *getTakeProfits(marketIndex, marketType, direction) {
864
914
  const marketTypeStr = (0, types_1.getVariant)(marketType);
865
- const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
915
+ const marketNodeLists = this.getMarketNodeLists(marketTypeStr, marketIndex);
866
916
  if ((0, types_1.isVariant)(direction, 'long') && marketNodeLists.trigger.above) {
867
917
  for (const node of marketNodeLists.trigger.above.getGenerator()) {
868
- if ((0, types_1.isVariant)(node.order.direction, 'short')) {
918
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'short')) {
869
919
  yield node;
870
920
  }
871
921
  }
872
922
  }
873
923
  else if ((0, types_1.isVariant)(direction, 'short') && marketNodeLists.trigger.below) {
874
924
  for (const node of marketNodeLists.trigger.below.getGenerator()) {
875
- if ((0, types_1.isVariant)(node.order.direction, 'long')) {
925
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).direction, 'long')) {
876
926
  yield node;
877
927
  }
878
928
  }
@@ -880,30 +930,32 @@ class DLOB {
880
930
  }
881
931
  *getTakeProfitMarkets(marketIndex, marketType, direction) {
882
932
  for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
883
- if ((0, types_1.isVariant)(node.order.orderType, 'triggerMarket')) {
933
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerMarket')) {
884
934
  yield node;
885
935
  }
886
936
  }
887
937
  }
888
938
  *getTakeProfitLimits(marketIndex, marketType, direction) {
889
939
  for (const node of this.getTakeProfits(marketIndex, marketType, direction)) {
890
- if ((0, types_1.isVariant)(node.order.orderType, 'triggerLimit')) {
940
+ if ((0, types_1.isVariant)(getOrderOrThrow(node).orderType, 'triggerLimit')) {
891
941
  yield node;
892
942
  }
893
943
  }
894
944
  }
895
945
  findNodesToTrigger(marketIndex, slot, triggerPrice, marketType, stateAccount) {
946
+ var _a;
896
947
  if ((0, exchangeStatus_1.exchangePaused)(stateAccount)) {
897
948
  return [];
898
949
  }
899
950
  const nodesToTrigger = [];
900
951
  const marketTypeStr = (0, types_1.getVariant)(marketType);
901
- const marketNodeLists = this.orderLists.get(marketTypeStr).get(marketIndex);
952
+ const marketNodeLists = (_a = this.orderLists
953
+ .get(marketTypeStr)) === null || _a === void 0 ? void 0 : _a.get(marketIndex);
902
954
  const triggerAboveList = marketNodeLists
903
955
  ? marketNodeLists.trigger.above
904
956
  : undefined;
905
957
  if (triggerAboveList) {
906
- for (const node of triggerAboveList.getGenerator()) {
958
+ for (let node = triggerAboveList.head; node !== undefined; node = node.next) {
907
959
  if (triggerPrice.gt(node.order.triggerPrice)) {
908
960
  nodesToTrigger.push({
909
961
  node: node,
@@ -918,7 +970,7 @@ class DLOB {
918
970
  ? marketNodeLists.trigger.below
919
971
  : undefined;
920
972
  if (triggerBelowList) {
921
- for (const node of triggerBelowList.getGenerator()) {
973
+ for (let node = triggerBelowList.head; node !== undefined; node = node.next) {
922
974
  if (triggerPrice.lt(node.order.triggerPrice)) {
923
975
  nodesToTrigger.push({
924
976
  node: node,
@@ -937,6 +989,9 @@ class DLOB {
937
989
  const oraclePriceData = velocityClient.getMMOracleDataForPerpMarket(marketIndex);
938
990
  const bestAsk = this.getBestAsk(marketIndex, slot, marketType, oraclePriceData);
939
991
  const bestBid = this.getBestBid(marketIndex, slot, marketType, oraclePriceData);
992
+ if (bestAsk === undefined || bestBid === undefined) {
993
+ throw new Error(`printTop requires both a best ask and best bid for market ${marketIndex}`);
994
+ }
940
995
  const mid = bestAsk.add(bestBid).div(new anchor_1.BN(2));
941
996
  const bidSpread = ((0, conversion_1.convertToNumber)(bestBid, numericConstants_1.PRICE_PRECISION) /
942
997
  (0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
@@ -946,7 +1001,7 @@ class DLOB {
946
1001
  (0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
947
1002
  1) *
948
1003
  100.0;
949
- const name = (0, userName_1.decodeName)(velocityClient.getPerpMarketAccount(marketIndex).name);
1004
+ const name = (0, userName_1.decodeName)(velocityClient.getPerpMarketAccountOrThrow(marketIndex).name);
950
1005
  console.log(`Market ${name} Orders`);
951
1006
  console.log(` Ask`, (0, conversion_1.convertToNumber)(bestAsk, numericConstants_1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
952
1007
  console.log(` Mid`, (0, conversion_1.convertToNumber)(mid, numericConstants_1.PRICE_PRECISION).toFixed(3));
@@ -957,6 +1012,9 @@ class DLOB {
957
1012
  const oraclePriceData = velocityClient.getOracleDataForSpotMarket(marketIndex);
958
1013
  const bestAsk = this.getBestAsk(marketIndex, slot, types_1.MarketType.SPOT, oraclePriceData);
959
1014
  const bestBid = this.getBestBid(marketIndex, slot, types_1.MarketType.SPOT, oraclePriceData);
1015
+ if (bestAsk === undefined || bestBid === undefined) {
1016
+ throw new Error(`printTop requires both a best ask and best bid for market ${marketIndex}`);
1017
+ }
960
1018
  const mid = bestAsk.add(bestBid).div(new anchor_1.BN(2));
961
1019
  const bidSpread = ((0, conversion_1.convertToNumber)(bestBid, numericConstants_1.PRICE_PRECISION) /
962
1020
  (0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
@@ -966,7 +1024,7 @@ class DLOB {
966
1024
  (0, conversion_1.convertToNumber)(oraclePriceData.price, numericConstants_1.PRICE_PRECISION) -
967
1025
  1) *
968
1026
  100.0;
969
- const name = (0, userName_1.decodeName)(velocityClient.getSpotMarketAccount(marketIndex).name);
1027
+ const name = (0, userName_1.decodeName)(velocityClient.getSpotMarketAccountOrThrow(marketIndex).name);
970
1028
  console.log(`Market ${name} Orders`);
971
1029
  console.log(` Ask`, (0, conversion_1.convertToNumber)(bestAsk, numericConstants_1.PRICE_PRECISION).toFixed(3), `(${askSpread.toFixed(4)}%)`);
972
1030
  console.log(` Mid`, (0, conversion_1.convertToNumber)(mid, numericConstants_1.PRICE_PRECISION).toFixed(3));
@@ -978,15 +1036,15 @@ class DLOB {
978
1036
  for (const nodeList of this.getNodeLists()) {
979
1037
  for (const node of nodeList.getGenerator()) {
980
1038
  dlobOrders.push({
981
- user: new web3_js_1.PublicKey(node.userAccount),
982
- order: node.order,
1039
+ user: new web3_js_1.PublicKey(getUserAccountOrThrow(node)),
1040
+ order: getOrderOrThrow(node),
983
1041
  });
984
1042
  }
985
1043
  }
986
1044
  return dlobOrders;
987
1045
  }
988
1046
  *getNodeLists() {
989
- for (const [_, nodeLists] of this.orderLists.get('perp')) {
1047
+ for (const [_, nodeLists] of this.getOrderListsForMarketType('perp')) {
990
1048
  yield nodeLists.restingLimit.bid;
991
1049
  yield nodeLists.restingLimit.ask;
992
1050
  yield nodeLists.takingLimit.bid;
@@ -998,7 +1056,7 @@ class DLOB {
998
1056
  yield nodeLists.trigger.above;
999
1057
  yield nodeLists.trigger.below;
1000
1058
  }
1001
- for (const [_, nodeLists] of this.orderLists.get('spot')) {
1059
+ for (const [_, nodeLists] of this.getOrderListsForMarketType('spot')) {
1002
1060
  yield nodeLists.restingLimit.bid;
1003
1061
  yield nodeLists.restingLimit.ask;
1004
1062
  yield nodeLists.takingLimit.bid;
@@ -1057,20 +1115,22 @@ class DLOB {
1057
1115
  const asks = [];
1058
1116
  const restingAsks = this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
1059
1117
  for (const ask of restingAsks) {
1118
+ const askOrder = getOrderOrThrow(ask);
1060
1119
  asks.push({
1061
- price: ask.getPrice(oraclePriceData, slot),
1062
- size: ask.order.baseAssetAmount.sub(ask.order.baseAssetAmountFilled),
1063
- maker: new web3_js_1.PublicKey(ask.userAccount),
1064
- orderId: ask.order.orderId,
1120
+ price: ask.getPriceOrThrow(oraclePriceData, slot),
1121
+ size: askOrder.baseAssetAmount.sub(askOrder.baseAssetAmountFilled),
1122
+ maker: new web3_js_1.PublicKey(getUserAccountOrThrow(ask)),
1123
+ orderId: askOrder.orderId,
1065
1124
  });
1066
1125
  }
1067
1126
  const restingBids = this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData);
1068
1127
  for (const bid of restingBids) {
1128
+ const bidOrder = getOrderOrThrow(bid);
1069
1129
  bids.push({
1070
- price: bid.getPrice(oraclePriceData, slot),
1071
- size: bid.order.baseAssetAmount.sub(bid.order.baseAssetAmountFilled),
1072
- maker: new web3_js_1.PublicKey(bid.userAccount),
1073
- orderId: bid.order.orderId,
1130
+ price: bid.getPriceOrThrow(oraclePriceData, slot),
1131
+ size: bidOrder.baseAssetAmount.sub(bidOrder.baseAssetAmountFilled),
1132
+ maker: new web3_js_1.PublicKey(getUserAccountOrThrow(bid)),
1133
+ orderId: bidOrder.orderId,
1074
1134
  });
1075
1135
  }
1076
1136
  return {
@@ -1083,8 +1143,9 @@ class DLOB {
1083
1143
  let runningSumQuote = numericConstants_1.ZERO;
1084
1144
  let runningSumBase = numericConstants_1.ZERO;
1085
1145
  for (const side of dlobSide) {
1086
- const price = side.getPrice(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
1087
- const baseAmountRemaining = side.order.baseAssetAmount.sub(side.order.baseAssetAmountFilled);
1146
+ const price = side.getPriceOrThrow(oraclePriceData, slot); //side.order.quoteAssetAmount.div(side.order.baseAssetAmount);
1147
+ const sideOrder = getOrderOrThrow(side);
1148
+ const baseAmountRemaining = sideOrder.baseAssetAmount.sub(sideOrder.baseAssetAmountFilled);
1088
1149
  if (runningSumBase.add(baseAmountRemaining).gt(baseAmountIn)) {
1089
1150
  const remainingBase = baseAmountIn.sub(runningSumBase);
1090
1151
  runningSumBase = runningSumBase.add(remainingBase);
@@ -1117,6 +1178,7 @@ class DLOB {
1117
1178
  else if ((0, types_1.isVariant)(orderDirection, 'short')) {
1118
1179
  return this.estimateFillExactBaseAmountInForSide(baseAmount, oraclePriceData, slot, this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData));
1119
1180
  }
1181
+ throw new Error(`Invalid order direction ${(0, types_1.getVariant)(orderDirection)}: must be long or short`);
1120
1182
  }
1121
1183
  getBestMakers({ marketIndex, marketType, direction, slot, oraclePriceData, numMakers, }) {
1122
1184
  const makers = new Map();
@@ -1124,8 +1186,9 @@ class DLOB {
1124
1186
  ? this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData)
1125
1187
  : this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData);
1126
1188
  for (const node of generator) {
1127
- if (!makers.has(node.userAccount.toString())) {
1128
- makers.set(node.userAccount.toString(), new web3_js_1.PublicKey(node.userAccount));
1189
+ const userAccount = getUserAccountOrThrow(node);
1190
+ if (!makers.has(userAccount)) {
1191
+ makers.set(userAccount, new web3_js_1.PublicKey(userAccount));
1129
1192
  }
1130
1193
  if (makers.size === numMakers) {
1131
1194
  break;