@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
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DriftClient = exports.VelocityClient = void 0;
6
+ exports.VelocityClient = void 0;
7
7
  /**
8
8
  * VelocityClient — main SDK entry point for all trading and keeper operations.
9
9
  *
@@ -90,7 +90,7 @@ class VelocityClient {
90
90
  this._isSubscribed = val;
91
91
  }
92
92
  constructor(config) {
93
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29;
93
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
94
94
  this.users = new Map();
95
95
  this._isSubscribed = false;
96
96
  this.perpMarketLastSlotCache = new Map();
@@ -213,18 +213,18 @@ class VelocityClient {
213
213
  this.accountSubscriber = new pollingVelocityClientAccountSubscriber_1.PollingVelocityClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_6 = config.perpMarketIndexes) !== null && _6 !== void 0 ? _6 : [], (_7 = config.spotMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.oracleInfos) !== null && _8 !== void 0 ? _8 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
214
214
  }
215
215
  else if (((_9 = config.accountSubscription) === null || _9 === void 0 ? void 0 : _9.type) === 'grpc') {
216
- const accountSubscriberClass = (_13 = (_11 = (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.velocityClientAccountSubscriber) !== null && _11 !== void 0 ? _11 : (_12 = config.accountSubscription) === null || _12 === void 0 ? void 0 : _12.driftClientAccountSubscriber) !== null && _13 !== void 0 ? _13 : grpcVelocityClientAccountSubscriber_1.grpcVelocityClientAccountSubscriber;
217
- this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (_14 = config.perpMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.spotMarketIndexes) !== null && _15 !== void 0 ? _15 : [], (_16 = config.oracleInfos) !== null && _16 !== void 0 ? _16 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
218
- resubTimeoutMs: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.resubTimeoutMs,
219
- logResubMessages: (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.logResubMessages,
216
+ const accountSubscriberClass = (_11 = (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.velocityClientAccountSubscriber) !== null && _11 !== void 0 ? _11 : grpcVelocityClientAccountSubscriber_1.grpcVelocityClientAccountSubscriber;
217
+ this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (_12 = config.perpMarketIndexes) !== null && _12 !== void 0 ? _12 : [], (_13 = config.spotMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.oracleInfos) !== null && _14 !== void 0 ? _14 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
218
+ resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
219
+ logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
220
220
  });
221
221
  }
222
222
  else {
223
- const accountSubscriberClass = (_22 = (_20 = (_19 = config.accountSubscription) === null || _19 === void 0 ? void 0 : _19.velocityClientAccountSubscriber) !== null && _20 !== void 0 ? _20 : (_21 = config.accountSubscription) === null || _21 === void 0 ? void 0 : _21.driftClientAccountSubscriber) !== null && _22 !== void 0 ? _22 : webSocketVelocityClientAccountSubscriber_1.WebSocketVelocityClientAccountSubscriber;
224
- this.accountSubscriber = new accountSubscriberClass(this.program, (_23 = config.perpMarketIndexes) !== null && _23 !== void 0 ? _23 : [], (_24 = config.spotMarketIndexes) !== null && _24 !== void 0 ? _24 : [], (_25 = config.oracleInfos) !== null && _25 !== void 0 ? _25 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
225
- resubTimeoutMs: (_26 = config.accountSubscription) === null || _26 === void 0 ? void 0 : _26.resubTimeoutMs,
226
- logResubMessages: (_27 = config.accountSubscription) === null || _27 === void 0 ? void 0 : _27.logResubMessages,
227
- }, (_28 = config.accountSubscription) === null || _28 === void 0 ? void 0 : _28.commitment);
223
+ const accountSubscriberClass = (_18 = (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.velocityClientAccountSubscriber) !== null && _18 !== void 0 ? _18 : webSocketVelocityClientAccountSubscriber_1.WebSocketVelocityClientAccountSubscriber;
224
+ this.accountSubscriber = new accountSubscriberClass(this.program, (_19 = config.perpMarketIndexes) !== null && _19 !== void 0 ? _19 : [], (_20 = config.spotMarketIndexes) !== null && _20 !== void 0 ? _20 : [], (_21 = config.oracleInfos) !== null && _21 !== void 0 ? _21 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
225
+ resubTimeoutMs: (_22 = config.accountSubscription) === null || _22 === void 0 ? void 0 : _22.resubTimeoutMs,
226
+ logResubMessages: (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.logResubMessages,
227
+ }, (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.commitment);
228
228
  }
229
229
  this.eventEmitter = this.accountSubscriber.eventEmitter;
230
230
  this.metricsEventEmitter = new events_1.EventEmitter();
@@ -232,7 +232,7 @@ class VelocityClient {
232
232
  this.enableMetricsEvents = true;
233
233
  }
234
234
  this.txSender =
235
- (_29 = config.txSender) !== null && _29 !== void 0 ? _29 : new retryTxSender_1.RetryTxSender({
235
+ (_25 = config.txSender) !== null && _25 !== void 0 ? _25 : new retryTxSender_1.RetryTxSender({
236
236
  connection: this.connection,
237
237
  wallet: this.wallet,
238
238
  opts: this.opts,
@@ -393,7 +393,7 @@ class VelocityClient {
393
393
  return walletSupportsVersionedTxns ? 0 : 'legacy';
394
394
  }
395
395
  /**
396
- * Update the wallet to use for drift transactions and linked user account
396
+ * Update the wallet to use for velocity transactions and linked user account
397
397
  * @param newWallet
398
398
  * @param subAccountIds
399
399
  * @param activeSubAccountId
@@ -528,7 +528,7 @@ class VelocityClient {
528
528
  */
529
529
  async addAndSubscribeToUsers(authority) {
530
530
  var _a, _b, _c, _d, _e, _f, _g;
531
- // save the rpc calls if driftclient is initialized without a real wallet
531
+ // save the rpc calls if velocityclient is initialized without a real wallet
532
532
  if (this.skipLoadUsers)
533
533
  return true;
534
534
  let result = true;
@@ -1013,6 +1013,19 @@ class VelocityClient {
1013
1013
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
1014
1014
  return txSig;
1015
1015
  }
1016
+ async getUpdateUserAllowDelegateTransferIx(allowDelegateTransfer) {
1017
+ return await this.program.instruction.updateUserAllowDelegateTransfer(allowDelegateTransfer, {
1018
+ accounts: {
1019
+ userStats: this.getUserStatsAccountPublicKey(),
1020
+ authority: this.wallet.publicKey,
1021
+ },
1022
+ });
1023
+ }
1024
+ async updateUserAllowDelegateTransfer(allowDelegateTransfer) {
1025
+ const tx = await this.buildTransaction(await this.getUpdateUserAllowDelegateTransferIx(allowDelegateTransfer), this.txParams);
1026
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1027
+ return txSig;
1028
+ }
1016
1029
  async updateUserAdvancedLp(updates) {
1017
1030
  const ixs = await Promise.all(updates.map(async ({ advancedLp, subAccountId }) => {
1018
1031
  return await this.getUpdateAdvancedDlpIx(advancedLp, subAccountId);
@@ -1219,7 +1232,7 @@ class VelocityClient {
1219
1232
  userStats,
1220
1233
  authority,
1221
1234
  state: await this.getStatePublicKey(),
1222
- driftSigner: this.getSignerPublicKey(),
1235
+ velocitySigner: this.getSignerPublicKey(),
1223
1236
  keeper: this.wallet.publicKey,
1224
1237
  },
1225
1238
  remainingAccounts,
@@ -1380,7 +1393,7 @@ class VelocityClient {
1380
1393
  }
1381
1394
  }
1382
1395
  /**
1383
- * Each drift instruction must include perp and sport market accounts in the ix remaining accounts.
1396
+ * Each velocity instruction must include perp and sport market accounts in the ix remaining accounts.
1384
1397
  * Use this function to force a subset of markets to be included in the remaining accounts for every ix
1385
1398
  *
1386
1399
  * @param perpMarketIndexes
@@ -1404,9 +1417,9 @@ class VelocityClient {
1404
1417
  isSigner: false,
1405
1418
  isWritable: writable,
1406
1419
  });
1407
- const oracleWritable = writable && (0, types_1.isVariant)(perpMarketAccount.amm.oracleSource, 'prelaunch');
1408
- oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
1409
- pubkey: perpMarketAccount.amm.oracle,
1420
+ const oracleWritable = writable && (0, types_1.isVariant)(perpMarketAccount.oracleSource, 'prelaunch');
1421
+ oracleAccountMap.set(perpMarketAccount.oracle.toString(), {
1422
+ pubkey: perpMarketAccount.oracle,
1410
1423
  isSigner: false,
1411
1424
  isWritable: oracleWritable,
1412
1425
  });
@@ -1429,20 +1442,27 @@ class VelocityClient {
1429
1442
  }
1430
1443
  addBuilderToRemainingAccounts(builders, remainingAccounts) {
1431
1444
  for (const builder of builders) {
1432
- // Add User account for the builder
1445
+ // Add User account for the builder. Dedupe by pubkey: an authority may be
1446
+ // both a builder and the referrer, in which case its User + RevenueShare
1447
+ // accounts would otherwise be pushed twice. On-chain `load_revenue_share_map`
1448
+ // rejects duplicates, which would silently abort the entire sweep.
1433
1449
  const builderUserAccount = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, builder, 0 // subAccountId 0 for builder user account
1434
1450
  );
1435
- remainingAccounts.push({
1436
- pubkey: builderUserAccount,
1437
- isSigner: false,
1438
- isWritable: true,
1439
- });
1451
+ if (!remainingAccounts.find((a) => a.pubkey.equals(builderUserAccount))) {
1452
+ remainingAccounts.push({
1453
+ pubkey: builderUserAccount,
1454
+ isSigner: false,
1455
+ isWritable: true,
1456
+ });
1457
+ }
1440
1458
  const builderAccount = (0, pda_1.getRevenueShareAccountPublicKey)(this.program.programId, builder);
1441
- remainingAccounts.push({
1442
- pubkey: builderAccount,
1443
- isSigner: false,
1444
- isWritable: true,
1445
- });
1459
+ if (!remainingAccounts.find((a) => a.pubkey.equals(builderAccount))) {
1460
+ remainingAccounts.push({
1461
+ pubkey: builderAccount,
1462
+ isSigner: false,
1463
+ isWritable: true,
1464
+ });
1465
+ }
1446
1466
  }
1447
1467
  }
1448
1468
  getRemainingAccountMapsForUsers(userAccounts) {
@@ -1914,7 +1934,7 @@ class VelocityClient {
1914
1934
  state: await this.getStatePublicKey(),
1915
1935
  spotMarket: spotMarketAccount.pubkey,
1916
1936
  spotMarketVault: spotMarketAccount.vault,
1917
- driftSigner: this.getSignerPublicKey(),
1937
+ velocitySigner: this.getSignerPublicKey(),
1918
1938
  user,
1919
1939
  userStats: this.getUserStatsAccountPublicKey(),
1920
1940
  userTokenAccount,
@@ -1972,6 +1992,46 @@ class VelocityClient {
1972
1992
  remainingAccounts,
1973
1993
  });
1974
1994
  }
1995
+ async transferDepositByDelegate(amount, marketIndex, fromSubAccountId, toSubAccountId, txParams) {
1996
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getTransferDepositByDelegateIx(amount, marketIndex, fromSubAccountId, toSubAccountId), txParams), [], this.opts);
1997
+ if (fromSubAccountId === this.activeSubAccountId ||
1998
+ toSubAccountId === this.activeSubAccountId) {
1999
+ this.spotMarketLastSlotCache.set(marketIndex, slot);
2000
+ }
2001
+ return txSig;
2002
+ }
2003
+ async getTransferDepositByDelegateIx(amount, marketIndex, fromSubAccountId, toSubAccountId) {
2004
+ const fromUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, fromSubAccountId);
2005
+ const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, toSubAccountId);
2006
+ let remainingAccounts;
2007
+ const userMapKey = this.getUserMapKey(fromSubAccountId, this.authority);
2008
+ if (this.users.has(userMapKey)) {
2009
+ remainingAccounts = this.getRemainingAccounts({
2010
+ userAccounts: [this.users.get(userMapKey).getUserAccount()],
2011
+ useMarketLastSlotCache: true,
2012
+ writableSpotMarketIndexes: [marketIndex],
2013
+ });
2014
+ }
2015
+ else {
2016
+ const fromUserAccount = (await this.program.account.user.fetch(fromUser));
2017
+ remainingAccounts = this.getRemainingAccounts({
2018
+ userAccounts: [fromUserAccount],
2019
+ useMarketLastSlotCache: true,
2020
+ writableSpotMarketIndexes: [marketIndex],
2021
+ });
2022
+ }
2023
+ return await this.program.instruction.transferDepositByDelegate(marketIndex, amount, {
2024
+ accounts: {
2025
+ delegate: this.wallet.publicKey,
2026
+ fromUser,
2027
+ toUser,
2028
+ userStats: this.getUserStatsAccountPublicKey(),
2029
+ state: await this.getStatePublicKey(),
2030
+ spotMarketVault: this.getSpotMarketAccount(marketIndex).vault,
2031
+ },
2032
+ remainingAccounts,
2033
+ });
2034
+ }
1975
2035
  async transferPools(depositFromMarketIndex, depositToMarketIndex, borrowFromMarketIndex, borrowToMarketIndex, depositAmount, borrowAmount, fromSubAccountId, toSubAccountId, txParams) {
1976
2036
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getTransferPoolsIx(depositFromMarketIndex, depositToMarketIndex, borrowFromMarketIndex, borrowToMarketIndex, depositAmount, borrowAmount, fromSubAccountId, toSubAccountId), txParams), [], this.opts);
1977
2037
  if (fromSubAccountId === this.activeSubAccountId ||
@@ -2023,7 +2083,7 @@ class VelocityClient {
2023
2083
  depositToSpotMarketVault: this.getSpotMarketAccount(depositToMarketIndex).vault,
2024
2084
  borrowFromSpotMarketVault: this.getSpotMarketAccount(borrowFromMarketIndex).vault,
2025
2085
  borrowToSpotMarketVault: this.getSpotMarketAccount(borrowToMarketIndex).vault,
2026
- driftSigner: this.getSignerPublicKey(),
2086
+ velocitySigner: this.getSignerPublicKey(),
2027
2087
  },
2028
2088
  remainingAccounts,
2029
2089
  });
@@ -2193,7 +2253,7 @@ class VelocityClient {
2193
2253
  authority: this.wallet.publicKey,
2194
2254
  userTokenAccount: userTokenAccount,
2195
2255
  tokenProgram: this.getTokenProgramForSpotMarket(spotMarketAccount),
2196
- driftSigner: this.getSignerPublicKey(),
2256
+ velocitySigner: this.getSignerPublicKey(),
2197
2257
  },
2198
2258
  remainingAccounts,
2199
2259
  });
@@ -2223,13 +2283,13 @@ class VelocityClient {
2223
2283
  direction,
2224
2284
  baseAssetAmount: amount,
2225
2285
  price: limitPrice,
2226
- }, undefined, undefined, undefined, undefined, undefined, subAccountId);
2286
+ }, undefined, undefined, undefined, undefined, subAccountId);
2227
2287
  }
2228
2288
  async sendSignedTx(tx, opts) {
2229
2289
  const { txSig } = await this.sendTransaction(tx, undefined, opts !== null && opts !== void 0 ? opts : this.opts, true);
2230
2290
  return txSig;
2231
2291
  }
2232
- async prepareMarketOrderTxs(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo, cancelExistingOrders, settlePnl, positionMaxLev, isolatedPositionDepositAmount) {
2292
+ async prepareMarketOrderTxs(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), cancelExistingOrders, settlePnl, positionMaxLev, isolatedPositionDepositAmount) {
2233
2293
  const marketIndex = orderParams.marketIndex;
2234
2294
  const orderId = userAccount.nextOrderId;
2235
2295
  const ixPromisesForTxs = {
@@ -2263,7 +2323,7 @@ class VelocityClient {
2263
2323
  ixPromisesForTxs.fillTx = this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
2264
2324
  orderId,
2265
2325
  marketIndex,
2266
- }, makerInfo, referrerInfo, userAccount.subAccountId);
2326
+ }, makerInfo, userAccount.subAccountId);
2267
2327
  }
2268
2328
  const ixs = await Promise.all(Object.values(ixPromisesForTxs));
2269
2329
  const ixsMap = ixs.reduce((acc, ix, i) => {
@@ -2284,8 +2344,8 @@ class VelocityClient {
2284
2344
  * @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same perp market. Intended use is to auto-cancel TP/SL orders when closing a position. Ignored if orderParams.marketType is not MarketType.PERP
2285
2345
  * @returns
2286
2346
  */
2287
- async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo, cancelExistingOrders, settlePnl) {
2288
- const preppedTxs = await this.prepareMarketOrderTxs(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams, referrerInfo, cancelExistingOrders, settlePnl);
2347
+ async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), cancelExistingOrders, settlePnl) {
2348
+ const preppedTxs = await this.prepareMarketOrderTxs(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams, cancelExistingOrders, settlePnl);
2289
2349
  const signedTxs = (await this.txHandler.getSignedTransactionMap(preppedTxs, this.wallet)).signedTxMap;
2290
2350
  const { txSig, slot } = await this.sendTransaction(signedTxs.marketOrderTx, [], this.opts, true);
2291
2351
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
@@ -2307,6 +2367,48 @@ class VelocityClient {
2307
2367
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
2308
2368
  return txSig;
2309
2369
  }
2370
+ /**
2371
+ * Returns the RevenueShareEscrow account meta for the placing user when `orderParams`
2372
+ * carries a builder code (`builderIdx` + `builderFeeTenthBps`), otherwise `undefined`.
2373
+ * The on-chain handlers peek for this account last in `remaining_accounts`, so callers
2374
+ * must push it after the market/oracle/maker accounts.
2375
+ */
2376
+ getBuilderEscrowAccountMeta(orderParams, subAccountId) {
2377
+ var _a, _b;
2378
+ if (!(0, builder_1.hasBuilderParams)(orderParams)) {
2379
+ return undefined;
2380
+ }
2381
+ const authority = (_b = (_a = this.getUserAccount(subAccountId)) === null || _a === void 0 ? void 0 : _a.authority) !== null && _b !== void 0 ? _b : this.authority;
2382
+ return {
2383
+ pubkey: (0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.program.programId, authority),
2384
+ isWritable: true,
2385
+ isSigner: false,
2386
+ };
2387
+ }
2388
+ /**
2389
+ * Returns the AccountMeta for the taker's RevenueShareEscrow when a fill of the
2390
+ * taker's order must include it: the order carries a builder code, or the taker
2391
+ * is referred (their escrow was initialized with a referrer). Returns `undefined`
2392
+ * when neither applies so no account meta is added to the transaction. The
2393
+ * on-chain handlers peek for this account last in `remaining_accounts`, so
2394
+ * callers must push it after the market/oracle/maker accounts.
2395
+ *
2396
+ * Throws when `takerEscrow` does not belong to `takerAuthority`.
2397
+ */
2398
+ getTakerEscrowAccountMeta(takerAuthority, orderHasBuilder, takerEscrow) {
2399
+ if (takerEscrow && !takerEscrow.authority.equals(takerAuthority)) {
2400
+ throw new Error('takerEscrow.authority does not match the taker user account authority');
2401
+ }
2402
+ const takerIsReferred = takerEscrow && (0, builder_1.escrowHasReferrer)(takerEscrow);
2403
+ if (!orderHasBuilder && !takerIsReferred) {
2404
+ return undefined;
2405
+ }
2406
+ return {
2407
+ pubkey: (0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.program.programId, takerAuthority),
2408
+ isWritable: true,
2409
+ isSigner: false,
2410
+ };
2411
+ }
2310
2412
  async getPlacePerpOrderIx(orderParams, subAccountId, depositToTradeArgs) {
2311
2413
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
2312
2414
  const isDepositToTradeTx = depositToTradeArgs !== undefined;
@@ -2323,6 +2425,10 @@ class VelocityClient {
2323
2425
  ? [depositToTradeArgs === null || depositToTradeArgs === void 0 ? void 0 : depositToTradeArgs.depositMarketIndex]
2324
2426
  : undefined,
2325
2427
  });
2428
+ const builderEscrow = this.getBuilderEscrowAccountMeta(orderParams, subAccountId);
2429
+ if (builderEscrow) {
2430
+ remainingAccounts.push(builderEscrow);
2431
+ }
2326
2432
  return await VelocityCore_1.VelocityCore.buildPlacePerpOrderInstruction({
2327
2433
  program: this.program,
2328
2434
  orderParams,
@@ -2348,7 +2454,7 @@ class VelocityClient {
2348
2454
  isSigner: false,
2349
2455
  });
2350
2456
  oracleAccountInfos.push({
2351
- pubkey: market.amm.oracle,
2457
+ pubkey: market.oracle,
2352
2458
  isWritable: false,
2353
2459
  isSigner: false,
2354
2460
  });
@@ -2439,7 +2545,7 @@ class VelocityClient {
2439
2545
  async getCancelOrderByUserIdIx(userOrderId, subAccountId) {
2440
2546
  const user = await this.getUserAccountPublicKey(subAccountId);
2441
2547
  const order = this.getOrderByUserId(userOrderId);
2442
- const oracle = this.getPerpMarketAccount(order.marketIndex).amm.oracle;
2548
+ const oracle = this.getPerpMarketAccount(order.marketIndex).oracle;
2443
2549
  const remainingAccounts = this.getRemainingAccounts({
2444
2550
  userAccounts: [this.getUserAccount(subAccountId)],
2445
2551
  useMarketLastSlotCache: true,
@@ -2581,6 +2687,15 @@ class VelocityClient {
2581
2687
  });
2582
2688
  const formattedParams = params.map((item) => (0, orderParams_1.getOrderParams)(item));
2583
2689
  const authority = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
2690
+ // The handler loads a single RevenueShareEscrow for the placing user, so push it once
2691
+ // if any order in the batch carries a builder code.
2692
+ const builderParam = formattedParams.find((p) => (0, builder_1.hasBuilderParams)(p));
2693
+ if (builderParam) {
2694
+ const builderEscrow = this.getBuilderEscrowAccountMeta(builderParam, subAccountId);
2695
+ if (builderEscrow) {
2696
+ remainingAccounts.push(builderEscrow);
2697
+ }
2698
+ }
2584
2699
  return await VelocityCore_1.VelocityCore.buildPlaceOrdersInstruction({
2585
2700
  program: this.program,
2586
2701
  formattedParams,
@@ -2679,11 +2794,16 @@ class VelocityClient {
2679
2794
  remainingAccounts,
2680
2795
  });
2681
2796
  }
2682
- async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams, fillerSubAccountId, fillerAuthority, hasBuilderFee) {
2683
- const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo, fillerSubAccountId, undefined, fillerAuthority, hasBuilderFee), txParams), [], this.opts);
2797
+ async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, txParams, fillerSubAccountId, fillerAuthority, hasBuilderFee, takerEscrow) {
2798
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, fillerSubAccountId, undefined, fillerAuthority, hasBuilderFee, takerEscrow), txParams), [], this.opts);
2684
2799
  return txSig;
2685
2800
  }
2686
- async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId, isSignedMsg, fillerAuthority, hasBuilderFee) {
2801
+ async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, fillerSubAccountId, isSignedMsg, fillerAuthority, hasBuilderFee,
2802
+ // The program rejects fills that omit the taker's RevenueShareEscrow when the
2803
+ // order has a builder OR the taker is referred with an escrow. The builder case
2804
+ // is detected from the order bitflags; pass the taker's decoded escrow (e.g.
2805
+ // from a RevenueShareEscrowMap) so referred takers also get it attached.
2806
+ takerEscrow) {
2687
2807
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
2688
2808
  let filler;
2689
2809
  if (fillerAuthority) {
@@ -2727,22 +2847,6 @@ class VelocityClient {
2727
2847
  isSigner: false,
2728
2848
  });
2729
2849
  }
2730
- if (referrerInfo) {
2731
- const referrerIsMaker = makerInfo.find((maker) => maker.maker.equals(referrerInfo.referrer)) !==
2732
- undefined;
2733
- if (!referrerIsMaker) {
2734
- remainingAccounts.push({
2735
- pubkey: referrerInfo.referrer,
2736
- isWritable: true,
2737
- isSigner: false,
2738
- });
2739
- remainingAccounts.push({
2740
- pubkey: referrerInfo.referrerStats,
2741
- isWritable: true,
2742
- isSigner: false,
2743
- });
2744
- }
2745
- }
2746
2850
  let withBuilder = false;
2747
2851
  if (hasBuilderFee) {
2748
2852
  withBuilder = true;
@@ -2761,12 +2865,9 @@ class VelocityClient {
2761
2865
  withBuilder = true;
2762
2866
  }
2763
2867
  }
2764
- if (withBuilder) {
2765
- remainingAccounts.push({
2766
- pubkey: (0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.program.programId, userAccount.authority),
2767
- isWritable: true,
2768
- isSigner: false,
2769
- });
2868
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta(userAccount.authority, withBuilder, takerEscrow);
2869
+ if (takerEscrowMeta) {
2870
+ remainingAccounts.push(takerEscrowMeta);
2770
2871
  }
2771
2872
  const orderId = isSignedMsg ? null : order.orderId;
2772
2873
  return await VelocityCore_1.VelocityCore.buildFillPerpOrderInstruction({
@@ -2802,14 +2903,14 @@ class VelocityClient {
2802
2903
  async getPlaceSpotOrderIx(_orderParams, _subAccountId, _overrides) {
2803
2904
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
2804
2905
  }
2805
- async fillSpotOrder(_userAccountPublicKey, _user, _order, _fulfillmentConfig, _makerInfo, _referrerInfo, _txParams) {
2906
+ async fillSpotOrder(_userAccountPublicKey, _user, _order, _fulfillmentConfig, _makerInfo, _txParams) {
2806
2907
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
2807
2908
  }
2808
- async getFillSpotOrderIx(_userAccountPublicKey, _userAccount, _order, _fulfillmentConfig, _makerInfo, _referrerInfo, _fillerPublicKey) {
2909
+ async getFillSpotOrderIx(_userAccountPublicKey, _userAccount, _order, _fulfillmentConfig, _makerInfo, _fillerPublicKey) {
2809
2910
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
2810
2911
  }
2811
2912
  /**
2812
- * Swap tokens in drift account using titan or jupiter
2913
+ * Swap tokens in velocity account using titan or jupiter
2813
2914
  * @param swapClient swap client to find routes and instructions (Titan or Jupiter)
2814
2915
  * @param jupiterClient @deprecated Use swapClient instead. Legacy parameter for backward compatibility
2815
2916
  * @param outMarketIndex the market index of the token you're buying
@@ -2820,7 +2921,7 @@ class VelocityClient {
2820
2921
  * @param slippageBps the max slippage passed to the swap provider api
2821
2922
  * @param swapMode swap provider swapMode (ExactIn or ExactOut), default is ExactIn
2822
2923
  * @param route the swap provider route to use for the swap
2823
- * @param reduceOnly specify if In or Out token on the drift account must reduceOnly, checked at end of swap
2924
+ * @param reduceOnly specify if In or Out token on the velocity account must reduceOnly, checked at end of swap
2824
2925
  * @param v6 pass in the quote response from swap provider quote's API (deprecated, use quote instead)
2825
2926
  * @param quote pass in the quote response from swap provider quote's API
2826
2927
  * @param txParams
@@ -2929,7 +3030,7 @@ class VelocityClient {
2929
3030
  slippageBps,
2930
3031
  swapMode: isExactOut ? titanClient_1.SwapMode.ExactOut : titanClient_1.SwapMode.ExactIn,
2931
3032
  onlyDirectRoutes,
2932
- sizeConstraint: utils_2.MAX_TX_BYTE_SIZE - 375, // buffer for drift instructions
3033
+ sizeConstraint: utils_2.MAX_TX_BYTE_SIZE - 375, // buffer for velocity instructions
2933
3034
  });
2934
3035
  const titanInstructions = titanClient.getTitanInstructions({
2935
3036
  transactionMessage,
@@ -3012,7 +3113,7 @@ class VelocityClient {
3012
3113
  return { ixs, lookupTables };
3013
3114
  }
3014
3115
  /**
3015
- * Get the drift begin_swap and end_swap instructions
3116
+ * Get the velocity begin_swap and end_swap instructions
3016
3117
  *
3017
3118
  * @param outMarketIndex the market index of the token you're buying
3018
3119
  * @param inMarketIndex the market index of the token you're selling
@@ -3079,7 +3180,7 @@ class VelocityClient {
3079
3180
  inTokenAccount,
3080
3181
  outTokenAccount,
3081
3182
  tokenProgram: inTokenProgram,
3082
- driftSigner: this.getStateAccount().signer,
3183
+ velocitySigner: this.getStateAccount().signer,
3083
3184
  instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3084
3185
  },
3085
3186
  remainingAccounts,
@@ -3095,7 +3196,7 @@ class VelocityClient {
3095
3196
  inTokenAccount,
3096
3197
  outTokenAccount,
3097
3198
  tokenProgram: inTokenProgram,
3098
- driftSigner: this.getStateAccount().signer,
3199
+ velocitySigner: this.getStateAccount().signer,
3099
3200
  instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3100
3201
  },
3101
3202
  remainingAccounts,
@@ -3141,7 +3242,7 @@ class VelocityClient {
3141
3242
  else {
3142
3243
  amountInForBeginSwap = amount;
3143
3244
  }
3144
- // Get drift swap instructions for begin and end
3245
+ // Get velocity swap instructions for begin and end
3145
3246
  const { beginSwapIx, endSwapIx } = await this.getSwapIx({
3146
3247
  outMarketIndex,
3147
3248
  inMarketIndex,
@@ -3328,12 +3429,12 @@ class VelocityClient {
3328
3429
  remainingAccounts,
3329
3430
  });
3330
3431
  }
3331
- async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, successCondition, auctionDurationPercentage, txParams, subAccountId) {
3332
- const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, successCondition, auctionDurationPercentage, subAccountId), txParams), [], this.opts);
3432
+ async placeAndTakePerpOrder(orderParams, makerInfo, successCondition, auctionDurationPercentage, txParams, subAccountId, takerEscrow) {
3433
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, successCondition, auctionDurationPercentage, subAccountId, undefined, takerEscrow), txParams), [], this.opts);
3333
3434
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3334
3435
  return txSig;
3335
3436
  }
3336
- async preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails, auctionDurationPercentage, optionalIxs, isolatedPositionDepositAmount) {
3437
+ async preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails, auctionDurationPercentage, optionalIxs, isolatedPositionDepositAmount) {
3337
3438
  const placeAndTakeIxs = [];
3338
3439
  const txsToSign = {
3339
3440
  placeAndTakeTx: undefined,
@@ -3346,7 +3447,7 @@ class VelocityClient {
3346
3447
  let earlyExitFailedPlaceAndTakeSim = false;
3347
3448
  const prepPlaceAndTakeTx = async () => {
3348
3449
  var _a, _b;
3349
- const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, undefined, auctionDurationPercentage, subAccountId);
3450
+ const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, undefined, auctionDurationPercentage, subAccountId);
3350
3451
  if ((0, types_1.isVariant)(orderParams.marketType, 'perp') &&
3351
3452
  ((_a = isolatedPositionDepositAmount === null || isolatedPositionDepositAmount === void 0 ? void 0 : isolatedPositionDepositAmount.gt) === null || _a === void 0 ? void 0 : _a.call(isolatedPositionDepositAmount, numericConstants_1.ZERO)) &&
3352
3453
  this.isOrderIncreasingPosition(orderParams, subAccountId)) {
@@ -3409,8 +3510,8 @@ class VelocityClient {
3409
3510
  }
3410
3511
  return txsToSign;
3411
3512
  }
3412
- async placeAndTakePerpWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails) {
3413
- const txsToSign = await this.preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, referrerInfo, bracketOrdersParams, txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails);
3513
+ async placeAndTakePerpWithAdditionalOrders(orderParams, makerInfo, bracketOrdersParams = new Array(), txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails) {
3514
+ const txsToSign = await this.preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams, makerInfo, bracketOrdersParams, txParams, subAccountId, cancelExistingOrders, settlePnl, exitEarlyIfSimFails);
3414
3515
  if (!txsToSign) {
3415
3516
  return null;
3416
3517
  }
@@ -3425,8 +3526,13 @@ class VelocityClient {
3425
3526
  signedSettlePnlTx: signedTxs.settlePnlTx,
3426
3527
  };
3427
3528
  }
3428
- async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, successCondition, auctionDurationPercentage, subAccountId, overrides) {
3429
- var _a;
3529
+ async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, successCondition, auctionDurationPercentage, subAccountId, overrides,
3530
+ // place_and_take fills the placing user's (the taker's) order in-instruction, so
3531
+ // their RevenueShareEscrow must be attached for BOTH builder fees and referrer
3532
+ // revenue share. The builder case is detected from orderParams; pass the user's
3533
+ // decoded escrow (e.g. from a RevenueShareEscrowMap) to cover the referred case.
3534
+ takerEscrow) {
3535
+ var _a, _b, _c;
3430
3536
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3431
3537
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
3432
3538
  const user = await this.getUserAccountPublicKey(subAccountId);
@@ -3456,28 +3562,16 @@ class VelocityClient {
3456
3562
  isSigner: false,
3457
3563
  });
3458
3564
  }
3459
- if (referrerInfo) {
3460
- const referrerIsMaker = makerInfo.find((maker) => maker.maker.equals(referrerInfo.referrer)) !==
3461
- undefined;
3462
- if (!referrerIsMaker) {
3463
- remainingAccounts.push({
3464
- pubkey: referrerInfo.referrer,
3465
- isWritable: true,
3466
- isSigner: false,
3467
- });
3468
- remainingAccounts.push({
3469
- pubkey: referrerInfo.referrerStats,
3470
- isWritable: true,
3471
- isSigner: false,
3472
- });
3473
- }
3565
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta((_b = (_a = this.getUserAccount(subAccountId)) === null || _a === void 0 ? void 0 : _a.authority) !== null && _b !== void 0 ? _b : this.authority, (0, builder_1.hasBuilderParams)(orderParams), takerEscrow);
3566
+ if (takerEscrowMeta) {
3567
+ remainingAccounts.push(takerEscrowMeta);
3474
3568
  }
3475
3569
  let optionalParams = null;
3476
3570
  if (auctionDurationPercentage || successCondition) {
3477
3571
  optionalParams =
3478
3572
  ((auctionDurationPercentage !== null && auctionDurationPercentage !== void 0 ? auctionDurationPercentage : 100) << 8) | (successCondition !== null && successCondition !== void 0 ? successCondition : 0);
3479
3573
  }
3480
- const authority = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
3574
+ const authority = (_c = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _c !== void 0 ? _c : this.wallet.publicKey;
3481
3575
  return await VelocityCore_1.VelocityCore.buildPlaceAndTakePerpOrderInstruction({
3482
3576
  program: this.program,
3483
3577
  orderParams,
@@ -3489,12 +3583,17 @@ class VelocityClient {
3489
3583
  remainingAccounts,
3490
3584
  });
3491
3585
  }
3492
- async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo, txParams, subAccountId) {
3493
- const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo, subAccountId), txParams), [], this.opts);
3586
+ async placeAndMakePerpOrder(orderParams, takerInfo, txParams, subAccountId, takerEscrow) {
3587
+ const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, subAccountId, takerEscrow), txParams), [], this.opts);
3494
3588
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3495
3589
  return txSig;
3496
3590
  }
3497
- async getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo, subAccountId) {
3591
+ async getPlaceAndMakePerpOrderIx(orderParams, takerInfo, subAccountId,
3592
+ // place_and_make fills the taker's order in-instruction, so the TAKER's
3593
+ // RevenueShareEscrow must be attached when their order has a builder or they
3594
+ // are referred with an escrow. The builder case is detected from the taker
3595
+ // order bitflags; pass the taker's decoded escrow to cover the referred case.
3596
+ takerEscrow) {
3498
3597
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3499
3598
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
3500
3599
  const user = await this.getUserAccountPublicKey(subAccountId);
@@ -3506,25 +3605,10 @@ class VelocityClient {
3506
3605
  useMarketLastSlotCache: true,
3507
3606
  writablePerpMarketIndexes: [orderParams.marketIndex],
3508
3607
  });
3509
- if (referrerInfo) {
3510
- remainingAccounts.push({
3511
- pubkey: referrerInfo.referrer,
3512
- isWritable: true,
3513
- isSigner: false,
3514
- });
3515
- remainingAccounts.push({
3516
- pubkey: referrerInfo.referrerStats,
3517
- isWritable: true,
3518
- isSigner: false,
3519
- });
3520
- }
3521
3608
  const takerOrderId = takerInfo.order.orderId;
3522
- if ((0, orders_1.hasBuilder)(takerInfo.order)) {
3523
- remainingAccounts.push({
3524
- pubkey: (0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.program.programId, takerInfo.takerUserAccount.authority),
3525
- isWritable: true,
3526
- isSigner: false,
3527
- });
3609
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta(takerInfo.takerUserAccount.authority, (0, orders_1.hasBuilder)(takerInfo.order), takerEscrow);
3610
+ if (takerEscrowMeta) {
3611
+ remainingAccounts.push(takerEscrowMeta);
3528
3612
  }
3529
3613
  return await VelocityCore_1.VelocityCore.buildPlaceAndMakePerpOrderInstruction({
3530
3614
  program: this.program,
@@ -3550,7 +3634,7 @@ class VelocityClient {
3550
3634
  /**
3551
3635
  * Builds a deposit and place request for Swift service
3552
3636
  *
3553
- * @param depositTx - The signed tx containing a drift deposit (e.g. see `buildSwiftDepositTx`)
3637
+ * @param depositTx - The signed tx containing a velocity deposit (e.g. see `buildSwiftDepositTx`)
3554
3638
  * @param orderParamsMessage - The order parameters message to sign
3555
3639
  * @param delegateSigner - Whether this is a delegate signer
3556
3640
  *
@@ -3611,8 +3695,7 @@ class VelocityClient {
3611
3695
  readablePerpMarketIndex: marketIndex,
3612
3696
  writableSpotMarketIndexes,
3613
3697
  });
3614
- if (signedMessage.builderFeeTenthBps !== null &&
3615
- signedMessage.builderIdx !== null) {
3698
+ if ((0, builder_1.hasBuilderParams)(signedMessage)) {
3616
3699
  remainingAccounts.push({
3617
3700
  pubkey: (0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.program.programId, takerInfo.takerUserAccount.authority),
3618
3701
  isWritable: true,
@@ -3641,13 +3724,17 @@ class VelocityClient {
3641
3724
  });
3642
3725
  return [signedMsgOrderParamsSignatureIx, placeTakerSignedMsgPerpOrderIx];
3643
3726
  }
3644
- async placeAndMakeSignedMsgPerpOrder(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, referrerInfo, txParams, subAccountId, precedingIxs = [], overrideCustomIxIndex) {
3645
- const ixs = await this.getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs, overrideCustomIxIndex);
3727
+ async placeAndMakeSignedMsgPerpOrder(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, txParams, subAccountId, precedingIxs = [], overrideCustomIxIndex, takerEscrow) {
3728
+ const ixs = await this.getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, subAccountId, precedingIxs, overrideCustomIxIndex, takerEscrow);
3646
3729
  const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(ixs, txParams), [], this.opts);
3647
3730
  this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
3648
3731
  return txSig;
3649
3732
  }
3650
- async getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, referrerInfo, subAccountId, precedingIxs = [], overrideCustomIxIndex) {
3733
+ async getPlaceAndMakeSignedMsgPerpOrderIxs(signedSignedMsgOrderParams, signedMsgOrderUuid, takerInfo, orderParams, subAccountId, precedingIxs = [], overrideCustomIxIndex,
3734
+ // fills the taker's order in-instruction; pass the taker's decoded escrow so a
3735
+ // referred taker's escrow is attached even when the signed order carries no
3736
+ // builder fee
3737
+ takerEscrow) {
3651
3738
  const [signedMsgOrderSignatureIx, placeTakerSignedMsgPerpOrderIx] = await this.getPlaceSignedMsgTakerPerpOrderIxs(signedSignedMsgOrderParams, orderParams.marketIndex, takerInfo, precedingIxs, overrideCustomIxIndex);
3652
3739
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3653
3740
  const userStatsPublicKey = this.getUserStatsAccountPublicKey();
@@ -3660,28 +3747,12 @@ class VelocityClient {
3660
3747
  useMarketLastSlotCache: false,
3661
3748
  writablePerpMarketIndexes: [orderParams.marketIndex],
3662
3749
  });
3663
- if (referrerInfo) {
3664
- remainingAccounts.push({
3665
- pubkey: referrerInfo.referrer,
3666
- isWritable: true,
3667
- isSigner: false,
3668
- });
3669
- remainingAccounts.push({
3670
- pubkey: referrerInfo.referrerStats,
3671
- isWritable: true,
3672
- isSigner: false,
3673
- });
3674
- }
3675
3750
  const isDelegateSigner = takerInfo.signingAuthority.equals(takerInfo.takerUserAccount.delegate);
3676
3751
  const borshBuf = Buffer.from(signedSignedMsgOrderParams.orderParams.toString(), 'hex');
3677
3752
  const signedMessage = this.decodeSignedMsgOrderParamsMessage(borshBuf, isDelegateSigner);
3678
- if (signedMessage.builderFeeTenthBps !== null &&
3679
- signedMessage.builderIdx !== null) {
3680
- remainingAccounts.push({
3681
- pubkey: (0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.program.programId, takerInfo.takerUserAccount.authority),
3682
- isWritable: true,
3683
- isSigner: false,
3684
- });
3753
+ const takerEscrowMeta = this.getTakerEscrowAccountMeta(takerInfo.takerUserAccount.authority, (0, builder_1.hasBuilderParams)(signedMessage), takerEscrow);
3754
+ if (takerEscrowMeta) {
3755
+ remainingAccounts.push(takerEscrowMeta);
3685
3756
  }
3686
3757
  const placeAndMakeIx = await this.program.instruction.placeAndMakeSignedMsgPerpOrder(orderParams, signedMsgOrderUuid, {
3687
3758
  accounts: {
@@ -3701,19 +3772,19 @@ class VelocityClient {
3701
3772
  placeAndMakeIx,
3702
3773
  ];
3703
3774
  }
3704
- async preparePlaceAndTakeSpotOrder(_orderParams, _fulfillmentConfig, _makerInfo, _referrerInfo, _txParams, _subAccountId) {
3775
+ async preparePlaceAndTakeSpotOrder(_orderParams, _fulfillmentConfig, _makerInfo, _txParams, _subAccountId) {
3705
3776
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
3706
3777
  }
3707
- async placeAndTakeSpotOrder(_orderParams, _fulfillmentConfig, _makerInfo, _referrerInfo, _txParams, _subAccountId) {
3778
+ async placeAndTakeSpotOrder(_orderParams, _fulfillmentConfig, _makerInfo, _txParams, _subAccountId) {
3708
3779
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
3709
3780
  }
3710
- async getPlaceAndTakeSpotOrderIx(_orderParams, _fulfillmentConfig, _makerInfo, _referrerInfo, _subAccountId) {
3781
+ async getPlaceAndTakeSpotOrderIx(_orderParams, _fulfillmentConfig, _makerInfo, _subAccountId) {
3711
3782
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
3712
3783
  }
3713
- async placeAndMakeSpotOrder(_orderParams, _takerInfo, _fulfillmentConfig, _referrerInfo, _txParams, _subAccountId) {
3784
+ async placeAndMakeSpotOrder(_orderParams, _takerInfo, _fulfillmentConfig, _txParams, _subAccountId) {
3714
3785
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
3715
3786
  }
3716
- async getPlaceAndMakeSpotOrderIx(_orderParams, _takerInfo, _fulfillmentConfig, _referrerInfo, _subAccountId) {
3787
+ async getPlaceAndMakeSpotOrderIx(_orderParams, _takerInfo, _fulfillmentConfig, _subAccountId) {
3717
3788
  throw new Error(SPOT_DLOB_TRADING_DISABLED_MSG);
3718
3789
  }
3719
3790
  /**
@@ -3731,7 +3802,7 @@ class VelocityClient {
3731
3802
  baseAssetAmount: userPosition.baseAssetAmount.abs(),
3732
3803
  reduceOnly: true,
3733
3804
  price: limitPrice,
3734
- }, undefined, undefined, undefined, undefined, undefined, subAccountId);
3805
+ }, undefined, undefined, undefined, undefined, subAccountId);
3735
3806
  }
3736
3807
  /**
3737
3808
  * Modifies an open order by closing it and replacing it with a new order.
@@ -3968,7 +4039,7 @@ class VelocityClient {
3968
4039
  isWritable: true,
3969
4040
  });
3970
4041
  }
3971
- if (!escrow.referrer.equals(web3_js_1.PublicKey.default)) {
4042
+ if ((0, builder_1.escrowHasReferrer)(escrow)) {
3972
4043
  this.addBuilderToRemainingAccounts([escrow.referrer], remainingAccounts);
3973
4044
  }
3974
4045
  }
@@ -4082,7 +4153,7 @@ class VelocityClient {
4082
4153
  });
4083
4154
  }
4084
4155
  // Add referrer's User and RevenueShare accounts
4085
- if (!escrow.referrer.equals(web3_js_1.PublicKey.default)) {
4156
+ if ((0, builder_1.escrowHasReferrer)(escrow)) {
4086
4157
  this.addBuilderToRemainingAccounts([escrow.referrer], remainingAccounts);
4087
4158
  }
4088
4159
  }
@@ -4227,7 +4298,7 @@ class VelocityClient {
4227
4298
  remainingAccounts,
4228
4299
  });
4229
4300
  }
4230
- async getJupiterLiquidateSpotWithSwapIxV6({ jupiterClient, liabilityMarketIndex, assetMarketIndex, swapAmount, assetTokenAccount, liabilityTokenAccount, slippageBps, swapMode, onlyDirectRoutes, quote, userAccount, userAccountPublicKey, userStatsAccountPublicKey, liquidatorSubAccountId, maxAccounts, }) {
4301
+ async getJupiterLiquidateSpotWithSwapIxV6({ jupiterClient, liabilityMarketIndex, assetMarketIndex, swapAmount, assetTokenAccount, liabilityTokenAccount, slippageBps, swapMode, onlyDirectRoutes, quote, userAccount, userAccountPublicKey, liquidatorSubAccountId, maxAccounts, }) {
4231
4302
  const liabilityMarket = this.getSpotMarketAccount(liabilityMarketIndex);
4232
4303
  const assetMarket = this.getSpotMarketAccount(assetMarketIndex);
4233
4304
  if (!quote) {
@@ -4278,7 +4349,6 @@ class VelocityClient {
4278
4349
  liabilityTokenAccount,
4279
4350
  userAccount,
4280
4351
  userAccountPublicKey,
4281
- userStatsAccountPublicKey,
4282
4352
  liquidatorSubAccountId,
4283
4353
  });
4284
4354
  const ixs = [
@@ -4290,7 +4360,7 @@ class VelocityClient {
4290
4360
  return { ixs, lookupTables };
4291
4361
  }
4292
4362
  /**
4293
- * Get the drift liquidate_spot_with_swap instructions
4363
+ * Get the velocity liquidate_spot_with_swap instructions
4294
4364
  *
4295
4365
  * @param liabilityMarketIndex the market index of the token you're buying
4296
4366
  * @param assetMarketIndex the market index of the token you're selling
@@ -4299,11 +4369,9 @@ class VelocityClient {
4299
4369
  * @param liabilityTokenAccount the token account to receive the tokens being bought
4300
4370
  * @param userAccount
4301
4371
  * @param userAccountPublicKey
4302
- * @param userStatsAccountPublicKey
4303
4372
  */
4304
- async getLiquidateSpotWithSwapIx({ liabilityMarketIndex, assetMarketIndex, swapAmount: swapAmount, assetTokenAccount, liabilityTokenAccount, userAccount, userAccountPublicKey, userStatsAccountPublicKey, liquidatorSubAccountId, }) {
4373
+ async getLiquidateSpotWithSwapIx({ liabilityMarketIndex, assetMarketIndex, swapAmount: swapAmount, assetTokenAccount, liabilityTokenAccount, userAccount, userAccountPublicKey, liquidatorSubAccountId, }) {
4305
4374
  const liquidatorAccountPublicKey = await this.getUserAccountPublicKey(liquidatorSubAccountId);
4306
- const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
4307
4375
  const userAccounts = [userAccount];
4308
4376
  const remainingAccounts = this.getRemainingAccounts({
4309
4377
  userAccounts,
@@ -4344,16 +4412,14 @@ class VelocityClient {
4344
4412
  accounts: {
4345
4413
  state: await this.getStatePublicKey(),
4346
4414
  user: userAccountPublicKey,
4347
- userStats: userStatsAccountPublicKey,
4348
4415
  liquidator: liquidatorAccountPublicKey,
4349
- liquidatorStats: liquidatorStatsPublicKey,
4350
4416
  authority: this.wallet.publicKey,
4351
4417
  liabilitySpotMarketVault: liabilitySpotMarket.vault,
4352
4418
  assetSpotMarketVault: assetSpotMarket.vault,
4353
4419
  assetTokenAccount: assetTokenAccount,
4354
4420
  liabilityTokenAccount: liabilityTokenAccount,
4355
4421
  tokenProgram: assetTokenProgram,
4356
- driftSigner: this.getStateAccount().signer,
4422
+ velocitySigner: this.getStateAccount().signer,
4357
4423
  instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4358
4424
  },
4359
4425
  remainingAccounts,
@@ -4362,16 +4428,14 @@ class VelocityClient {
4362
4428
  accounts: {
4363
4429
  state: await this.getStatePublicKey(),
4364
4430
  user: userAccountPublicKey,
4365
- userStats: userStatsAccountPublicKey,
4366
4431
  liquidator: liquidatorAccountPublicKey,
4367
- liquidatorStats: liquidatorStatsPublicKey,
4368
4432
  authority: this.wallet.publicKey,
4369
4433
  liabilitySpotMarketVault: liabilitySpotMarket.vault,
4370
4434
  assetSpotMarketVault: assetSpotMarket.vault,
4371
4435
  assetTokenAccount: assetTokenAccount,
4372
4436
  liabilityTokenAccount: liabilityTokenAccount,
4373
4437
  tokenProgram: assetTokenProgram,
4374
- driftSigner: this.getStateAccount().signer,
4438
+ velocitySigner: this.getStateAccount().signer,
4375
4439
  instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4376
4440
  },
4377
4441
  remainingAccounts,
@@ -4414,7 +4478,7 @@ class VelocityClient {
4414
4478
  inTokenAccount,
4415
4479
  ifRebalanceConfig: ifRebalanceConfig,
4416
4480
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4417
- driftSigner: this.getStateAccount().signer,
4481
+ velocitySigner: this.getStateAccount().signer,
4418
4482
  instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4419
4483
  },
4420
4484
  remainingAccounts,
@@ -4429,7 +4493,7 @@ class VelocityClient {
4429
4493
  inTokenAccount,
4430
4494
  ifRebalanceConfig: ifRebalanceConfig,
4431
4495
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4432
- driftSigner: this.getStateAccount().signer,
4496
+ velocitySigner: this.getStateAccount().signer,
4433
4497
  instructions: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4434
4498
  },
4435
4499
  remainingAccounts,
@@ -4514,7 +4578,7 @@ class VelocityClient {
4514
4578
  liquidatorStats: liquidatorStatsPublicKey,
4515
4579
  spotMarketVault: spotMarket.vault,
4516
4580
  insuranceFundVault: spotMarket.insuranceFund.vault,
4517
- driftSigner: this.getSignerPublicKey(),
4581
+ velocitySigner: this.getSignerPublicKey(),
4518
4582
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4519
4583
  },
4520
4584
  remainingAccounts: remainingAccounts,
@@ -4548,7 +4612,7 @@ class VelocityClient {
4548
4612
  liquidator,
4549
4613
  spotMarketVault: spotMarket.vault,
4550
4614
  insuranceFundVault: spotMarket.insuranceFund.vault,
4551
- driftSigner: this.getSignerPublicKey(),
4615
+ velocitySigner: this.getSignerPublicKey(),
4552
4616
  tokenProgram: tokenProgramId,
4553
4617
  },
4554
4618
  remainingAccounts: remainingAccounts,
@@ -4574,14 +4638,14 @@ class VelocityClient {
4574
4638
  }
4575
4639
  async getUpdatePrelaunchOracleIx(perpMarketIndex) {
4576
4640
  const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
4577
- if (!(0, types_1.isVariant)(perpMarket.amm.oracleSource, 'prelaunch')) {
4578
- throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
4641
+ if (!(0, types_1.isVariant)(perpMarket.oracleSource, 'prelaunch')) {
4642
+ throw new Error(`Wrong oracle source ${perpMarket.oracleSource}`);
4579
4643
  }
4580
4644
  return await this.program.instruction.updatePrelaunchOracle({
4581
4645
  accounts: {
4582
4646
  state: await this.getStatePublicKey(),
4583
4647
  perpMarket: perpMarket.pubkey,
4584
- oracle: perpMarket.amm.oracle,
4648
+ oracle: perpMarket.oracle,
4585
4649
  },
4586
4650
  });
4587
4651
  }
@@ -4608,7 +4672,7 @@ class VelocityClient {
4608
4672
  accounts: {
4609
4673
  state: await this.getStatePublicKey(),
4610
4674
  perpMarket: perpMarket.pubkey,
4611
- oracle: perpMarket.amm.oracle,
4675
+ oracle: perpMarket.oracle,
4612
4676
  authority: this.wallet.publicKey,
4613
4677
  keeperStats: this.getUserStatsAccountPublicKey(),
4614
4678
  },
@@ -4649,38 +4713,38 @@ class VelocityClient {
4649
4713
  const perpMarket = this.getPerpMarketAccount(marketIndex);
4650
4714
  const oracleData = this.getOracleDataForPerpMarket(marketIndex);
4651
4715
  const stateAccountAndSlot = this.accountSubscriber.getStateAccountAndSlot();
4652
- const isMMOracleActive = !perpMarket.amm.mmOracleSlot.eq(numericConstants_1.ZERO);
4653
- const pctDiff = perpMarket.amm.mmOraclePrice
4716
+ const isMMOracleActive = !perpMarket.marketStats.mmOracleSlot.eq(numericConstants_1.ZERO);
4717
+ const pctDiff = perpMarket.marketStats.mmOraclePrice
4654
4718
  .sub(oracleData.price)
4655
4719
  .abs()
4656
4720
  .mul(numericConstants_1.PERCENTAGE_PRECISION)
4657
4721
  .div(anchor_1.BN.max(oracleData.price, numericConstants_1.ONE));
4658
- const mmOracleSequenceId = perpMarket.amm.mmOracleSequenceId;
4722
+ const mmOracleSequenceId = perpMarket.marketStats.mmOracleSequenceId;
4659
4723
  // Do slot check for recency if sequence ids are zero or they're too divergent
4660
4724
  const doSlotCheckForRecency = oracleData.sequenceId == null ||
4661
4725
  oracleData.sequenceId.eq(numericConstants_1.ZERO) ||
4662
4726
  mmOracleSequenceId.eq(numericConstants_1.ZERO) ||
4663
4727
  oracleData.sequenceId
4664
- .sub(perpMarket.amm.mmOracleSequenceId)
4728
+ .sub(perpMarket.marketStats.mmOracleSequenceId)
4665
4729
  .abs()
4666
4730
  .gt(oracleData.sequenceId.div(new anchor_1.BN(10000)));
4667
4731
  let isExchangeOracleMoreRecent = true;
4668
4732
  if (doSlotCheckForRecency &&
4669
- oracleData.slot <= perpMarket.amm.mmOracleSlot) {
4733
+ oracleData.slot <= perpMarket.marketStats.mmOracleSlot) {
4670
4734
  isExchangeOracleMoreRecent = false;
4671
4735
  }
4672
4736
  else if (!doSlotCheckForRecency &&
4673
4737
  oracleData.sequenceId < mmOracleSequenceId) {
4674
4738
  isExchangeOracleMoreRecent = false;
4675
4739
  }
4676
- const conf = (0, utils_3.getOracleConfidenceFromMMOracleData)(perpMarket.amm.mmOraclePrice, oracleData);
4677
- if ((0, oracles_1.isOracleTooDivergent)(perpMarket.amm, {
4678
- price: perpMarket.amm.mmOraclePrice,
4679
- slot: perpMarket.amm.mmOracleSlot,
4740
+ const conf = (0, utils_3.getOracleConfidenceFromMMOracleData)(perpMarket.marketStats.mmOraclePrice, oracleData);
4741
+ if ((0, oracles_1.isOracleTooDivergent)(perpMarket.marketStats, {
4742
+ price: perpMarket.marketStats.mmOraclePrice,
4743
+ slot: perpMarket.marketStats.mmOracleSlot,
4680
4744
  confidence: conf,
4681
4745
  hasSufficientNumberOfDataPoints: true,
4682
4746
  }, stateAccountAndSlot.data.oracleGuardRails) ||
4683
- perpMarket.amm.mmOraclePrice.eq(numericConstants_1.ZERO) ||
4747
+ perpMarket.marketStats.mmOraclePrice.eq(numericConstants_1.ZERO) ||
4684
4748
  isExchangeOracleMoreRecent ||
4685
4749
  pctDiff.gt(numericConstants_1.PERCENTAGE_PRECISION.divn(100)) // 1% threshold
4686
4750
  ) {
@@ -4688,8 +4752,8 @@ class VelocityClient {
4688
4752
  }
4689
4753
  else {
4690
4754
  return {
4691
- price: perpMarket.amm.mmOraclePrice,
4692
- slot: perpMarket.amm.mmOracleSlot,
4755
+ price: perpMarket.marketStats.mmOraclePrice,
4756
+ slot: perpMarket.marketStats.mmOracleSlot,
4693
4757
  confidence: conf,
4694
4758
  hasSufficientNumberOfDataPoints: true,
4695
4759
  isMMOracleActive,
@@ -4739,7 +4803,7 @@ class VelocityClient {
4739
4803
  authority: this.wallet.publicKey,
4740
4804
  spotMarketVault: spotMarket.vault,
4741
4805
  insuranceFundVault: spotMarket.insuranceFund.vault,
4742
- driftSigner: this.getSignerPublicKey(),
4806
+ velocitySigner: this.getSignerPublicKey(),
4743
4807
  userTokenAccount: collateralAccountPublicKey,
4744
4808
  tokenProgram,
4745
4809
  },
@@ -4880,7 +4944,7 @@ class VelocityClient {
4880
4944
  ),
4881
4945
  authority: this.wallet.publicKey,
4882
4946
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
4883
- driftSigner: this.getSignerPublicKey(),
4947
+ velocitySigner: this.getSignerPublicKey(),
4884
4948
  userTokenAccount: tokenAccount,
4885
4949
  tokenProgram,
4886
4950
  },
@@ -4958,7 +5022,7 @@ class VelocityClient {
4958
5022
  state: await this.getStatePublicKey(),
4959
5023
  spotMarket: spotMarketAccount.pubkey,
4960
5024
  spotMarketVault: spotMarketAccount.vault,
4961
- driftSigner: this.getSignerPublicKey(),
5025
+ velocitySigner: this.getSignerPublicKey(),
4962
5026
  insuranceFundVault: spotMarketAccount.insuranceFund.vault,
4963
5027
  tokenProgram: tokenProgramId,
4964
5028
  },
@@ -4984,7 +5048,7 @@ class VelocityClient {
4984
5048
  authority: this.wallet.publicKey,
4985
5049
  spotMarketVault: spotMarket.vault,
4986
5050
  insuranceFundVault: spotMarket.insuranceFund.vault,
4987
- driftSigner: this.getSignerPublicKey(),
5051
+ velocitySigner: this.getSignerPublicKey(),
4988
5052
  tokenProgram: tokenProgramId,
4989
5053
  },
4990
5054
  remainingAccounts: remainingAccounts,
@@ -5011,7 +5075,7 @@ class VelocityClient {
5011
5075
  return ix;
5012
5076
  }
5013
5077
  /**
5014
- * This ix will donate your funds to drift revenue pool. It does not deposit into your user account
5078
+ * This ix will donate your funds to velocity revenue pool. It does not deposit into your user account
5015
5079
  * @param marketIndex
5016
5080
  * @param amount
5017
5081
  * @param userTokenAccountPublicKey
@@ -5029,7 +5093,7 @@ class VelocityClient {
5029
5093
  const quoteAccount = this.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
5030
5094
  const extendedInfo = {
5031
5095
  marketIndex,
5032
- minOrderSize: (_a = marketAccount.amm) === null || _a === void 0 ? void 0 : _a.minOrderSize,
5096
+ minOrderSize: (_a = marketAccount.marketStats) === null || _a === void 0 ? void 0 : _a.minOrderSize,
5033
5097
  marginMaintenance: marketAccount.marginRatioMaintenance,
5034
5098
  pnlPoolValue: (0, spotBalance_1.getTokenAmount)((_b = marketAccount.pnlPool) === null || _b === void 0 ? void 0 : _b.scaledBalance, quoteAccount, types_1.SpotBalanceType.DEPOSIT),
5035
5099
  contractTier: marketAccount.contractTier,
@@ -5367,7 +5431,7 @@ class VelocityClient {
5367
5431
  return this.program.instruction.viewLpPoolSwapFees(inMarketIndex, outMarketIndex, inAmount, inTargetWeight, outTargetWeight, {
5368
5432
  remainingAccounts,
5369
5433
  accounts: {
5370
- driftSigner: this.getSignerPublicKey(),
5434
+ velocitySigner: this.getSignerPublicKey(),
5371
5435
  state: await this.getStatePublicKey(),
5372
5436
  lpPool,
5373
5437
  constituentTargetBase,
@@ -5514,7 +5578,7 @@ class VelocityClient {
5514
5578
  ixs.push(this.program.instruction.lpPoolRemoveLiquidity(outMarketIndex, lpToBurn, minAmountOut, {
5515
5579
  remainingAccounts,
5516
5580
  accounts: {
5517
- driftSigner: this.getSignerPublicKey(),
5581
+ velocitySigner: this.getSignerPublicKey(),
5518
5582
  state: await this.getStatePublicKey(),
5519
5583
  lpPool: lpPool.pubkey,
5520
5584
  authority: this.wallet.publicKey,
@@ -5587,7 +5651,7 @@ class VelocityClient {
5587
5651
  async getAllLpPoolRemoveLiquidityIxs({ outMarketIndex, lpToBurn, minAmountOut, lpPool, }, constituentMap, includeUpdateConstituentOracleInfo = true, view = false) {
5588
5652
  const ixs = [];
5589
5653
  ixs.push(...(await this.getAllSettlePerpToLpPoolIxs(lpPool.lpPoolId, this.getPerpMarketAccounts()
5590
- .filter((marketAccount) => marketAccount.lpStatus > 0)
5654
+ .filter((marketAccount) => marketAccount.hedgeConfig.status > 0)
5591
5655
  .map((marketAccount) => marketAccount.marketIndex))));
5592
5656
  ixs.push(...(await this.getAllUpdateLpPoolAumIxs(lpPool, constituentMap, includeUpdateConstituentOracleInfo)));
5593
5657
  if (view) {
@@ -5655,7 +5719,7 @@ class VelocityClient {
5655
5719
  const lpPool = (0, pda_1.getLpPoolPublicKey)(this.program.programId, lpPoolId);
5656
5720
  return this.program.instruction.settlePerpToLpPool({
5657
5721
  accounts: {
5658
- driftSigner: this.getSignerPublicKey(),
5722
+ velocitySigner: this.getSignerPublicKey(),
5659
5723
  state: await this.getStatePublicKey(),
5660
5724
  keeper: this.wallet.publicKey,
5661
5725
  ammCache: (0, pda_1.getAmmCachePublicKey)(this.program.programId),
@@ -5774,5 +5838,3 @@ class VelocityClient {
5774
5838
  }
5775
5839
  }
5776
5840
  exports.VelocityClient = VelocityClient;
5777
- /** @deprecated Use `VelocityClient` instead. `DriftClient` will be removed in a future major. */
5778
- exports.DriftClient = VelocityClient;