@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
@@ -4,13 +4,14 @@ exports.User = void 0;
4
4
  const types_1 = require("./types");
5
5
  const position_1 = require("./math/position");
6
6
  const numericConstants_1 = require("./constants/numericConstants");
7
+ const utils_1 = require("./accounts/utils");
7
8
  const bigNum_1 = require("./factory/bigNum");
8
9
  const anchor_1 = require("./isomorphic/anchor");
9
10
  const position_2 = require("./math/position");
10
11
  const market_1 = require("./math/market");
11
12
  const margin_1 = require("./math/margin");
12
13
  const spotMarket_1 = require("./math/spotMarket");
13
- const utils_1 = require("./math/utils");
14
+ const utils_2 = require("./math/utils");
14
15
  const spotBalance_1 = require("./math/spotBalance");
15
16
  const trade_1 = require("./math/trade");
16
17
  const types_2 = require("./types");
@@ -92,15 +93,37 @@ class User {
92
93
  this.isSubscribed = false;
93
94
  }
94
95
  getUserAccount() {
95
- return this.accountSubscriber.getUserAccountAndSlot().data;
96
+ var _a;
97
+ return (_a = this.accountSubscriber.getUserAccountAndSlot()) === null || _a === void 0 ? void 0 : _a.data;
98
+ }
99
+ /**
100
+ * Like {@link getUserAccount} but throws a named error instead of returning
101
+ * `undefined` when the account has not been loaded yet. Use at call sites
102
+ * that structurally require a loaded account.
103
+ */
104
+ getUserAccountOrThrow() {
105
+ const userAccount = this.getUserAccount();
106
+ if (!userAccount) {
107
+ throw new Error(`User account not loaded: ${this.getUserAccountPublicKey().toString()}`);
108
+ }
109
+ return userAccount;
96
110
  }
97
111
  async forceGetUserAccount() {
98
112
  await this.fetchAccounts();
99
- return this.accountSubscriber.getUserAccountAndSlot().data;
113
+ const account = this.accountSubscriber.getUserAccountAndSlot();
114
+ return account === null || account === void 0 ? void 0 : account.data;
100
115
  }
101
116
  getUserAccountAndSlot() {
102
117
  return this.accountSubscriber.getUserAccountAndSlot();
103
118
  }
119
+ /**
120
+ * Like {@link getUserAccountAndSlot} but throws a named error instead of
121
+ * returning `undefined` when the account has not been loaded yet. Use at
122
+ * call sites that structurally require a loaded account.
123
+ */
124
+ getUserAccountAndSlotOrThrow() {
125
+ return (0, utils_1.assertDataAndSlot)(this.accountSubscriber.getUserAccountAndSlot(), `User account not loaded: ${this.getUserAccountPublicKey().toString()}`);
126
+ }
104
127
  getPerpPositionForUserAccount(userAccount, marketIndex) {
105
128
  return this.getActivePerpPositionsForUserAccount(userAccount).find((position) => position.marketIndex === marketIndex);
106
129
  }
@@ -110,16 +133,23 @@ class User {
110
133
  * @returns userPerpPosition
111
134
  */
112
135
  getPerpPosition(marketIndex) {
113
- const userAccount = this.getUserAccount();
136
+ const userAccount = this.getUserAccountOrThrow();
114
137
  return this.getPerpPositionForUserAccount(userAccount, marketIndex);
115
138
  }
116
139
  getPerpPositionOrEmpty(marketIndex) {
117
140
  var _a;
118
- const userAccount = this.getUserAccount();
141
+ const userAccount = this.getUserAccountOrThrow();
119
142
  return ((_a = this.getPerpPositionForUserAccount(userAccount, marketIndex)) !== null && _a !== void 0 ? _a : this.getEmptyPosition(marketIndex));
120
143
  }
144
+ getPerpPositionOrThrow(marketIndex) {
145
+ const position = this.getPerpPosition(marketIndex);
146
+ if (!position) {
147
+ throw new Error(`No perp position found for market ${marketIndex}`);
148
+ }
149
+ return position;
150
+ }
121
151
  getPerpPositionAndSlot(marketIndex) {
122
- const userAccount = this.getUserAccountAndSlot();
152
+ const userAccount = this.getUserAccountAndSlotOrThrow();
123
153
  const perpPosition = this.getPerpPositionForUserAccount(userAccount.data, marketIndex);
124
154
  return {
125
155
  data: perpPosition,
@@ -135,11 +165,11 @@ class User {
135
165
  * @returns userSpotPosition
136
166
  */
137
167
  getSpotPosition(marketIndex) {
138
- const userAccount = this.getUserAccount();
168
+ const userAccount = this.getUserAccountOrThrow();
139
169
  return this.getSpotPositionForUserAccount(userAccount, marketIndex);
140
170
  }
141
171
  getSpotPositionAndSlot(marketIndex) {
142
- const userAccount = this.getUserAccountAndSlot();
172
+ const userAccount = this.getUserAccountAndSlotOrThrow();
143
173
  const spotPosition = this.getSpotPositionForUserAccount(userAccount.data, marketIndex);
144
174
  return {
145
175
  data: spotPosition,
@@ -168,7 +198,7 @@ class User {
168
198
  if (spotPosition === undefined) {
169
199
  return numericConstants_1.ZERO;
170
200
  }
171
- const spotMarket = this.velocityClient.getSpotMarketAccount(marketIndex);
201
+ const spotMarket = this.velocityClient.getSpotMarketAccountOrThrow(marketIndex);
172
202
  return (0, spotBalance_1.getSignedTokenAmount)((0, spotBalance_2.getTokenAmount)(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType), spotPosition.balanceType);
173
203
  }
174
204
  getEmptyPosition(marketIndex) {
@@ -197,8 +227,8 @@ class User {
197
227
  const perpPosition = this.getPerpPosition(perpMarketIndex);
198
228
  if (!perpPosition)
199
229
  return numericConstants_1.ZERO;
200
- const perpMarket = this.velocityClient.getPerpMarketAccount(perpMarketIndex);
201
- const spotMarket = this.velocityClient.getSpotMarketAccount(perpMarket.quoteSpotMarketIndex);
230
+ const perpMarket = this.velocityClient.getPerpMarketAccountOrThrow(perpMarketIndex);
231
+ const spotMarket = this.velocityClient.getSpotMarketAccountOrThrow(perpMarket.quoteSpotMarketIndex);
202
232
  if (perpPosition === undefined) {
203
233
  return numericConstants_1.ZERO;
204
234
  }
@@ -214,8 +244,8 @@ class User {
214
244
  if (!((_a = perpPosition.isolatedPositionScaledBalance) === null || _a === void 0 ? void 0 : _a.gt(numericConstants_1.ZERO))) {
215
245
  return total;
216
246
  }
217
- const perpMarket = this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex);
218
- const quoteSpotMarket = this.velocityClient.getSpotMarketAccount(perpMarket.quoteSpotMarketIndex);
247
+ const perpMarket = this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex);
248
+ const quoteSpotMarket = this.velocityClient.getSpotMarketAccountOrThrow(perpMarket.quoteSpotMarketIndex);
219
249
  const quoteOraclePriceData = this.getOracleDataForSpotMarket(perpMarket.quoteSpotMarketIndex);
220
250
  const strictOracle = new strictOraclePrice_1.StrictOraclePrice(quoteOraclePriceData.price, quoteOraclePriceData.twap);
221
251
  const tokenAmount = (0, spotBalance_2.getTokenAmount)(perpPosition.isolatedPositionScaledBalance, quoteSpotMarket, types_2.SpotBalanceType.DEPOSIT);
@@ -234,11 +264,11 @@ class User {
234
264
  * @returns Order
235
265
  */
236
266
  getOrder(orderId) {
237
- const userAccount = this.getUserAccount();
267
+ const userAccount = this.getUserAccountOrThrow();
238
268
  return this.getOrderForUserAccount(userAccount, orderId);
239
269
  }
240
270
  getOrderAndSlot(orderId) {
241
- const userAccount = this.getUserAccountAndSlot();
271
+ const userAccount = this.getUserAccountAndSlotOrThrow();
242
272
  const order = this.getOrderForUserAccount(userAccount.data, orderId);
243
273
  return {
244
274
  data: order,
@@ -253,11 +283,11 @@ class User {
253
283
  * @returns Order
254
284
  */
255
285
  getOrderByUserOrderId(userOrderId) {
256
- const userAccount = this.getUserAccount();
286
+ const userAccount = this.getUserAccountOrThrow();
257
287
  return this.getOrderByUserIdForUserAccount(userAccount, userOrderId);
258
288
  }
259
289
  getOrderByUserOrderIdAndSlot(userOrderId) {
260
- const userAccount = this.getUserAccountAndSlot();
290
+ const userAccount = this.getUserAccountAndSlotOrThrow();
261
291
  const order = this.getOrderByUserIdForUserAccount(userAccount.data, userOrderId);
262
292
  return {
263
293
  data: order,
@@ -268,12 +298,14 @@ class User {
268
298
  return userAccount === null || userAccount === void 0 ? void 0 : userAccount.orders.filter((order) => (0, types_1.isVariant)(order.status, 'open'));
269
299
  }
270
300
  getOpenOrders() {
301
+ var _a;
271
302
  const userAccount = this.getUserAccount();
272
- return this.getOpenOrdersForUserAccount(userAccount);
303
+ return (_a = this.getOpenOrdersForUserAccount(userAccount)) !== null && _a !== void 0 ? _a : [];
273
304
  }
274
305
  getOpenOrdersAndSlot() {
275
- const userAccount = this.getUserAccountAndSlot();
276
- const openOrders = this.getOpenOrdersForUserAccount(userAccount.data);
306
+ var _a;
307
+ const userAccount = this.getUserAccountAndSlotOrThrow();
308
+ const openOrders = (_a = this.getOpenOrdersForUserAccount(userAccount.data)) !== null && _a !== void 0 ? _a : [];
277
309
  return {
278
310
  data: openOrders,
279
311
  slot: userAccount.slot,
@@ -292,7 +324,7 @@ class User {
292
324
  * @returns : open asks
293
325
  */
294
326
  getPerpBidAsks(marketIndex) {
295
- const position = this.getPerpPosition(marketIndex);
327
+ const position = this.getPerpPositionOrThrow(marketIndex);
296
328
  const totalOpenBids = position.openBids;
297
329
  const totalOpenAsks = position.openAsks;
298
330
  return [totalOpenBids, totalOpenAsks];
@@ -303,7 +335,7 @@ class User {
303
335
  */
304
336
  getPerpBuyingPower(marketIndex, collateralBuffer = numericConstants_1.ZERO, maxMarginRatio = undefined, positionType = 'cross') {
305
337
  const perpPosition = this.getPerpPositionOrEmpty(marketIndex);
306
- const perpMarket = this.velocityClient.getPerpMarketAccount(marketIndex);
338
+ const perpMarket = this.velocityClient.getPerpMarketAccountOrThrow(marketIndex);
307
339
  const oraclePriceData = this.getOracleDataForPerpMarket(marketIndex);
308
340
  const worstCaseBaseAssetAmount = perpPosition
309
341
  ? (0, margin_2.calculateWorstCaseBaseAssetAmount)(perpPosition, perpMarket, oraclePriceData.price)
@@ -322,9 +354,14 @@ class User {
322
354
  }
323
355
  return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount, maxMarginRatio || perpPosition.maxMarginRatio);
324
356
  }
357
+ resolveMaxMarginRatio(perpMarketMaxMarginRatio) {
358
+ // 0 means "no custom margin ratio override", so Math.max returns
359
+ // userAccount.maxMarginRatio unchanged — the expected semantic.
360
+ return Math.max(perpMarketMaxMarginRatio !== null && perpMarketMaxMarginRatio !== void 0 ? perpMarketMaxMarginRatio : 0, this.getUserAccountOrThrow().maxMarginRatio);
361
+ }
325
362
  getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount, perpMarketMaxMarginRatio = undefined) {
326
- const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
327
- const marginRatio = (0, market_1.calculateMarketMarginRatio)(this.velocityClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial', maxMarginRatio);
363
+ const maxMarginRatio = this.resolveMaxMarginRatio(perpMarketMaxMarginRatio);
364
+ const marginRatio = (0, market_1.calculateMarketMarginRatio)(this.velocityClient.getPerpMarketAccountOrThrow(marketIndex), baseAssetAmount, 'Initial', maxMarginRatio);
328
365
  return freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new anchor_1.BN(marginRatio));
329
366
  }
330
367
  /**
@@ -402,11 +439,11 @@ class User {
402
439
  });
403
440
  }
404
441
  getActivePerpPositions() {
405
- const userAccount = this.getUserAccount();
442
+ const userAccount = this.getUserAccountOrThrow();
406
443
  return this.getActivePerpPositionsForUserAccount(userAccount);
407
444
  }
408
445
  getActivePerpPositionsAndSlot() {
409
- const userAccount = this.getUserAccountAndSlot();
446
+ const userAccount = this.getUserAccountAndSlotOrThrow();
410
447
  const positions = this.getActivePerpPositionsForUserAccount(userAccount.data);
411
448
  return {
412
449
  data: positions,
@@ -417,11 +454,11 @@ class User {
417
454
  return userAccount.spotPositions.filter((pos) => !(0, spotPosition_1.isSpotPositionAvailable)(pos));
418
455
  }
419
456
  getActiveSpotPositions() {
420
- const userAccount = this.getUserAccount();
457
+ const userAccount = this.getUserAccountOrThrow();
421
458
  return this.getActiveSpotPositionsForUserAccount(userAccount);
422
459
  }
423
460
  getActiveSpotPositionsAndSlot() {
424
- const userAccount = this.getUserAccountAndSlot();
461
+ const userAccount = this.getUserAccountAndSlotOrThrow();
425
462
  const positions = this.getActiveSpotPositionsForUserAccount(userAccount.data);
426
463
  return {
427
464
  data: positions,
@@ -436,9 +473,9 @@ class User {
436
473
  return this.getActivePerpPositions()
437
474
  .filter((pos) => marketIndex !== undefined ? pos.marketIndex === marketIndex : true)
438
475
  .reduce((unrealizedPnl, perpPosition) => {
439
- const market = this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex);
476
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex);
440
477
  const oraclePriceData = this.getMMOracleDataForPerpMarket(market.marketIndex);
441
- const quoteSpotMarket = this.velocityClient.getSpotMarketAccount(market.quoteSpotMarketIndex);
478
+ const quoteSpotMarket = this.velocityClient.getSpotMarketAccountOrThrow(market.quoteSpotMarketIndex);
442
479
  const quoteOraclePriceData = this.getOracleDataForSpotMarket(market.quoteSpotMarketIndex);
443
480
  let positionUnrealizedPnl = (0, position_2.calculatePositionPNL)(market, perpPosition, withFunding, oraclePriceData);
444
481
  let quotePrice;
@@ -472,10 +509,10 @@ class User {
472
509
  * @returns : Precision QUOTE_PRECISION
473
510
  */
474
511
  getUnrealizedFundingPNL(marketIndex) {
475
- return this.getUserAccount()
512
+ return this.getUserAccountOrThrow()
476
513
  .perpPositions.filter((pos) => marketIndex !== undefined ? pos.marketIndex === marketIndex : true)
477
514
  .reduce((pnl, perpPosition) => {
478
- const market = this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex);
515
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex);
479
516
  return pnl.add((0, position_1.calculateUnsettledFundingPnl)(market, perpPosition));
480
517
  }, numericConstants_1.ZERO);
481
518
  }
@@ -484,7 +521,7 @@ class User {
484
521
  let netQuoteValue = numericConstants_1.ZERO;
485
522
  let totalAssetValue = numericConstants_1.ZERO;
486
523
  let totalLiabilityValue = numericConstants_1.ZERO;
487
- for (const spotPosition of this.getUserAccount().spotPositions) {
524
+ for (const spotPosition of this.getUserAccountOrThrow().spotPositions) {
488
525
  const countForBase = marketIndex === undefined || spotPosition.marketIndex === marketIndex;
489
526
  const countForQuote = marketIndex === undefined ||
490
527
  marketIndex === numericConstants_1.QUOTE_SPOT_MARKET_INDEX ||
@@ -493,7 +530,7 @@ class User {
493
530
  (!countForBase && !countForQuote)) {
494
531
  continue;
495
532
  }
496
- const spotMarketAccount = this.velocityClient.getSpotMarketAccount(spotPosition.marketIndex);
533
+ const spotMarketAccount = this.velocityClient.getSpotMarketAccountOrThrow(spotPosition.marketIndex);
497
534
  const oraclePriceData = this.getOracleDataForSpotMarket(spotPosition.marketIndex);
498
535
  let twap5min;
499
536
  if (strict) {
@@ -528,7 +565,7 @@ class User {
528
565
  continue;
529
566
  }
530
567
  }
531
- const { tokenAmount: worstCaseTokenAmount, ordersValue: worstCaseQuoteTokenAmount, } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, marginCategory, this.getUserAccount().maxMarginRatio);
568
+ const { tokenAmount: worstCaseTokenAmount, ordersValue: worstCaseQuoteTokenAmount, } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, marginCategory, this.getUserAccountOrThrow().maxMarginRatio);
532
569
  if (worstCaseTokenAmount.gt(numericConstants_1.ZERO) && countForBase) {
533
570
  const baseAssetValue = this.getSpotAssetValue(worstCaseTokenAmount, strictOraclePrice, spotMarketAccount, marginCategory);
534
571
  totalAssetValue = totalAssetValue.add(baseAssetValue);
@@ -543,7 +580,7 @@ class User {
543
580
  if (worstCaseQuoteTokenAmount.lt(numericConstants_1.ZERO) && countForQuote) {
544
581
  let weight = numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION;
545
582
  if (marginCategory === 'Initial') {
546
- weight = anchor_1.BN.max(weight, new anchor_1.BN(this.getUserAccount().maxMarginRatio));
583
+ weight = anchor_1.BN.max(weight, new anchor_1.BN(this.getUserAccountOrThrow().maxMarginRatio));
547
584
  }
548
585
  const weightedTokenValue = worstCaseQuoteTokenAmount
549
586
  .abs()
@@ -568,14 +605,14 @@ class User {
568
605
  return totalLiabilityValue;
569
606
  }
570
607
  getSpotLiabilityValue(tokenAmount, strictOraclePrice, spotMarketAccount, marginCategory, liquidationBuffer) {
571
- return (0, spotBalance_2.getSpotLiabilityValue)(tokenAmount, strictOraclePrice, spotMarketAccount, this.getUserAccount().maxMarginRatio, marginCategory, liquidationBuffer);
608
+ return (0, spotBalance_2.getSpotLiabilityValue)(tokenAmount, strictOraclePrice, spotMarketAccount, this.getUserAccountOrThrow().maxMarginRatio, marginCategory, liquidationBuffer);
572
609
  }
573
610
  getSpotMarketAssetValue(marketIndex, marginCategory, includeOpenOrders, strict = false, now) {
574
611
  const { totalAssetValue } = this.getSpotMarketAssetAndLiabilityValue(marketIndex, marginCategory, undefined, includeOpenOrders, strict, now);
575
612
  return totalAssetValue;
576
613
  }
577
614
  getSpotAssetValue(tokenAmount, strictOraclePrice, spotMarketAccount, marginCategory) {
578
- return (0, spotBalance_2.getSpotAssetValue)(tokenAmount, strictOraclePrice, spotMarketAccount, this.getUserAccount().maxMarginRatio, marginCategory);
615
+ return (0, spotBalance_2.getSpotAssetValue)(tokenAmount, strictOraclePrice, spotMarketAccount, this.getUserAccountOrThrow().maxMarginRatio, marginCategory);
579
616
  }
580
617
  getSpotPositionValue(marketIndex, marginCategory, includeOpenOrders, strict = false, now) {
581
618
  const { totalAssetValue, totalLiabilityValue } = this.getSpotMarketAssetAndLiabilityValue(marketIndex, marginCategory, undefined, includeOpenOrders, strict, now);
@@ -605,7 +642,11 @@ class User {
605
642
  liquidationBufferMap,
606
643
  });
607
644
  if (perpMarketIndex !== undefined) {
608
- const { totalCollateral, totalCollateralBuffer } = marginCalc.isolatedMarginCalculations.get(perpMarketIndex);
645
+ const isolatedMarginCalculation = marginCalc.isolatedMarginCalculations.get(perpMarketIndex);
646
+ if (!isolatedMarginCalculation) {
647
+ throw new Error(`No isolated margin calculation for perp market ${perpMarketIndex}`);
648
+ }
649
+ const { totalCollateral, totalCollateralBuffer } = isolatedMarginCalculation;
609
650
  if (liquidationBuffer === null || liquidationBuffer === void 0 ? void 0 : liquidationBuffer.gt(numericConstants_1.ZERO)) {
610
651
  return totalCollateralBuffer;
611
652
  }
@@ -669,7 +710,7 @@ class User {
669
710
  return health;
670
711
  }
671
712
  calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict = false) {
672
- const market = this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex);
713
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex);
673
714
  let valuationPrice = this.getOracleDataForPerpMarket(market.marketIndex).price;
674
715
  if ((0, types_1.isVariant)(market.status, 'settlement')) {
675
716
  valuationPrice = market.expiryPrice;
@@ -686,7 +727,7 @@ class User {
686
727
  liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, valuationPrice);
687
728
  }
688
729
  if (marginCategory) {
689
- const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
730
+ const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccountOrThrow().maxMarginRatio);
690
731
  let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, userCustomMargin));
691
732
  if (liquidationBuffer !== undefined) {
692
733
  marginRatio = marginRatio.add(liquidationBuffer);
@@ -694,7 +735,7 @@ class User {
694
735
  if ((0, types_1.isVariant)(market.status, 'settlement')) {
695
736
  marginRatio = numericConstants_1.ZERO;
696
737
  }
697
- const quoteSpotMarket = this.velocityClient.getSpotMarketAccount(market.quoteSpotMarketIndex);
738
+ const quoteSpotMarket = this.velocityClient.getSpotMarketAccountOrThrow(market.quoteSpotMarketIndex);
698
739
  const quoteOraclePriceData = this.velocityClient.getOracleDataForSpotMarket(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
699
740
  let quotePrice;
700
741
  if (strict) {
@@ -719,7 +760,7 @@ class User {
719
760
  * @returns : Precision QUOTE_PRECISION
720
761
  */
721
762
  getPerpMarketLiabilityValue(marketIndex, marginCategory, liquidationBuffer, includeOpenOrders, strict = false) {
722
- const perpPosition = this.getPerpPosition(marketIndex);
763
+ const perpPosition = this.getPerpPositionOrThrow(marketIndex);
723
764
  return this.calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict);
724
765
  }
725
766
  /**
@@ -738,7 +779,7 @@ class User {
738
779
  */
739
780
  getPerpPositionValue(marketIndex, oraclePriceData, includeOpenOrders = false) {
740
781
  const userPosition = this.getPerpPositionOrEmpty(marketIndex);
741
- const market = this.velocityClient.getPerpMarketAccount(userPosition.marketIndex);
782
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(userPosition.marketIndex);
742
783
  return (0, margin_2.calculateBaseAssetValueWithOracle)(market, userPosition, oraclePriceData, includeOpenOrders);
743
784
  }
744
785
  /**
@@ -747,7 +788,7 @@ class User {
747
788
  */
748
789
  getPerpLiabilityValue(marketIndex, oraclePriceData, includeOpenOrders = false) {
749
790
  const userPosition = this.getPerpPositionOrEmpty(marketIndex);
750
- const market = this.velocityClient.getPerpMarketAccount(userPosition.marketIndex);
791
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(userPosition.marketIndex);
751
792
  if (includeOpenOrders) {
752
793
  return (0, margin_1.calculateWorstCasePerpLiabilityValue)(userPosition, market, oraclePriceData.price).worstCaseLiabilityValue;
753
794
  }
@@ -771,7 +812,7 @@ class User {
771
812
  * @returns : Precision PRICE_PRECISION
772
813
  */
773
814
  getPositionEstimatedExitPriceAndPnl(position, amountToClose, useAMMClose = false) {
774
- const market = this.velocityClient.getPerpMarketAccount(position.marketIndex);
815
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(position.marketIndex);
775
816
  const entryPrice = (0, position_1.calculateEntryPrice)(position);
776
817
  const oraclePriceData = this.getMMOracleDataForPerpMarket(position.marketIndex);
777
818
  if (amountToClose) {
@@ -827,9 +868,9 @@ class User {
827
868
  if (perpMarketIndex) {
828
869
  const perpPosition = this.getPerpPositionOrEmpty(perpMarketIndex);
829
870
  const perpLiability = this.calculateWeightedPerpPositionLiability(perpPosition, marginCategory, undefined, includeOpenOrders);
830
- const perpMarket = this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex);
871
+ const perpMarket = this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex);
831
872
  const oraclePriceData = this.getOracleDataForPerpMarket(perpPosition.marketIndex);
832
- const quoteSpotMarket = this.velocityClient.getSpotMarketAccount(perpMarket.quoteSpotMarketIndex);
873
+ const quoteSpotMarket = this.velocityClient.getSpotMarketAccountOrThrow(perpMarket.quoteSpotMarketIndex);
833
874
  const quoteOraclePriceData = this.getOracleDataForSpotMarket(perpMarket.quoteSpotMarketIndex);
834
875
  const strictOracle = new strictOraclePrice_1.StrictOraclePrice(quoteOraclePriceData.price, quoteOraclePriceData.twap);
835
876
  const positionUnrealizedPnl = (0, position_2.calculatePositionPNL)(perpMarket, perpPosition, true, oraclePriceData);
@@ -858,6 +899,9 @@ class User {
858
899
  isDustDepositPosition(spotMarketAccount) {
859
900
  const marketIndex = spotMarketAccount.marketIndex;
860
901
  const spotPosition = this.getSpotPosition(spotMarketAccount.marketIndex);
902
+ if (!spotPosition) {
903
+ throw new Error(`No spot position found for market ${spotMarketAccount.marketIndex}`);
904
+ }
861
905
  if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition)) {
862
906
  return false;
863
907
  }
@@ -907,8 +951,8 @@ class User {
907
951
  */
908
952
  getTotalAllTimePnl() {
909
953
  const netUsdValue = this.getNetUsdValue();
910
- const totalDeposits = this.getUserAccount().totalDeposits;
911
- const totalWithdraws = this.getUserAccount().totalWithdraws;
954
+ const totalDeposits = this.getUserAccountOrThrow().totalDeposits;
955
+ const totalWithdraws = this.getUserAccountOrThrow().totalWithdraws;
912
956
  const totalPnl = netUsdValue.add(totalWithdraws).sub(totalDeposits);
913
957
  return totalPnl;
914
958
  }
@@ -1048,7 +1092,7 @@ class User {
1048
1092
  this.hasIsolatedPositionBeingLiquidated());
1049
1093
  }
1050
1094
  isCrossMarginBeingLiquidated() {
1051
- return ((this.getUserAccount().status &
1095
+ return ((this.getUserAccountOrThrow().status &
1052
1096
  (types_1.UserStatus.BEING_LIQUIDATED | types_1.UserStatus.BANKRUPT)) >
1053
1097
  0);
1054
1098
  }
@@ -1063,8 +1107,9 @@ class User {
1063
1107
  0);
1064
1108
  }
1065
1109
  isIsolatedPositionBeingLiquidated(perpMarketIndex) {
1110
+ var _a;
1066
1111
  const position = this.getActivePerpPositions().find((position) => position.marketIndex === perpMarketIndex);
1067
- return (((position === null || position === void 0 ? void 0 : position.positionFlag) &
1112
+ return ((((_a = position === null || position === void 0 ? void 0 : position.positionFlag) !== null && _a !== void 0 ? _a : 0) &
1068
1113
  (types_2.PositionFlag.BeingLiquidated | types_2.PositionFlag.Bankruptcy)) >
1069
1114
  0);
1070
1115
  }
@@ -1083,21 +1128,21 @@ class User {
1083
1128
  return isolatedMarginCalculation.totalCollateral.lt(isolatedMarginCalculation.marginRequirement);
1084
1129
  }
1085
1130
  hasStatus(status) {
1086
- return (this.getUserAccount().status & status) > 0;
1131
+ return (this.getUserAccountOrThrow().status & status) > 0;
1087
1132
  }
1088
1133
  isBankrupt() {
1089
- return (this.getUserAccount().status & types_1.UserStatus.BANKRUPT) > 0;
1134
+ return (this.getUserAccountOrThrow().status & types_1.UserStatus.BANKRUPT) > 0;
1090
1135
  }
1091
1136
  /**
1092
1137
  * Checks if any user position cumulative funding differs from respective market cumulative funding
1093
1138
  * @returns
1094
1139
  */
1095
1140
  needsToSettleFundingPayment() {
1096
- for (const userPosition of this.getUserAccount().perpPositions) {
1141
+ for (const userPosition of this.getUserAccountOrThrow().perpPositions) {
1097
1142
  if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
1098
1143
  continue;
1099
1144
  }
1100
- const market = this.velocityClient.getPerpMarketAccount(userPosition.marketIndex);
1145
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(userPosition.marketIndex);
1101
1146
  if (market.cumulativeFundingRateLong.eq(userPosition.lastCumulativeFundingRate) ||
1102
1147
  market.cumulativeFundingRateShort.eq(userPosition.lastCumulativeFundingRate)) {
1103
1148
  continue;
@@ -1119,7 +1164,7 @@ class User {
1119
1164
  const totalCollateral = this.getTotalCollateral('Maintenance');
1120
1165
  const maintenanceMarginRequirement = this.getMaintenanceMarginRequirement();
1121
1166
  const freeCollateral = anchor_1.BN.max(numericConstants_1.ZERO, totalCollateral.sub(maintenanceMarginRequirement));
1122
- const market = this.velocityClient.getSpotMarketAccount(marketIndex);
1167
+ const market = this.velocityClient.getSpotMarketAccountOrThrow(marketIndex);
1123
1168
  let signedTokenAmount = (0, spotBalance_1.getSignedTokenAmount)((0, spotBalance_2.getTokenAmount)(currentSpotPosition.scaledBalance, market, currentSpotPosition.balanceType), currentSpotPosition.balanceType);
1124
1169
  signedTokenAmount = signedTokenAmount.add(positionBaseSizeChange);
1125
1170
  if (signedTokenAmount.eq(numericConstants_1.ZERO)) {
@@ -1167,8 +1212,8 @@ class User {
1167
1212
  * @returns Precision : PRICE_PRECISION
1168
1213
  */
1169
1214
  liquidationPrice(marketIndex, positionBaseSizeChange = numericConstants_1.ZERO, estimatedEntryPrice = numericConstants_1.ZERO, marginCategory = 'Maintenance', includeOpenOrders = false, offsetCollateral = numericConstants_1.ZERO, marginType) {
1170
- const market = this.velocityClient.getPerpMarketAccount(marketIndex);
1171
- const oracle = this.velocityClient.getPerpMarketAccount(marketIndex).oracle;
1215
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(marketIndex);
1216
+ const oracle = market.oracle;
1172
1217
  const oraclePrice = this.velocityClient.getOracleDataForPerpMarket(marketIndex).price;
1173
1218
  const currentPerpPosition = this.getPerpPositionOrEmpty(marketIndex);
1174
1219
  if (marginType === 'Isolated') {
@@ -1270,7 +1315,7 @@ class User {
1270
1315
  baseAssetAmount = perpPosition.baseAssetAmount;
1271
1316
  liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, oraclePrice);
1272
1317
  }
1273
- const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
1318
+ const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccountOrThrow().maxMarginRatio);
1274
1319
  const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, userCustomMargin);
1275
1320
  return liabilityValue.mul(new anchor_1.BN(marginRatio)).div(numericConstants_1.MARGIN_PRECISION);
1276
1321
  };
@@ -1287,7 +1332,7 @@ class User {
1287
1332
  // zero if include orders == false
1288
1333
  const orderBaseAssetAmount = baseAssetAmount.sub(perpPosition.baseAssetAmount);
1289
1334
  const proposedBaseAssetAmount = baseAssetAmount.add(positionBaseSizeChange);
1290
- const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
1335
+ const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccountOrThrow().maxMarginRatio);
1291
1336
  const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, proposedBaseAssetAmount.abs(), marginCategory, userCustomMargin);
1292
1337
  const marginRatioQuotePrecision = new anchor_1.BN(marginRatio)
1293
1338
  .mul(numericConstants_1.QUOTE_PRECISION)
@@ -1351,11 +1396,11 @@ class User {
1351
1396
  return this.liquidationPrice(positionMarketIndex, closeBaseAmount, estimatedEntryPrice);
1352
1397
  }
1353
1398
  getMarginUSDCRequiredForTrade(targetMarketIndex, baseSize, estEntryPrice, perpMarketMaxMarginRatio) {
1354
- const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
1399
+ const maxMarginRatio = this.resolveMaxMarginRatio(perpMarketMaxMarginRatio);
1355
1400
  return (0, margin_2.calculateMarginUSDCRequiredForTrade)(this.velocityClient, targetMarketIndex, baseSize, maxMarginRatio, estEntryPrice);
1356
1401
  }
1357
1402
  getCollateralDepositRequiredForTrade(targetMarketIndex, baseSize, collateralIndex, perpMarketMaxMarginRatio) {
1358
- const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
1403
+ const maxMarginRatio = this.resolveMaxMarginRatio(perpMarketMaxMarginRatio);
1359
1404
  return (0, margin_2.calculateCollateralDepositRequiredForTrade)(this.velocityClient, targetMarketIndex, baseSize, collateralIndex, maxMarginRatio);
1360
1405
  }
1361
1406
  /**
@@ -1378,7 +1423,7 @@ class User {
1378
1423
  ? true
1379
1424
  : targetSide === currentPositionSide;
1380
1425
  const oracleData = this.getMMOracleDataForPerpMarket(targetMarketIndex);
1381
- const marketAccount = this.velocityClient.getPerpMarketAccount(targetMarketIndex);
1426
+ const marketAccount = this.velocityClient.getPerpMarketAccountOrThrow(targetMarketIndex);
1382
1427
  // add any position we have on the opposite side of the current trade, because we can "flip" the size of this position without taking any extra leverage.
1383
1428
  const oppositeSizeLiabilityValue = targetingSameSide
1384
1429
  ? numericConstants_1.ZERO
@@ -1402,7 +1447,7 @@ class User {
1402
1447
  const perpLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price);
1403
1448
  const totalCollateral = this.getTotalCollateral();
1404
1449
  const marginRequirement = this.getInitialMarginRequirement();
1405
- const marginRatio = Math.max(currentPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
1450
+ const marginRatio = Math.max(currentPosition.maxMarginRatio, this.getUserAccountOrThrow().maxMarginRatio);
1406
1451
  const marginFreedByClosing = perpLiabilityValue
1407
1452
  .mul(new anchor_1.BN(marginRatio))
1408
1453
  .div(numericConstants_1.MARGIN_PRECISION);
@@ -1449,7 +1494,7 @@ class User {
1449
1494
  * @returns tradeSizeAllowed : Precision QUOTE_PRECISION
1450
1495
  */
1451
1496
  getMaxTradeSizeUSDCForSpot(targetMarketIndex, direction, currentQuoteAssetValue, currentSpotMarketNetValue) {
1452
- const market = this.velocityClient.getSpotMarketAccount(targetMarketIndex);
1497
+ const market = this.velocityClient.getSpotMarketAccountOrThrow(targetMarketIndex);
1453
1498
  const oraclePrice = this.velocityClient.getOracleDataForSpotMarket(targetMarketIndex).price;
1454
1499
  currentQuoteAssetValue = this.getSpotMarketAssetValue(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
1455
1500
  currentSpotMarketNetValue =
@@ -1457,19 +1502,19 @@ class User {
1457
1502
  let freeCollateral = this.getFreeCollateral();
1458
1503
  const marginRatio = (0, spotMarket_1.calculateSpotMarketMarginRatio)(market, oraclePrice, 'Initial', numericConstants_1.ZERO, (0, types_1.isVariant)(direction, 'long')
1459
1504
  ? types_2.SpotBalanceType.DEPOSIT
1460
- : types_2.SpotBalanceType.BORROW, this.getUserAccount().maxMarginRatio);
1505
+ : types_2.SpotBalanceType.BORROW, this.getUserAccountOrThrow().maxMarginRatio);
1461
1506
  let tradeAmount = numericConstants_1.ZERO;
1462
- if (this.getUserAccount().isMarginTradingEnabled) {
1507
+ if (this.getUserAccountOrThrow().isMarginTradingEnabled) {
1463
1508
  // if the user is buying/selling and already short/long, need to account for closing out short/long
1464
1509
  if ((0, types_1.isVariant)(direction, 'long') && currentSpotMarketNetValue.lt(numericConstants_1.ZERO)) {
1465
1510
  tradeAmount = currentSpotMarketNetValue.abs();
1466
- const marginRatio = (0, spotMarket_1.calculateSpotMarketMarginRatio)(market, oraclePrice, 'Initial', this.getTokenAmount(targetMarketIndex).abs(), types_2.SpotBalanceType.BORROW, this.getUserAccount().maxMarginRatio);
1511
+ const marginRatio = (0, spotMarket_1.calculateSpotMarketMarginRatio)(market, oraclePrice, 'Initial', this.getTokenAmount(targetMarketIndex).abs(), types_2.SpotBalanceType.BORROW, this.getUserAccountOrThrow().maxMarginRatio);
1467
1512
  freeCollateral = freeCollateral.add(tradeAmount.mul(new anchor_1.BN(marginRatio)).div(numericConstants_1.MARGIN_PRECISION));
1468
1513
  }
1469
1514
  else if ((0, types_1.isVariant)(direction, 'short') &&
1470
1515
  currentSpotMarketNetValue.gt(numericConstants_1.ZERO)) {
1471
1516
  tradeAmount = currentSpotMarketNetValue;
1472
- const marginRatio = (0, spotMarket_1.calculateSpotMarketMarginRatio)(market, oraclePrice, 'Initial', this.getTokenAmount(targetMarketIndex), types_2.SpotBalanceType.DEPOSIT, this.getUserAccount().maxMarginRatio);
1517
+ const marginRatio = (0, spotMarket_1.calculateSpotMarketMarginRatio)(market, oraclePrice, 'Initial', this.getTokenAmount(targetMarketIndex), types_2.SpotBalanceType.DEPOSIT, this.getUserAccountOrThrow().maxMarginRatio);
1473
1518
  freeCollateral = freeCollateral.add(tradeAmount.mul(new anchor_1.BN(marginRatio)).div(numericConstants_1.MARGIN_PRECISION));
1474
1519
  }
1475
1520
  tradeAmount = tradeAmount.add(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new anchor_1.BN(marginRatio)));
@@ -1492,8 +1537,8 @@ class User {
1492
1537
  * @param iterationLimit how long to run appromixation before erroring out
1493
1538
  */
1494
1539
  getMaxSwapAmount({ inMarketIndex, outMarketIndex, calculateSwap, iterationLimit = 1000, }) {
1495
- const inMarket = this.velocityClient.getSpotMarketAccount(inMarketIndex);
1496
- const outMarket = this.velocityClient.getSpotMarketAccount(outMarketIndex);
1540
+ const inMarket = this.velocityClient.getSpotMarketAccountOrThrow(inMarketIndex);
1541
+ const outMarket = this.velocityClient.getSpotMarketAccountOrThrow(outMarketIndex);
1497
1542
  const inOraclePriceData = this.getOracleDataForSpotMarket(inMarketIndex);
1498
1543
  const inOraclePrice = inOraclePriceData.price;
1499
1544
  const outOraclePriceData = this.getOracleDataForSpotMarket(outMarketIndex);
@@ -1599,7 +1644,7 @@ class User {
1599
1644
  return clonedPosition;
1600
1645
  }
1601
1646
  const preTokenAmount = (0, spotBalance_1.getSignedTokenAmount)((0, spotBalance_2.getTokenAmount)(position.scaledBalance, market, position.balanceType), position.balanceType);
1602
- if ((0, utils_1.sigNum)(preTokenAmount).eq((0, utils_1.sigNum)(tokenAmount))) {
1647
+ if ((0, utils_2.sigNum)(preTokenAmount).eq((0, utils_2.sigNum)(tokenAmount))) {
1603
1648
  const scaledBalanceDelta = (0, spotBalance_1.getBalance)(tokenAmount.abs(), market, position.balanceType);
1604
1649
  clonedPosition.scaledBalance =
1605
1650
  clonedPosition.scaledBalance.add(scaledBalanceDelta);
@@ -1621,15 +1666,15 @@ class User {
1621
1666
  }
1622
1667
  calculateSpotPositionFreeCollateralContribution(spotPosition, strictOraclePrice) {
1623
1668
  const marginCategory = 'Initial';
1624
- const spotMarketAccount = this.velocityClient.getSpotMarketAccount(spotPosition.marketIndex);
1625
- const { freeCollateralContribution } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, marginCategory, this.getUserAccount().maxMarginRatio);
1669
+ const spotMarketAccount = this.velocityClient.getSpotMarketAccountOrThrow(spotPosition.marketIndex);
1670
+ const { freeCollateralContribution } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, marginCategory, this.getUserAccountOrThrow().maxMarginRatio);
1626
1671
  return freeCollateralContribution;
1627
1672
  }
1628
1673
  calculateSpotPositionLeverageContribution(spotPosition, strictOraclePrice) {
1629
1674
  let totalAssetValue = numericConstants_1.ZERO;
1630
1675
  let totalLiabilityValue = numericConstants_1.ZERO;
1631
- const spotMarketAccount = this.velocityClient.getSpotMarketAccount(spotPosition.marketIndex);
1632
- const { tokenValue, ordersValue } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, 'Initial', this.getUserAccount().maxMarginRatio);
1676
+ const spotMarketAccount = this.velocityClient.getSpotMarketAccountOrThrow(spotPosition.marketIndex);
1677
+ const { tokenValue, ordersValue } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, 'Initial', this.getUserAccountOrThrow().maxMarginRatio);
1633
1678
  if (tokenValue.gte(numericConstants_1.ZERO)) {
1634
1679
  totalAssetValue = tokenValue;
1635
1680
  }
@@ -1655,8 +1700,8 @@ class User {
1655
1700
  * @param outAmount
1656
1701
  */
1657
1702
  accountLeverageAfterSwap({ inMarketIndex, outMarketIndex, inAmount, outAmount, }) {
1658
- const inMarket = this.velocityClient.getSpotMarketAccount(inMarketIndex);
1659
- const outMarket = this.velocityClient.getSpotMarketAccount(outMarketIndex);
1703
+ const inMarket = this.velocityClient.getSpotMarketAccountOrThrow(inMarketIndex);
1704
+ const outMarket = this.velocityClient.getSpotMarketAccountOrThrow(outMarketIndex);
1660
1705
  const inOraclePriceData = this.getOracleDataForSpotMarket(inMarketIndex);
1661
1706
  const inOraclePrice = inOraclePriceData.price;
1662
1707
  const outOraclePriceData = this.getOracleDataForSpotMarket(outMarketIndex);
@@ -1743,7 +1788,7 @@ class User {
1743
1788
  return newLeverage;
1744
1789
  }
1745
1790
  const currentPosition = this.getPerpPositionOrEmpty(targetMarketIndex);
1746
- const perpMarket = this.velocityClient.getPerpMarketAccount(targetMarketIndex);
1791
+ const perpMarket = this.velocityClient.getPerpMarketAccountOrThrow(targetMarketIndex);
1747
1792
  const oracleData = this.getOracleDataForPerpMarket(targetMarketIndex);
1748
1793
  let {
1749
1794
  // eslint-disable-next-line prefer-const
@@ -1778,13 +1823,11 @@ class User {
1778
1823
  }
1779
1824
  getUserFeeTier(marketType, now) {
1780
1825
  const state = this.velocityClient.getStateAccount();
1781
- const feeTierIndex = 0;
1782
1826
  if ((0, types_1.isVariant)(marketType, 'perp')) {
1783
1827
  const userStatsAccount = this.velocityClient
1784
- .getUserStats()
1785
- .getAccount();
1828
+ .getUserStatsOrThrow()
1829
+ .getAccountOrThrow();
1786
1830
  const total30dVolume = (0, trade_1.getUser30dRollingVolumeEstimate)(userStatsAccount, now);
1787
- const stakedGovAssetAmount = userStatsAccount.ifStakedGovTokenAmount;
1788
1831
  const volumeThresholds = [
1789
1832
  new anchor_1.BN(2000000).mul(numericConstants_1.QUOTE_PRECISION),
1790
1833
  new anchor_1.BN(10000000).mul(numericConstants_1.QUOTE_PRECISION),
@@ -1792,14 +1835,6 @@ class User {
1792
1835
  new anchor_1.BN(80000000).mul(numericConstants_1.QUOTE_PRECISION),
1793
1836
  new anchor_1.BN(200000000).mul(numericConstants_1.QUOTE_PRECISION),
1794
1837
  ];
1795
- const stakeThresholds = [
1796
- new anchor_1.BN(1000 - 1).mul(numericConstants_1.QUOTE_PRECISION),
1797
- new anchor_1.BN(10000 - 1).mul(numericConstants_1.QUOTE_PRECISION),
1798
- new anchor_1.BN(50000 - 1).mul(numericConstants_1.QUOTE_PRECISION),
1799
- new anchor_1.BN(100000 - 1).mul(numericConstants_1.QUOTE_PRECISION),
1800
- new anchor_1.BN(250000 - 5).mul(numericConstants_1.QUOTE_PRECISION),
1801
- ];
1802
- const stakeBenefitFrac = [0, 5, 10, 20, 30, 40];
1803
1838
  let feeTierIndex = 5;
1804
1839
  for (let i = 0; i < volumeThresholds.length; i++) {
1805
1840
  if (total30dVolume.lt(volumeThresholds[i])) {
@@ -1807,23 +1842,9 @@ class User {
1807
1842
  break;
1808
1843
  }
1809
1844
  }
1810
- let stakeBenefitIndex = 5;
1811
- for (let i = 0; i < stakeThresholds.length; i++) {
1812
- if (stakedGovAssetAmount.lt(stakeThresholds[i])) {
1813
- stakeBenefitIndex = i;
1814
- break;
1815
- }
1816
- }
1817
- const stakeBenefit = stakeBenefitFrac[stakeBenefitIndex];
1818
- const tier = { ...state.perpFeeStructure.feeTiers[feeTierIndex] };
1819
- if (stakeBenefit > 0) {
1820
- tier.feeNumerator = (tier.feeNumerator * (100 - stakeBenefit)) / 100;
1821
- tier.makerRebateNumerator =
1822
- (tier.makerRebateNumerator * (100 + stakeBenefit)) / 100;
1823
- }
1824
- return tier;
1845
+ return state.perpFeeStructure.feeTiers[feeTierIndex];
1825
1846
  }
1826
- return state.spotFeeStructure.feeTiers[feeTierIndex];
1847
+ return state.spotFeeStructure.feeTiers[0];
1827
1848
  }
1828
1849
  /**
1829
1850
  * Calculates how much perp fee will be taken for a given sized trade
@@ -1852,7 +1873,7 @@ class User {
1852
1873
  */
1853
1874
  getWithdrawalLimit(marketIndex, reduceOnly) {
1854
1875
  const nowTs = new anchor_1.BN(Math.floor(Date.now() / 1000));
1855
- const spotMarket = this.velocityClient.getSpotMarketAccount(marketIndex);
1876
+ const spotMarket = this.velocityClient.getSpotMarketAccountOrThrow(marketIndex);
1856
1877
  // eslint-disable-next-line prefer-const
1857
1878
  let { borrowLimit, withdrawLimit } = (0, spotBalance_2.calculateWithdrawLimit)(spotMarket, nowTs);
1858
1879
  const freeCollateral = this.getFreeCollateral();
@@ -1880,7 +1901,7 @@ class User {
1880
1901
  amountWithdrawable = userDepositAmount;
1881
1902
  }
1882
1903
  else {
1883
- amountWithdrawable = (0, utils_1.divCeil)((0, utils_1.divCeil)(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION), assetWeight).mul(numericConstants_1.PRICE_PRECISION), oracleData.price)
1904
+ amountWithdrawable = (0, utils_2.divCeil)((0, utils_2.divCeil)(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION), assetWeight).mul(numericConstants_1.PRICE_PRECISION), oracleData.price)
1884
1905
  .mul(numeratorScale)
1885
1906
  .div(denominatorScale);
1886
1907
  }
@@ -1905,10 +1926,10 @@ class User {
1905
1926
  }
1906
1927
  }
1907
1928
  canBypassWithdrawLimits(marketIndex) {
1908
- const spotMarket = this.velocityClient.getSpotMarketAccount(marketIndex);
1929
+ const spotMarket = this.velocityClient.getSpotMarketAccountOrThrow(marketIndex);
1909
1930
  const maxDepositAmount = spotMarket.withdrawGuardThreshold.div(new anchor_1.BN(10));
1910
1931
  const position = this.getSpotPosition(marketIndex);
1911
- const netDeposits = this.getUserAccount().totalDeposits.sub(this.getUserAccount().totalWithdraws);
1932
+ const netDeposits = this.getUserAccountOrThrow().totalDeposits.sub(this.getUserAccountOrThrow().totalWithdraws);
1912
1933
  if (!position) {
1913
1934
  return {
1914
1935
  canBypass: false,
@@ -1942,7 +1963,7 @@ class User {
1942
1963
  };
1943
1964
  }
1944
1965
  canMakeIdle(slot) {
1945
- const userAccount = this.getUserAccount();
1966
+ const userAccount = this.getUserAccountOrThrow();
1946
1967
  if (userAccount.idle) {
1947
1968
  return false;
1948
1969
  }
@@ -1985,12 +2006,13 @@ class User {
1985
2006
  return true;
1986
2007
  }
1987
2008
  canBeDeleted(userStatsAccount, now) {
1988
- const userAccount = this.getUserAccount();
1989
- const userStatsAccountToUse = userStatsAccount || this.velocityClient.getUserStats().getAccount();
2009
+ const userAccount = this.getUserAccountOrThrow();
2010
+ const userStatsAccountToUse = userStatsAccount !== null && userStatsAccount !== void 0 ? userStatsAccount : this.velocityClient.getUserStatsOrThrow().getAccount();
1990
2011
  const nowInSeconds = now || new anchor_1.BN(Math.floor(Date.now() / 1000));
1991
2012
  const stateAccount = this.velocityClient.getStateAccount();
1992
2013
  // Referrer cannot delete sub_account_id 0
1993
- const isReferrer = (userStatsAccountToUse.referrerStatus & types_1.ReferrerStatus.IsReferrer) > 0;
2014
+ const isReferrer = userStatsAccountToUse !== undefined &&
2015
+ (userStatsAccountToUse.referrerStatus & types_1.ReferrerStatus.IsReferrer) > 0;
1994
2016
  if (isReferrer && userAccount.subAccountId === 0) {
1995
2017
  return { canDelete: false, reason: 'is-subaccount-0-referrer' };
1996
2018
  }
@@ -2019,7 +2041,7 @@ class User {
2019
2041
  }
2020
2042
  }
2021
2043
  // Fresh account (< 13 days) with init fee must be idle
2022
- if (stateAccount.maxInitializeUserFee > 0) {
2044
+ if (stateAccount.maxInitializeUserFee > 0 && userStatsAccountToUse) {
2023
2045
  const minActionTs = anchor_1.BN.min(userStatsAccountToUse.lastFillerVolume30DTs, anchor_1.BN.min(userStatsAccountToUse.lastMakerVolume30DTs, userStatsAccountToUse.lastTakerVolume30DTs));
2024
2046
  const estimatedAge = anchor_1.BN.max(nowInSeconds.sub(minActionTs), numericConstants_1.ZERO);
2025
2047
  if (estimatedAge.lt(new anchor_1.BN(numericConstants_1.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS))) {
@@ -2037,13 +2059,13 @@ class User {
2037
2059
  let safestPerpTier = 4;
2038
2060
  let safestSpotTier = 4;
2039
2061
  for (const perpPosition of this.getActivePerpPositions()) {
2040
- safestPerpTier = Math.min(safestPerpTier, (0, tiers_1.getPerpMarketTierNumber)(this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex)));
2062
+ safestPerpTier = Math.min(safestPerpTier, (0, tiers_1.getPerpMarketTierNumber)(this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex)));
2041
2063
  }
2042
2064
  for (const spotPosition of this.getActiveSpotPositions()) {
2043
2065
  if ((0, types_1.isVariant)(spotPosition.balanceType, 'deposit')) {
2044
2066
  continue;
2045
2067
  }
2046
- safestSpotTier = Math.min(safestSpotTier, (0, tiers_1.getSpotMarketTierNumber)(this.velocityClient.getSpotMarketAccount(spotPosition.marketIndex)));
2068
+ safestSpotTier = Math.min(safestSpotTier, (0, tiers_1.getSpotMarketTierNumber)(this.velocityClient.getSpotMarketAccountOrThrow(spotPosition.marketIndex)));
2047
2069
  }
2048
2070
  return {
2049
2071
  perpTier: safestPerpTier,
@@ -2051,7 +2073,7 @@ class User {
2051
2073
  };
2052
2074
  }
2053
2075
  getPerpPositionHealth({ marginCategory, perpPosition, oraclePriceData, quoteOraclePriceData, includeOpenOrders = true, }) {
2054
- const perpMarket = this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex);
2076
+ const perpMarket = this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex);
2055
2077
  const _oraclePriceData = oraclePriceData ||
2056
2078
  this.velocityClient.getOracleDataForPerpMarket(perpMarket.marketIndex);
2057
2079
  const oraclePrice = _oraclePriceData.price;
@@ -2066,7 +2088,7 @@ class User {
2066
2088
  worstCaseBaseAmount = perpPosition.baseAssetAmount;
2067
2089
  worstCaseLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(perpPosition.baseAssetAmount, oraclePrice);
2068
2090
  }
2069
- const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
2091
+ const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccountOrThrow().maxMarginRatio);
2070
2092
  const marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(perpMarket, worstCaseBaseAmount.abs(), marginCategory, userCustomMargin));
2071
2093
  const _quoteOraclePriceData = quoteOraclePriceData ||
2072
2094
  this.velocityClient.getOracleDataForSpotMarket(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
@@ -2092,7 +2114,7 @@ class User {
2092
2114
  perpPnl: [],
2093
2115
  };
2094
2116
  for (const perpPosition of this.getActivePerpPositions()) {
2095
- const perpMarket = this.velocityClient.getPerpMarketAccount(perpPosition.marketIndex);
2117
+ const perpMarket = this.velocityClient.getPerpMarketAccountOrThrow(perpPosition.marketIndex);
2096
2118
  const oraclePriceData = this.velocityClient.getOracleDataForPerpMarket(perpMarket.marketIndex);
2097
2119
  const quoteOraclePriceData = this.velocityClient.getOracleDataForSpotMarket(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
2098
2120
  healthComponents.perpPositions.push(this.getPerpPositionHealth({
@@ -2101,7 +2123,7 @@ class User {
2101
2123
  oraclePriceData,
2102
2124
  quoteOraclePriceData,
2103
2125
  }));
2104
- const quoteSpotMarket = this.velocityClient.getSpotMarketAccount(perpMarket.quoteSpotMarketIndex);
2126
+ const quoteSpotMarket = this.velocityClient.getSpotMarketAccountOrThrow(perpMarket.quoteSpotMarketIndex);
2105
2127
  const positionUnrealizedPnl = (0, position_2.calculatePositionPNL)(perpMarket, perpPosition, true, oraclePriceData);
2106
2128
  let pnlWeight;
2107
2129
  if (positionUnrealizedPnl.gt(numericConstants_1.ZERO)) {
@@ -2126,7 +2148,7 @@ class User {
2126
2148
  }
2127
2149
  let netQuoteValue = numericConstants_1.ZERO;
2128
2150
  for (const spotPosition of this.getActiveSpotPositions()) {
2129
- const spotMarketAccount = this.velocityClient.getSpotMarketAccount(spotPosition.marketIndex);
2151
+ const spotMarketAccount = this.velocityClient.getSpotMarketAccountOrThrow(spotPosition.marketIndex);
2130
2152
  const oraclePriceData = this.getOracleDataForSpotMarket(spotPosition.marketIndex);
2131
2153
  const strictOraclePrice = new strictOraclePrice_1.StrictOraclePrice(oraclePriceData.price);
2132
2154
  if (spotPosition.marketIndex === numericConstants_1.QUOTE_SPOT_MARKET_INDEX) {
@@ -2134,7 +2156,7 @@ class User {
2134
2156
  netQuoteValue = netQuoteValue.add(tokenAmount);
2135
2157
  continue;
2136
2158
  }
2137
- const { tokenAmount: worstCaseTokenAmount, tokenValue: tokenValue, weight, weightedTokenValue: weightedTokenValue, ordersValue: ordersValue, } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, marginCategory, this.getUserAccount().maxMarginRatio);
2159
+ const { tokenAmount: worstCaseTokenAmount, tokenValue: tokenValue, weight, weightedTokenValue: weightedTokenValue, ordersValue: ordersValue, } = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, strictOraclePrice, marginCategory, this.getUserAccountOrThrow().maxMarginRatio);
2138
2160
  netQuoteValue = netQuoteValue.add(ordersValue);
2139
2161
  const baseAssetValue = tokenValue.abs();
2140
2162
  const weightedValue = weightedTokenValue.abs();
@@ -2161,7 +2183,7 @@ class User {
2161
2183
  const spotMarketAccount = this.velocityClient.getQuoteSpotMarketAccount();
2162
2184
  const oraclePriceData = this.getOracleDataForSpotMarket(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
2163
2185
  const baseAssetValue = (0, spotBalance_1.getTokenValue)(netQuoteValue, spotMarketAccount.decimals, oraclePriceData);
2164
- const { weight, weightedTokenValue } = (0, spotPosition_1.calculateWeightedTokenValue)(netQuoteValue, baseAssetValue, oraclePriceData.price, spotMarketAccount, marginCategory, this.getUserAccount().maxMarginRatio);
2186
+ const { weight, weightedTokenValue } = (0, spotPosition_1.calculateWeightedTokenValue)(netQuoteValue, baseAssetValue, oraclePriceData.price, spotMarketAccount, marginCategory, this.getUserAccountOrThrow().maxMarginRatio);
2165
2187
  if (netQuoteValue.lt(numericConstants_1.ZERO)) {
2166
2188
  healthComponents.borrows.push({
2167
2189
  marketIndex: spotMarketAccount.marketIndex,
@@ -2228,7 +2250,9 @@ class User {
2228
2250
  const liquidationBufferMap = (_b = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _b !== void 0 ? _b : new Map();
2229
2251
  const includeOpenOrders = (_c = opts === null || opts === void 0 ? void 0 : opts.includeOpenOrders) !== null && _c !== void 0 ? _c : true;
2230
2252
  // Equivalent to on-chain user_custom_margin_ratio
2231
- const userCustomMarginRatio = marginCategory === 'Initial' ? this.getUserAccount().maxMarginRatio : 0;
2253
+ const userCustomMarginRatio = marginCategory === 'Initial'
2254
+ ? this.getUserAccountOrThrow().maxMarginRatio
2255
+ : 0;
2232
2256
  // Initialize calc via JS mirror of Rust/on-chain MarginCalculation
2233
2257
  const isolatedMarginBuffers = new Map();
2234
2258
  for (const [marketIndex, isolatedMarginBuffer,] of (_d = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _d !== void 0 ? _d : new Map()) {
@@ -2242,11 +2266,11 @@ class User {
2242
2266
  .setIsolatedMarginBuffers(isolatedMarginBuffers);
2243
2267
  const calc = new marginCalculation_1.MarginCalculation(ctx);
2244
2268
  // SPOT POSITIONS
2245
- for (const spotPosition of this.getUserAccount().spotPositions) {
2269
+ for (const spotPosition of this.getUserAccountOrThrow().spotPositions) {
2246
2270
  if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition))
2247
2271
  continue;
2248
2272
  const isQuote = spotPosition.marketIndex === numericConstants_1.QUOTE_SPOT_MARKET_INDEX;
2249
- const spotMarket = this.velocityClient.getSpotMarketAccount(spotPosition.marketIndex);
2273
+ const spotMarket = this.velocityClient.getSpotMarketAccountOrThrow(spotPosition.marketIndex);
2250
2274
  const oraclePriceData = this.getOracleDataForSpotMarket(spotPosition.marketIndex);
2251
2275
  const twap5 = strict
2252
2276
  ? (0, oracles_1.calculateLiveOracleTwap)(spotMarket.historicalOracleData, oraclePriceData, new anchor_1.BN(Math.floor(Date.now() / 1000)), numericConstants_1.FIVE_MINUTE)
@@ -2295,8 +2319,8 @@ class User {
2295
2319
  }
2296
2320
  // PERP POSITIONS
2297
2321
  for (const marketPosition of this.getActivePerpPositions()) {
2298
- const market = this.velocityClient.getPerpMarketAccount(marketPosition.marketIndex);
2299
- const quoteSpotMarket = this.velocityClient.getSpotMarketAccount(market.quoteSpotMarketIndex);
2322
+ const market = this.velocityClient.getPerpMarketAccountOrThrow(marketPosition.marketIndex);
2323
+ const quoteSpotMarket = this.velocityClient.getSpotMarketAccountOrThrow(market.quoteSpotMarketIndex);
2300
2324
  const quoteOraclePriceData = this.getOracleDataForSpotMarket(market.quoteSpotMarketIndex);
2301
2325
  const oraclePriceData = this.getMMOracleDataForPerpMarket(market.marketIndex);
2302
2326
  const nonMmmOraclePriceData = this.getOracleDataForPerpMarket(market.marketIndex);
@@ -2349,7 +2373,7 @@ class User {
2349
2373
  // derive isolated quote deposit value, mirroring on-chain logic
2350
2374
  let depositValue = numericConstants_1.ZERO;
2351
2375
  if ((_h = marketPosition.isolatedPositionScaledBalance) === null || _h === void 0 ? void 0 : _h.gt(numericConstants_1.ZERO)) {
2352
- const quoteSpotMarket = this.velocityClient.getSpotMarketAccount(market.quoteSpotMarketIndex);
2376
+ const quoteSpotMarket = this.velocityClient.getSpotMarketAccountOrThrow(market.quoteSpotMarketIndex);
2353
2377
  const quoteOraclePriceData = this.getOracleDataForSpotMarket(market.quoteSpotMarketIndex);
2354
2378
  const strictQuote = new strictOraclePrice_1.StrictOraclePrice(quoteOraclePriceData.price, strict
2355
2379
  ? quoteSpotMarket.historicalOracleData.lastOraclePriceTwap5Min