@velocity-exchange/sdk 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/.prettierignore +1 -1
  2. package/CHANGELOG.md +20 -0
  3. package/README.md +30 -30
  4. package/bun.lock +1 -1
  5. package/lib/browser/accounts/grpcProgramAccountSubscriber.js +1 -1
  6. package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
  7. package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +1 -3
  8. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +0 -4
  9. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +5 -7
  10. package/lib/browser/accounts/laserProgramAccountSubscriber.js +1 -1
  11. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +0 -4
  12. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +5 -7
  13. package/lib/browser/accounts/types.d.ts +2 -8
  14. package/lib/browser/accounts/utils.js +2 -2
  15. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +0 -4
  16. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +5 -7
  17. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +0 -4
  18. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +5 -7
  19. package/lib/browser/addresses/pda.d.ts +1 -7
  20. package/lib/browser/addresses/pda.js +4 -10
  21. package/lib/browser/adminClient.d.ts +1 -1
  22. package/lib/browser/adminClient.js +21 -21
  23. package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +1 -3
  24. package/lib/browser/auctionSubscriber/auctionSubscriber.js +2 -6
  25. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -3
  26. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +2 -6
  27. package/lib/browser/auctionSubscriber/types.d.ts +3 -2
  28. package/lib/browser/config.d.ts +10 -19
  29. package/lib/browser/config.js +6 -33
  30. package/lib/browser/constants/insuranceFund.d.ts +1 -1
  31. package/lib/browser/constants/insuranceFund.js +1 -1
  32. package/lib/browser/constituentMap/constituentMap.d.ts +0 -2
  33. package/lib/browser/constituentMap/constituentMap.js +5 -5
  34. package/lib/browser/core/VelocityCore.d.ts +9 -15
  35. package/lib/browser/core/VelocityCore.js +5 -7
  36. package/lib/browser/core/instructions/withdraw.d.ts +1 -1
  37. package/lib/browser/core/instructions/withdraw.js +1 -1
  38. package/lib/browser/core/remainingAccounts.js +3 -3
  39. package/lib/browser/dlob/DLOB.d.ts +1 -1
  40. package/lib/browser/dlob/DLOB.js +6 -6
  41. package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -2
  42. package/lib/browser/dlob/DLOBSubscriber.js +2 -7
  43. package/lib/browser/dlob/orderBookLevels.js +7 -7
  44. package/lib/browser/dlob/types.d.ts +0 -2
  45. package/lib/browser/events/eventSubscriber.d.ts +1 -1
  46. package/lib/browser/events/eventsServerLogProvider.js +2 -2
  47. package/lib/browser/events/parse.js +14 -14
  48. package/lib/browser/events/types.d.ts +3 -5
  49. package/lib/browser/events/types.js +1 -1
  50. package/lib/browser/idl/{drift.d.ts → velocity.d.ts} +1042 -767
  51. package/lib/browser/idl/{drift.json → velocity.json} +1033 -758
  52. package/lib/browser/index.d.ts +1 -1
  53. package/lib/browser/index.js +1 -2
  54. package/lib/browser/math/amm.d.ts +10 -10
  55. package/lib/browser/math/amm.js +29 -28
  56. package/lib/browser/math/auction.js +16 -12
  57. package/lib/browser/math/builder.d.ts +18 -1
  58. package/lib/browser/math/builder.js +32 -1
  59. package/lib/browser/math/funding.js +26 -26
  60. package/lib/browser/math/margin.d.ts +4 -4
  61. package/lib/browser/math/margin.js +15 -15
  62. package/lib/browser/math/market.js +13 -13
  63. package/lib/browser/math/oracles.d.ts +4 -4
  64. package/lib/browser/math/oracles.js +23 -23
  65. package/lib/browser/math/orders.d.ts +2 -2
  66. package/lib/browser/math/orders.js +9 -9
  67. package/lib/browser/math/position.js +4 -4
  68. package/lib/browser/math/superStake.d.ts +8 -10
  69. package/lib/browser/math/superStake.js +18 -20
  70. package/lib/browser/math/trade.js +5 -5
  71. package/lib/browser/math/utils.d.ts +1 -1
  72. package/lib/browser/math/utils.js +1 -1
  73. package/lib/browser/oracles/pythLazerClient.js +2 -2
  74. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +0 -2
  75. package/lib/browser/orderSubscriber/OrderSubscriber.js +8 -12
  76. package/lib/browser/orderSubscriber/WebsocketSubscription.js +1 -1
  77. package/lib/browser/orderSubscriber/grpcSubscription.js +2 -2
  78. package/lib/browser/orderSubscriber/types.d.ts +0 -2
  79. package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +1 -5
  80. package/lib/browser/priorityFee/priorityFeeSubscriber.js +7 -15
  81. package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
  82. package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +3 -11
  83. package/lib/browser/priorityFee/types.d.ts +3 -8
  84. package/lib/browser/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
  85. package/lib/browser/priorityFee/velocityPriorityFeeMethod.js +1 -3
  86. package/lib/browser/pyth/pythLazerSubscriber.d.ts +1 -1
  87. package/lib/browser/pyth/pythLazerSubscriber.js +1 -1
  88. package/lib/browser/swap/UnifiedSwapClient.js +1 -1
  89. package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +4 -5
  90. package/lib/browser/swift/signedMsgUserAccountSubscriber.js +2 -6
  91. package/lib/browser/swift/swiftOrderSubscriber.d.ts +6 -5
  92. package/lib/browser/swift/swiftOrderSubscriber.js +5 -11
  93. package/lib/browser/types.d.ts +79 -91
  94. package/lib/browser/types.js +4 -0
  95. package/lib/browser/user.d.ts +1 -3
  96. package/lib/browser/user.js +19 -23
  97. package/lib/browser/userConfig.d.ts +3 -2
  98. package/lib/browser/userMap/WebsocketSubscription.js +1 -1
  99. package/lib/browser/userMap/grpcSubscription.js +1 -1
  100. package/lib/browser/userMap/referrerMap.d.ts +0 -2
  101. package/lib/browser/userMap/referrerMap.js +0 -4
  102. package/lib/browser/userMap/revenueShareEscrowMap.d.ts +0 -2
  103. package/lib/browser/userMap/revenueShareEscrowMap.js +0 -4
  104. package/lib/browser/userMap/userMap.d.ts +2 -4
  105. package/lib/browser/userMap/userMap.js +10 -14
  106. package/lib/browser/userMap/userMapConfig.d.ts +3 -2
  107. package/lib/browser/userMap/userStatsMap.d.ts +0 -2
  108. package/lib/browser/userMap/userStatsMap.js +0 -4
  109. package/lib/browser/userStats.d.ts +0 -2
  110. package/lib/browser/userStats.js +10 -14
  111. package/lib/browser/userStatsConfig.d.ts +3 -2
  112. package/lib/browser/util/ed25519Utils.d.ts +1 -1
  113. package/lib/browser/util/ed25519Utils.js +1 -1
  114. package/lib/browser/velocityClient.d.ts +53 -38
  115. package/lib/browser/velocityClient.js +258 -196
  116. package/lib/browser/velocityClientConfig.d.ts +0 -8
  117. package/lib/node/accounts/grpcProgramAccountSubscriber.js +1 -1
  118. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
  119. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
  120. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +1 -3
  121. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +0 -4
  122. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  123. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +5 -7
  124. package/lib/node/accounts/laserProgramAccountSubscriber.js +1 -1
  125. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +0 -4
  126. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
  127. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +5 -7
  128. package/lib/node/accounts/types.d.ts +2 -8
  129. package/lib/node/accounts/types.d.ts.map +1 -1
  130. package/lib/node/accounts/utils.js +2 -2
  131. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +0 -4
  132. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
  133. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +5 -7
  134. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +0 -4
  135. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  136. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +5 -7
  137. package/lib/node/addresses/pda.d.ts +1 -7
  138. package/lib/node/addresses/pda.d.ts.map +1 -1
  139. package/lib/node/addresses/pda.js +4 -10
  140. package/lib/node/adminClient.d.ts +1 -1
  141. package/lib/node/adminClient.js +21 -21
  142. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +1 -3
  143. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
  144. package/lib/node/auctionSubscriber/auctionSubscriber.js +2 -6
  145. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +1 -3
  146. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
  147. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +2 -6
  148. package/lib/node/auctionSubscriber/types.d.ts +3 -2
  149. package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
  150. package/lib/node/config.d.ts +10 -19
  151. package/lib/node/config.d.ts.map +1 -1
  152. package/lib/node/config.js +6 -33
  153. package/lib/node/constants/insuranceFund.d.ts +1 -1
  154. package/lib/node/constants/insuranceFund.js +1 -1
  155. package/lib/node/constituentMap/constituentMap.d.ts +0 -2
  156. package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
  157. package/lib/node/constituentMap/constituentMap.js +5 -5
  158. package/lib/node/core/VelocityCore.d.ts +9 -15
  159. package/lib/node/core/VelocityCore.d.ts.map +1 -1
  160. package/lib/node/core/VelocityCore.js +5 -7
  161. package/lib/node/core/instructions/withdraw.d.ts +1 -1
  162. package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
  163. package/lib/node/core/instructions/withdraw.js +1 -1
  164. package/lib/node/core/remainingAccounts.js +3 -3
  165. package/lib/node/dlob/DLOB.d.ts +1 -1
  166. package/lib/node/dlob/DLOB.d.ts.map +1 -1
  167. package/lib/node/dlob/DLOB.js +6 -6
  168. package/lib/node/dlob/DLOBSubscriber.d.ts +0 -2
  169. package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
  170. package/lib/node/dlob/DLOBSubscriber.js +2 -7
  171. package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
  172. package/lib/node/dlob/orderBookLevels.js +7 -7
  173. package/lib/node/dlob/types.d.ts +0 -2
  174. package/lib/node/dlob/types.d.ts.map +1 -1
  175. package/lib/node/events/eventSubscriber.d.ts +1 -1
  176. package/lib/node/events/eventsServerLogProvider.js +2 -2
  177. package/lib/node/events/parse.d.ts.map +1 -1
  178. package/lib/node/events/parse.js +14 -14
  179. package/lib/node/events/types.d.ts +3 -5
  180. package/lib/node/events/types.d.ts.map +1 -1
  181. package/lib/node/events/types.js +1 -1
  182. package/lib/node/idl/{drift.d.ts → velocity.d.ts} +1043 -768
  183. package/lib/node/idl/velocity.d.ts.map +1 -0
  184. package/lib/node/idl/{drift.json → velocity.json} +1033 -758
  185. package/lib/node/index.d.ts +1 -1
  186. package/lib/node/index.d.ts.map +1 -1
  187. package/lib/node/index.js +1 -2
  188. package/lib/node/math/amm.d.ts +10 -10
  189. package/lib/node/math/amm.d.ts.map +1 -1
  190. package/lib/node/math/amm.js +29 -28
  191. package/lib/node/math/auction.d.ts.map +1 -1
  192. package/lib/node/math/auction.js +16 -12
  193. package/lib/node/math/builder.d.ts +18 -1
  194. package/lib/node/math/builder.d.ts.map +1 -1
  195. package/lib/node/math/builder.js +32 -1
  196. package/lib/node/math/funding.d.ts.map +1 -1
  197. package/lib/node/math/funding.js +26 -26
  198. package/lib/node/math/margin.d.ts +4 -4
  199. package/lib/node/math/margin.d.ts.map +1 -1
  200. package/lib/node/math/margin.js +15 -15
  201. package/lib/node/math/market.d.ts.map +1 -1
  202. package/lib/node/math/market.js +13 -13
  203. package/lib/node/math/oracles.d.ts +4 -4
  204. package/lib/node/math/oracles.d.ts.map +1 -1
  205. package/lib/node/math/oracles.js +23 -23
  206. package/lib/node/math/orders.d.ts +2 -2
  207. package/lib/node/math/orders.d.ts.map +1 -1
  208. package/lib/node/math/orders.js +9 -9
  209. package/lib/node/math/position.d.ts.map +1 -1
  210. package/lib/node/math/position.js +4 -4
  211. package/lib/node/math/superStake.d.ts +8 -10
  212. package/lib/node/math/superStake.d.ts.map +1 -1
  213. package/lib/node/math/superStake.js +18 -20
  214. package/lib/node/math/trade.d.ts.map +1 -1
  215. package/lib/node/math/trade.js +5 -5
  216. package/lib/node/math/utils.d.ts +1 -1
  217. package/lib/node/math/utils.js +1 -1
  218. package/lib/node/oracles/pythLazerClient.js +2 -2
  219. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +0 -2
  220. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  221. package/lib/node/orderSubscriber/OrderSubscriber.js +8 -12
  222. package/lib/node/orderSubscriber/WebsocketSubscription.js +1 -1
  223. package/lib/node/orderSubscriber/grpcSubscription.js +2 -2
  224. package/lib/node/orderSubscriber/types.d.ts +0 -2
  225. package/lib/node/orderSubscriber/types.d.ts.map +1 -1
  226. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +1 -5
  227. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
  228. package/lib/node/priorityFee/priorityFeeSubscriber.js +7 -15
  229. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
  230. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
  231. package/lib/node/priorityFee/priorityFeeSubscriberMap.js +3 -11
  232. package/lib/node/priorityFee/types.d.ts +3 -8
  233. package/lib/node/priorityFee/types.d.ts.map +1 -1
  234. package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
  235. package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts.map +1 -1
  236. package/lib/node/priorityFee/velocityPriorityFeeMethod.js +1 -3
  237. package/lib/node/pyth/pythLazerSubscriber.d.ts +1 -1
  238. package/lib/node/pyth/pythLazerSubscriber.js +1 -1
  239. package/lib/node/swap/UnifiedSwapClient.js +1 -1
  240. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +4 -5
  241. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
  242. package/lib/node/swift/signedMsgUserAccountSubscriber.js +2 -6
  243. package/lib/node/swift/swiftOrderSubscriber.d.ts +6 -5
  244. package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
  245. package/lib/node/swift/swiftOrderSubscriber.js +5 -11
  246. package/lib/node/types.d.ts +79 -91
  247. package/lib/node/types.d.ts.map +1 -1
  248. package/lib/node/types.js +4 -0
  249. package/lib/node/user.d.ts +1 -3
  250. package/lib/node/user.d.ts.map +1 -1
  251. package/lib/node/user.js +19 -23
  252. package/lib/node/userConfig.d.ts +3 -2
  253. package/lib/node/userConfig.d.ts.map +1 -1
  254. package/lib/node/userMap/WebsocketSubscription.js +1 -1
  255. package/lib/node/userMap/grpcSubscription.js +1 -1
  256. package/lib/node/userMap/referrerMap.d.ts +0 -2
  257. package/lib/node/userMap/referrerMap.d.ts.map +1 -1
  258. package/lib/node/userMap/referrerMap.js +0 -4
  259. package/lib/node/userMap/revenueShareEscrowMap.d.ts +0 -2
  260. package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
  261. package/lib/node/userMap/revenueShareEscrowMap.js +0 -4
  262. package/lib/node/userMap/userMap.d.ts +2 -4
  263. package/lib/node/userMap/userMap.d.ts.map +1 -1
  264. package/lib/node/userMap/userMap.js +10 -14
  265. package/lib/node/userMap/userMapConfig.d.ts +3 -2
  266. package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
  267. package/lib/node/userMap/userStatsMap.d.ts +0 -2
  268. package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
  269. package/lib/node/userMap/userStatsMap.js +0 -4
  270. package/lib/node/userStats.d.ts +0 -2
  271. package/lib/node/userStats.d.ts.map +1 -1
  272. package/lib/node/userStats.js +10 -14
  273. package/lib/node/userStatsConfig.d.ts +3 -2
  274. package/lib/node/userStatsConfig.d.ts.map +1 -1
  275. package/lib/node/util/ed25519Utils.d.ts +1 -1
  276. package/lib/node/util/ed25519Utils.js +1 -1
  277. package/lib/node/velocityClient.d.ts +53 -38
  278. package/lib/node/velocityClient.d.ts.map +1 -1
  279. package/lib/node/velocityClient.js +258 -196
  280. package/lib/node/velocityClientConfig.d.ts +0 -8
  281. package/lib/node/velocityClientConfig.d.ts.map +1 -1
  282. package/package.json +6 -7
  283. package/scripts/deposit-isolated-positions.ts +2 -2
  284. package/scripts/find-flagged-users.ts +1 -1
  285. package/scripts/grpc-client-test-comparison.ts +4 -4
  286. package/scripts/grpc-multiuser-client-test-comparison.ts +2 -2
  287. package/scripts/single-grpc-client-test.ts +3 -3
  288. package/scripts/updateVersion.js +4 -4
  289. package/scripts/withdraw-isolated-positions.ts +2 -2
  290. package/src/accounts/grpcProgramAccountSubscriber.ts +1 -1
  291. package/src/accounts/grpcVelocityClientAccountSubscriber.ts +0 -7
  292. package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +4 -11
  293. package/src/accounts/laserProgramAccountSubscriber.ts +1 -1
  294. package/src/accounts/pollingVelocityClientAccountSubscriber.ts +4 -11
  295. package/src/accounts/types.ts +2 -9
  296. package/src/accounts/utils.ts +2 -2
  297. package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +4 -11
  298. package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +4 -11
  299. package/src/addresses/pda.ts +3 -13
  300. package/src/adminClient.ts +21 -21
  301. package/src/auctionSubscriber/auctionSubscriber.ts +1 -6
  302. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +1 -6
  303. package/src/auctionSubscriber/types.ts +3 -3
  304. package/src/config.ts +8 -67
  305. package/src/constants/insuranceFund.ts +1 -1
  306. package/src/constituentMap/constituentMap.ts +2 -6
  307. package/src/core/VelocityCore.ts +11 -20
  308. package/src/core/instructions/withdraw.ts +2 -2
  309. package/src/core/remainingAccounts.ts +3 -3
  310. package/src/dlob/DLOB.ts +6 -6
  311. package/src/dlob/DLOBSubscriber.ts +2 -8
  312. package/src/dlob/orderBookLevels.ts +12 -6
  313. package/src/dlob/types.ts +0 -2
  314. package/src/events/eventSubscriber.ts +1 -1
  315. package/src/events/eventsServerLogProvider.ts +2 -2
  316. package/src/events/parse.ts +14 -14
  317. package/src/events/types.ts +4 -7
  318. package/src/idl/{drift.json → velocity.json} +1033 -758
  319. package/src/idl/{drift.ts → velocity.ts} +1035 -760
  320. package/src/index.ts +1 -4
  321. package/src/margin/README.md +2 -2
  322. package/src/math/amm.ts +43 -21
  323. package/src/math/auction.ts +16 -12
  324. package/src/math/builder.ts +45 -1
  325. package/src/math/funding.ts +46 -43
  326. package/src/math/margin.ts +15 -15
  327. package/src/math/market.ts +21 -13
  328. package/src/math/oracles.ts +29 -26
  329. package/src/math/orders.ts +18 -5
  330. package/src/math/position.ts +9 -3
  331. package/src/math/superStake.ts +21 -24
  332. package/src/math/trade.ts +9 -1
  333. package/src/math/utils.ts +1 -1
  334. package/src/oracles/pythLazerClient.ts +3 -3
  335. package/src/orderSubscriber/OrderSubscriber.ts +2 -8
  336. package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
  337. package/src/orderSubscriber/grpcSubscription.ts +2 -2
  338. package/src/orderSubscriber/types.ts +0 -2
  339. package/src/priorityFee/priorityFeeSubscriber.ts +5 -12
  340. package/src/priorityFee/priorityFeeSubscriberMap.ts +2 -10
  341. package/src/priorityFee/types.ts +3 -13
  342. package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -12
  343. package/src/pyth/pythLazerSubscriber.ts +1 -1
  344. package/src/swap/UnifiedSwapClient.ts +1 -1
  345. package/src/swift/signedMsgUserAccountSubscriber.ts +2 -8
  346. package/src/swift/swiftOrderSubscriber.ts +7 -12
  347. package/src/types.ts +84 -102
  348. package/src/user.ts +9 -14
  349. package/src/userConfig.ts +1 -3
  350. package/src/userMap/WebsocketSubscription.ts +1 -1
  351. package/src/userMap/grpcSubscription.ts +1 -1
  352. package/src/userMap/referrerMap.ts +0 -4
  353. package/src/userMap/revenueShareEscrowMap.ts +0 -4
  354. package/src/userMap/userMap.ts +3 -7
  355. package/src/userMap/userMapConfig.ts +3 -3
  356. package/src/userMap/userStatsMap.ts +0 -4
  357. package/src/userStats.ts +1 -5
  358. package/src/userStatsConfig.ts +3 -3
  359. package/src/util/ed25519Utils.ts +1 -1
  360. package/src/velocityClient.ts +339 -225
  361. package/src/velocityClientConfig.ts +0 -10
  362. package/tests/{DriftCore → VelocityCore}/decode.test.ts +1 -1
  363. package/tests/{DriftCore → VelocityCore}/fill_trigger.test.ts +1 -1
  364. package/tests/{DriftCore → VelocityCore}/instructions.test.ts +1 -1
  365. package/tests/{DriftCore → VelocityCore}/pdas.test.ts +4 -2
  366. package/tests/ci/verifyConstants.ts +24 -27
  367. package/tests/decode/test.ts +2 -2
  368. package/tests/dlob/helpers.ts +5 -9
  369. package/tests/events/parseLogsForCuUsage.ts +15 -15
  370. package/tests/user/helpers.ts +9 -9
  371. package/tests/user/test.ts +13 -10
  372. package/lib/browser/util/deprecatedAlias.d.ts +0 -26
  373. package/lib/browser/util/deprecatedAlias.js +0 -10
  374. package/lib/node/idl/drift.d.ts.map +0 -1
  375. package/lib/node/util/deprecatedAlias.d.ts +0 -27
  376. package/lib/node/util/deprecatedAlias.d.ts.map +0 -1
  377. package/lib/node/util/deprecatedAlias.js +0 -10
  378. package/src/util/deprecatedAlias.ts +0 -21
  379. /package/lib/browser/idl/{drift.js → velocity.js} +0 -0
  380. /package/lib/node/idl/{drift.js → velocity.js} +0 -0
  381. /package/tests/{DriftCore → VelocityCore}/perp_orders.test.ts +0 -0
  382. /package/tests/{DriftCore → VelocityCore}/remainingAccounts.test.ts +0 -0
  383. /package/tests/{DriftCore → VelocityCore}/settlement_liquidation.test.ts +0 -0
@@ -45,7 +45,11 @@ export function calculateReservePrice(
45
45
  market: PerpMarketAccount,
46
46
  mmOraclePriceData: MMOraclePriceData
47
47
  ): BN {
48
- const newAmm = calculateUpdatedAMM(market.amm, mmOraclePriceData);
48
+ const newAmm = calculateUpdatedAMM(
49
+ market.amm,
50
+ market.totalExchangeFee,
51
+ mmOraclePriceData
52
+ );
49
53
  return calculatePrice(
50
54
  newAmm.baseAssetReserve,
51
55
  newAmm.quoteAssetReserve,
@@ -67,6 +71,8 @@ export function calculateBidPrice(
67
71
  const { baseAssetReserve, quoteAssetReserve, newPeg } =
68
72
  calculateUpdatedAMMSpreadReserves(
69
73
  market.amm,
74
+ market.marketStats,
75
+ market.totalExchangeFee,
70
76
  PositionDirection.SHORT,
71
77
  mmOraclePriceData,
72
78
  latestSlot
@@ -89,6 +95,8 @@ export function calculateAskPrice(
89
95
  const { baseAssetReserve, quoteAssetReserve, newPeg } =
90
96
  calculateUpdatedAMMSpreadReserves(
91
97
  market.amm,
98
+ market.marketStats,
99
+ market.totalExchangeFee,
92
100
  PositionDirection.LONG,
93
101
  mmOraclePriceData,
94
102
  latestSlot
@@ -251,8 +259,8 @@ export function calculateNetUserPnl(
251
259
  .div(BASE_PRECISION)
252
260
  .div(PRICE_TO_QUOTE_PRECISION);
253
261
 
254
- const netUserCostBasis = perpMarket.amm.quoteAssetAmount.add(
255
- perpMarket.amm.netUnsettledFundingPnl
262
+ const netUserCostBasis = perpMarket.quoteAssetAmount.add(
263
+ perpMarket.netUnsettledFundingPnl
256
264
  );
257
265
 
258
266
  const netUserPnl = netUserPositionValue.add(netUserCostBasis);
@@ -297,7 +305,7 @@ export function calculateAvailablePerpLiquidity(
297
305
  market.amm.baseAssetReserve,
298
306
  market.amm.minBaseAssetReserve,
299
307
  market.amm.maxBaseAssetReserve,
300
- market.amm.orderStepSize
308
+ market.orderStepSize
301
309
  );
302
310
 
303
311
  asks = asks.abs();
@@ -358,9 +366,9 @@ export function getTriggerPrice(
358
366
  const lastFillPrice = market.lastFillPrice;
359
367
 
360
368
  // Calculate 5-minute basis
361
- const markPrice5minTwap = market.amm.lastMarkPriceTwap5Min;
369
+ const markPrice5minTwap = market.marketStats.lastMarkPriceTwap5Min;
362
370
  const lastOraclePriceTwap5min =
363
- market.amm.historicalOracleData.lastOraclePriceTwap5Min;
371
+ market.marketStats.historicalOracleData.lastOraclePriceTwap5Min;
364
372
  const basis5min = markPrice5minTwap.sub(lastOraclePriceTwap5min);
365
373
 
366
374
  const oraclePlusBasis5min = oraclePrice.add(basis5min);
@@ -388,23 +396,23 @@ function getLastFundingBasis(
388
396
  oraclePrice: BN,
389
397
  now: BN
390
398
  ): BN {
391
- if (market.amm.lastFundingOracleTwap.gt(ZERO)) {
392
- const lastFundingRate = market.amm.lastFundingRate
399
+ if (market.lastFundingOracleTwap.gt(ZERO)) {
400
+ const lastFundingRate = market.lastFundingRate
393
401
  .mul(PRICE_PRECISION)
394
- .div(market.amm.lastFundingOracleTwap)
402
+ .div(market.lastFundingOracleTwap)
395
403
  .muln(24);
396
404
  const lastFundingRatePreAdj = lastFundingRate.sub(
397
405
  FUNDING_RATE_PRECISION.div(new BN(3333)) // FUNDING_RATE_OFFSET_PERCENTAGE
398
406
  );
399
407
  const timeLeftUntilFundingUpdate = BN.min(
400
- BN.max(now.sub(market.amm.lastFundingRateTs), ZERO),
401
- market.amm.fundingPeriod
408
+ BN.max(now.sub(market.lastFundingRateTs), ZERO),
409
+ market.marketStats.fundingPeriod
402
410
  );
403
411
  const lastFundingBasis = oraclePrice
404
412
  .mul(lastFundingRatePreAdj)
405
413
  .div(PERCENTAGE_PRECISION)
406
- .mul(market.amm.fundingPeriod.sub(timeLeftUntilFundingUpdate))
407
- .div(market.amm.fundingPeriod)
414
+ .mul(market.marketStats.fundingPeriod.sub(timeLeftUntilFundingUpdate))
415
+ .div(market.marketStats.fundingPeriod)
408
416
  .div(new BN(1000)); // FUNDING_RATE_BUFFER
409
417
  return lastFundingBasis;
410
418
  } else {
@@ -1,6 +1,6 @@
1
1
  import {
2
- AMM,
3
2
  HistoricalOracleData,
3
+ MarketStats,
4
4
  OracleGuardRails,
5
5
  OracleSource,
6
6
  OracleValidity,
@@ -64,14 +64,14 @@ export function getOracleValidity(
64
64
  const isNonPositive = oraclePriceData.price.lte(ZERO);
65
65
  const isTooVolatile = BN.max(
66
66
  oraclePriceData.price,
67
- market.amm.historicalOracleData.lastOraclePriceTwap
67
+ market.marketStats.historicalOracleData.lastOraclePriceTwap
68
68
  )
69
69
  .div(
70
70
  BN.max(
71
71
  ONE,
72
72
  BN.min(
73
73
  oraclePriceData.price,
74
- market.amm.historicalOracleData.lastOraclePriceTwap
74
+ market.marketStats.historicalOracleData.lastOraclePriceTwap
75
75
  )
76
76
  )
77
77
  )
@@ -89,16 +89,16 @@ export function getOracleValidity(
89
89
  const oracleDelay = slot.sub(oraclePriceData.slot).sub(oracleStalenessBuffer);
90
90
 
91
91
  let isStaleForAmmImmediate = true;
92
- if (market.amm.oracleSlotDelayOverride != 0) {
92
+ if (market.oracleSlotDelayOverride != 0) {
93
93
  isStaleForAmmImmediate = oracleDelay.gt(
94
- BN.max(new BN(market.amm.oracleSlotDelayOverride), ZERO)
94
+ BN.max(new BN(market.oracleSlotDelayOverride), ZERO)
95
95
  );
96
96
  }
97
97
 
98
98
  let isStaleForAmmLowRisk = false;
99
- if (market.amm.oracleLowRiskSlotDelayOverride != 0) {
99
+ if (market.oracleLowRiskSlotDelayOverride != 0) {
100
100
  isStaleForAmmLowRisk = oracleDelay.gt(
101
- BN.max(new BN(market.amm.oracleLowRiskSlotDelayOverride), ZERO)
101
+ BN.max(new BN(market.oracleLowRiskSlotDelayOverride), ZERO)
102
102
  );
103
103
  } else {
104
104
  isStaleForAmmLowRisk = oracleDelay.gt(
@@ -109,7 +109,7 @@ export function getOracleValidity(
109
109
  let isStaleForMargin = oracleDelay.gt(
110
110
  new BN(oracleGuardRails.validity.slotsBeforeStaleForMargin)
111
111
  );
112
- if (isVariant(market.amm.oracleSource, 'pythLazerStableCoin')) {
112
+ if (isVariant(market.oracleSource, 'pythLazerStableCoin')) {
113
113
  isStaleForMargin = oracleDelay.gt(
114
114
  new BN(oracleGuardRails.validity.slotsBeforeStaleForMargin).muln(3)
115
115
  );
@@ -142,13 +142,13 @@ export function isOracleValid(
142
142
  ): boolean {
143
143
  // checks if oracle is valid for an AMM only fill
144
144
 
145
- const amm = market.amm;
145
+ const stats = market.marketStats;
146
146
  const isOraclePriceNonPositive = oraclePriceData.price.lte(ZERO);
147
147
  const isOraclePriceTooVolatile =
148
148
  oraclePriceData.price
149
- .div(BN.max(ONE, amm.historicalOracleData.lastOraclePriceTwap))
149
+ .div(BN.max(ONE, stats.historicalOracleData.lastOraclePriceTwap))
150
150
  .gt(oracleGuardRails.validity.tooVolatileRatio) ||
151
- amm.historicalOracleData.lastOraclePriceTwap
151
+ stats.historicalOracleData.lastOraclePriceTwap
152
152
  .div(BN.max(ONE, oraclePriceData.price))
153
153
  .gt(oracleGuardRails.validity.tooVolatileRatio);
154
154
 
@@ -177,14 +177,14 @@ export function isOracleValid(
177
177
  }
178
178
 
179
179
  export function isOracleTooDivergent(
180
- amm: AMM,
180
+ marketStats: MarketStats,
181
181
  oraclePriceData: OraclePriceData,
182
182
  oracleGuardRails: OracleGuardRails
183
183
  ): boolean {
184
184
  const oracleSpreadPct = oraclePriceData.price
185
- .sub(amm.historicalOracleData.lastOraclePriceTwap5Min)
185
+ .sub(marketStats.historicalOracleData.lastOraclePriceTwap5Min)
186
186
  .mul(PERCENTAGE_PRECISION)
187
- .div(amm.historicalOracleData.lastOraclePriceTwap5Min);
187
+ .div(marketStats.historicalOracleData.lastOraclePriceTwap5Min);
188
188
  const maxDivergence = BN.max(
189
189
  oracleGuardRails.priceDivergence.oracleTwap5MinPercentDivergence,
190
190
  PERCENTAGE_PRECISION.div(new BN(2))
@@ -230,25 +230,28 @@ export function calculateLiveOracleTwap(
230
230
  }
231
231
 
232
232
  export function calculateLiveOracleStd(
233
- amm: AMM,
233
+ marketStats: MarketStats,
234
234
  oraclePriceData: OraclePriceData,
235
235
  now: BN
236
236
  ): BN {
237
237
  const sinceLastUpdate = BN.max(
238
238
  ONE,
239
- now.sub(amm.historicalOracleData.lastOraclePriceTwapTs)
239
+ now.sub(marketStats.historicalOracleData.lastOraclePriceTwapTs)
240
+ );
241
+ const sinceStart = BN.max(
242
+ ZERO,
243
+ marketStats.fundingPeriod.sub(sinceLastUpdate)
240
244
  );
241
- const sinceStart = BN.max(ZERO, amm.fundingPeriod.sub(sinceLastUpdate));
242
245
 
243
246
  const liveOracleTwap = calculateLiveOracleTwap(
244
- amm.historicalOracleData,
247
+ marketStats.historicalOracleData,
245
248
  oraclePriceData,
246
249
  now,
247
- amm.fundingPeriod
250
+ marketStats.fundingPeriod
248
251
  );
249
252
 
250
253
  const liveOracleTwap5MIN = calculateLiveOracleTwap(
251
- amm.historicalOracleData,
254
+ marketStats.historicalOracleData,
252
255
  oraclePriceData,
253
256
  now,
254
257
  FIVE_MINUTE
@@ -260,14 +263,14 @@ export function calculateLiveOracleStd(
260
263
  );
261
264
 
262
265
  const oracleStd = priceDeltaVsTwap.add(
263
- amm.oracleStd.mul(sinceStart).div(sinceStart.add(sinceLastUpdate))
266
+ marketStats.oracleStd.mul(sinceStart).div(sinceStart.add(sinceLastUpdate))
264
267
  );
265
268
 
266
269
  return oracleStd;
267
270
  }
268
271
 
269
272
  export function getNewOracleConfPct(
270
- amm: AMM,
273
+ marketStats: MarketStats,
271
274
  oraclePriceData: OraclePriceData,
272
275
  reservePrice: BN,
273
276
  now: BN
@@ -276,16 +279,16 @@ export function getNewOracleConfPct(
276
279
 
277
280
  const sinceLastUpdate = BN.max(
278
281
  ZERO,
279
- now.sub(amm.historicalOracleData.lastOraclePriceTwapTs)
282
+ now.sub(marketStats.historicalOracleData.lastOraclePriceTwapTs)
280
283
  );
281
- let lowerBoundConfPct = amm.lastOracleConfPct;
284
+ let lowerBoundConfPct = marketStats.lastOracleConfPct;
282
285
  if (sinceLastUpdate.gt(ZERO)) {
283
286
  const lowerBoundConfDivisor = BN.max(
284
287
  new BN(21).sub(sinceLastUpdate),
285
288
  new BN(5)
286
289
  );
287
- lowerBoundConfPct = amm.lastOracleConfPct.sub(
288
- amm.lastOracleConfPct.div(lowerBoundConfDivisor)
290
+ lowerBoundConfPct = marketStats.lastOracleConfPct.sub(
291
+ marketStats.lastOracleConfPct.div(lowerBoundConfDivisor)
289
292
  );
290
293
  }
291
294
  const confIntervalPct = confInterval
@@ -4,6 +4,7 @@ import {
4
4
  isVariant,
5
5
  PerpMarketAccount,
6
6
  AMM,
7
+ MarketStats,
7
8
  Order,
8
9
  PositionDirection,
9
10
  MarketTypeStr,
@@ -251,11 +252,18 @@ export function calculateBaseAssetAmountForAmmToFulfill(
251
252
  const limitPrice = getLimitPrice(order, mmOraclePriceData, slot);
252
253
  let baseAssetAmount;
253
254
 
254
- const updatedAMM = calculateUpdatedAMM(market.amm, mmOraclePriceData);
255
+ const updatedAMM = calculateUpdatedAMM(
256
+ market.amm,
257
+ market.totalExchangeFee,
258
+ mmOraclePriceData
259
+ );
255
260
  if (limitPrice !== undefined) {
256
261
  baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(
257
262
  order,
258
263
  updatedAMM,
264
+ market.marketStats,
265
+ market.orderStepSize,
266
+ market.orderTickSize,
259
267
  limitPrice,
260
268
  mmOraclePriceData
261
269
  );
@@ -265,6 +273,7 @@ export function calculateBaseAssetAmountForAmmToFulfill(
265
273
 
266
274
  const maxBaseAssetAmount = calculateMaxBaseAssetAmountFillable(
267
275
  updatedAMM,
276
+ market.orderStepSize,
268
277
  order.direction
269
278
  );
270
279
 
@@ -274,15 +283,19 @@ export function calculateBaseAssetAmountForAmmToFulfill(
274
283
  export function calculateBaseAssetAmountToFillUpToLimitPrice(
275
284
  order: Order,
276
285
  amm: AMM,
286
+ marketStats: MarketStats,
287
+ orderStepSize: BN,
288
+ orderTickSize: BN,
277
289
  limitPrice: BN,
278
290
  mmOraclePriceData: MMOraclePriceData
279
291
  ): BN {
280
292
  const adjustedLimitPrice = isVariant(order.direction, 'long')
281
- ? limitPrice.sub(amm.orderTickSize)
282
- : limitPrice.add(amm.orderTickSize);
293
+ ? limitPrice.sub(orderTickSize)
294
+ : limitPrice.add(orderTickSize);
283
295
 
284
296
  const [maxAmountToTrade, direction] = calculateMaxBaseAssetAmountToTrade(
285
297
  amm,
298
+ marketStats,
286
299
  adjustedLimitPrice,
287
300
  order.direction,
288
301
  mmOraclePriceData
@@ -290,7 +303,7 @@ export function calculateBaseAssetAmountToFillUpToLimitPrice(
290
303
 
291
304
  const baseAssetAmount = standardizeBaseAssetAmount(
292
305
  maxAmountToTrade,
293
- amm.orderStepSize
306
+ orderStepSize
294
307
  );
295
308
 
296
309
  // Check that directions are the same
@@ -461,7 +474,7 @@ export function maxSizeForTargetLiabilityWeightBN(
461
474
  }
462
475
 
463
476
  // cap at max OI
464
- const maxOpenInterest = market.amm.maxOpenInterest;
477
+ const maxOpenInterest = market.maxOpenInterest;
465
478
  if (lo.gt(maxOpenInterest)) {
466
479
  return maxOpenInterest;
467
480
  }
@@ -53,6 +53,8 @@ export function calculateBaseAssetValue(
53
53
  const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
54
54
  calculateUpdatedAMMSpreadReserves(
55
55
  market.amm,
56
+ market.marketStats,
57
+ market.totalExchangeFee,
56
58
  directionToClose,
57
59
  mmOraclePriceData,
58
60
  latestSlot
@@ -64,7 +66,11 @@ export function calculateBaseAssetValue(
64
66
  pegMultiplier: newPeg,
65
67
  };
66
68
  } else {
67
- prepegAmm = calculateUpdatedAMM(market.amm, mmOraclePriceData);
69
+ prepegAmm = calculateUpdatedAMM(
70
+ market.amm,
71
+ market.totalExchangeFee,
72
+ mmOraclePriceData
73
+ );
68
74
  }
69
75
  } else {
70
76
  prepegAmm = market.amm;
@@ -213,9 +219,9 @@ export function calculateUnsettledFundingPnl(
213
219
 
214
220
  let ammCumulativeFundingRate: BN;
215
221
  if (perpPosition.baseAssetAmount.gt(ZERO)) {
216
- ammCumulativeFundingRate = market.amm.cumulativeFundingRateLong;
222
+ ammCumulativeFundingRate = market.cumulativeFundingRateLong;
217
223
  } else {
218
- ammCumulativeFundingRate = market.amm.cumulativeFundingRateShort;
224
+ ammCumulativeFundingRate = market.cumulativeFundingRateShort;
219
225
  }
220
226
 
221
227
  const perPositionFundingRate = ammCumulativeFundingRate
@@ -43,17 +43,14 @@ export async function fetchBSolMetrics() {
43
43
  }
44
44
 
45
45
  export async function fetchBSolVelocityEmissions() {
46
- return await fetch('https://stake.solblaze.org/api/v1/drift_emissions');
46
+ return await fetch('https://stake.solblaze.org/api/v1/velocity_emissions');
47
47
  }
48
48
 
49
- /** @deprecated Use `fetchBSolVelocityEmissions` instead. `fetchBSolDriftEmissions` will be removed in a future major. */
50
- export const fetchBSolDriftEmissions = fetchBSolVelocityEmissions;
51
-
52
49
  export async function findBestSuperStakeIxs({
53
50
  marketIndex,
54
51
  amount,
55
52
  jupiterClient,
56
- driftClient,
53
+ velocityClient,
57
54
  userAccountPublicKey,
58
55
  price,
59
56
  forceMarinade,
@@ -63,7 +60,7 @@ export async function findBestSuperStakeIxs({
63
60
  marketIndex: number;
64
61
  amount: BN;
65
62
  jupiterClient: JupiterClient;
66
- driftClient: VelocityClient;
63
+ velocityClient: VelocityClient;
67
64
  price?: number;
68
65
  userAccountPublicKey?: PublicKey;
69
66
  forceMarinade?: boolean;
@@ -79,7 +76,7 @@ export async function findBestSuperStakeIxs({
79
76
  return findBestMSolSuperStakeIxs({
80
77
  amount,
81
78
  jupiterClient,
82
- driftClient,
79
+ velocityClient,
83
80
  userAccountPublicKey,
84
81
  price,
85
82
  forceMarinade,
@@ -90,7 +87,7 @@ export async function findBestSuperStakeIxs({
90
87
  return findBestJitoSolSuperStakeIxs({
91
88
  amount,
92
89
  jupiterClient,
93
- driftClient,
90
+ velocityClient,
94
91
  userAccountPublicKey,
95
92
  onlyDirectRoutes,
96
93
  jupiterQuote,
@@ -98,10 +95,10 @@ export async function findBestSuperStakeIxs({
98
95
  } else if (marketIndex === 8) {
99
96
  return findBestLstSuperStakeIxs({
100
97
  amount,
101
- lstMint: driftClient.getSpotMarketAccount(8).mint,
98
+ lstMint: velocityClient.getSpotMarketAccount(8).mint,
102
99
  lstMarketIndex: 8,
103
100
  jupiterClient,
104
- driftClient,
101
+ velocityClient,
105
102
  userAccountPublicKey,
106
103
  onlyDirectRoutes,
107
104
  jupiterQuote,
@@ -114,7 +111,7 @@ export async function findBestSuperStakeIxs({
114
111
  export async function findBestMSolSuperStakeIxs({
115
112
  amount,
116
113
  jupiterClient,
117
- driftClient,
114
+ velocityClient,
118
115
  userAccountPublicKey,
119
116
  price,
120
117
  forceMarinade,
@@ -123,7 +120,7 @@ export async function findBestMSolSuperStakeIxs({
123
120
  }: {
124
121
  amount: BN;
125
122
  jupiterClient: JupiterClient;
126
- driftClient: VelocityClient;
123
+ velocityClient: VelocityClient;
127
124
  price?: number;
128
125
  userAccountPublicKey?: PublicKey;
129
126
  forceMarinade?: boolean;
@@ -136,12 +133,12 @@ export async function findBestMSolSuperStakeIxs({
136
133
  price: number;
137
134
  }> {
138
135
  if (!price) {
139
- const marinadeProgram = getMarinadeFinanceProgram(driftClient.provider);
136
+ const marinadeProgram = getMarinadeFinanceProgram(velocityClient.provider);
140
137
  price = await getMarinadeMSolPrice(marinadeProgram);
141
138
  }
142
139
 
143
- const solSpotMarketAccount = driftClient.getSpotMarketAccount(1);
144
- const mSolSpotMarketAccount = driftClient.getSpotMarketAccount(2);
140
+ const solSpotMarketAccount = velocityClient.getSpotMarketAccount(1);
141
+ const mSolSpotMarketAccount = velocityClient.getSpotMarketAccount(2);
145
142
 
146
143
  let jupiterPrice: number;
147
144
  let quote = jupiterQuote;
@@ -164,7 +161,7 @@ export async function findBestMSolSuperStakeIxs({
164
161
  }
165
162
 
166
163
  if (!jupiterPrice || price <= jupiterPrice || forceMarinade) {
167
- const ixs = await driftClient.getStakeForMSOLIx({
164
+ const ixs = await velocityClient.getStakeForMSOLIx({
168
165
  amount,
169
166
  userAccountPublicKey,
170
167
  });
@@ -175,7 +172,7 @@ export async function findBestMSolSuperStakeIxs({
175
172
  price: price,
176
173
  };
177
174
  } else {
178
- const { ixs, lookupTables } = await driftClient.getJupiterSwapIxV6({
175
+ const { ixs, lookupTables } = await velocityClient.getJupiterSwapIxV6({
179
176
  inMarketIndex: 1,
180
177
  outMarketIndex: 2,
181
178
  jupiterClient,
@@ -196,14 +193,14 @@ export async function findBestMSolSuperStakeIxs({
196
193
  export async function findBestJitoSolSuperStakeIxs({
197
194
  amount,
198
195
  jupiterClient,
199
- driftClient,
196
+ velocityClient,
200
197
  userAccountPublicKey,
201
198
  onlyDirectRoutes,
202
199
  jupiterQuote,
203
200
  }: {
204
201
  amount: BN;
205
202
  jupiterClient: JupiterClient;
206
- driftClient: VelocityClient;
203
+ velocityClient: VelocityClient;
207
204
  userAccountPublicKey?: PublicKey;
208
205
  onlyDirectRoutes?: boolean;
209
206
  jupiterQuote?: QuoteResponse;
@@ -216,10 +213,10 @@ export async function findBestJitoSolSuperStakeIxs({
216
213
  return await findBestLstSuperStakeIxs({
217
214
  amount,
218
215
  jupiterClient,
219
- driftClient,
216
+ velocityClient,
220
217
  userAccountPublicKey,
221
218
  onlyDirectRoutes,
222
- lstMint: driftClient.getSpotMarketAccount(6).mint,
219
+ lstMint: velocityClient.getSpotMarketAccount(6).mint,
223
220
  lstMarketIndex: 6,
224
221
  jupiterQuote,
225
222
  });
@@ -233,7 +230,7 @@ export async function findBestJitoSolSuperStakeIxs({
233
230
  export async function findBestLstSuperStakeIxs({
234
231
  amount,
235
232
  jupiterClient,
236
- driftClient,
233
+ velocityClient,
237
234
  userAccountPublicKey,
238
235
  onlyDirectRoutes,
239
236
  lstMarketIndex,
@@ -243,7 +240,7 @@ export async function findBestLstSuperStakeIxs({
243
240
  lstMint: PublicKey;
244
241
  lstMarketIndex: number;
245
242
  jupiterClient: JupiterClient;
246
- driftClient: VelocityClient;
243
+ velocityClient: VelocityClient;
247
244
  userAccountPublicKey?: PublicKey;
248
245
  onlyDirectRoutes?: boolean;
249
246
  jupiterQuote?: QuoteResponse;
@@ -252,7 +249,7 @@ export async function findBestLstSuperStakeIxs({
252
249
  lookupTables: AddressLookupTableAccount[];
253
250
  method: 'jupiter' | 'marinade';
254
251
  }> {
255
- const { ixs, lookupTables } = await driftClient.getJupiterSwapIxV6({
252
+ const { ixs, lookupTables } = await velocityClient.getJupiterSwapIxV6({
256
253
  inMarketIndex: 1,
257
254
  outMarketIndex: lstMarketIndex,
258
255
  jupiterClient,
package/src/math/trade.ts CHANGED
@@ -113,6 +113,8 @@ export function calculateTradeSlippage(
113
113
  const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
114
114
  calculateUpdatedAMMSpreadReserves(
115
115
  market.amm,
116
+ market.marketStats,
117
+ market.totalExchangeFee,
116
118
  direction,
117
119
  mmOraclePriceData,
118
120
  latestSlot
@@ -184,6 +186,8 @@ export function calculateTradeAcquiredAmounts(
184
186
  const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
185
187
  calculateUpdatedAMMSpreadReserves(
186
188
  market.amm,
189
+ market.marketStats,
190
+ market.totalExchangeFee,
187
191
  direction,
188
192
  mmOraclePriceData,
189
193
  latestSlot
@@ -274,6 +278,8 @@ export function calculateTargetPriceTrade(
274
278
  const { baseAssetReserve, quoteAssetReserve, newPeg } =
275
279
  calculateUpdatedAMMSpreadReserves(
276
280
  market.amm,
281
+ market.marketStats,
282
+ market.totalExchangeFee,
277
283
  direction,
278
284
  mmOraclePriceData,
279
285
  latestSlot
@@ -436,6 +442,8 @@ export function calculateEstimatedPerpEntryPrice(
436
442
  const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } =
437
443
  calculateUpdatedAMMSpreadReserves(
438
444
  market.amm,
445
+ market.marketStats,
446
+ market.totalExchangeFee,
439
447
  direction,
440
448
  mmOraclePriceData,
441
449
  new BN(slot)
@@ -451,7 +459,7 @@ export function calculateEstimatedPerpEntryPrice(
451
459
  market.amm.baseAssetReserve,
452
460
  market.amm.minBaseAssetReserve,
453
461
  market.amm.maxBaseAssetReserve,
454
- market.amm.orderStepSize
462
+ market.orderStepSize
455
463
  );
456
464
 
457
465
  let ammLiquidity: BN;
package/src/math/utils.ts CHANGED
@@ -104,7 +104,7 @@ export function isBNSafe(number: number): boolean {
104
104
  /**
105
105
  * Converts a number to BN makes sure the number is safe to convert to BN (that it does not overflow number after multiplying by precision)
106
106
  * @param number the number to convert to BN
107
- * @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from drift sdk)
107
+ * @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from velocity sdk)
108
108
  */
109
109
  export function numberToSafeBN(number: number, precision: BN): BN {
110
110
  // check if number has decimals
@@ -1,7 +1,7 @@
1
1
  import { Connection, Keypair, PublicKey } from '@solana/web3.js';
2
2
  import { OracleClient, OraclePriceData } from './types';
3
3
  import { AnchorProvider, BN, Program } from '../isomorphic/anchor';
4
- import { Drift } from '../idl/drift';
4
+ import { Velocity } from '../idl/velocity';
5
5
  import { VelocityProgram } from '../config';
6
6
  import {
7
7
  ONE,
@@ -10,7 +10,7 @@ import {
10
10
  TEN,
11
11
  } from '../constants/numericConstants';
12
12
  import { Wallet } from '../wallet';
13
- import driftIDL from '../idl/drift.json';
13
+ import velocityIDL from '../idl/velocity.json';
14
14
 
15
15
  export class PythLazerClient implements OracleClient {
16
16
  private connection: Connection;
@@ -35,7 +35,7 @@ export class PythLazerClient implements OracleClient {
35
35
  commitment: connection.commitment,
36
36
  }
37
37
  );
38
- this.program = new Program<Drift>(driftIDL as Drift, provider);
38
+ this.program = new Program<Velocity>(velocityIDL as Velocity, provider);
39
39
  this.decodeFunc = (
40
40
  this.program.account as any
41
41
  ).pythLazerOracle.coder.accounts.decodeUnchecked.bind(
@@ -21,10 +21,6 @@ import { ZERO } from '../constants/numericConstants';
21
21
 
22
22
  export class OrderSubscriber {
23
23
  velocityClient: VelocityClient;
24
- /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
25
- public get driftClient(): VelocityClient {
26
- return this.velocityClient;
27
- }
28
24
  usersAccounts = new Map<string, { slot: number; userAccount: UserAccount }>();
29
25
  subscription: PollingSubscription | WebsocketSubscription | grpcSubscription;
30
26
  commitment: Commitment;
@@ -40,11 +36,9 @@ export class OrderSubscriber {
40
36
  fetchAllNonIdleUsers?: boolean;
41
37
 
42
38
  constructor(config: OrderSubscriberConfig) {
43
- const velocityClient = config.velocityClient ?? config.driftClient;
39
+ const velocityClient = config.velocityClient;
44
40
  if (!velocityClient) {
45
- throw new Error(
46
- 'OrderSubscriber: velocityClient (or deprecated driftClient) must be provided'
47
- );
41
+ throw new Error('OrderSubscriber: velocityClient must be provided');
48
42
  }
49
43
  this.velocityClient = velocityClient;
50
44
  this.commitment = config.subscriptionConfig.commitment || 'processed';
@@ -48,7 +48,7 @@ export class WebsocketSubscription {
48
48
  this.subscriber = new WebSocketProgramAccountSubscriber<UserAccount>(
49
49
  'OrderSubscriber',
50
50
  'user',
51
- this.orderSubscriber.driftClient.program,
51
+ this.orderSubscriber.velocityClient.program,
52
52
  this.orderSubscriber.decodeFn,
53
53
  {
54
54
  filters: [getUserFilter(), getNonIdleUserFilter()],
@@ -56,7 +56,7 @@ export class grpcSubscription {
56
56
  this.grpcConfigs,
57
57
  'OrderSubscriber',
58
58
  'user',
59
- this.orderSubscriber.driftClient.program,
59
+ this.orderSubscriber.velocityClient.program,
60
60
  this.orderSubscriber.decodeFn,
61
61
  {
62
62
  filters: [getUserFilter(), getNonIdleUserFilter()],
@@ -68,7 +68,7 @@ export class grpcSubscription {
68
68
  this.grpcConfigs,
69
69
  'OrderSubscriber',
70
70
  'user',
71
- this.orderSubscriber.driftClient.program,
71
+ this.orderSubscriber.velocityClient.program,
72
72
  this.orderSubscriber.decodeFn,
73
73
  {
74
74
  filters: [getUserFilter(), getNonIdleUserFilter()],
@@ -5,8 +5,6 @@ import { GrpcConfigs } from '../accounts/types';
5
5
 
6
6
  export type OrderSubscriberConfig = {
7
7
  velocityClient?: VelocityClient;
8
- /** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
9
- driftClient?: VelocityClient;
10
8
  subscriptionConfig:
11
9
  | {
12
10
  type: 'polling';