@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
@@ -25,14 +25,14 @@ export type OrderFillSimulation = {
25
25
  tokenValue: BN;
26
26
  weight: BN;
27
27
  weightedTokenValue: BN;
28
- freeCollateralContribution;
28
+ freeCollateralContribution: BN;
29
29
  };
30
30
 
31
31
  export function getWorstCaseTokenAmounts(
32
32
  spotPosition: SpotPosition,
33
33
  spotMarketAccount: SpotMarketAccount,
34
34
  strictOraclePrice: StrictOraclePrice,
35
- marginCategory: MarginCategory,
35
+ marginCategory: MarginCategory | undefined,
36
36
  customMarginRatio?: number,
37
37
  includeOpenOrders: boolean = true
38
38
  ): OrderFillSimulation {
@@ -108,7 +108,7 @@ export function calculateWeightedTokenValue(
108
108
  tokenValue: BN,
109
109
  oraclePrice: BN,
110
110
  spotMarket: SpotMarketAccount,
111
- marginCategory: MarginCategory,
111
+ marginCategory: MarginCategory | undefined,
112
112
  customMarginRatio?: number
113
113
  ): { weight: BN; weightedTokenValue: BN } {
114
114
  let weight: BN;
@@ -158,7 +158,7 @@ export function simulateOrderFill(
158
158
  openOrders: BN,
159
159
  strictOraclePrice: StrictOraclePrice,
160
160
  spotMarket: SpotMarketAccount,
161
- marginCategory: MarginCategory,
161
+ marginCategory: MarginCategory | undefined,
162
162
  customMarginRatio?: number
163
163
  ): OrderFillSimulation {
164
164
  const ordersValue = getTokenValue(openOrders.neg(), spotMarket.decimals, {
package/src/math/state.ts CHANGED
@@ -38,11 +38,3 @@ export function useMedianTriggerPrice(stateAccount: StateAccount): boolean {
38
38
  (stateAccount.featureBitFlags & FeatureBitFlags.MEDIAN_TRIGGER_PRICE) > 0
39
39
  );
40
40
  }
41
-
42
- export function builderCodesEnabled(stateAccount: StateAccount): boolean {
43
- return (stateAccount.featureBitFlags & FeatureBitFlags.BUILDER_CODES) > 0;
44
- }
45
-
46
- export function builderReferralEnabled(stateAccount: StateAccount): boolean {
47
- return (stateAccount.featureBitFlags & FeatureBitFlags.BUILDER_REFERRAL) > 0;
48
- }
@@ -95,7 +95,7 @@ export async function findBestSuperStakeIxs({
95
95
  } else if (marketIndex === 8) {
96
96
  return findBestLstSuperStakeIxs({
97
97
  amount,
98
- lstMint: velocityClient.getSpotMarketAccount(8).mint,
98
+ lstMint: velocityClient.getSpotMarketAccountOrThrow(8).mint,
99
99
  lstMarketIndex: 8,
100
100
  jupiterClient,
101
101
  velocityClient,
@@ -137,10 +137,10 @@ export async function findBestMSolSuperStakeIxs({
137
137
  price = await getMarinadeMSolPrice(marinadeProgram);
138
138
  }
139
139
 
140
- const solSpotMarketAccount = velocityClient.getSpotMarketAccount(1);
141
- const mSolSpotMarketAccount = velocityClient.getSpotMarketAccount(2);
140
+ const solSpotMarketAccount = velocityClient.getSpotMarketAccountOrThrow(1);
141
+ const mSolSpotMarketAccount = velocityClient.getSpotMarketAccountOrThrow(2);
142
142
 
143
- let jupiterPrice: number;
143
+ let jupiterPrice: number | undefined;
144
144
  let quote = jupiterQuote;
145
145
  if (!jupiterQuote) {
146
146
  try {
@@ -152,7 +152,7 @@ export async function findBestMSolSuperStakeIxs({
152
152
  onlyDirectRoutes,
153
153
  });
154
154
 
155
- jupiterPrice = +quote.outAmount / +quote.inAmount;
155
+ jupiterPrice = +fetchedQuote.outAmount / +fetchedQuote.inAmount;
156
156
 
157
157
  quote = fetchedQuote;
158
158
  } catch (e) {
@@ -216,7 +216,7 @@ export async function findBestJitoSolSuperStakeIxs({
216
216
  velocityClient,
217
217
  userAccountPublicKey,
218
218
  onlyDirectRoutes,
219
- lstMint: velocityClient.getSpotMarketAccount(6).mint,
219
+ lstMint: velocityClient.getSpotMarketAccountOrThrow(6).mint,
220
220
  lstMarketIndex: 6,
221
221
  jupiterQuote,
222
222
  });
@@ -326,63 +326,6 @@ export async function fetchJitoSolMetrics() {
326
326
  return data;
327
327
  }
328
328
 
329
- export type MSOL_METRICS_ENDPOINT_RESPONSE = {
330
- total_active_balance: number;
331
- available_reserve_balance: number;
332
- emergency_cooling_down: number;
333
- tvl_sol: number;
334
- msol_directed_stake_sol: number;
335
- msol_directed_stake_msol: number;
336
- mnde_total_supply: number;
337
- mnde_circulating_supply: number;
338
- validators_count: number;
339
- stake_accounts: number;
340
- staking_sol_cap: number;
341
- m_sol_price: number;
342
- avg_staking_apy: number;
343
- msol_price_apy_14d: number;
344
- msol_price_apy_30d: number;
345
- msol_price_apy_90d: number;
346
- msol_price_apy_365d: number;
347
- reserve_pda: number;
348
- treasury_m_sol_amount: number;
349
- m_sol_mint_supply: number;
350
- m_sol_supply_state: number;
351
- liq_pool_sol: number;
352
- liq_pool_m_sol: number;
353
- liq_pool_value: number;
354
- liq_pool_token_supply: number;
355
- liq_pool_token_price: number;
356
- liq_pool_target: number;
357
- liq_pool_min_fee: number;
358
- liq_pool_max_fee: number;
359
- liq_pool_current_fee: number;
360
- liq_pool_treasury_cut: number;
361
- liq_pool_cap: number;
362
- total_cooling_down: number;
363
- last_stake_delta_epoch: number;
364
- circulating_ticket_count: number;
365
- circulating_ticket_balance: number;
366
- reward_fee_bp: number;
367
- lido_staking: number;
368
- lido_st_sol_price: number;
369
- lido_stsol_price_apy_14d: number;
370
- lido_stsol_price_apy_30d: number;
371
- lido_stsol_price_apy_90d: number;
372
- lido_stsol_price_apy_365d: number;
373
- stake_delta: number;
374
- bot_balance: number;
375
- treasury_farm_claim_mnde_balance: number;
376
- last_3_epochs_avg_duration_hs: number;
377
- mnde_votes_validators: number;
378
- };
379
-
380
- export const fetchMSolMetrics = async () => {
381
- const res = await fetch('https://api2.marinade.finance/metrics_json');
382
- const data: MSOL_METRICS_ENDPOINT_RESPONSE = await res.json();
383
- return data;
384
- };
385
-
386
329
  const getJitoSolHistoricalPriceMap = async (timestamps: number[]) => {
387
330
  try {
388
331
  const data = await fetchJitoSolMetrics();
@@ -436,7 +379,7 @@ export async function calculateSolEarned({
436
379
 
437
380
  let lstRatios = new Map<number, number>();
438
381
 
439
- const getMsolPrice = async (timestamp) => {
382
+ const getMsolPrice = async (timestamp: number) => {
440
383
  const date = new Date(timestamp * 1000); // Convert Unix timestamp to milliseconds
441
384
  const swaggerApiDateTime = date.toISOString(); // Format date as swagger API date-time
442
385
  const url = `https://api.marinade.finance/msol/price_sol?time=${swaggerApiDateTime}`;
@@ -465,7 +408,10 @@ export async function calculateSolEarned({
465
408
  if (marketIndex === 2) {
466
409
  await Promise.all(timestamps.map(getMsolPrice));
467
410
  } else if (marketIndex === 6) {
468
- lstRatios = await getJitoSolHistoricalPriceMap(timestamps);
411
+ const jitoSolRatios = await getJitoSolHistoricalPriceMap(timestamps);
412
+ if (jitoSolRatios) {
413
+ lstRatios = jitoSolRatios;
414
+ }
469
415
  } else if (marketIndex === 8) {
470
416
  await getBSolPrice(timestamps);
471
417
  }
@@ -484,6 +430,11 @@ export async function calculateSolEarned({
484
430
  record.marketIndex === 8
485
431
  ) {
486
432
  const lstRatio = lstRatios.get(record.ts.toNumber());
433
+ if (lstRatio === undefined) {
434
+ throw new Error(
435
+ `Missing LST/SOL ratio for deposit record at timestamp ${record.ts.toNumber()}`
436
+ );
437
+ }
487
438
  const lstRatioBN = new BN(lstRatio * LAMPORTS_PER_SOL);
488
439
 
489
440
  const solAmount = record.amount.mul(lstRatioBN).div(LAMPORTS_PRECISION);
@@ -497,6 +448,9 @@ export async function calculateSolEarned({
497
448
 
498
449
  const currentLstTokenAmount = await user.getTokenAmount(marketIndex);
499
450
  const currentLstRatio = lstRatios.get(now);
451
+ if (currentLstRatio === undefined) {
452
+ throw new Error(`Missing current LST/SOL ratio for timestamp ${now}`);
453
+ }
500
454
  const currentLstRatioBN = new BN(currentLstRatio * LAMPORTS_PER_SOL);
501
455
 
502
456
  solEarned = solEarned.add(
package/src/math/trade.ts CHANGED
@@ -114,7 +114,6 @@ export function calculateTradeSlippage(
114
114
  calculateUpdatedAMMSpreadReserves(
115
115
  market.amm,
116
116
  market.marketStats,
117
- market.totalExchangeFee,
118
117
  direction,
119
118
  mmOraclePriceData,
120
119
  latestSlot
@@ -187,7 +186,6 @@ export function calculateTradeAcquiredAmounts(
187
186
  calculateUpdatedAMMSpreadReserves(
188
187
  market.amm,
189
188
  market.marketStats,
190
- market.totalExchangeFee,
191
189
  direction,
192
190
  mmOraclePriceData,
193
191
  latestSlot
@@ -279,7 +277,6 @@ export function calculateTargetPriceTrade(
279
277
  calculateUpdatedAMMSpreadReserves(
280
278
  market.amm,
281
279
  market.marketStats,
282
- market.totalExchangeFee,
283
280
  direction,
284
281
  mmOraclePriceData,
285
282
  latestSlot
@@ -376,7 +373,7 @@ export function calculateTargetPriceTrade(
376
373
 
377
374
  assert(tp1.sub(tp2).lte(originalDiff), 'Target Price Calculation incorrect');
378
375
  assert(
379
- tp2.lte(tp1) || tp2.sub(tp1).abs() < 100000,
376
+ tp2.lte(tp1) || tp2.sub(tp1).abs().ltn(100000),
380
377
  'Target Price Calculation incorrect' +
381
378
  tp2.toString() +
382
379
  '>=' +
@@ -443,7 +440,6 @@ export function calculateEstimatedPerpEntryPrice(
443
440
  calculateUpdatedAMMSpreadReserves(
444
441
  market.amm,
445
442
  market.marketStats,
446
- market.totalExchangeFee,
447
443
  direction,
448
444
  mmOraclePriceData,
449
445
  new BN(slot)
@@ -493,7 +489,7 @@ export function calculateEstimatedPerpEntryPrice(
493
489
 
494
490
  let limitOrder = limitOrders.next().value;
495
491
  if (limitOrder) {
496
- const limitOrderPrice = limitOrder.getPrice(mmOraclePriceData, slot);
492
+ const limitOrderPrice = limitOrder.getPriceOrThrow(mmOraclePriceData, slot);
497
493
  bestPrice = takerIsLong
498
494
  ? BN.min(limitOrderPrice, bestPrice)
499
495
  : BN.max(limitOrderPrice, bestPrice);
package/src/memcmp.ts CHANGED
@@ -48,15 +48,6 @@ export function getUserWithAuctionFilter(): MemcmpFilter {
48
48
  };
49
49
  }
50
50
 
51
- export function getUserThatHasBeenLP(): MemcmpFilter {
52
- return {
53
- memcmp: {
54
- offset: 4267,
55
- bytes: bs58.encode(Uint8Array.from([99])),
56
- },
57
- };
58
- }
59
-
60
51
  export function getUserWithName(name: string): MemcmpFilter {
61
52
  return {
62
53
  memcmp: {
@@ -2,6 +2,7 @@ import { Connection, PublicKey } from '@solana/web3.js';
2
2
  import { OracleClient, OraclePriceData } from './types';
3
3
  import { VelocityProgram } from '../config';
4
4
  import { PrelaunchOracle } from '../types';
5
+ import { getOracleAccountDataOrThrow } from './utils';
5
6
 
6
7
  export class PrelaunchOracleClient implements OracleClient {
7
8
  private connection: Connection;
@@ -15,8 +16,12 @@ export class PrelaunchOracleClient implements OracleClient {
15
16
  public async getOraclePriceData(
16
17
  pricePublicKey: PublicKey
17
18
  ): Promise<OraclePriceData> {
18
- const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
19
- return this.getOraclePriceDataFromBuffer(accountInfo.data);
19
+ const data = await getOracleAccountDataOrThrow(
20
+ this.connection,
21
+ pricePublicKey,
22
+ 'Prelaunch oracle'
23
+ );
24
+ return this.getOraclePriceDataFromBuffer(data);
20
25
  }
21
26
 
22
27
  public getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData {
@@ -8,6 +8,7 @@ import {
8
8
  QUOTE_PRECISION,
9
9
  TEN,
10
10
  } from '../constants/numericConstants';
11
+ import { getOracleAccountDataOrThrow } from './utils';
11
12
 
12
13
  export class PythClient implements OracleClient {
13
14
  private connection: Connection;
@@ -27,14 +28,22 @@ export class PythClient implements OracleClient {
27
28
  public async getOraclePriceData(
28
29
  pricePublicKey: PublicKey
29
30
  ): Promise<OraclePriceData> {
30
- const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
31
- return this.getOraclePriceDataFromBuffer(accountInfo.data);
31
+ const data = await getOracleAccountDataOrThrow(
32
+ this.connection,
33
+ pricePublicKey,
34
+ 'Pyth oracle'
35
+ );
36
+ return this.getOraclePriceDataFromBuffer(data);
32
37
  }
33
38
 
34
39
  public getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData {
35
40
  const priceData = parsePriceData(buffer);
41
+ // `confidence` is absent on uninitialized/invalid price accounts. Base passed it
42
+ // straight into convertPythPrice, where `undefined * 10**exponent` is `NaN` and
43
+ // `new BN(NaN)` coerces to 0 — so base already yielded a zero-confidence price.
44
+ // `?? 0` makes that explicit and type-checks, preserving the same result.
36
45
  const confidence = convertPythPrice(
37
- priceData.confidence,
46
+ priceData.confidence ?? 0,
38
47
  priceData.exponent,
39
48
  this.multiple
40
49
  );
@@ -11,6 +11,7 @@ import {
11
11
  } from '../constants/numericConstants';
12
12
  import { Wallet } from '../wallet';
13
13
  import velocityIDL from '../idl/velocity.json';
14
+ import { getOracleAccountDataOrThrow } from './utils';
14
15
 
15
16
  export class PythLazerClient implements OracleClient {
16
17
  private connection: Connection;
@@ -46,8 +47,12 @@ export class PythLazerClient implements OracleClient {
46
47
  public async getOraclePriceData(
47
48
  pricePublicKey: PublicKey
48
49
  ): Promise<OraclePriceData> {
49
- const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
50
- return this.getOraclePriceDataFromBuffer(accountInfo.data);
50
+ const data = await getOracleAccountDataOrThrow(
51
+ this.connection,
52
+ pricePublicKey,
53
+ 'Pyth lazer oracle'
54
+ );
55
+ return this.getOraclePriceDataFromBuffer(data);
51
56
  }
52
57
 
53
58
  public getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData {
@@ -1,6 +1,21 @@
1
+ import { Connection, PublicKey } from '@solana/web3.js';
1
2
  import { BN } from '../isomorphic/anchor';
2
3
  import { OraclePriceData } from './types';
3
4
 
5
+ export async function getOracleAccountDataOrThrow(
6
+ connection: Connection,
7
+ pricePublicKey: PublicKey,
8
+ oracleName: string
9
+ ): Promise<Buffer> {
10
+ const accountInfo = await connection.getAccountInfo(pricePublicKey);
11
+ if (!accountInfo) {
12
+ throw new Error(
13
+ `${oracleName} account not found: ${pricePublicKey.toBase58()}`
14
+ );
15
+ }
16
+ return accountInfo.data;
17
+ }
18
+
4
19
  export function getOracleConfidenceFromMMOracleData(
5
20
  mmOraclePrice: BN,
6
21
  oraclePriceData: OraclePriceData
@@ -27,9 +27,9 @@ export class OrderSubscriber {
27
27
  eventEmitter: StrictEventEmitter<EventEmitter, OrderSubscriberEvents>;
28
28
 
29
29
  fetchPromise?: Promise<void>;
30
- fetchPromiseResolver: () => void;
30
+ private fetchPromiseResolver: () => void = () => {};
31
31
 
32
- mostRecentSlot: number;
32
+ mostRecentSlot = 0;
33
33
  decodeFn: (name: string, data: Buffer) => UserAccount;
34
34
  decodeData?: boolean;
35
35
 
@@ -276,7 +276,7 @@ export class OrderSubscriber {
276
276
  userAccountPublicKey,
277
277
  this.commitment
278
278
  );
279
- if (accountInfo) {
279
+ if (accountInfo.value) {
280
280
  this.tryUpdateUserAccount(
281
281
  userAccountPublicKey.toString(),
282
282
  'buffer',
@@ -290,7 +290,13 @@ export class OrderSubscriber {
290
290
  if (!this.usersAccounts.has(key)) {
291
291
  await this.addPubkey(new PublicKey(key));
292
292
  }
293
- return this.usersAccounts.get(key).userAccount;
293
+ const slotAndUserAccount = this.usersAccounts.get(key);
294
+ if (!slotAndUserAccount) {
295
+ throw new Error(
296
+ `OrderSubscriber: user account ${key} not found after addPubkey`
297
+ );
298
+ }
299
+ return slotAndUserAccount.userAccount;
294
300
  }
295
301
 
296
302
  public async unsubscribe(): Promise<void> {
@@ -28,7 +28,7 @@ export async function fetchHeliusPriorityFee(
28
28
  heliusRpcUrl: string,
29
29
  lookbackDistance: number,
30
30
  addresses: string[]
31
- ): Promise<HeliusPriorityFeeResponse> {
31
+ ): Promise<HeliusPriorityFeeResponse | undefined> {
32
32
  try {
33
33
  const response = await fetch(heliusRpcUrl, {
34
34
  method: 'POST',
@@ -19,7 +19,7 @@ import {
19
19
  } from './velocityPriorityFeeMethod';
20
20
 
21
21
  export class PriorityFeeSubscriber {
22
- connection: Connection;
22
+ connection?: Connection;
23
23
  frequencyMs: number;
24
24
  addresses: string[];
25
25
  velocityMarkets?: VelocityMarketInfo[];
@@ -64,7 +64,7 @@ export class PriorityFeeSubscriber {
64
64
 
65
65
  if (this.priorityFeeMethod === PriorityFeeMethod.HELIUS) {
66
66
  if (config.heliusRpcUrl === undefined) {
67
- if (this.connection.rpcEndpoint.includes('helius')) {
67
+ if (this.connection?.rpcEndpoint.includes('helius')) {
68
68
  this.heliusRpcUrl = this.connection.rpcEndpoint;
69
69
  } else {
70
70
  throw new Error(
@@ -103,11 +103,19 @@ export class PriorityFeeSubscriber {
103
103
  }
104
104
 
105
105
  private async loadForSolana(): Promise<void> {
106
+ if (this.connection === undefined) {
107
+ throw new Error(
108
+ 'connection must be provided to use SOLANA priority fee API'
109
+ );
110
+ }
106
111
  const samples = await fetchSolanaPriorityFee(
107
- this.connection!,
112
+ this.connection,
108
113
  this.lookbackDistance,
109
114
  this.addresses
110
115
  );
116
+ if (samples === undefined) {
117
+ throw new Error('fetchSolanaPriorityFee returned no samples');
118
+ }
111
119
  if (samples.length > 0) {
112
120
  this.latestPriorityFee = samples[0].prioritizationFee;
113
121
  this.lastSlotSeen = samples[0].slot;
@@ -121,6 +129,11 @@ export class PriorityFeeSubscriber {
121
129
  }
122
130
 
123
131
  private async loadForHelius(): Promise<void> {
132
+ if (this.heliusRpcUrl === undefined) {
133
+ throw new Error(
134
+ 'heliusRpcUrl must be provided to use PriorityFeeMethod.HELIUS'
135
+ );
136
+ }
124
137
  const sample = await fetchHeliusPriorityFee(
125
138
  this.heliusRpcUrl,
126
139
  this.lookbackDistance,
@@ -128,13 +141,13 @@ export class PriorityFeeSubscriber {
128
141
  );
129
142
  this.lastHeliusSample = sample?.result?.priorityFeeLevels ?? undefined;
130
143
 
131
- if (this.lastHeliusSample) {
144
+ if (sample !== undefined && this.lastHeliusSample) {
132
145
  this.lastAvgStrategyResult =
133
146
  this.lastHeliusSample[HeliusPriorityLevel.MEDIUM];
134
147
  this.lastMaxStrategyResult =
135
148
  this.lastHeliusSample[HeliusPriorityLevel.UNSAFE_MAX];
136
149
  if (this.customStrategy) {
137
- this.lastCustomStrategyResult = this.customStrategy.calculate(sample!);
150
+ this.lastCustomStrategyResult = this.customStrategy.calculate(sample);
138
151
  }
139
152
  }
140
153
  }
@@ -143,16 +156,39 @@ export class PriorityFeeSubscriber {
143
156
  if (!this.velocityMarkets) {
144
157
  return;
145
158
  }
159
+ if (this.velocityPriorityFeeEndpoint === undefined) {
160
+ throw new Error(
161
+ 'velocityPriorityFeeEndpoint must be provided to use PriorityFeeMethod.VELOCITY'
162
+ );
163
+ }
146
164
  const sample = await fetchVelocityPriorityFee(
147
- this.velocityPriorityFeeEndpoint!,
165
+ this.velocityPriorityFeeEndpoint,
148
166
  this.velocityMarkets.map((m) => m.marketType),
149
167
  this.velocityMarkets.map((m) => m.marketIndex)
150
168
  );
151
169
  if (sample.length > 0) {
152
- this.lastAvgStrategyResult = sample[HeliusPriorityLevel.MEDIUM];
153
- this.lastMaxStrategyResult = sample[HeliusPriorityLevel.UNSAFE_MAX];
170
+ // The endpoint returns one fee-level set per requested market. Take the
171
+ // max level across markets so a transaction touching several markets is
172
+ // covered by the most expensive one. (Base indexed the array itself with
173
+ // a string enum key — `sample['medium']` — which yielded `undefined` and
174
+ // produced NaN strategy results; the missing per-element index is fixed
175
+ // here.)
176
+ this.lastAvgStrategyResult = Math.max(
177
+ ...sample.map((s) => s[HeliusPriorityLevel.MEDIUM])
178
+ );
179
+ this.lastMaxStrategyResult = Math.max(
180
+ ...sample.map((s) => s[HeliusPriorityLevel.UNSAFE_MAX])
181
+ );
154
182
  if (this.customStrategy) {
155
- this.lastCustomStrategyResult = this.customStrategy.calculate(sample);
183
+ // Custom strategies expect `{ slot, prioritizationFee }[]`; map each
184
+ // market's medium level into that shape so they aggregate real values
185
+ // instead of summing the absent `prioritizationFee` field (NaN).
186
+ this.lastCustomStrategyResult = this.customStrategy.calculate(
187
+ sample.map((s) => ({
188
+ slot: 0,
189
+ prioritizationFee: s[HeliusPriorityLevel.MEDIUM],
190
+ }))
191
+ );
156
192
  }
157
193
  }
158
194
  }
@@ -9,7 +9,7 @@ export async function fetchSolanaPriorityFee(
9
9
  connection: Connection,
10
10
  lookbackDistance: number,
11
11
  addresses: string[]
12
- ): Promise<SolanaPriorityFeeResponse[]> {
12
+ ): Promise<SolanaPriorityFeeResponse[] | undefined> {
13
13
  try {
14
14
  // @ts-ignore
15
15
  const rpcJSONResponse: any = await connection._rpcRequest(
package/src/pyth/types.ts CHANGED
@@ -4445,8 +4445,6 @@ export const IDL: PythSolanaReceiver = {
4445
4445
  },
4446
4446
  ],
4447
4447
  };
4448
-
4449
- export declare const PYTH_SOLANA_RECEIVER_IDL: PythSolanaReceiver;
4450
4448
  //# sourceMappingURL=pyth_solana_receiver.d.ts.map
4451
4449
 
4452
4450
  export type PriceUpdateAccount =
@@ -12,8 +12,8 @@ export interface SlotSubscriberEvents {
12
12
  }
13
13
 
14
14
  export class SlotSubscriber {
15
- currentSlot: number;
16
- subscriptionId: number;
15
+ currentSlot = 0;
16
+ subscriptionId?: number;
17
17
  eventEmitter: StrictEventEmitter<EventEmitter, SlotSubscriberEvents>;
18
18
 
19
19
  // Reconnection
@@ -28,7 +28,7 @@ export class SlotSubscriber {
28
28
  ) {
29
29
  this.eventEmitter = new EventEmitter();
30
30
  this.resubTimeoutMs = config?.resubTimeoutMs;
31
- if (this.resubTimeoutMs < 1000) {
31
+ if (this.resubTimeoutMs !== undefined && this.resubTimeoutMs < 1000) {
32
32
  console.log(
33
33
  'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
34
34
  );
@@ -18,8 +18,16 @@ export type Slothash = {
18
18
  };
19
19
 
20
20
  export class SlothashSubscriber {
21
- currentSlothash: Slothash;
22
- subscriptionId: number;
21
+ private _currentSlothash?: Slothash;
22
+ private get currentSlothash(): Slothash {
23
+ if (!this._currentSlothash) {
24
+ throw new Error(
25
+ 'SlothashSubscriber: slothash accessed before subscribe()'
26
+ );
27
+ }
28
+ return this._currentSlothash;
29
+ }
30
+ subscriptionId?: number;
23
31
  commitment: Commitment;
24
32
 
25
33
  // Reconnection
@@ -34,7 +42,7 @@ export class SlothashSubscriber {
34
42
  ) {
35
43
  this.resubTimeoutMs = config?.resubTimeoutMs;
36
44
  this.commitment = config?.commitment ?? 'processed';
37
- if (this.resubTimeoutMs < 1000) {
45
+ if (this.resubTimeoutMs != null && this.resubTimeoutMs < 1000) {
38
46
  console.log(
39
47
  'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
40
48
  );
@@ -53,18 +61,21 @@ export class SlothashSubscriber {
53
61
  if (currentAccountData == null) {
54
62
  throw new Error('Failed to retrieve current slot hash');
55
63
  }
56
- this.currentSlothash = deserializeSlothash(currentAccountData.data);
64
+ this._currentSlothash = deserializeSlothash(currentAccountData.data);
57
65
 
58
66
  this.subscriptionId = this.connection.onAccountChange(
59
67
  SYSVAR_SLOT_HASHES_PUBKEY,
60
68
  (slothashInfo, context) => {
61
- if (!this.currentSlothash || this.currentSlothash.slot < context.slot) {
69
+ if (
70
+ !this._currentSlothash ||
71
+ this._currentSlothash.slot < context.slot
72
+ ) {
62
73
  if (this.resubTimeoutMs && !this.isUnsubscribing) {
63
74
  this.receivingData = true;
64
75
  clearTimeout(this.timeoutId);
65
76
  this.setTimeout();
66
77
  }
67
- this.currentSlothash = deserializeSlothash(slothashInfo.data);
78
+ this._currentSlothash = deserializeSlothash(slothashInfo.data);
68
79
  }
69
80
  },
70
81
  this.commitment
@@ -10,7 +10,6 @@ import {
10
10
 
11
11
  export class grpcSignedMsgUserOrdersAccountSubscriber extends SignedMsgUserOrdersAccountSubscriber {
12
12
  private grpcConfigs: GrpcConfigs;
13
- override subscriber: grpcProgramAccountSubscriber<SignedMsgUserOrdersAccount>;
14
13
 
15
14
  constructor({
16
15
  grpcConfigs,
@@ -23,8 +22,8 @@ export class grpcSignedMsgUserOrdersAccountSubscriber extends SignedMsgUserOrder
23
22
  }
24
23
 
25
24
  public async subscribe(): Promise<void> {
26
- if (!this.subscriber) {
27
- this.subscriber =
25
+ if (!this._subscriber) {
26
+ this._subscriber =
28
27
  await grpcProgramAccountSubscriber.create<SignedMsgUserOrdersAccount>(
29
28
  this.grpcConfigs,
30
29
  'SingedMsgUserOrdersAccountMap',
@@ -71,9 +70,9 @@ export class grpcSignedMsgUserOrdersAccountSubscriber extends SignedMsgUserOrder
71
70
  }
72
71
 
73
72
  public async unsubscribe(): Promise<void> {
74
- if (!this.subscriber) return;
75
- await this.subscriber.unsubscribe();
76
- this.subscriber = undefined;
73
+ if (!this._subscriber) return;
74
+ await this._subscriber.unsubscribe();
75
+ this._subscriber = undefined;
77
76
  if (this.resyncTimeoutId !== undefined) {
78
77
  clearTimeout(this.resyncTimeoutId);
79
78
  this.resyncTimeoutId = undefined;