@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
@@ -16,7 +16,7 @@ function calculateLiveMarkTwap(market, mmOraclePriceData, markPrice, now, period
16
16
  const timeSinceLastMarkChange = now.sub(lastMarkPriceTwapTs);
17
17
  const markTwapTimeSinceLastUpdate = anchor_1.BN.max(period, anchor_1.BN.max(numericConstants_1.ZERO, period.sub(timeSinceLastMarkChange)));
18
18
  if (!markPrice) {
19
- const [bid, ask] = (0, amm_1.calculateBidAskPrice)(market.amm, market.marketStats, market.totalExchangeFee, mmOraclePriceData);
19
+ const [bid, ask] = (0, amm_1.calculateBidAskPrice)(market.amm, market.marketStats, mmOraclePriceData);
20
20
  markPrice = bid.add(ask).div(new anchor_1.BN(2));
21
21
  }
22
22
  const markTwapWithMantissa = markTwapTimeSinceLastUpdate
@@ -66,6 +66,9 @@ function calculateAllEstimatedFundingRate(market, mmOraclePriceData, oraclePrice
66
66
  now = now || new anchor_1.BN((Date.now() / 1000).toFixed(0));
67
67
  // calculate real-time mark and oracle twap
68
68
  const liveMarkTwap = calculateLiveMarkTwap(market, mmOraclePriceData, markPrice, now, market.marketStats.fundingPeriod);
69
+ if (!oraclePriceData) {
70
+ throw new Error('calculateAllEstimatedFundingRate: oraclePriceData is required for an initialized market');
71
+ }
69
72
  const liveOracleTwap = (0, oracles_1.calculateLiveOracleTwap)(market.marketStats.historicalOracleData, oraclePriceData, now, market.marketStats.fundingPeriod);
70
73
  const [markTwap, oracleTwap] = shrinkStaleTwaps(market, liveMarkTwap, liveOracleTwap, now);
71
74
  // if(!markTwap.eq(liveMarkTwap)){
@@ -250,11 +253,8 @@ exports.calculateLongShortFundingRateAndLiveTwaps = calculateLongShortFundingRat
250
253
  */
251
254
  function calculateFundingPool(market) {
252
255
  // todo
253
- const totalFeeLB = market.totalExchangeFee.div(new anchor_1.BN(2));
254
- const feePool = anchor_1.BN.max(numericConstants_1.ZERO, market.amm.totalFeeMinusDistributions
255
- .sub(totalFeeLB)
256
- .mul(new anchor_1.BN(1))
257
- .div(new anchor_1.BN(3)));
256
+ // no protocol floor post-isolation: 1/3 of the AMM's own equity
257
+ const feePool = anchor_1.BN.max(numericConstants_1.ZERO, market.amm.totalFeeMinusDistributions.mul(new anchor_1.BN(1)).div(new anchor_1.BN(3)));
258
258
  return feePool;
259
259
  }
260
260
  exports.calculateFundingPool = calculateFundingPool;
@@ -1,8 +1,7 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../isomorphic/anchor';
3
2
  import { SpotMarketAccount } from '../types';
4
3
  export declare function nextRevenuePoolSettleApr(spotMarket: SpotMarketAccount, vaultBalance: BN, // vault token amount
5
- amount?: BN): number;
4
+ amount: BN): number;
6
5
  export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
7
6
  export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
8
7
  export declare function unstakeSharesToAmountWithOpenRequest(nShares: BN, withdrawRequestShares: BN, withdrawRequestAmount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
@@ -1 +1 @@
1
- {"version":3,"file":"insurance.d.ts","sourceRoot":"","sources":["../../../src/math/insurance.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAmB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE9D,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,iBAAiB,EAC7B,YAAY,EAAE,EAAE,EAAE,qBAAqB;AACvC,MAAM,CAAC,EAAE,EAAE,GACT,MAAM,CAuCR;AAED,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,EAAE,EACV,aAAa,EAAE,EAAE,EACjB,yBAAyB,EAAE,EAAE,GAC3B,EAAE,CASJ;AAED,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,EAAE,EACX,aAAa,EAAE,EAAE,EACjB,yBAAyB,EAAE,EAAE,GAC3B,EAAE,CAYJ;AAED,wBAAgB,oCAAoC,CACnD,OAAO,EAAE,EAAE,EACX,qBAAqB,EAAE,EAAE,EACzB,qBAAqB,EAAE,EAAE,EACzB,aAAa,EAAE,EAAE,EACjB,yBAAyB,EAAE,EAAE,GAC3B,EAAE,CAqBJ"}
1
+ {"version":3,"file":"insurance.d.ts","sourceRoot":"","sources":["../../../src/math/insurance.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAmB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE9D,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,iBAAiB,EAC7B,YAAY,EAAE,EAAE,EAAE,qBAAqB;AACvC,MAAM,EAAE,EAAE,GACR,MAAM,CAqCR;AAED,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,EAAE,EACV,aAAa,EAAE,EAAE,EACjB,yBAAyB,EAAE,EAAE,GAC3B,EAAE,CASJ;AAED,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,EAAE,EACX,aAAa,EAAE,EAAE,EACjB,yBAAyB,EAAE,EAAE,GAC3B,EAAE,CAYJ;AAED,wBAAgB,oCAAoC,CACnD,OAAO,EAAE,EAAE,EACX,qBAAqB,EAAE,EAAE,EACzB,qBAAqB,EAAE,EAAE,EACzB,aAAa,EAAE,EAAE,EACjB,yBAAyB,EAAE,EAAE,GAC3B,EAAE,CAqBJ"}
@@ -12,11 +12,10 @@ amount // delta token amount
12
12
  // Conmputing the APR:
13
13
  const revenuePoolBN = (0, spotBalance_1.getTokenAmount)(spotMarket.revenuePool.scaledBalance, spotMarket, types_1.SpotBalanceType.DEPOSIT);
14
14
  const payoutRatio = 0.1;
15
- const ratioForStakers = spotMarket.insuranceFund.totalFactor > 0 &&
16
- spotMarket.insuranceFund.userFactor > 0 &&
17
- spotMarket.insuranceFund.revenueSettlePeriod.gt(numericConstants_1.ZERO)
18
- ? spotMarket.insuranceFund.userFactor /
19
- spotMarket.insuranceFund.totalFactor
15
+ // the insurance fund is 100% staker-owned: every settled token accrues to
16
+ // stakers as share-price appreciation (no protocol split)
17
+ const ratioForStakers = spotMarket.insuranceFund.revenueSettlePeriod.gt(numericConstants_1.ZERO)
18
+ ? 1
20
19
  : 0;
21
20
  // Settle periods from on-chain data:
22
21
  const revSettlePeriod = spotMarket.insuranceFund.revenueSettlePeriod.toNumber() * 1000;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../isomorphic/anchor';
3
2
  export declare function calculateBaseAssetAmountToCoverMarginShortage(marginShortage: BN, marginRatio: number, liquidationFee: number, ifLiquidationFee: number, oraclePrice: BN, quoteOraclePrice: BN): BN | undefined;
4
3
  export declare function calculateLiabilityTransferToCoverMarginShortage(marginShortage: BN, assetWeight: number, assetLiquidationMultiplier: number, liabilityWeight: number, liabilityLiquidationMultiplier: number, liabilityDecimals: number, liabilityPrice: BN, ifLiquidationFee: number): BN | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/math/liquidation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAa1C,wBAAgB,6CAA6C,CAC5D,cAAc,EAAE,EAAE,EAClB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,EAAE,EACf,gBAAgB,EAAE,EAAE,GAClB,EAAE,GAAG,SAAS,CAqBhB;AAED,wBAAgB,+CAA+C,CAC9D,cAAc,EAAE,EAAE,EAClB,WAAW,EAAE,MAAM,EACnB,0BAA0B,EAAE,MAAM,EAClC,eAAe,EAAE,MAAM,EACvB,8BAA8B,EAAE,MAAM,EACtC,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,EAAE,EAClB,gBAAgB,EAAE,MAAM,GACtB,EAAE,GAAG,SAAS,CA8ChB;AAED,wBAAgB,0CAA0C,CACzD,WAAW,EAAE,EAAE,EACf,0BAA0B,E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,EAAE,MAAM,EACtC,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,EAAE,GAChB,EAAE,GAAG,SAAS,CAkDhB;AAED,wBAAgB,0BAA0B,CACzC,kBAAkB,EAAE,EAAE,EACtB,0BAA0B,EAAE,EAAE,EAC9B,cAAc,EAAE,EAAE,EAClB,IAAI,EAAE,EAAE,EACR,qBAAqB,EAAE,EAAE,EACzB,mBAAmB,EAAE,EAAE,GACrB,EAAE,CA+BJ;AAED,wBAAgB,iBAAiB,CAChC,sCAAsC,EAAE,EAAE,EAC1C,0BAA0B,EAAE,EAAE,GAC5B,EAAE,CAIJ"}
@@ -1,14 +1,11 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../isomorphic/anchor';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { VelocityClient } from '../velocityClient';
5
- import { PerpMarketAccount, PerpPosition, PositionDirection, UserAccount } from '../types';
6
- import { PublicKey } from '@solana/web3.js';
4
+ import { PerpMarketAccount, PerpPosition } from '../types';
7
5
  export declare function calculateSizePremiumLiabilityWeight(size: BN, // AMM_RESERVE_PRECISION
8
6
  imfFactor: BN, liabilityWeight: BN, precision: BN, isBounded?: boolean): BN;
9
7
  export declare function calculateSizeDiscountAssetWeight(size: BN, // AMM_RESERVE_PRECISION
10
8
  imfFactor: BN, assetWeight: BN): BN;
11
- export declare function calculateOraclePriceForPerpMargin(perpPosition: PerpPosition, market: PerpMarketAccount, oraclePriceData: OraclePriceData): BN;
12
9
  /**
13
10
  * This is _not_ the same as liability value as for prediction markets, the liability for the short in prediction market is (1 - oracle price) * base
14
11
  * See {@link calculatePerpLiabilityValue} to get the liabiltiy value
@@ -37,10 +34,4 @@ export declare function calculateMarginUSDCRequiredForTrade(velocityClient: Velo
37
34
  * Returns collateral required in the precision of the target collateral market.
38
35
  */
39
36
  export declare function calculateCollateralDepositRequiredForTrade(velocityClient: VelocityClient, targetMarketIndex: number, baseSize: BN, collateralIndex: number, userMaxMarginRatio?: number, estEntryPrice?: BN): BN;
40
- export declare function calculateCollateralValueOfDeposit(velocityClient: VelocityClient, collateralIndex: number, baseSize: BN): BN;
41
- export declare function calculateLiquidationPrice(freeCollateral: BN, freeCollateralDelta: BN, oraclePrice: BN): BN;
42
- export declare function calculateUserMaxPerpOrderSize(velocityClient: VelocityClient, userAccountKey: PublicKey, userAccount: UserAccount, targetMarketIndex: number, tradeSide: PositionDirection): {
43
- tradeSize: BN;
44
- oppositeSideTradeSize: BN;
45
- };
46
37
  //# sourceMappingURL=margin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"margin.d.ts","sourceRoot":"","sources":["../../../src/math/margin.ts"],"names":[],"mappings":";AAiBA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EACN,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5C,wBAAgB,mCAAmC,CAClD,IAAI,EAAE,EAAE,EAAE,wBAAwB;AAClC,SAAS,EAAE,EAAE,EACb,eAAe,EAAE,EAAE,EACnB,SAAS,EAAE,EAAE,EACb,SAAS,UAAO,GACd,EAAE,CA4BJ;AAED,wBAAgB,gCAAgC,CAC/C,IAAI,EAAE,EAAE,EAAE,wBAAwB;AAClC,SAAS,EAAE,EAAE,EACb,WAAW,EAAE,EAAE,GACb,EAAE,CAuBJ;AAED,wBAAgB,iCAAiC,CAChD,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,eAAe,GAC9B,EAAE,CAoBJ;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAChD,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,YAAY,EAC1B,eAAe,EA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CAAA;CAAE,CAkC/D;AAED,wBAAgB,2BAA2B,CAC1C,eAAe,EAAE,EAAE,EACnB,KAAK,EAAE,EAAE,GACP,EAAE,CAEJ;AAED;;;;;GAKG;AACH,wBAAgB,mCAAmC,CAClD,cAAc,EAAE,cAAc,EAC9B,iBAAiB,EAAE,MAAM,EACzB,QAAQ,EAAE,EAAE,EACZ,kBAAkB,CAAC,EAAE,MAAM,EAC3B,UAAU,CAAC,EAAE,EAAE,GACb,EAAE,CAsBJ;AAED;;;;GAIG;AACH,wBAAgB,0CAA0C,CACzD,cAAc,EAAE,cAAc,EAC9B,iBAAiB,EAAE,MAAM,EACzB,QAAQ,EAAE,EAAE,EACZ,eAAe,EAAE,MAAM,EACvB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,aAAa,CAAC,EAAE,EAAE,GAChB,EAAE,CAgCJ"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateUserMaxPerpOrderSize = exports.calculateLiquidationPrice = exports.calculateCollateralValueOfDeposit = exports.calculateCollateralDepositRequiredForTrade = exports.calculateMarginUSDCRequiredForTrade = exports.calculatePerpLiabilityValue = exports.calculateWorstCasePerpLiabilityValue = exports.calculateWorstCaseBaseAssetAmount = exports.calculateBaseAssetValueWithOracle = exports.calculateOraclePriceForPerpMargin = exports.calculateSizeDiscountAssetWeight = exports.calculateSizePremiumLiabilityWeight = void 0;
3
+ exports.calculateCollateralDepositRequiredForTrade = exports.calculateMarginUSDCRequiredForTrade = exports.calculatePerpLiabilityValue = exports.calculateWorstCasePerpLiabilityValue = exports.calculateWorstCaseBaseAssetAmount = exports.calculateBaseAssetValueWithOracle = exports.calculateSizeDiscountAssetWeight = exports.calculateSizePremiumLiabilityWeight = void 0;
4
4
  /**
5
5
  * Margin calculation helpers — TypeScript mirror of `programs/velocity/src/math/margin.rs`.
6
6
  * Computes initial/maintenance margin requirements, free collateral, and account health.
@@ -11,8 +11,6 @@ const numericConstants_1 = require("../constants/numericConstants");
11
11
  const anchor_1 = require("../isomorphic/anchor");
12
12
  const market_1 = require("./market");
13
13
  const spotBalance_1 = require("./spotBalance");
14
- const oneShotUserAccountSubscriber_1 = require("../accounts/oneShotUserAccountSubscriber");
15
- const user_1 = require("../user");
16
14
  const types_1 = require("../types");
17
15
  const assert_1 = require("../assert/assert");
18
16
  function calculateSizePremiumLiabilityWeight(size, // AMM_RESERVE_PRECISION
@@ -55,22 +53,6 @@ imfFactor, assetWeight) {
55
53
  return minAssetWeight;
56
54
  }
57
55
  exports.calculateSizeDiscountAssetWeight = calculateSizeDiscountAssetWeight;
58
- function calculateOraclePriceForPerpMargin(perpPosition, market, oraclePriceData) {
59
- const oraclePriceOffset = anchor_1.BN.min(new anchor_1.BN(market.amm.maxSpread)
60
- .mul(oraclePriceData.price)
61
- .div(numericConstants_1.BID_ASK_SPREAD_PRECISION), oraclePriceData.confidence.add(new anchor_1.BN(market.amm.baseSpread)
62
- .mul(oraclePriceData.price)
63
- .div(numericConstants_1.BID_ASK_SPREAD_PRECISION)));
64
- let marginPrice;
65
- if (perpPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
66
- marginPrice = oraclePriceData.price.sub(oraclePriceOffset);
67
- }
68
- else {
69
- marginPrice = oraclePriceData.price.add(oraclePriceOffset);
70
- }
71
- return marginPrice;
72
- }
73
- exports.calculateOraclePriceForPerpMargin = calculateOraclePriceForPerpMargin;
74
56
  /**
75
57
  * This is _not_ the same as liability value as for prediction markets, the liability for the short in prediction market is (1 - oracle price) * base
76
58
  * See {@link calculatePerpLiabilityValue} to get the liabiltiy value
@@ -131,7 +113,7 @@ exports.calculatePerpLiabilityValue = calculatePerpLiabilityValue;
131
113
  * @returns
132
114
  */
133
115
  function calculateMarginUSDCRequiredForTrade(velocityClient, targetMarketIndex, baseSize, userMaxMarginRatio, entryPrice) {
134
- const targetMarket = velocityClient.getPerpMarketAccount(targetMarketIndex);
116
+ const targetMarket = velocityClient.getPerpMarketAccountOrThrow(targetMarketIndex);
135
117
  const price = entryPrice !== null && entryPrice !== void 0 ? entryPrice : velocityClient.getOracleDataForPerpMarket(targetMarket.marketIndex).price;
136
118
  const perpLiabilityValue = calculatePerpLiabilityValue(baseSize, price);
137
119
  const marginRequired = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(targetMarket, baseSize.abs(), 'Initial', userMaxMarginRatio))
@@ -147,7 +129,7 @@ exports.calculateMarginUSDCRequiredForTrade = calculateMarginUSDCRequiredForTrad
147
129
  */
148
130
  function calculateCollateralDepositRequiredForTrade(velocityClient, targetMarketIndex, baseSize, collateralIndex, userMaxMarginRatio, estEntryPrice) {
149
131
  const marginRequiredUsdc = calculateMarginUSDCRequiredForTrade(velocityClient, targetMarketIndex, baseSize, userMaxMarginRatio, estEntryPrice);
150
- const collateralMarket = velocityClient.getSpotMarketAccount(collateralIndex);
132
+ const collateralMarket = velocityClient.getSpotMarketAccountOrThrow(collateralIndex);
151
133
  const collateralOracleData = velocityClient.getOracleDataForSpotMarket(collateralIndex);
152
134
  const scaledAssetWeight = (0, spotBalance_1.calculateScaledInitialAssetWeight)(collateralMarket, collateralOracleData.price);
153
135
  // Base amount required to deposit = (marginRequiredUsdc / priceOfAsset) / assetWeight .. (E.g. $100 required / $10000 price / 0.5 weight)
@@ -162,44 +144,3 @@ function calculateCollateralDepositRequiredForTrade(velocityClient, targetMarket
162
144
  return baseAmountRequired;
163
145
  }
164
146
  exports.calculateCollateralDepositRequiredForTrade = calculateCollateralDepositRequiredForTrade;
165
- function calculateCollateralValueOfDeposit(velocityClient, collateralIndex, baseSize) {
166
- const collateralMarket = velocityClient.getSpotMarketAccount(collateralIndex);
167
- const collateralOracleData = velocityClient.getOracleDataForSpotMarket(collateralIndex);
168
- const scaledAssetWeight = (0, spotBalance_1.calculateScaledInitialAssetWeight)(collateralMarket, collateralOracleData.price);
169
- // CollateralBaseValue = oracle price * collateral base amount (and shift to QUOTE_PRECISION)
170
- const collateralBaseValue = collateralOracleData.price
171
- .mul(baseSize)
172
- .mul(numericConstants_1.QUOTE_PRECISION)
173
- .div(numericConstants_1.PRICE_PRECISION)
174
- .div(new anchor_1.BN(10).pow(new anchor_1.BN(collateralMarket.decimals)));
175
- const depositCollateralValue = collateralBaseValue
176
- .mul(scaledAssetWeight)
177
- .div(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
178
- return depositCollateralValue;
179
- }
180
- exports.calculateCollateralValueOfDeposit = calculateCollateralValueOfDeposit;
181
- function calculateLiquidationPrice(freeCollateral, freeCollateralDelta, oraclePrice) {
182
- const liqPriceDelta = freeCollateral
183
- .mul(numericConstants_1.QUOTE_PRECISION)
184
- .div(freeCollateralDelta);
185
- const liqPrice = oraclePrice.sub(liqPriceDelta);
186
- if (liqPrice.lt(numericConstants_1.ZERO)) {
187
- return new anchor_1.BN(-1);
188
- }
189
- return liqPrice;
190
- }
191
- exports.calculateLiquidationPrice = calculateLiquidationPrice;
192
- function calculateUserMaxPerpOrderSize(velocityClient, userAccountKey, userAccount, targetMarketIndex, tradeSide) {
193
- const userAccountSubscriber = new oneShotUserAccountSubscriber_1.OneShotUserAccountSubscriber(velocityClient.program, userAccountKey, userAccount);
194
- const user = new user_1.User({
195
- velocityClient,
196
- userAccountPublicKey: userAccountKey,
197
- accountSubscription: {
198
- type: 'custom',
199
- userAccountSubscriber: userAccountSubscriber,
200
- },
201
- });
202
- user.isSubscribed = true;
203
- return user.getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide);
204
- }
205
- exports.calculateUserMaxPerpOrderSize = calculateUserMaxPerpOrderSize;
@@ -1,31 +1,27 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../isomorphic/anchor';
3
- import { PerpMarketAccount, PositionDirection, MarginCategory, SpotMarketAccount } from '../types';
2
+ import { PerpMarketAccount, MarginCategory, SpotMarketAccount } from '../types';
4
3
  import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
5
- import { DLOB } from '../dlob/DLOB';
6
4
  /**
7
5
  * Calculates market mark price
8
6
  *
9
7
  * @param market
10
8
  * @return markPrice : Precision PRICE_PRECISION
11
9
  */
12
- export declare function calculateReservePrice(market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData): BN;
10
+ export declare function calculateReservePrice(market: PerpMarketAccount, mmOraclePriceData?: MMOraclePriceData): BN;
13
11
  /**
14
12
  * Calculates market bid price
15
13
  *
16
14
  * @param market
17
15
  * @return bidPrice : Precision PRICE_PRECISION
18
16
  */
19
- export declare function calculateBidPrice(market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData, latestSlot?: BN): BN;
17
+ export declare function calculateBidPrice(market: PerpMarketAccount, mmOraclePriceData?: MMOraclePriceData, latestSlot?: BN): BN;
20
18
  /**
21
19
  * Calculates market ask price
22
20
  *
23
21
  * @param market
24
22
  * @return askPrice : Precision PRICE_PRECISION
25
23
  */
26
- export declare function calculateAskPrice(market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData, latestSlot?: BN): BN;
27
- export declare function calculateNewMarketAfterTrade(baseAssetAmount: BN, direction: PositionDirection, market: PerpMarketAccount): PerpMarketAccount;
28
- export declare function calculateOracleReserveSpread(market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData): BN;
24
+ export declare function calculateAskPrice(market: PerpMarketAccount, mmOraclePriceData?: MMOraclePriceData, latestSlot?: BN): BN;
29
25
  export declare function calculateOracleSpread(price: BN, oraclePriceData: OraclePriceData): BN;
30
26
  export declare function calculateMarketMarginRatio(market: PerpMarketAccount, size: BN, marginCategory: MarginCategory, customMarginRatio?: number): number;
31
27
  export declare function calculateUnrealizedAssetWeight(market: PerpMarketAccount, quoteSpotMarket: SpotMarketAccount, unrealizedPnl: BN, marginCategory: MarginCategory, oraclePriceData: Pick<OraclePriceData, 'price'>): BN;
@@ -33,11 +29,6 @@ export declare function calculateMarketAvailablePNL(perpMarket: PerpMarketAccoun
33
29
  export declare function calculateMarketMaxAvailableInsurance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount): BN;
34
30
  export declare function calculateNetUserPnl(perpMarket: PerpMarketAccount, oraclePriceData: Pick<OraclePriceData, 'price'>): BN;
35
31
  export declare function calculateNetUserPnlImbalance(perpMarket: PerpMarketAccount, spotMarket: SpotMarketAccount, oraclePriceData: Pick<OraclePriceData, 'price'>, applyFeePoolDiscount?: boolean): BN;
36
- export declare function calculateAvailablePerpLiquidity(market: PerpMarketAccount, mmOraclePriceData: MMOraclePriceData, dlob: DLOB, slot: number): {
37
- bids: BN;
38
- asks: BN;
39
- };
40
- export declare function calculatePerpMarketBaseLiquidatorFee(market: PerpMarketAccount): number;
41
32
  /**
42
33
  * Calculates trigger price for a perp market based on oracle price and current time
43
34
  * Implements the same logic as the Rust get_trigger_price function
@@ -1 +1 @@
1
- {"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../../src/math/market.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EAIjB,MAAM,UAAU,CAAC;AAalB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAYtE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,iBAAiB,EACzB,iBAAiB,EAAE,iBAAiB,GAClC,EAAE,CAWJ;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,iBAAiB,EACzB,iBAAiB,EAAE,iBAAiB,EACpC,UAAU,CAAC,EAAE,EAAE,GACb,EAAE,CAYJ;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,iBAAiB,EACzB,iBAAiB,EAAE,iBAAiB,EACpC,UAAU,CAAC,EAAE,EAAE,GACb,EAAE,CAYJ;AAED,wBAAgB,4BAA4B,CAC3C,eAAe,EAAE,EA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E,iBAAiB,EACzB,eAAe,EAAE,iBAAiB,EAClC,aAAa,EAAE,EAAE,EACjB,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAC7C,EAAE,CA+BJ;AAED,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,iBAAiB,EAC7B,UAAU,EAAE,iBAAiB,GAC3B,EAAE,CAMJ;AAED,wBAAgB,oCAAoC,CACnD,UAAU,EAAE,iBAAiB,EAC7B,UAAU,EAAE,iBAAiB,GAC3B,EAAE,CAcJ;AAED,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,iBAAiB,EAC7B,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAC7C,EAAE,CAaJ;AAED,wBAAgB,4BAA4B,CAC3C,UAAU,EAAE,iBAAiB,EAC7B,UAAU,EAAE,iBAAiB,EAC7B,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,EAC/C,oBAAoB,UAAO,GACzB,EAAE,CAoBJ;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,iBAAiB,EACzB,WAAW,EAAE,EAAE,EACf,GAAG,EAAE,EAAE,EACP,cAAc,EAAE,OAAO,GACrB,EAAE,CA2BJ"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTriggerPrice = exports.calculatePerpMarketBaseLiquidatorFee = exports.calculateAvailablePerpLiquidity = exports.calculateNetUserPnlImbalance = exports.calculateNetUserPnl = exports.calculateMarketMaxAvailableInsurance = exports.calculateMarketAvailablePNL = exports.calculateUnrealizedAssetWeight = exports.calculateMarketMarginRatio = exports.calculateOracleSpread = exports.calculateOracleReserveSpread = exports.calculateNewMarketAfterTrade = exports.calculateAskPrice = exports.calculateBidPrice = exports.calculateReservePrice = void 0;
3
+ exports.getTriggerPrice = exports.calculateNetUserPnlImbalance = exports.calculateNetUserPnl = exports.calculateMarketMaxAvailableInsurance = exports.calculateMarketAvailablePNL = exports.calculateUnrealizedAssetWeight = exports.calculateMarketMarginRatio = exports.calculateOracleSpread = exports.calculateAskPrice = exports.calculateBidPrice = exports.calculateReservePrice = void 0;
4
4
  const anchor_1 = require("../isomorphic/anchor");
5
5
  const types_1 = require("../types");
6
6
  const amm_1 = require("./amm");
@@ -15,7 +15,7 @@ const assert_1 = require("../assert/assert");
15
15
  * @return markPrice : Precision PRICE_PRECISION
16
16
  */
17
17
  function calculateReservePrice(market, mmOraclePriceData) {
18
- const newAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, market.totalExchangeFee, mmOraclePriceData);
18
+ const newAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, mmOraclePriceData);
19
19
  return (0, amm_1.calculatePrice)(newAmm.baseAssetReserve, newAmm.quoteAssetReserve, newAmm.pegMultiplier);
20
20
  }
21
21
  exports.calculateReservePrice = calculateReservePrice;
@@ -26,7 +26,7 @@ exports.calculateReservePrice = calculateReservePrice;
26
26
  * @return bidPrice : Precision PRICE_PRECISION
27
27
  */
28
28
  function calculateBidPrice(market, mmOraclePriceData, latestSlot) {
29
- const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, types_1.PositionDirection.SHORT, mmOraclePriceData, latestSlot);
29
+ const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, types_1.PositionDirection.SHORT, mmOraclePriceData, latestSlot);
30
30
  return (0, amm_1.calculatePrice)(baseAssetReserve, quoteAssetReserve, newPeg);
31
31
  }
32
32
  exports.calculateBidPrice = calculateBidPrice;
@@ -37,25 +37,10 @@ exports.calculateBidPrice = calculateBidPrice;
37
37
  * @return askPrice : Precision PRICE_PRECISION
38
38
  */
39
39
  function calculateAskPrice(market, mmOraclePriceData, latestSlot) {
40
- const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, market.totalExchangeFee, types_1.PositionDirection.LONG, mmOraclePriceData, latestSlot);
40
+ const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, market.marketStats, types_1.PositionDirection.LONG, mmOraclePriceData, latestSlot);
41
41
  return (0, amm_1.calculatePrice)(baseAssetReserve, quoteAssetReserve, newPeg);
42
42
  }
43
43
  exports.calculateAskPrice = calculateAskPrice;
44
- function calculateNewMarketAfterTrade(baseAssetAmount, direction, market) {
45
- const [newQuoteAssetReserve, newBaseAssetReserve] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'base', baseAssetAmount.abs(), (0, amm_1.getSwapDirection)('base', direction));
46
- const newAmm = Object.assign({}, market.amm);
47
- const newMarket = Object.assign({}, market);
48
- newMarket.amm = newAmm;
49
- newMarket.amm.quoteAssetReserve = newQuoteAssetReserve;
50
- newMarket.amm.baseAssetReserve = newBaseAssetReserve;
51
- return newMarket;
52
- }
53
- exports.calculateNewMarketAfterTrade = calculateNewMarketAfterTrade;
54
- function calculateOracleReserveSpread(market, mmOraclePriceData) {
55
- const reservePrice = calculateReservePrice(market, mmOraclePriceData);
56
- return calculateOracleSpread(reservePrice, mmOraclePriceData);
57
- }
58
- exports.calculateOracleReserveSpread = calculateOracleReserveSpread;
59
44
  function calculateOracleSpread(price, oraclePriceData) {
60
45
  return price.sub(oraclePriceData.price);
61
46
  }
@@ -138,25 +123,6 @@ function calculateNetUserPnlImbalance(perpMarket, spotMarket, oraclePriceData, a
138
123
  return imbalance;
139
124
  }
140
125
  exports.calculateNetUserPnlImbalance = calculateNetUserPnlImbalance;
141
- function calculateAvailablePerpLiquidity(market, mmOraclePriceData, dlob, slot) {
142
- let [bids, asks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.orderStepSize);
143
- asks = asks.abs();
144
- for (const bid of dlob.getRestingLimitBids(market.marketIndex, slot, types_1.MarketType.PERP, mmOraclePriceData)) {
145
- bids = bids.add(bid.order.baseAssetAmount.sub(bid.order.baseAssetAmountFilled));
146
- }
147
- for (const ask of dlob.getRestingLimitAsks(market.marketIndex, slot, types_1.MarketType.PERP, mmOraclePriceData)) {
148
- asks = asks.add(ask.order.baseAssetAmount.sub(ask.order.baseAssetAmountFilled));
149
- }
150
- return {
151
- bids: bids,
152
- asks: asks,
153
- };
154
- }
155
- exports.calculateAvailablePerpLiquidity = calculateAvailablePerpLiquidity;
156
- function calculatePerpMarketBaseLiquidatorFee(market) {
157
- return market.liquidatorFee;
158
- }
159
- exports.calculatePerpMarketBaseLiquidatorFee = calculatePerpMarketBaseLiquidatorFee;
160
126
  /**
161
127
  * Calculates trigger price for a perp market based on oracle price and current time
162
128
  * Implements the same logic as the Rust get_trigger_price function
@@ -193,10 +159,10 @@ exports.getTriggerPrice = getTriggerPrice;
193
159
  * Implements the same logic as the Rust get_last_funding_basis function
194
160
  */
195
161
  function getLastFundingBasis(market, oraclePrice, now) {
196
- if (market.lastFundingOracleTwap.gt(numericConstants_1.ZERO)) {
162
+ if (market.marketStats.lastFundingOracleTwap.gt(numericConstants_1.ZERO)) {
197
163
  const lastFundingRate = market.lastFundingRate
198
164
  .mul(numericConstants_1.PRICE_PRECISION)
199
- .div(market.lastFundingOracleTwap)
165
+ .div(market.marketStats.lastFundingOracleTwap)
200
166
  .muln(24);
201
167
  const lastFundingRatePreAdj = lastFundingRate.sub(numericConstants_1.FUNDING_RATE_PRECISION.div(new anchor_1.BN(3333)) // FUNDING_RATE_OFFSET_PERCENTAGE
202
168
  );
@@ -1,6 +1,3 @@
1
- /// <reference types="bn.js" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
1
  import { HistoricalOracleData, MarketStats, OracleGuardRails, OracleSource, OracleValidity, PerpMarketAccount } from '../types';
5
2
  import { OraclePriceData } from '../oracles/types';
6
3
  import { BN } from '../isomorphic/anchor';
@@ -12,7 +9,6 @@ export declare function isOracleTooDivergent(marketStats: MarketStats, oraclePri
12
9
  export declare function calculateLiveOracleTwap(histOracleData: HistoricalOracleData, oraclePriceData: OraclePriceData, now: BN, period: BN): BN;
13
10
  export declare function calculateLiveOracleStd(marketStats: MarketStats, oraclePriceData: OraclePriceData, now: BN): BN;
14
11
  export declare function getNewOracleConfPct(marketStats: MarketStats, oraclePriceData: OraclePriceData, reservePrice: BN, now: BN): BN;
15
- export declare function trimVaaSignatures(vaa: Buffer, n?: number): Buffer;
16
12
  export declare function getMultipleBetweenOracleSources(firstOracleSource: OracleSource, secondOracleSource: OracleSource): {
17
13
  numerator: BN;
18
14
  denominator: BN;
@@ -1 +1 @@
1
- {"version":3,"file":"oracles.d.ts","sourceRoot":"","sources":["../../../src/math/oracles.ts"],"names":[],"mappings":";;;AAAA,OAAO,EACN,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,iBAAiB,EAGjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAWnD,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAE1C,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAC7C,CAAC,EAAE,EAAE,EAAE,CAAC,CAUV;AAED,wBAAgB,kCAAkC,CACjD,MAAM,EAAE,iBAAiB,GACvB,EAAE,CAcJ;AAED,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,eAAe,EAChC,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,EAAE,EACR,qBAAqB,KAAO,GAC1B,cAAc,CAwEhB;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,eAAe,EAChC,gBAAgB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E,CAAC,CAUV;AAED,wBAAgB,kCAAkC,CACjD,MAAM,EAAE,iBAAiB,GACvB,EAAE,CAcJ;AAED,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,eAAe,EAChC,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,EAAE,EACR,qBAAqB,KAAO,GAC1B,cAAc,CAwEhB;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,eAAe,EAChC,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,MAAM,GACV,OAAO,CAmCT;AAED,wBAAgB,oBAAoB,CACnC,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,EAChC,gBAAgB,EAAE,gBAAgB,GAChC,OAAO,CAWT;AAED,wBAAgB,uBAAuB,CACtC,cAAc,EAAE,oBAAoB,EACpC,eAAe,EAAE,eAAe,EAChC,GAAG,EAAE,EAAE,EACP,MAAM,EAAE,EAAE,GACR,EAAE,CA6BJ;AAED,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,EAChC,GAAG,EAAE,EAAE,GACL,EAAE,CAkCJ;AAED,wBAAgB,mBAAmB,CAClC,WAAW,EAAE,WAAW,EACxB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,EAAE,EAChB,GAAG,EAAE,EAAE,GACL,EAAE,CAwBJ;AAED,wBAAgB,+BAA+B,CAC9C,iBAAiB,EAAE,YAAY,EAC/B,kBAAkB,EAAE,YAAY,GAC9B;IAAE,SAAS,EAAE,EAAE,CAAC;IAAC,WAAW,EAAE,EAAE,CAAA;CAAE,CA+CpC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMultipleBetweenOracleSources = exports.trimVaaSignatures = exports.getNewOracleConfPct = exports.calculateLiveOracleStd = exports.calculateLiveOracleTwap = exports.isOracleTooDivergent = exports.isOracleValid = exports.getOracleValidity = exports.getMaxConfidenceIntervalMultiplier = exports.oraclePriceBands = void 0;
3
+ exports.getMultipleBetweenOracleSources = exports.getNewOracleConfPct = exports.calculateLiveOracleStd = exports.calculateLiveOracleTwap = exports.isOracleTooDivergent = exports.isOracleValid = exports.getOracleValidity = exports.getMaxConfidenceIntervalMultiplier = exports.oraclePriceBands = void 0;
4
4
  const types_1 = require("../types");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const assert_1 = require("../assert/assert");
@@ -166,19 +166,6 @@ function getNewOracleConfPct(marketStats, oraclePriceData, reservePrice, now) {
166
166
  return confIntervalPctResult;
167
167
  }
168
168
  exports.getNewOracleConfPct = getNewOracleConfPct;
169
- function trimVaaSignatures(vaa, n = 3) {
170
- const currentNumSignatures = vaa[5];
171
- if (n > currentNumSignatures) {
172
- throw new Error("Resulting VAA can't have more signatures than the original VAA");
173
- }
174
- const trimmedVaa = Buffer.concat([
175
- vaa.subarray(0, 6 + n * 66),
176
- vaa.subarray(6 + currentNumSignatures * 66),
177
- ]);
178
- trimmedVaa[5] = n;
179
- return trimmedVaa;
180
- }
181
- exports.trimVaaSignatures = trimVaaSignatures;
182
169
  function getMultipleBetweenOracleSources(firstOracleSource, secondOracleSource) {
183
170
  if ((0, types_1.isOneOfVariant)(firstOracleSource, [
184
171
  'pythPull',
@@ -1,11 +1,6 @@
1
- /// <reference types="bn.js" />
2
- import { User } from '../user';
3
1
  import { PerpMarketAccount, AMM, MarketStats, Order, PositionDirection, MarketTypeStr, StateAccount } from '../types';
4
2
  import { BN } from '../isomorphic/anchor';
5
3
  import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
6
- export declare function isOrderRiskIncreasing(user: User, order: Order): boolean;
7
- export declare function isOrderRiskIncreasingInSameDirection(user: User, order: Order): boolean;
8
- export declare function isOrderReduceOnly(user: User, order: Order): boolean;
9
4
  export declare function standardizeBaseAssetAmount(baseAssetAmount: BN, stepSize: BN): BN;
10
5
  export declare function standardizePrice(price: BN, tickSize: BN, direction: PositionDirection): BN;
11
6
  export declare function getLimitPrice<T extends MarketTypeStr>(order: Order, oraclePriceData: T extends 'spot' ? OraclePriceData : MMOraclePriceData, slot: number, fallbackPrice?: BN): BN | undefined;
@@ -21,7 +16,6 @@ export declare function isLimitOrder(order: Order): boolean;
21
16
  export declare function mustBeTriggered(order: Order): boolean;
22
17
  export declare function isTriggered(order: Order): boolean;
23
18
  export declare function isRestingLimitOrder(order: Order, slot: number): boolean;
24
- export declare function isTakingOrder(order: Order, slot: number): boolean;
25
19
  export declare function isSignedMsgOrder(order: Order): boolean;
26
20
  export declare function hasBuilder(order: Order): boolean;
27
21
  export declare function calculateOrderBaseAssetAmount(order: Order, existingBaseAssetAmount: BN): BN;
@@ -1 +1 @@
1
- {"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../../../src/math/orders.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAGN,iBAAiB,EACjB,GAAG,EACH,WAAW,EACX,KAAK,EACL,iBAAiB,EACjB,aAAa,EAEb,YAAY,EACZ,MAAM,UAAU,CAAC;AAQlB,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAatE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAoCvE;AAED,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,GACV,OAAO,CA4BT;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CA0BnE;AAED,wBAAgB,0BAA0B,CACzC,eAAe,EAAE,EAAE,EACnB,QAAQ,EAAE,EAAE,GACV,EAAE,CAGJ;AAED,wBAAgB,gBAAgB,CAC/B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,CAC7B,KAAK,EAAE,KAAK,EACZ,EAAE,EAAE,MAAM,EACV,aAAa,UAAQ,EACrB,aAAa,SAAK,GAChB,OAAO,CAiBT;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEnD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAElD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAErD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAKjD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMvE;AAGD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEtD;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEhD;AAED,wBAAgB,6BAA6B,CAC5C,KAAK,EAAE,KAAK,EACZ,uBAAuB,EAAE,EAAE,GACzB,EAAE,CAaJ;AAGD;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAChD,MAAM,EAAE,EAAE,EACV,SAAS,EAAE,EAAE,EACb,eAAe,EAAE,EAAE,EACnB,MAAM,EAAE,iBAAiB,GACvB,EAAE,GAAG,IAAI,CAqDX"}
@@ -1,80 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maxSizeForTargetLiabilityWeightBN = exports.calculateOrderBaseAssetAmount = exports.hasBuilder = exports.isSignedMsgOrder = exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isLowRiskForAmm = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
3
+ exports.maxSizeForTargetLiabilityWeightBN = exports.calculateOrderBaseAssetAmount = exports.hasBuilder = exports.isSignedMsgOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isLowRiskForAmm = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizePrice = exports.standardizeBaseAssetAmount = void 0;
4
4
  const types_1 = require("../types");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const anchor_1 = require("../isomorphic/anchor");
7
7
  const auction_1 = require("./auction");
8
8
  const amm_1 = require("./amm");
9
9
  const margin_1 = require("./margin");
10
- function isOrderRiskIncreasing(user, order) {
11
- if (!(0, types_1.isVariant)(order.status, 'open')) {
12
- return false;
13
- }
14
- const position = user.getPerpPosition(order.marketIndex) ||
15
- user.getEmptyPosition(order.marketIndex);
16
- // if no position exists, it's risk increasing
17
- if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
18
- return true;
19
- }
20
- // if position is long and order is long
21
- if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
22
- return true;
23
- }
24
- // if position is short and order is short
25
- if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
26
- (0, types_1.isVariant)(order.direction, 'short')) {
27
- return true;
28
- }
29
- const baseAssetAmountToFill = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
30
- // if order will flip position
31
- if (baseAssetAmountToFill.gt(position.baseAssetAmount.abs().mul(numericConstants_1.TWO))) {
32
- return true;
33
- }
34
- return false;
35
- }
36
- exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
37
- function isOrderRiskIncreasingInSameDirection(user, order) {
38
- if (!(0, types_1.isVariant)(order.status, 'open')) {
39
- return false;
40
- }
41
- const position = user.getPerpPosition(order.marketIndex) ||
42
- user.getEmptyPosition(order.marketIndex);
43
- // if no position exists, it's risk increasing
44
- if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
45
- return true;
46
- }
47
- // if position is long and order is long
48
- if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
49
- return true;
50
- }
51
- // if position is short and order is short
52
- if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
53
- (0, types_1.isVariant)(order.direction, 'short')) {
54
- return true;
55
- }
56
- return false;
57
- }
58
- exports.isOrderRiskIncreasingInSameDirection = isOrderRiskIncreasingInSameDirection;
59
- function isOrderReduceOnly(user, order) {
60
- if (!(0, types_1.isVariant)(order.status, 'open')) {
61
- return false;
62
- }
63
- const position = user.getPerpPosition(order.marketIndex) ||
64
- user.getEmptyPosition(order.marketIndex);
65
- // if position is long and order is long
66
- if (position.baseAssetAmount.gte(numericConstants_1.ZERO) &&
67
- (0, types_1.isVariant)(order.direction, 'long')) {
68
- return false;
69
- }
70
- // if position is short and order is short
71
- if (position.baseAssetAmount.lte(numericConstants_1.ZERO) &&
72
- (0, types_1.isVariant)(order.direction, 'short')) {
73
- return false;
74
- }
75
- return true;
76
- }
77
- exports.isOrderReduceOnly = isOrderReduceOnly;
78
10
  function standardizeBaseAssetAmount(baseAssetAmount, stepSize) {
79
11
  const remainder = baseAssetAmount.mod(stepSize);
80
12
  return baseAssetAmount.sub(remainder);
@@ -145,7 +77,7 @@ function calculateBaseAssetAmountForAmmToFulfill(order, market, mmOraclePriceDat
145
77
  }
146
78
  const limitPrice = getLimitPrice(order, mmOraclePriceData, slot);
147
79
  let baseAssetAmount;
148
- const updatedAMM = (0, amm_1.calculateUpdatedAMM)(market.amm, market.totalExchangeFee, mmOraclePriceData);
80
+ const updatedAMM = (0, amm_1.calculateUpdatedAMM)(market.amm, mmOraclePriceData);
149
81
  if (limitPrice !== undefined) {
150
82
  baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(order, updatedAMM, market.marketStats, market.orderStepSize, market.orderTickSize, limitPrice, mmOraclePriceData);
151
83
  }
@@ -219,10 +151,6 @@ function isRestingLimitOrder(order, slot) {
219
151
  return order.postOnly || (0, auction_1.isAuctionComplete)(order, slot);
220
152
  }
221
153
  exports.isRestingLimitOrder = isRestingLimitOrder;
222
- function isTakingOrder(order, slot) {
223
- return isMarketOrder(order) || !isRestingLimitOrder(order, slot);
224
- }
225
- exports.isTakingOrder = isTakingOrder;
226
154
  const FLAG_IS_SIGNED_MSG = 0x01;
227
155
  function isSignedMsgOrder(order) {
228
156
  return (order.bitFlags & FLAG_IS_SIGNED_MSG) !== 0;
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../isomorphic/anchor';
3
2
  import { MMOraclePriceData, OraclePriceData } from '../oracles/types';
4
3
  import { PerpMarketAccount, PositionDirection, PerpPosition, SpotMarketAccount } from '../types';
@@ -20,7 +19,7 @@ export declare function calculateBaseAssetValue(market: PerpMarketAccount, userP
20
19
  * @param oraclePriceData
21
20
  * @returns BaseAssetAmount : Precision QUOTE_PRECISION
22
21
  */
23
- export declare function calculatePositionPNL(market: PerpMarketAccount, perpPosition: PerpPosition, withFunding: boolean, oraclePriceData: Pick<OraclePriceData, 'price'>): BN;
22
+ export declare function calculatePositionPNL(market: PerpMarketAccount, perpPosition: PerpPosition, withFunding: boolean | undefined, oraclePriceData: Pick<OraclePriceData, 'price'>): BN;
24
23
  export declare function calculateClaimablePnl(market: PerpMarketAccount, spotMarket: SpotMarketAccount, perpPosition: PerpPosition, oraclePriceData: Pick<OraclePriceData, 'price'>): BN;
25
24
  /**
26
25
  * Returns total fees and funding pnl for a position
@@ -41,10 +40,6 @@ export declare function calculateFeesAndFundingPnl(market: PerpMarketAccount, pe
41
40
  * @returns // QUOTE_PRECISION
42
41
  */
43
42
  export declare function calculateUnsettledFundingPnl(market: PerpMarketAccount, perpPosition: PerpPosition): BN;
44
- /**
45
- * @deprecated use calculateUnsettledFundingPnl or calculateFeesAndFundingPnl instead
46
- */
47
- export declare function calculatePositionFundingPNL(market: PerpMarketAccount, perpPosition: PerpPosition): BN;
48
43
  export declare function positionIsAvailable(position: PerpPosition): boolean;
49
44
  export declare function positionIsBeingLiquidated(position: PerpPosition): boolean;
50
45
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../src/math/position.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAU1C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EAEjB,MAAM,UAAU,CAAC;AAUlB;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,YAAY,EAC1B,iBAAiB,EAAE,iBAAiB,EACpC,SAAS,UAAO,EAChB,UAAU,UAAQ,EAClB,UAAU,CAAC,EAAE,EAAE,GACb,EAAE,CAyDJ;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,YAAY,EAC1B,WAAW,SAAQ,EACnB,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAC7C,EAAE,CAwBJ;AAED,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,iBAAiB,EAC7B,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAC7C,EAAE,CAyBJ;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,YAAY,EAC1B,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