@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
@@ -52,6 +52,7 @@ import {
52
52
  PositionDirection,
53
53
  ReferrerInfo,
54
54
  ReferrerNameAccount,
55
+ RevenueShareEscrowAccount,
55
56
  ScaleOrderParams,
56
57
  SettlePnlMode,
57
58
  SignedTxData,
@@ -167,7 +168,7 @@ import {
167
168
  VelocityProgram,
168
169
  PYTH_LAZER_STORAGE_ACCOUNT_KEY,
169
170
  } from './config';
170
- import { Drift } from './idl/drift';
171
+ import { Velocity } from './idl/velocity';
171
172
  import { WRAPPED_SOL_MINT } from './constants/spotMarkets';
172
173
  import { UserStats } from './userStats';
173
174
  import { isSpotPositionAvailable } from './math/spotPosition';
@@ -202,6 +203,8 @@ import { RevenueShareEscrowMap } from './userMap/revenueShareEscrowMap';
202
203
  import {
203
204
  isBuilderOrderReferral,
204
205
  isBuilderOrderCompleted,
206
+ escrowHasReferrer,
207
+ hasBuilderParams,
205
208
  } from './math/builder';
206
209
  import { TitanClient, SwapMode as TitanSwapMode } from './titan/titanClient';
207
210
  import { UnifiedSwapClient } from './swap/UnifiedSwapClient';
@@ -329,8 +332,8 @@ export class VelocityClient {
329
332
  config.wallet,
330
333
  this.opts
331
334
  );
332
- this.program = new Program<Drift>(
333
- VelocityCore.defaultIdl() as unknown as Drift,
335
+ this.program = new Program<Velocity>(
336
+ VelocityCore.defaultIdl() as unknown as Velocity,
334
337
  this.provider,
335
338
  config.coder
336
339
  );
@@ -471,7 +474,6 @@ export class VelocityClient {
471
474
  } else if (config.accountSubscription?.type === 'grpc') {
472
475
  const accountSubscriberClass: any =
473
476
  config.accountSubscription?.velocityClientAccountSubscriber ??
474
- config.accountSubscription?.driftClientAccountSubscriber ??
475
477
  grpcVelocityClientAccountSubscriber;
476
478
  this.accountSubscriber = new accountSubscriberClass(
477
479
  config.accountSubscription.grpcConfigs,
@@ -489,7 +491,6 @@ export class VelocityClient {
489
491
  } else {
490
492
  const accountSubscriberClass: any =
491
493
  config.accountSubscription?.velocityClientAccountSubscriber ??
492
- config.accountSubscription?.driftClientAccountSubscriber ??
493
494
  WebSocketVelocityClientAccountSubscriber;
494
495
  this.accountSubscriber = new accountSubscriberClass(
495
496
  this.program as any,
@@ -751,7 +752,7 @@ export class VelocityClient {
751
752
  }
752
753
 
753
754
  /**
754
- * Update the wallet to use for drift transactions and linked user account
755
+ * Update the wallet to use for velocity transactions and linked user account
755
756
  * @param newWallet
756
757
  * @param subAccountIds
757
758
  * @param activeSubAccountId
@@ -770,8 +771,8 @@ export class VelocityClient {
770
771
  newWallet,
771
772
  this.opts
772
773
  );
773
- const newProgram = new Program<Drift>(
774
- VelocityCore.defaultIdl() as unknown as Drift,
774
+ const newProgram = new Program<Velocity>(
775
+ VelocityCore.defaultIdl() as unknown as Velocity,
775
776
  newProvider
776
777
  );
777
778
 
@@ -944,7 +945,7 @@ export class VelocityClient {
944
945
  * Adds and subscribes to users based on params set by the constructor or by updateWallet.
945
946
  */
946
947
  public async addAndSubscribeToUsers(authority?: PublicKey): Promise<boolean> {
947
- // save the rpc calls if driftclient is initialized without a real wallet
948
+ // save the rpc calls if velocityclient is initialized without a real wallet
948
949
  if (this.skipLoadUsers) return true;
949
950
 
950
951
  let result = true;
@@ -1838,6 +1839,32 @@ export class VelocityClient {
1838
1839
  return txSig;
1839
1840
  }
1840
1841
 
1842
+ public async getUpdateUserAllowDelegateTransferIx(
1843
+ allowDelegateTransfer: boolean
1844
+ ): Promise<TransactionInstruction> {
1845
+ return await this.program.instruction.updateUserAllowDelegateTransfer(
1846
+ allowDelegateTransfer,
1847
+ {
1848
+ accounts: {
1849
+ userStats: this.getUserStatsAccountPublicKey(),
1850
+ authority: this.wallet.publicKey,
1851
+ },
1852
+ }
1853
+ );
1854
+ }
1855
+
1856
+ public async updateUserAllowDelegateTransfer(
1857
+ allowDelegateTransfer: boolean
1858
+ ): Promise<TransactionSignature> {
1859
+ const tx = await this.buildTransaction(
1860
+ await this.getUpdateUserAllowDelegateTransferIx(allowDelegateTransfer),
1861
+ this.txParams
1862
+ );
1863
+
1864
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1865
+ return txSig;
1866
+ }
1867
+
1841
1868
  public async updateUserAdvancedLp(
1842
1869
  updates: { advancedLp: boolean; subAccountId: number }[]
1843
1870
  ): Promise<TransactionSignature> {
@@ -2178,7 +2205,7 @@ export class VelocityClient {
2178
2205
  userStats,
2179
2206
  authority,
2180
2207
  state: await this.getStatePublicKey(),
2181
- driftSigner: this.getSignerPublicKey(),
2208
+ velocitySigner: this.getSignerPublicKey(),
2182
2209
  keeper: this.wallet.publicKey,
2183
2210
  },
2184
2211
  remainingAccounts,
@@ -2444,7 +2471,7 @@ export class VelocityClient {
2444
2471
  }
2445
2472
 
2446
2473
  /**
2447
- * Each drift instruction must include perp and sport market accounts in the ix remaining accounts.
2474
+ * Each velocity instruction must include perp and sport market accounts in the ix remaining accounts.
2448
2475
  * Use this function to force a subset of markets to be included in the remaining accounts for every ix
2449
2476
  *
2450
2477
  * @param perpMarketIndexes
@@ -2483,9 +2510,9 @@ export class VelocityClient {
2483
2510
  isWritable: writable,
2484
2511
  });
2485
2512
  const oracleWritable =
2486
- writable && isVariant(perpMarketAccount.amm.oracleSource, 'prelaunch');
2487
- oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
2488
- pubkey: perpMarketAccount.amm.oracle,
2513
+ writable && isVariant(perpMarketAccount.oracleSource, 'prelaunch');
2514
+ oracleAccountMap.set(perpMarketAccount.oracle.toString(), {
2515
+ pubkey: perpMarketAccount.oracle,
2489
2516
  isSigner: false,
2490
2517
  isWritable: oracleWritable,
2491
2518
  });
@@ -2523,27 +2550,34 @@ export class VelocityClient {
2523
2550
  remainingAccounts: AccountMeta[]
2524
2551
  ): void {
2525
2552
  for (const builder of builders) {
2526
- // Add User account for the builder
2553
+ // Add User account for the builder. Dedupe by pubkey: an authority may be
2554
+ // both a builder and the referrer, in which case its User + RevenueShare
2555
+ // accounts would otherwise be pushed twice. On-chain `load_revenue_share_map`
2556
+ // rejects duplicates, which would silently abort the entire sweep.
2527
2557
  const builderUserAccount = getUserAccountPublicKeySync(
2528
2558
  this.program.programId,
2529
2559
  builder,
2530
2560
  0 // subAccountId 0 for builder user account
2531
2561
  );
2532
- remainingAccounts.push({
2533
- pubkey: builderUserAccount,
2534
- isSigner: false,
2535
- isWritable: true,
2536
- });
2562
+ if (!remainingAccounts.find((a) => a.pubkey.equals(builderUserAccount))) {
2563
+ remainingAccounts.push({
2564
+ pubkey: builderUserAccount,
2565
+ isSigner: false,
2566
+ isWritable: true,
2567
+ });
2568
+ }
2537
2569
 
2538
2570
  const builderAccount = getRevenueShareAccountPublicKey(
2539
2571
  this.program.programId,
2540
2572
  builder
2541
2573
  );
2542
- remainingAccounts.push({
2543
- pubkey: builderAccount,
2544
- isSigner: false,
2545
- isWritable: true,
2546
- });
2574
+ if (!remainingAccounts.find((a) => a.pubkey.equals(builderAccount))) {
2575
+ remainingAccounts.push({
2576
+ pubkey: builderAccount,
2577
+ isSigner: false,
2578
+ isWritable: true,
2579
+ });
2580
+ }
2547
2581
  }
2548
2582
  }
2549
2583
 
@@ -3611,7 +3645,7 @@ export class VelocityClient {
3611
3645
  state: await this.getStatePublicKey(),
3612
3646
  spotMarket: spotMarketAccount.pubkey,
3613
3647
  spotMarketVault: spotMarketAccount.vault,
3614
- driftSigner: this.getSignerPublicKey(),
3648
+ velocitySigner: this.getSignerPublicKey(),
3615
3649
  user,
3616
3650
  userStats: this.getUserStatsAccountPublicKey(),
3617
3651
  userTokenAccount,
@@ -3717,6 +3751,89 @@ export class VelocityClient {
3717
3751
  });
3718
3752
  }
3719
3753
 
3754
+ public async transferDepositByDelegate(
3755
+ amount: BN,
3756
+ marketIndex: number,
3757
+ fromSubAccountId: number,
3758
+ toSubAccountId: number,
3759
+ txParams?: TxParams
3760
+ ): Promise<TransactionSignature> {
3761
+ const { txSig, slot } = await this.sendTransaction(
3762
+ await this.buildTransaction(
3763
+ await this.getTransferDepositByDelegateIx(
3764
+ amount,
3765
+ marketIndex,
3766
+ fromSubAccountId,
3767
+ toSubAccountId
3768
+ ),
3769
+ txParams
3770
+ ),
3771
+ [],
3772
+ this.opts
3773
+ );
3774
+ if (
3775
+ fromSubAccountId === this.activeSubAccountId ||
3776
+ toSubAccountId === this.activeSubAccountId
3777
+ ) {
3778
+ this.spotMarketLastSlotCache.set(marketIndex, slot);
3779
+ }
3780
+ return txSig;
3781
+ }
3782
+
3783
+ public async getTransferDepositByDelegateIx(
3784
+ amount: BN,
3785
+ marketIndex: number,
3786
+ fromSubAccountId: number,
3787
+ toSubAccountId: number
3788
+ ): Promise<TransactionInstruction> {
3789
+ const fromUser = await getUserAccountPublicKey(
3790
+ this.program.programId,
3791
+ this.authority,
3792
+ fromSubAccountId
3793
+ );
3794
+ const toUser = await getUserAccountPublicKey(
3795
+ this.program.programId,
3796
+ this.authority,
3797
+ toSubAccountId
3798
+ );
3799
+
3800
+ let remainingAccounts;
3801
+
3802
+ const userMapKey = this.getUserMapKey(fromSubAccountId, this.authority);
3803
+ if (this.users.has(userMapKey)) {
3804
+ remainingAccounts = this.getRemainingAccounts({
3805
+ userAccounts: [this.users.get(userMapKey).getUserAccount()],
3806
+ useMarketLastSlotCache: true,
3807
+ writableSpotMarketIndexes: [marketIndex],
3808
+ });
3809
+ } else {
3810
+ const fromUserAccount = (await (this.program.account as any).user.fetch(
3811
+ fromUser
3812
+ )) as UserAccount;
3813
+ remainingAccounts = this.getRemainingAccounts({
3814
+ userAccounts: [fromUserAccount],
3815
+ useMarketLastSlotCache: true,
3816
+ writableSpotMarketIndexes: [marketIndex],
3817
+ });
3818
+ }
3819
+
3820
+ return await this.program.instruction.transferDepositByDelegate(
3821
+ marketIndex,
3822
+ amount,
3823
+ {
3824
+ accounts: {
3825
+ delegate: this.wallet.publicKey,
3826
+ fromUser,
3827
+ toUser,
3828
+ userStats: this.getUserStatsAccountPublicKey(),
3829
+ state: await this.getStatePublicKey(),
3830
+ spotMarketVault: this.getSpotMarketAccount(marketIndex).vault,
3831
+ },
3832
+ remainingAccounts,
3833
+ }
3834
+ );
3835
+ }
3836
+
3720
3837
  public async transferPools(
3721
3838
  depositFromMarketIndex: number,
3722
3839
  depositToMarketIndex: number,
@@ -3844,7 +3961,7 @@ export class VelocityClient {
3844
3961
  ).vault,
3845
3962
  borrowToSpotMarketVault:
3846
3963
  this.getSpotMarketAccount(borrowToMarketIndex).vault,
3847
- driftSigner: this.getSignerPublicKey(),
3964
+ velocitySigner: this.getSignerPublicKey(),
3848
3965
  },
3849
3966
  remainingAccounts,
3850
3967
  }
@@ -4228,7 +4345,7 @@ export class VelocityClient {
4228
4345
  authority: this.wallet.publicKey,
4229
4346
  userTokenAccount: userTokenAccount,
4230
4347
  tokenProgram: this.getTokenProgramForSpotMarket(spotMarketAccount),
4231
- driftSigner: this.getSignerPublicKey(),
4348
+ velocitySigner: this.getSignerPublicKey(),
4232
4349
  },
4233
4350
  remainingAccounts,
4234
4351
  }
@@ -4286,7 +4403,6 @@ export class VelocityClient {
4286
4403
  undefined,
4287
4404
  undefined,
4288
4405
  undefined,
4289
- undefined,
4290
4406
  subAccountId
4291
4407
  );
4292
4408
  }
@@ -4312,7 +4428,6 @@ export class VelocityClient {
4312
4428
  makerInfo?: MakerInfo | MakerInfo[],
4313
4429
  txParams?: TxParams,
4314
4430
  bracketOrdersParams = new Array<OptionalOrderParams>(),
4315
- referrerInfo?: ReferrerInfo,
4316
4431
  cancelExistingOrders?: boolean,
4317
4432
  settlePnl?: boolean,
4318
4433
  positionMaxLev?: number,
@@ -4393,7 +4508,6 @@ export class VelocityClient {
4393
4508
  marketIndex,
4394
4509
  },
4395
4510
  makerInfo,
4396
- referrerInfo,
4397
4511
  userAccount.subAccountId
4398
4512
  );
4399
4513
  }
@@ -4434,7 +4548,6 @@ export class VelocityClient {
4434
4548
  makerInfo?: MakerInfo | MakerInfo[],
4435
4549
  txParams?: TxParams,
4436
4550
  bracketOrdersParams = new Array<OptionalOrderParams>(),
4437
- referrerInfo?: ReferrerInfo,
4438
4551
  cancelExistingOrders?: boolean,
4439
4552
  settlePnl?: boolean
4440
4553
  ): Promise<{
@@ -4450,7 +4563,6 @@ export class VelocityClient {
4450
4563
  makerInfo,
4451
4564
  txParams,
4452
4565
  bracketOrdersParams,
4453
- referrerInfo,
4454
4566
  cancelExistingOrders,
4455
4567
  settlePnl
4456
4568
  );
@@ -4514,6 +4626,65 @@ export class VelocityClient {
4514
4626
  return txSig;
4515
4627
  }
4516
4628
 
4629
+ /**
4630
+ * Returns the RevenueShareEscrow account meta for the placing user when `orderParams`
4631
+ * carries a builder code (`builderIdx` + `builderFeeTenthBps`), otherwise `undefined`.
4632
+ * The on-chain handlers peek for this account last in `remaining_accounts`, so callers
4633
+ * must push it after the market/oracle/maker accounts.
4634
+ */
4635
+ private getBuilderEscrowAccountMeta(
4636
+ orderParams: Pick<OrderParams, 'builderIdx' | 'builderFeeTenthBps'>,
4637
+ subAccountId?: number
4638
+ ): AccountMeta | undefined {
4639
+ if (!hasBuilderParams(orderParams)) {
4640
+ return undefined;
4641
+ }
4642
+ const authority =
4643
+ this.getUserAccount(subAccountId)?.authority ?? this.authority;
4644
+ return {
4645
+ pubkey: getRevenueShareEscrowAccountPublicKey(
4646
+ this.program.programId,
4647
+ authority
4648
+ ),
4649
+ isWritable: true,
4650
+ isSigner: false,
4651
+ };
4652
+ }
4653
+
4654
+ /**
4655
+ * Returns the AccountMeta for the taker's RevenueShareEscrow when a fill of the
4656
+ * taker's order must include it: the order carries a builder code, or the taker
4657
+ * is referred (their escrow was initialized with a referrer). Returns `undefined`
4658
+ * when neither applies so no account meta is added to the transaction. The
4659
+ * on-chain handlers peek for this account last in `remaining_accounts`, so
4660
+ * callers must push it after the market/oracle/maker accounts.
4661
+ *
4662
+ * Throws when `takerEscrow` does not belong to `takerAuthority`.
4663
+ */
4664
+ private getTakerEscrowAccountMeta(
4665
+ takerAuthority: PublicKey,
4666
+ orderHasBuilder: boolean,
4667
+ takerEscrow?: RevenueShareEscrowAccount
4668
+ ): AccountMeta | undefined {
4669
+ if (takerEscrow && !takerEscrow.authority.equals(takerAuthority)) {
4670
+ throw new Error(
4671
+ 'takerEscrow.authority does not match the taker user account authority'
4672
+ );
4673
+ }
4674
+ const takerIsReferred = takerEscrow && escrowHasReferrer(takerEscrow);
4675
+ if (!orderHasBuilder && !takerIsReferred) {
4676
+ return undefined;
4677
+ }
4678
+ return {
4679
+ pubkey: getRevenueShareEscrowAccountPublicKey(
4680
+ this.program.programId,
4681
+ takerAuthority
4682
+ ),
4683
+ isWritable: true,
4684
+ isSigner: false,
4685
+ };
4686
+ }
4687
+
4517
4688
  public async getPlacePerpOrderIx(
4518
4689
  orderParams: OptionalOrderParams,
4519
4690
  subAccountId?: number,
@@ -4545,6 +4716,14 @@ export class VelocityClient {
4545
4716
  : undefined,
4546
4717
  });
4547
4718
 
4719
+ const builderEscrow = this.getBuilderEscrowAccountMeta(
4720
+ orderParams,
4721
+ subAccountId
4722
+ );
4723
+ if (builderEscrow) {
4724
+ remainingAccounts.push(builderEscrow);
4725
+ }
4726
+
4548
4727
  return await VelocityCore.buildPlacePerpOrderInstruction({
4549
4728
  program: this.program,
4550
4729
  orderParams,
@@ -4584,7 +4763,7 @@ export class VelocityClient {
4584
4763
  isSigner: false,
4585
4764
  });
4586
4765
  oracleAccountInfos.push({
4587
- pubkey: market.amm.oracle,
4766
+ pubkey: market.oracle,
4588
4767
  isWritable: false,
4589
4768
  isSigner: false,
4590
4769
  });
@@ -4760,7 +4939,7 @@ export class VelocityClient {
4760
4939
  const user = await this.getUserAccountPublicKey(subAccountId);
4761
4940
 
4762
4941
  const order = this.getOrderByUserId(userOrderId);
4763
- const oracle = this.getPerpMarketAccount(order.marketIndex).amm.oracle;
4942
+ const oracle = this.getPerpMarketAccount(order.marketIndex).oracle;
4764
4943
 
4765
4944
  const remainingAccounts = this.getRemainingAccounts({
4766
4945
  userAccounts: [this.getUserAccount(subAccountId)],
@@ -5034,6 +5213,19 @@ export class VelocityClient {
5034
5213
  const formattedParams = params.map((item) => getOrderParams(item));
5035
5214
  const authority = overrides?.authority ?? this.wallet.publicKey;
5036
5215
 
5216
+ // The handler loads a single RevenueShareEscrow for the placing user, so push it once
5217
+ // if any order in the batch carries a builder code.
5218
+ const builderParam = formattedParams.find((p) => hasBuilderParams(p));
5219
+ if (builderParam) {
5220
+ const builderEscrow = this.getBuilderEscrowAccountMeta(
5221
+ builderParam,
5222
+ subAccountId
5223
+ );
5224
+ if (builderEscrow) {
5225
+ remainingAccounts.push(builderEscrow);
5226
+ }
5227
+ }
5228
+
5037
5229
  return await VelocityCore.buildPlaceOrdersInstruction({
5038
5230
  program: this.program,
5039
5231
  formattedParams,
@@ -5191,11 +5383,11 @@ export class VelocityClient {
5191
5383
  user: UserAccount,
5192
5384
  order?: Pick<Order, 'marketIndex' | 'orderId'>,
5193
5385
  makerInfo?: MakerInfo | MakerInfo[],
5194
- referrerInfo?: ReferrerInfo,
5195
5386
  txParams?: TxParams,
5196
5387
  fillerSubAccountId?: number,
5197
5388
  fillerAuthority?: PublicKey,
5198
- hasBuilderFee?: boolean
5389
+ hasBuilderFee?: boolean,
5390
+ takerEscrow?: RevenueShareEscrowAccount
5199
5391
  ): Promise<TransactionSignature> {
5200
5392
  const { txSig } = await this.sendTransaction(
5201
5393
  await this.buildTransaction(
@@ -5204,11 +5396,11 @@ export class VelocityClient {
5204
5396
  user,
5205
5397
  order,
5206
5398
  makerInfo,
5207
- referrerInfo,
5208
5399
  fillerSubAccountId,
5209
5400
  undefined,
5210
5401
  fillerAuthority,
5211
- hasBuilderFee
5402
+ hasBuilderFee,
5403
+ takerEscrow
5212
5404
  ),
5213
5405
  txParams
5214
5406
  ),
@@ -5223,11 +5415,15 @@ export class VelocityClient {
5223
5415
  userAccount: UserAccount,
5224
5416
  order: Pick<Order, 'marketIndex' | 'orderId'>,
5225
5417
  makerInfo?: MakerInfo | MakerInfo[],
5226
- referrerInfo?: ReferrerInfo,
5227
5418
  fillerSubAccountId?: number,
5228
5419
  isSignedMsg?: boolean,
5229
5420
  fillerAuthority?: PublicKey,
5230
- hasBuilderFee?: boolean
5421
+ hasBuilderFee?: boolean,
5422
+ // The program rejects fills that omit the taker's RevenueShareEscrow when the
5423
+ // order has a builder OR the taker is referred with an escrow. The builder case
5424
+ // is detected from the order bitflags; pass the taker's decoded escrow (e.g.
5425
+ // from a RevenueShareEscrowMap) so referred takers also get it attached.
5426
+ takerEscrow?: RevenueShareEscrowAccount
5231
5427
  ): Promise<TransactionInstruction> {
5232
5428
  const userStatsPublicKey = getUserStatsAccountPublicKey(
5233
5429
  this.program.programId,
@@ -5291,24 +5487,6 @@ export class VelocityClient {
5291
5487
  });
5292
5488
  }
5293
5489
 
5294
- if (referrerInfo) {
5295
- const referrerIsMaker =
5296
- makerInfo.find((maker) => maker.maker.equals(referrerInfo.referrer)) !==
5297
- undefined;
5298
- if (!referrerIsMaker) {
5299
- remainingAccounts.push({
5300
- pubkey: referrerInfo.referrer,
5301
- isWritable: true,
5302
- isSigner: false,
5303
- });
5304
- remainingAccounts.push({
5305
- pubkey: referrerInfo.referrerStats,
5306
- isWritable: true,
5307
- isSigner: false,
5308
- });
5309
- }
5310
- }
5311
-
5312
5490
  let withBuilder = false;
5313
5491
  if (hasBuilderFee) {
5314
5492
  withBuilder = true;
@@ -5328,15 +5506,13 @@ export class VelocityClient {
5328
5506
  }
5329
5507
  }
5330
5508
 
5331
- if (withBuilder) {
5332
- remainingAccounts.push({
5333
- pubkey: getRevenueShareEscrowAccountPublicKey(
5334
- this.program.programId,
5335
- userAccount.authority
5336
- ),
5337
- isWritable: true,
5338
- isSigner: false,
5339
- });
5509
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta(
5510
+ userAccount.authority,
5511
+ withBuilder,
5512
+ takerEscrow
5513
+ );
5514
+ if (takerEscrowMeta) {
5515
+ remainingAccounts.push(takerEscrowMeta);
5340
5516
  }
5341
5517
 
5342
5518
  const orderId = isSignedMsg ? null : order.orderId;
@@ -5401,7 +5577,6 @@ export class VelocityClient {
5401
5577
  _order?: Pick<Order, 'marketIndex' | 'orderId'>,
5402
5578
  _fulfillmentConfig?: unknown,
5403
5579
  _makerInfo?: MakerInfo | MakerInfo[],
5404
- _referrerInfo?: ReferrerInfo,
5405
5580
  _txParams?: TxParams
5406
5581
  ): Promise<TransactionSignature> {
5407
5582
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
@@ -5413,14 +5588,13 @@ export class VelocityClient {
5413
5588
  _order?: Pick<Order, 'marketIndex' | 'orderId'>,
5414
5589
  _fulfillmentConfig?: unknown,
5415
5590
  _makerInfo?: MakerInfo | MakerInfo[],
5416
- _referrerInfo?: ReferrerInfo,
5417
5591
  _fillerPublicKey?: PublicKey
5418
5592
  ): Promise<TransactionInstruction> {
5419
5593
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
5420
5594
  }
5421
5595
 
5422
5596
  /**
5423
- * Swap tokens in drift account using titan or jupiter
5597
+ * Swap tokens in velocity account using titan or jupiter
5424
5598
  * @param swapClient swap client to find routes and instructions (Titan or Jupiter)
5425
5599
  * @param jupiterClient @deprecated Use swapClient instead. Legacy parameter for backward compatibility
5426
5600
  * @param outMarketIndex the market index of the token you're buying
@@ -5431,7 +5605,7 @@ export class VelocityClient {
5431
5605
  * @param slippageBps the max slippage passed to the swap provider api
5432
5606
  * @param swapMode swap provider swapMode (ExactIn or ExactOut), default is ExactIn
5433
5607
  * @param route the swap provider route to use for the swap
5434
- * @param reduceOnly specify if In or Out token on the drift account must reduceOnly, checked at end of swap
5608
+ * @param reduceOnly specify if In or Out token on the velocity account must reduceOnly, checked at end of swap
5435
5609
  * @param v6 pass in the quote response from swap provider quote's API (deprecated, use quote instead)
5436
5610
  * @param quote pass in the quote response from swap provider quote's API
5437
5611
  * @param txParams
@@ -5650,7 +5824,7 @@ export class VelocityClient {
5650
5824
  slippageBps,
5651
5825
  swapMode: isExactOut ? TitanSwapMode.ExactOut : TitanSwapMode.ExactIn,
5652
5826
  onlyDirectRoutes,
5653
- sizeConstraint: MAX_TX_BYTE_SIZE - 375, // buffer for drift instructions
5827
+ sizeConstraint: MAX_TX_BYTE_SIZE - 375, // buffer for velocity instructions
5654
5828
  });
5655
5829
 
5656
5830
  const titanInstructions = titanClient.getTitanInstructions({
@@ -5810,7 +5984,7 @@ export class VelocityClient {
5810
5984
  }
5811
5985
 
5812
5986
  /**
5813
- * Get the drift begin_swap and end_swap instructions
5987
+ * Get the velocity begin_swap and end_swap instructions
5814
5988
  *
5815
5989
  * @param outMarketIndex the market index of the token you're buying
5816
5990
  * @param inMarketIndex the market index of the token you're selling
@@ -5915,7 +6089,7 @@ export class VelocityClient {
5915
6089
  inTokenAccount,
5916
6090
  outTokenAccount,
5917
6091
  tokenProgram: inTokenProgram,
5918
- driftSigner: this.getStateAccount().signer,
6092
+ velocitySigner: this.getStateAccount().signer,
5919
6093
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
5920
6094
  },
5921
6095
  remainingAccounts,
@@ -5938,7 +6112,7 @@ export class VelocityClient {
5938
6112
  inTokenAccount,
5939
6113
  outTokenAccount,
5940
6114
  tokenProgram: inTokenProgram,
5941
- driftSigner: this.getStateAccount().signer,
6115
+ velocitySigner: this.getStateAccount().signer,
5942
6116
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
5943
6117
  },
5944
6118
  remainingAccounts,
@@ -6055,7 +6229,7 @@ export class VelocityClient {
6055
6229
  amountInForBeginSwap = amount;
6056
6230
  }
6057
6231
 
6058
- // Get drift swap instructions for begin and end
6232
+ // Get velocity swap instructions for begin and end
6059
6233
  const { beginSwapIx, endSwapIx } = await this.getSwapIx({
6060
6234
  outMarketIndex,
6061
6235
  inMarketIndex,
@@ -6411,21 +6585,22 @@ export class VelocityClient {
6411
6585
  public async placeAndTakePerpOrder(
6412
6586
  orderParams: OptionalOrderParams,
6413
6587
  makerInfo?: MakerInfo | MakerInfo[],
6414
- referrerInfo?: ReferrerInfo,
6415
6588
  successCondition?: PlaceAndTakeOrderSuccessCondition,
6416
6589
  auctionDurationPercentage?: number,
6417
6590
  txParams?: TxParams,
6418
- subAccountId?: number
6591
+ subAccountId?: number,
6592
+ takerEscrow?: RevenueShareEscrowAccount
6419
6593
  ): Promise<TransactionSignature> {
6420
6594
  const { txSig, slot } = await this.sendTransaction(
6421
6595
  await this.buildTransaction(
6422
6596
  await this.getPlaceAndTakePerpOrderIx(
6423
6597
  orderParams,
6424
6598
  makerInfo,
6425
- referrerInfo,
6426
6599
  successCondition,
6427
6600
  auctionDurationPercentage,
6428
- subAccountId
6601
+ subAccountId,
6602
+ undefined,
6603
+ takerEscrow
6429
6604
  ),
6430
6605
  txParams
6431
6606
  ),
@@ -6438,7 +6613,6 @@ export class VelocityClient {
6438
6613
  public async preparePlaceAndTakePerpOrderWithAdditionalOrders(
6439
6614
  orderParams: OptionalOrderParams,
6440
6615
  makerInfo?: MakerInfo | MakerInfo[],
6441
- referrerInfo?: ReferrerInfo,
6442
6616
  bracketOrdersParams = new Array<OptionalOrderParams>(),
6443
6617
  txParams?: TxParams,
6444
6618
  subAccountId?: number,
@@ -6475,7 +6649,6 @@ export class VelocityClient {
6475
6649
  const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(
6476
6650
  orderParams,
6477
6651
  makerInfo,
6478
- referrerInfo,
6479
6652
  undefined,
6480
6653
  auctionDurationPercentage,
6481
6654
  subAccountId
@@ -6634,7 +6807,6 @@ export class VelocityClient {
6634
6807
  public async placeAndTakePerpWithAdditionalOrders(
6635
6808
  orderParams: OptionalOrderParams,
6636
6809
  makerInfo?: MakerInfo | MakerInfo[],
6637
- referrerInfo?: ReferrerInfo,
6638
6810
  bracketOrdersParams = new Array<OptionalOrderParams>(),
6639
6811
  txParams?: TxParams,
6640
6812
  subAccountId?: number,
@@ -6650,7 +6822,6 @@ export class VelocityClient {
6650
6822
  await this.preparePlaceAndTakePerpOrderWithAdditionalOrders(
6651
6823
  orderParams,
6652
6824
  makerInfo,
6653
- referrerInfo,
6654
6825
  bracketOrdersParams,
6655
6826
  txParams,
6656
6827
  subAccountId,
@@ -6691,13 +6862,17 @@ export class VelocityClient {
6691
6862
  public async getPlaceAndTakePerpOrderIx(
6692
6863
  orderParams: OptionalOrderParams,
6693
6864
  makerInfo?: MakerInfo | MakerInfo[],
6694
- referrerInfo?: ReferrerInfo,
6695
6865
  successCondition?: PlaceAndTakeOrderSuccessCondition,
6696
6866
  auctionDurationPercentage?: number,
6697
6867
  subAccountId?: number,
6698
6868
  overrides?: {
6699
6869
  authority?: PublicKey;
6700
- }
6870
+ },
6871
+ // place_and_take fills the placing user's (the taker's) order in-instruction, so
6872
+ // their RevenueShareEscrow must be attached for BOTH builder fees and referrer
6873
+ // revenue share. The builder case is detected from orderParams; pass the user's
6874
+ // decoded escrow (e.g. from a RevenueShareEscrowMap) to cover the referred case.
6875
+ takerEscrow?: RevenueShareEscrowAccount
6701
6876
  ): Promise<TransactionInstruction> {
6702
6877
  orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
6703
6878
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
@@ -6733,22 +6908,13 @@ export class VelocityClient {
6733
6908
  });
6734
6909
  }
6735
6910
 
6736
- if (referrerInfo) {
6737
- const referrerIsMaker =
6738
- makerInfo.find((maker) => maker.maker.equals(referrerInfo.referrer)) !==
6739
- undefined;
6740
- if (!referrerIsMaker) {
6741
- remainingAccounts.push({
6742
- pubkey: referrerInfo.referrer,
6743
- isWritable: true,
6744
- isSigner: false,
6745
- });
6746
- remainingAccounts.push({
6747
- pubkey: referrerInfo.referrerStats,
6748
- isWritable: true,
6749
- isSigner: false,
6750
- });
6751
- }
6911
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta(
6912
+ this.getUserAccount(subAccountId)?.authority ?? this.authority,
6913
+ hasBuilderParams(orderParams),
6914
+ takerEscrow
6915
+ );
6916
+ if (takerEscrowMeta) {
6917
+ remainingAccounts.push(takerEscrowMeta);
6752
6918
  }
6753
6919
 
6754
6920
  let optionalParams = null;
@@ -6774,17 +6940,17 @@ export class VelocityClient {
6774
6940
  public async placeAndMakePerpOrder(
6775
6941
  orderParams: OptionalOrderParams,
6776
6942
  takerInfo: TakerInfo,
6777
- referrerInfo?: ReferrerInfo,
6778
6943
  txParams?: TxParams,
6779
- subAccountId?: number
6944
+ subAccountId?: number,
6945
+ takerEscrow?: RevenueShareEscrowAccount
6780
6946
  ): Promise<TransactionSignature> {
6781
6947
  const { txSig, slot } = await this.sendTransaction(
6782
6948
  await this.buildTransaction(
6783
6949
  await this.getPlaceAndMakePerpOrderIx(
6784
6950
  orderParams,
6785
6951
  takerInfo,
6786
- referrerInfo,
6787
- subAccountId
6952
+ subAccountId,
6953
+ takerEscrow
6788
6954
  ),
6789
6955
  txParams
6790
6956
  ),
@@ -6800,8 +6966,12 @@ export class VelocityClient {
6800
6966
  public async getPlaceAndMakePerpOrderIx(
6801
6967
  orderParams: OptionalOrderParams,
6802
6968
  takerInfo: TakerInfo,
6803
- referrerInfo?: ReferrerInfo,
6804
- subAccountId?: number
6969
+ subAccountId?: number,
6970
+ // place_and_make fills the taker's order in-instruction, so the TAKER's
6971
+ // RevenueShareEscrow must be attached when their order has a builder or they
6972
+ // are referred with an escrow. The builder case is detected from the taker
6973
+ // order bitflags; pass the taker's decoded escrow to cover the referred case.
6974
+ takerEscrow?: RevenueShareEscrowAccount
6805
6975
  ): Promise<TransactionInstruction> {
6806
6976
  orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
6807
6977
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
@@ -6816,29 +6986,14 @@ export class VelocityClient {
6816
6986
  writablePerpMarketIndexes: [orderParams.marketIndex],
6817
6987
  });
6818
6988
 
6819
- if (referrerInfo) {
6820
- remainingAccounts.push({
6821
- pubkey: referrerInfo.referrer,
6822
- isWritable: true,
6823
- isSigner: false,
6824
- });
6825
- remainingAccounts.push({
6826
- pubkey: referrerInfo.referrerStats,
6827
- isWritable: true,
6828
- isSigner: false,
6829
- });
6830
- }
6831
-
6832
6989
  const takerOrderId = takerInfo.order.orderId;
6833
- if (hasBuilder(takerInfo.order)) {
6834
- remainingAccounts.push({
6835
- pubkey: getRevenueShareEscrowAccountPublicKey(
6836
- this.program.programId,
6837
- takerInfo.takerUserAccount.authority
6838
- ),
6839
- isWritable: true,
6840
- isSigner: false,
6841
- });
6990
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta(
6991
+ takerInfo.takerUserAccount.authority,
6992
+ hasBuilder(takerInfo.order),
6993
+ takerEscrow
6994
+ );
6995
+ if (takerEscrowMeta) {
6996
+ remainingAccounts.push(takerEscrowMeta);
6842
6997
  }
6843
6998
  return await VelocityCore.buildPlaceAndMakePerpOrderInstruction({
6844
6999
  program: this.program,
@@ -6874,7 +7029,7 @@ export class VelocityClient {
6874
7029
  /**
6875
7030
  * Builds a deposit and place request for Swift service
6876
7031
  *
6877
- * @param depositTx - The signed tx containing a drift deposit (e.g. see `buildSwiftDepositTx`)
7032
+ * @param depositTx - The signed tx containing a velocity deposit (e.g. see `buildSwiftDepositTx`)
6878
7033
  * @param orderParamsMessage - The order parameters message to sign
6879
7034
  * @param delegateSigner - Whether this is a delegate signer
6880
7035
  *
@@ -7012,10 +7167,7 @@ export class VelocityClient {
7012
7167
  writableSpotMarketIndexes,
7013
7168
  });
7014
7169
 
7015
- if (
7016
- signedMessage.builderFeeTenthBps !== null &&
7017
- signedMessage.builderIdx !== null
7018
- ) {
7170
+ if (hasBuilderParams(signedMessage)) {
7019
7171
  remainingAccounts.push({
7020
7172
  pubkey: getRevenueShareEscrowAccountPublicKey(
7021
7173
  this.program.programId,
@@ -7078,21 +7230,21 @@ export class VelocityClient {
7078
7230
  signingAuthority: PublicKey;
7079
7231
  },
7080
7232
  orderParams: OptionalOrderParams,
7081
- referrerInfo?: ReferrerInfo,
7082
7233
  txParams?: TxParams,
7083
7234
  subAccountId?: number,
7084
7235
  precedingIxs: TransactionInstruction[] = [],
7085
- overrideCustomIxIndex?: number
7236
+ overrideCustomIxIndex?: number,
7237
+ takerEscrow?: RevenueShareEscrowAccount
7086
7238
  ): Promise<TransactionSignature> {
7087
7239
  const ixs = await this.getPlaceAndMakeSignedMsgPerpOrderIxs(
7088
7240
  signedSignedMsgOrderParams,
7089
7241
  signedMsgOrderUuid,
7090
7242
  takerInfo,
7091
7243
  orderParams,
7092
- referrerInfo,
7093
7244
  subAccountId,
7094
7245
  precedingIxs,
7095
- overrideCustomIxIndex
7246
+ overrideCustomIxIndex,
7247
+ takerEscrow
7096
7248
  );
7097
7249
  const { txSig, slot } = await this.sendTransaction(
7098
7250
  await this.buildTransaction(ixs, txParams),
@@ -7114,10 +7266,13 @@ export class VelocityClient {
7114
7266
  signingAuthority: PublicKey;
7115
7267
  },
7116
7268
  orderParams: OptionalOrderParams,
7117
- referrerInfo?: ReferrerInfo,
7118
7269
  subAccountId?: number,
7119
7270
  precedingIxs: TransactionInstruction[] = [],
7120
- overrideCustomIxIndex?: number
7271
+ overrideCustomIxIndex?: number,
7272
+ // fills the taker's order in-instruction; pass the taker's decoded escrow so a
7273
+ // referred taker's escrow is attached even when the signed order carries no
7274
+ // builder fee
7275
+ takerEscrow?: RevenueShareEscrowAccount
7121
7276
  ): Promise<TransactionInstruction[]> {
7122
7277
  const [signedMsgOrderSignatureIx, placeTakerSignedMsgPerpOrderIx] =
7123
7278
  await this.getPlaceSignedMsgTakerPerpOrderIxs(
@@ -7141,19 +7296,6 @@ export class VelocityClient {
7141
7296
  writablePerpMarketIndexes: [orderParams.marketIndex],
7142
7297
  });
7143
7298
 
7144
- if (referrerInfo) {
7145
- remainingAccounts.push({
7146
- pubkey: referrerInfo.referrer,
7147
- isWritable: true,
7148
- isSigner: false,
7149
- });
7150
- remainingAccounts.push({
7151
- pubkey: referrerInfo.referrerStats,
7152
- isWritable: true,
7153
- isSigner: false,
7154
- });
7155
- }
7156
-
7157
7299
  const isDelegateSigner = takerInfo.signingAuthority.equals(
7158
7300
  takerInfo.takerUserAccount.delegate
7159
7301
  );
@@ -7166,18 +7308,13 @@ export class VelocityClient {
7166
7308
  borshBuf,
7167
7309
  isDelegateSigner
7168
7310
  );
7169
- if (
7170
- signedMessage.builderFeeTenthBps !== null &&
7171
- signedMessage.builderIdx !== null
7172
- ) {
7173
- remainingAccounts.push({
7174
- pubkey: getRevenueShareEscrowAccountPublicKey(
7175
- this.program.programId,
7176
- takerInfo.takerUserAccount.authority
7177
- ),
7178
- isWritable: true,
7179
- isSigner: false,
7180
- });
7311
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta(
7312
+ takerInfo.takerUserAccount.authority,
7313
+ hasBuilderParams(signedMessage),
7314
+ takerEscrow
7315
+ );
7316
+ if (takerEscrowMeta) {
7317
+ remainingAccounts.push(takerEscrowMeta);
7181
7318
  }
7182
7319
 
7183
7320
  const placeAndMakeIx =
@@ -7212,7 +7349,6 @@ export class VelocityClient {
7212
7349
  _orderParams: OptionalOrderParams,
7213
7350
  _fulfillmentConfig?: unknown,
7214
7351
  _makerInfo?: MakerInfo,
7215
- _referrerInfo?: ReferrerInfo,
7216
7352
  _txParams?: TxParams,
7217
7353
  _subAccountId?: number
7218
7354
  ) {
@@ -7223,7 +7359,6 @@ export class VelocityClient {
7223
7359
  _orderParams: OptionalOrderParams,
7224
7360
  _fulfillmentConfig?: unknown,
7225
7361
  _makerInfo?: MakerInfo,
7226
- _referrerInfo?: ReferrerInfo,
7227
7362
  _txParams?: TxParams,
7228
7363
  _subAccountId?: number
7229
7364
  ): Promise<TransactionSignature> {
@@ -7233,7 +7368,6 @@ export class VelocityClient {
7233
7368
  _orderParams: OptionalOrderParams,
7234
7369
  _fulfillmentConfig?: unknown,
7235
7370
  _makerInfo?: MakerInfo,
7236
- _referrerInfo?: ReferrerInfo,
7237
7371
  _subAccountId?: number
7238
7372
  ): Promise<TransactionInstruction> {
7239
7373
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
@@ -7243,7 +7377,6 @@ export class VelocityClient {
7243
7377
  _orderParams: OptionalOrderParams,
7244
7378
  _takerInfo: TakerInfo,
7245
7379
  _fulfillmentConfig?: unknown,
7246
- _referrerInfo?: ReferrerInfo,
7247
7380
  _txParams?: TxParams,
7248
7381
  _subAccountId?: number
7249
7382
  ): Promise<TransactionSignature> {
@@ -7254,7 +7387,6 @@ export class VelocityClient {
7254
7387
  _orderParams: OptionalOrderParams,
7255
7388
  _takerInfo: TakerInfo,
7256
7389
  _fulfillmentConfig?: unknown,
7257
- _referrerInfo?: ReferrerInfo,
7258
7390
  _subAccountId?: number
7259
7391
  ): Promise<TransactionInstruction> {
7260
7392
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
@@ -7287,7 +7419,6 @@ export class VelocityClient {
7287
7419
  undefined,
7288
7420
  undefined,
7289
7421
  undefined,
7290
- undefined,
7291
7422
  subAccountId
7292
7423
  );
7293
7424
  }
@@ -7775,7 +7906,7 @@ export class VelocityClient {
7775
7906
  isWritable: true,
7776
7907
  });
7777
7908
  }
7778
- if (!escrow.referrer.equals(PublicKey.default)) {
7909
+ if (escrowHasReferrer(escrow)) {
7779
7910
  this.addBuilderToRemainingAccounts(
7780
7911
  [escrow.referrer],
7781
7912
  remainingAccounts
@@ -7978,7 +8109,7 @@ export class VelocityClient {
7978
8109
  }
7979
8110
 
7980
8111
  // Add referrer's User and RevenueShare accounts
7981
- if (!escrow.referrer.equals(PublicKey.default)) {
8112
+ if (escrowHasReferrer(escrow)) {
7982
8113
  this.addBuilderToRemainingAccounts(
7983
8114
  [escrow.referrer],
7984
8115
  remainingAccounts
@@ -8287,7 +8418,6 @@ export class VelocityClient {
8287
8418
  quote,
8288
8419
  userAccount,
8289
8420
  userAccountPublicKey,
8290
- userStatsAccountPublicKey,
8291
8421
  liquidatorSubAccountId,
8292
8422
  maxAccounts,
8293
8423
  }: {
@@ -8303,7 +8433,6 @@ export class VelocityClient {
8303
8433
  quote?: QuoteResponse;
8304
8434
  userAccount: UserAccount;
8305
8435
  userAccountPublicKey: PublicKey;
8306
- userStatsAccountPublicKey: PublicKey;
8307
8436
  liquidatorSubAccountId?: number;
8308
8437
  maxAccounts?: number;
8309
8438
  }): Promise<{
@@ -8397,7 +8526,6 @@ export class VelocityClient {
8397
8526
  liabilityTokenAccount,
8398
8527
  userAccount,
8399
8528
  userAccountPublicKey,
8400
- userStatsAccountPublicKey,
8401
8529
  liquidatorSubAccountId,
8402
8530
  });
8403
8531
 
@@ -8412,7 +8540,7 @@ export class VelocityClient {
8412
8540
  }
8413
8541
 
8414
8542
  /**
8415
- * Get the drift liquidate_spot_with_swap instructions
8543
+ * Get the velocity liquidate_spot_with_swap instructions
8416
8544
  *
8417
8545
  * @param liabilityMarketIndex the market index of the token you're buying
8418
8546
  * @param assetMarketIndex the market index of the token you're selling
@@ -8421,7 +8549,6 @@ export class VelocityClient {
8421
8549
  * @param liabilityTokenAccount the token account to receive the tokens being bought
8422
8550
  * @param userAccount
8423
8551
  * @param userAccountPublicKey
8424
- * @param userStatsAccountPublicKey
8425
8552
  */
8426
8553
  public async getLiquidateSpotWithSwapIx({
8427
8554
  liabilityMarketIndex,
@@ -8431,7 +8558,6 @@ export class VelocityClient {
8431
8558
  liabilityTokenAccount,
8432
8559
  userAccount,
8433
8560
  userAccountPublicKey,
8434
- userStatsAccountPublicKey,
8435
8561
  liquidatorSubAccountId,
8436
8562
  }: {
8437
8563
  liabilityMarketIndex: number;
@@ -8441,7 +8567,6 @@ export class VelocityClient {
8441
8567
  liabilityTokenAccount: PublicKey;
8442
8568
  userAccount: UserAccount;
8443
8569
  userAccountPublicKey: PublicKey;
8444
- userStatsAccountPublicKey: PublicKey;
8445
8570
  liquidatorSubAccountId?: number;
8446
8571
  }): Promise<{
8447
8572
  beginSwapIx: TransactionInstruction;
@@ -8450,7 +8575,6 @@ export class VelocityClient {
8450
8575
  const liquidatorAccountPublicKey = await this.getUserAccountPublicKey(
8451
8576
  liquidatorSubAccountId
8452
8577
  );
8453
- const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
8454
8578
 
8455
8579
  const userAccounts = [userAccount];
8456
8580
  const remainingAccounts = this.getRemainingAccounts({
@@ -8512,16 +8636,14 @@ export class VelocityClient {
8512
8636
  accounts: {
8513
8637
  state: await this.getStatePublicKey(),
8514
8638
  user: userAccountPublicKey,
8515
- userStats: userStatsAccountPublicKey,
8516
8639
  liquidator: liquidatorAccountPublicKey,
8517
- liquidatorStats: liquidatorStatsPublicKey,
8518
8640
  authority: this.wallet.publicKey,
8519
8641
  liabilitySpotMarketVault: liabilitySpotMarket.vault,
8520
8642
  assetSpotMarketVault: assetSpotMarket.vault,
8521
8643
  assetTokenAccount: assetTokenAccount,
8522
8644
  liabilityTokenAccount: liabilityTokenAccount,
8523
8645
  tokenProgram: assetTokenProgram,
8524
- driftSigner: this.getStateAccount().signer,
8646
+ velocitySigner: this.getStateAccount().signer,
8525
8647
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
8526
8648
  },
8527
8649
  remainingAccounts,
@@ -8535,16 +8657,14 @@ export class VelocityClient {
8535
8657
  accounts: {
8536
8658
  state: await this.getStatePublicKey(),
8537
8659
  user: userAccountPublicKey,
8538
- userStats: userStatsAccountPublicKey,
8539
8660
  liquidator: liquidatorAccountPublicKey,
8540
- liquidatorStats: liquidatorStatsPublicKey,
8541
8661
  authority: this.wallet.publicKey,
8542
8662
  liabilitySpotMarketVault: liabilitySpotMarket.vault,
8543
8663
  assetSpotMarketVault: assetSpotMarket.vault,
8544
8664
  assetTokenAccount: assetTokenAccount,
8545
8665
  liabilityTokenAccount: liabilityTokenAccount,
8546
8666
  tokenProgram: assetTokenProgram,
8547
- driftSigner: this.getStateAccount().signer,
8667
+ velocitySigner: this.getStateAccount().signer,
8548
8668
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
8549
8669
  },
8550
8670
  remainingAccounts,
@@ -8623,7 +8743,7 @@ export class VelocityClient {
8623
8743
  inTokenAccount,
8624
8744
  ifRebalanceConfig: ifRebalanceConfig,
8625
8745
  tokenProgram: TOKEN_PROGRAM_ID,
8626
- driftSigner: this.getStateAccount().signer,
8746
+ velocitySigner: this.getStateAccount().signer,
8627
8747
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
8628
8748
  },
8629
8749
  remainingAccounts,
@@ -8643,7 +8763,7 @@ export class VelocityClient {
8643
8763
  inTokenAccount,
8644
8764
  ifRebalanceConfig: ifRebalanceConfig,
8645
8765
  tokenProgram: TOKEN_PROGRAM_ID,
8646
- driftSigner: this.getStateAccount().signer,
8766
+ velocitySigner: this.getStateAccount().signer,
8647
8767
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
8648
8768
  },
8649
8769
  remainingAccounts,
@@ -8863,7 +8983,7 @@ export class VelocityClient {
8863
8983
  liquidatorStats: liquidatorStatsPublicKey,
8864
8984
  spotMarketVault: spotMarket.vault,
8865
8985
  insuranceFundVault: spotMarket.insuranceFund.vault,
8866
- driftSigner: this.getSignerPublicKey(),
8986
+ velocitySigner: this.getSignerPublicKey(),
8867
8987
  tokenProgram: TOKEN_PROGRAM_ID,
8868
8988
  },
8869
8989
  remainingAccounts: remainingAccounts,
@@ -8935,7 +9055,7 @@ export class VelocityClient {
8935
9055
  liquidator,
8936
9056
  spotMarketVault: spotMarket.vault,
8937
9057
  insuranceFundVault: spotMarket.insuranceFund.vault,
8938
- driftSigner: this.getSignerPublicKey(),
9058
+ velocitySigner: this.getSignerPublicKey(),
8939
9059
  tokenProgram: tokenProgramId,
8940
9060
  },
8941
9061
  remainingAccounts: remainingAccounts,
@@ -8995,15 +9115,15 @@ export class VelocityClient {
8995
9115
  ): Promise<TransactionInstruction> {
8996
9116
  const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
8997
9117
 
8998
- if (!isVariant(perpMarket.amm.oracleSource, 'prelaunch')) {
8999
- throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
9118
+ if (!isVariant(perpMarket.oracleSource, 'prelaunch')) {
9119
+ throw new Error(`Wrong oracle source ${perpMarket.oracleSource}`);
9000
9120
  }
9001
9121
 
9002
9122
  return await this.program.instruction.updatePrelaunchOracle({
9003
9123
  accounts: {
9004
9124
  state: await this.getStatePublicKey(),
9005
9125
  perpMarket: perpMarket.pubkey,
9006
- oracle: perpMarket.amm.oracle,
9126
+ oracle: perpMarket.oracle,
9007
9127
  },
9008
9128
  });
9009
9129
  }
@@ -9048,7 +9168,7 @@ export class VelocityClient {
9048
9168
  accounts: {
9049
9169
  state: await this.getStatePublicKey(),
9050
9170
  perpMarket: perpMarket.pubkey,
9051
- oracle: perpMarket.amm.oracle,
9171
+ oracle: perpMarket.oracle,
9052
9172
  authority: this.wallet.publicKey,
9053
9173
  keeperStats: this.getUserStatsAccountPublicKey(),
9054
9174
  },
@@ -9116,14 +9236,14 @@ export class VelocityClient {
9116
9236
  const perpMarket = this.getPerpMarketAccount(marketIndex);
9117
9237
  const oracleData = this.getOracleDataForPerpMarket(marketIndex);
9118
9238
  const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
9119
- const isMMOracleActive = !perpMarket.amm.mmOracleSlot.eq(ZERO);
9120
- const pctDiff = perpMarket.amm.mmOraclePrice
9239
+ const isMMOracleActive = !perpMarket.marketStats.mmOracleSlot.eq(ZERO);
9240
+ const pctDiff = perpMarket.marketStats.mmOraclePrice
9121
9241
  .sub(oracleData.price)
9122
9242
  .abs()
9123
9243
  .mul(PERCENTAGE_PRECISION)
9124
9244
  .div(BN.max(oracleData.price, ONE));
9125
9245
 
9126
- const mmOracleSequenceId = perpMarket.amm.mmOracleSequenceId;
9246
+ const mmOracleSequenceId = perpMarket.marketStats.mmOracleSequenceId;
9127
9247
 
9128
9248
  // Do slot check for recency if sequence ids are zero or they're too divergent
9129
9249
  const doSlotCheckForRecency =
@@ -9131,14 +9251,14 @@ export class VelocityClient {
9131
9251
  oracleData.sequenceId.eq(ZERO) ||
9132
9252
  mmOracleSequenceId.eq(ZERO) ||
9133
9253
  oracleData.sequenceId
9134
- .sub(perpMarket.amm.mmOracleSequenceId)
9254
+ .sub(perpMarket.marketStats.mmOracleSequenceId)
9135
9255
  .abs()
9136
9256
  .gt(oracleData.sequenceId.div(new BN(10_000)));
9137
9257
 
9138
9258
  let isExchangeOracleMoreRecent = true;
9139
9259
  if (
9140
9260
  doSlotCheckForRecency &&
9141
- oracleData.slot <= perpMarket.amm.mmOracleSlot
9261
+ oracleData.slot <= perpMarket.marketStats.mmOracleSlot
9142
9262
  ) {
9143
9263
  isExchangeOracleMoreRecent = false;
9144
9264
  } else if (
@@ -9149,30 +9269,30 @@ export class VelocityClient {
9149
9269
  }
9150
9270
 
9151
9271
  const conf = getOracleConfidenceFromMMOracleData(
9152
- perpMarket.amm.mmOraclePrice,
9272
+ perpMarket.marketStats.mmOraclePrice,
9153
9273
  oracleData
9154
9274
  );
9155
9275
 
9156
9276
  if (
9157
9277
  isOracleTooDivergent(
9158
- perpMarket.amm,
9278
+ perpMarket.marketStats,
9159
9279
  {
9160
- price: perpMarket.amm.mmOraclePrice,
9161
- slot: perpMarket.amm.mmOracleSlot,
9280
+ price: perpMarket.marketStats.mmOraclePrice,
9281
+ slot: perpMarket.marketStats.mmOracleSlot,
9162
9282
  confidence: conf,
9163
9283
  hasSufficientNumberOfDataPoints: true,
9164
9284
  },
9165
9285
  stateAccountAndSlot.data.oracleGuardRails
9166
9286
  ) ||
9167
- perpMarket.amm.mmOraclePrice.eq(ZERO) ||
9287
+ perpMarket.marketStats.mmOraclePrice.eq(ZERO) ||
9168
9288
  isExchangeOracleMoreRecent ||
9169
9289
  pctDiff.gt(PERCENTAGE_PRECISION.divn(100)) // 1% threshold
9170
9290
  ) {
9171
9291
  return { ...oracleData, isMMOracleActive };
9172
9292
  } else {
9173
9293
  return {
9174
- price: perpMarket.amm.mmOraclePrice,
9175
- slot: perpMarket.amm.mmOracleSlot,
9294
+ price: perpMarket.marketStats.mmOraclePrice,
9295
+ slot: perpMarket.marketStats.mmOracleSlot,
9176
9296
  confidence: conf,
9177
9297
  hasSufficientNumberOfDataPoints: true,
9178
9298
  isMMOracleActive,
@@ -9269,7 +9389,7 @@ export class VelocityClient {
9269
9389
  authority: this.wallet.publicKey,
9270
9390
  spotMarketVault: spotMarket.vault,
9271
9391
  insuranceFundVault: spotMarket.insuranceFund.vault,
9272
- driftSigner: this.getSignerPublicKey(),
9392
+ velocitySigner: this.getSignerPublicKey(),
9273
9393
  userTokenAccount: collateralAccountPublicKey,
9274
9394
  tokenProgram,
9275
9395
  },
@@ -9583,7 +9703,7 @@ export class VelocityClient {
9583
9703
  ),
9584
9704
  authority: this.wallet.publicKey,
9585
9705
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
9586
- driftSigner: this.getSignerPublicKey(),
9706
+ velocitySigner: this.getSignerPublicKey(),
9587
9707
  userTokenAccount: tokenAccount,
9588
9708
  tokenProgram,
9589
9709
  },
@@ -9727,7 +9847,7 @@ export class VelocityClient {
9727
9847
  state: await this.getStatePublicKey(),
9728
9848
  spotMarket: spotMarketAccount.pubkey,
9729
9849
  spotMarketVault: spotMarketAccount.vault,
9730
- driftSigner: this.getSignerPublicKey(),
9850
+ velocitySigner: this.getSignerPublicKey(),
9731
9851
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
9732
9852
  tokenProgram: tokenProgramId,
9733
9853
  },
@@ -9775,7 +9895,7 @@ export class VelocityClient {
9775
9895
  authority: this.wallet.publicKey,
9776
9896
  spotMarketVault: spotMarket.vault,
9777
9897
  insuranceFundVault: spotMarket.insuranceFund.vault,
9778
- driftSigner: this.getSignerPublicKey(),
9898
+ velocitySigner: this.getSignerPublicKey(),
9779
9899
  tokenProgram: tokenProgramId,
9780
9900
  },
9781
9901
  remainingAccounts: remainingAccounts,
@@ -9818,7 +9938,7 @@ export class VelocityClient {
9818
9938
  }
9819
9939
 
9820
9940
  /**
9821
- * This ix will donate your funds to drift revenue pool. It does not deposit into your user account
9941
+ * This ix will donate your funds to velocity revenue pool. It does not deposit into your user account
9822
9942
  * @param marketIndex
9823
9943
  * @param amount
9824
9944
  * @param userTokenAccountPublicKey
@@ -9848,7 +9968,7 @@ export class VelocityClient {
9848
9968
 
9849
9969
  const extendedInfo: PerpMarketExtendedInfo = {
9850
9970
  marketIndex,
9851
- minOrderSize: marketAccount.amm?.minOrderSize,
9971
+ minOrderSize: marketAccount.marketStats?.minOrderSize,
9852
9972
  marginMaintenance: marketAccount.marginRatioMaintenance,
9853
9973
  pnlPoolValue: getTokenAmount(
9854
9974
  marketAccount.pnlPool?.scaledBalance,
@@ -10490,7 +10610,7 @@ export class VelocityClient {
10490
10610
  {
10491
10611
  remainingAccounts,
10492
10612
  accounts: {
10493
- driftSigner: this.getSignerPublicKey(),
10613
+ velocitySigner: this.getSignerPublicKey(),
10494
10614
  state: await this.getStatePublicKey(),
10495
10615
  lpPool,
10496
10616
  constituentTargetBase,
@@ -10848,7 +10968,7 @@ export class VelocityClient {
10848
10968
  {
10849
10969
  remainingAccounts,
10850
10970
  accounts: {
10851
- driftSigner: this.getSignerPublicKey(),
10971
+ velocitySigner: this.getSignerPublicKey(),
10852
10972
  state: await this.getStatePublicKey(),
10853
10973
  lpPool: lpPool.pubkey,
10854
10974
  authority: this.wallet.publicKey,
@@ -11013,7 +11133,7 @@ export class VelocityClient {
11013
11133
  ...(await this.getAllSettlePerpToLpPoolIxs(
11014
11134
  lpPool.lpPoolId,
11015
11135
  this.getPerpMarketAccounts()
11016
- .filter((marketAccount) => marketAccount.lpStatus > 0)
11136
+ .filter((marketAccount) => marketAccount.hedgeConfig.status > 0)
11017
11137
  .map((marketAccount) => marketAccount.marketIndex)
11018
11138
  ))
11019
11139
  );
@@ -11162,7 +11282,7 @@ export class VelocityClient {
11162
11282
  const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
11163
11283
  return this.program.instruction.settlePerpToLpPool({
11164
11284
  accounts: {
11165
- driftSigner: this.getSignerPublicKey(),
11285
+ velocitySigner: this.getSignerPublicKey(),
11166
11286
  state: await this.getStatePublicKey(),
11167
11287
  keeper: this.wallet.publicKey,
11168
11288
  ammCache: getAmmCachePublicKey(this.program.programId),
@@ -11356,9 +11476,3 @@ export class VelocityClient {
11356
11476
  return currentBase.add(orderBaseAmount).abs().gt(currentBase.abs());
11357
11477
  }
11358
11478
  }
11359
-
11360
- /** @deprecated Use `VelocityClient` instead. `DriftClient` will be removed in a future major. */
11361
- export const DriftClient = VelocityClient;
11362
-
11363
- /** @deprecated Use `VelocityClient` instead. `DriftClient` will be removed in a future major. */
11364
- export type DriftClient = VelocityClient;