@velocity-exchange/sdk 0.0.5 → 0.2.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 (815) hide show
  1. package/.prettierignore +1 -1
  2. package/CHANGELOG.md +35 -0
  3. package/README.md +30 -30
  4. package/bun.lock +24 -2
  5. package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +5 -3
  6. package/lib/browser/accounts/basicUserAccountSubscriber.js +4 -3
  7. package/lib/browser/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
  8. package/lib/browser/accounts/basicUserStatsAccountSubscriber.js +4 -3
  9. package/lib/browser/accounts/bulkAccountLoader.d.ts +5 -5
  10. package/lib/browser/accounts/bulkAccountLoader.js +12 -1
  11. package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -1
  12. package/lib/browser/accounts/grpcAccountSubscriber.js +8 -2
  13. package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
  14. package/lib/browser/accounts/grpcMultiAccountSubscriber.js +13 -5
  15. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
  16. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +12 -8
  17. package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
  18. package/lib/browser/accounts/grpcProgramAccountSubscriber.js +9 -3
  19. package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
  20. package/lib/browser/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
  21. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
  22. package/lib/browser/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
  23. package/lib/browser/accounts/laserProgramAccountSubscriber.js +4 -1
  24. package/lib/browser/accounts/oneShotUserAccountSubscriber.js +4 -3
  25. package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
  26. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  27. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
  28. package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
  29. package/lib/browser/accounts/pollingOracleAccountSubscriber.js +16 -5
  30. package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
  31. package/lib/browser/accounts/pollingTokenAccountSubscriber.js +16 -5
  32. package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +8 -4
  33. package/lib/browser/accounts/pollingUserAccountSubscriber.js +17 -11
  34. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
  35. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +6 -6
  36. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -5
  37. package/lib/browser/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
  38. package/lib/browser/accounts/types.d.ts +6 -12
  39. package/lib/browser/accounts/utils.d.ts +1 -0
  40. package/lib/browser/accounts/utils.js +10 -3
  41. package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +4 -2
  42. package/lib/browser/accounts/webSocketAccountSubscriber.js +17 -5
  43. package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
  44. package/lib/browser/accounts/webSocketAccountSubscriberV2.js +17 -6
  45. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  46. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
  47. package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
  48. package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +14 -3
  49. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
  50. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
  51. package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
  52. package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
  53. package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
  54. package/lib/browser/accounts/webSocketUserAccountSubscriber.js +9 -0
  55. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
  56. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
  57. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -8
  58. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
  59. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
  60. package/lib/browser/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
  61. package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
  62. package/lib/browser/accounts/websocketProgramUserAccountSubscriber.js +0 -3
  63. package/lib/browser/addresses/marketAddresses.js +3 -2
  64. package/lib/browser/addresses/pda.d.ts +1 -9
  65. package/lib/browser/addresses/pda.js +4 -23
  66. package/lib/browser/adminClient.d.ts +25 -29
  67. package/lib/browser/adminClient.js +168 -169
  68. package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +2 -4
  69. package/lib/browser/auctionSubscriber/auctionSubscriber.js +8 -10
  70. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
  71. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
  72. package/lib/browser/auctionSubscriber/types.d.ts +3 -2
  73. package/lib/browser/bankrun/bankrunConnection.d.ts +6 -4
  74. package/lib/browser/bankrun/bankrunConnection.js +69 -31
  75. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
  76. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +3 -2
  77. package/lib/browser/clock/clockSubscriber.d.ts +6 -6
  78. package/lib/browser/clock/clockSubscriber.js +4 -3
  79. package/lib/browser/config.d.ts +11 -20
  80. package/lib/browser/config.js +13 -36
  81. package/lib/browser/constants/index.d.ts +1 -2
  82. package/lib/browser/constants/index.js +1 -2
  83. package/lib/browser/constants/numericConstants.d.ts +1 -3
  84. package/lib/browser/constants/numericConstants.js +3 -5
  85. package/lib/browser/constituentMap/constituentMap.d.ts +0 -2
  86. package/lib/browser/constituentMap/constituentMap.js +10 -6
  87. package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
  88. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
  89. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
  90. package/lib/browser/core/VelocityCore.d.ts +9 -15
  91. package/lib/browser/core/VelocityCore.js +5 -7
  92. package/lib/browser/core/instructions/perpOrders.d.ts +14 -0
  93. package/lib/browser/core/instructions/perpOrders.js +14 -0
  94. package/lib/browser/core/instructions/withdraw.d.ts +1 -1
  95. package/lib/browser/core/instructions/withdraw.js +1 -1
  96. package/lib/browser/core/remainingAccounts.d.ts +2 -2
  97. package/lib/browser/core/remainingAccounts.js +5 -5
  98. package/lib/browser/decode/user.js +9 -1
  99. package/lib/browser/dlob/DLOB.d.ts +7 -2
  100. package/lib/browser/dlob/DLOB.js +205 -142
  101. package/lib/browser/dlob/DLOBNode.d.ts +5 -2
  102. package/lib/browser/dlob/DLOBNode.js +7 -0
  103. package/lib/browser/dlob/DLOBSubscriber.d.ts +0 -2
  104. package/lib/browser/dlob/DLOBSubscriber.js +39 -39
  105. package/lib/browser/dlob/NodeList.js +8 -7
  106. package/lib/browser/dlob/orderBookLevels.js +24 -17
  107. package/lib/browser/dlob/types.d.ts +0 -2
  108. package/lib/browser/events/eventList.js +4 -1
  109. package/lib/browser/events/eventSubscriber.d.ts +6 -3
  110. package/lib/browser/events/eventSubscriber.js +75 -26
  111. package/lib/browser/events/eventsServerLogProvider.d.ts +1 -1
  112. package/lib/browser/events/eventsServerLogProvider.js +17 -10
  113. package/lib/browser/events/fetchLogs.d.ts +1 -1
  114. package/lib/browser/events/fetchLogs.js +4 -2
  115. package/lib/browser/events/parse.js +14 -14
  116. package/lib/browser/events/pollingLogProvider.d.ts +1 -1
  117. package/lib/browser/events/pollingLogProvider.js +1 -0
  118. package/lib/browser/events/txEventCache.js +6 -2
  119. package/lib/browser/events/types.d.ts +3 -7
  120. package/lib/browser/events/types.js +1 -3
  121. package/lib/browser/events/webSocketLogProvider.d.ts +1 -1
  122. package/lib/browser/events/webSocketLogProvider.js +5 -2
  123. package/lib/browser/factory/bigNum.js +1 -1
  124. package/lib/{node/idl/drift.d.ts → browser/idl/velocity.d.ts} +2412 -2481
  125. package/lib/browser/idl/{drift.json → velocity.json} +2265 -2333
  126. package/lib/browser/index.d.ts +1 -3
  127. package/lib/browser/index.js +1 -4
  128. package/lib/browser/jupiter/jupiterClient.d.ts +1 -1
  129. package/lib/browser/jupiter/jupiterClient.js +18 -8
  130. package/lib/browser/marginCalculation.js +1 -0
  131. package/lib/browser/math/amm.d.ts +31 -13
  132. package/lib/browser/math/amm.js +87 -31
  133. package/lib/browser/math/auction.js +16 -12
  134. package/lib/browser/math/bankruptcy.js +1 -1
  135. package/lib/browser/math/builder.d.ts +18 -1
  136. package/lib/browser/math/builder.js +32 -1
  137. package/lib/browser/math/funding.js +30 -30
  138. package/lib/browser/math/insurance.d.ts +1 -1
  139. package/lib/browser/math/insurance.js +4 -5
  140. package/lib/browser/math/margin.d.ts +3 -11
  141. package/lib/browser/math/margin.js +10 -69
  142. package/lib/browser/math/market.d.ts +4 -12
  143. package/lib/browser/math/market.js +12 -46
  144. package/lib/browser/math/oracles.d.ts +4 -7
  145. package/lib/browser/math/oracles.js +24 -37
  146. package/lib/browser/math/orders.d.ts +2 -7
  147. package/lib/browser/math/orders.js +9 -81
  148. package/lib/browser/math/position.d.ts +0 -4
  149. package/lib/browser/math/position.js +6 -11
  150. package/lib/browser/math/repeg.d.ts +0 -1
  151. package/lib/browser/math/repeg.js +1 -23
  152. package/lib/browser/math/spotBalance.d.ts +4 -4
  153. package/lib/browser/math/spotBalance.js +6 -6
  154. package/lib/browser/math/spotMarket.d.ts +0 -6
  155. package/lib/browser/math/spotMarket.js +1 -16
  156. package/lib/browser/math/spotPosition.d.ts +4 -4
  157. package/lib/browser/math/state.d.ts +0 -2
  158. package/lib/browser/math/state.js +1 -9
  159. package/lib/browser/math/superStake.d.ts +11 -63
  160. package/lib/browser/math/superStake.js +29 -28
  161. package/lib/browser/math/trade.js +7 -7
  162. package/lib/browser/math/utils.d.ts +1 -1
  163. package/lib/browser/math/utils.js +1 -1
  164. package/lib/browser/memcmp.d.ts +0 -1
  165. package/lib/browser/memcmp.js +1 -10
  166. package/lib/browser/oracles/prelaunchOracleClient.js +3 -2
  167. package/lib/browser/oracles/pythClient.js +9 -3
  168. package/lib/browser/oracles/pythLazerClient.js +5 -4
  169. package/lib/browser/oracles/utils.d.ts +4 -0
  170. package/lib/browser/oracles/utils.js +9 -1
  171. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +1 -3
  172. package/lib/browser/orderSubscriber/OrderSubscriber.js +16 -14
  173. package/lib/browser/orderSubscriber/WebsocketSubscription.js +1 -1
  174. package/lib/browser/orderSubscriber/grpcSubscription.js +2 -2
  175. package/lib/browser/orderSubscriber/types.d.ts +0 -2
  176. package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
  177. package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +2 -6
  178. package/lib/browser/priorityFee/priorityFeeSubscriber.js +34 -18
  179. package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
  180. package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +3 -11
  181. package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
  182. package/lib/browser/priorityFee/types.d.ts +3 -8
  183. package/lib/browser/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
  184. package/lib/browser/priorityFee/velocityPriorityFeeMethod.js +1 -3
  185. package/lib/browser/pyth/pythLazerSubscriber.d.ts +1 -1
  186. package/lib/browser/pyth/pythLazerSubscriber.js +1 -1
  187. package/lib/browser/pyth/types.d.ts +0 -1
  188. package/lib/browser/slot/SlotSubscriber.d.ts +1 -1
  189. package/lib/browser/slot/SlotSubscriber.js +2 -1
  190. package/lib/browser/slot/SlothashSubscriber.d.ts +3 -2
  191. package/lib/browser/slot/SlothashSubscriber.js +11 -4
  192. package/lib/browser/swap/UnifiedSwapClient.js +1 -1
  193. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
  194. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
  195. package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +7 -7
  196. package/lib/browser/swift/signedMsgUserAccountSubscriber.js +14 -10
  197. package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -6
  198. package/lib/browser/swift/swiftOrderSubscriber.js +15 -16
  199. package/lib/browser/testClient.js +3 -2
  200. package/lib/browser/tokenFaucet.js +16 -2
  201. package/lib/browser/tx/baseTxSender.d.ts +4 -4
  202. package/lib/browser/tx/baseTxSender.js +5 -4
  203. package/lib/browser/tx/fastSingleTxSender.d.ts +3 -3
  204. package/lib/browser/tx/fastSingleTxSender.js +9 -5
  205. package/lib/browser/tx/reportTransactionError.d.ts +2 -2
  206. package/lib/browser/tx/reportTransactionError.js +5 -1
  207. package/lib/browser/tx/retryTxSender.d.ts +1 -1
  208. package/lib/browser/tx/retryTxSender.js +4 -2
  209. package/lib/browser/tx/txHandler.d.ts +7 -1
  210. package/lib/browser/tx/txHandler.js +54 -40
  211. package/lib/browser/tx/txParamProcessor.d.ts +4 -1
  212. package/lib/browser/tx/txParamProcessor.js +6 -0
  213. package/lib/browser/tx/types.d.ts +1 -1
  214. package/lib/browser/tx/whileValidTxSender.d.ts +1 -6
  215. package/lib/browser/tx/whileValidTxSender.js +35 -13
  216. package/lib/browser/types.d.ts +102 -157
  217. package/lib/browser/types.js +6 -2
  218. package/lib/browser/user.d.ts +22 -10
  219. package/lib/browser/user.js +174 -154
  220. package/lib/browser/userConfig.d.ts +3 -2
  221. package/lib/browser/userMap/WebsocketSubscription.d.ts +1 -1
  222. package/lib/browser/userMap/WebsocketSubscription.js +1 -1
  223. package/lib/browser/userMap/grpcSubscription.d.ts +1 -1
  224. package/lib/browser/userMap/grpcSubscription.js +1 -1
  225. package/lib/browser/userMap/referrerMap.d.ts +0 -2
  226. package/lib/browser/userMap/referrerMap.js +10 -7
  227. package/lib/browser/userMap/revenueShareEscrowMap.d.ts +0 -2
  228. package/lib/browser/userMap/revenueShareEscrowMap.js +4 -4
  229. package/lib/browser/userMap/userMap.d.ts +3 -5
  230. package/lib/browser/userMap/userMap.js +39 -30
  231. package/lib/browser/userMap/userMapConfig.d.ts +3 -2
  232. package/lib/browser/userMap/userStatsMap.d.ts +1 -3
  233. package/lib/browser/userMap/userStatsMap.js +18 -17
  234. package/lib/browser/userStats.d.ts +7 -4
  235. package/lib/browser/userStats.js +28 -18
  236. package/lib/browser/userStatsConfig.d.ts +3 -2
  237. package/lib/browser/util/TransactionConfirmationManager.js +4 -2
  238. package/lib/browser/util/chainClock.d.ts +1 -1
  239. package/lib/browser/util/computeUnits.d.ts +1 -1
  240. package/lib/browser/util/computeUnits.js +6 -1
  241. package/lib/browser/util/ed25519Utils.d.ts +1 -1
  242. package/lib/browser/util/ed25519Utils.js +1 -1
  243. package/lib/browser/velocityClient.d.ts +144 -71
  244. package/lib/browser/velocityClient.js +653 -457
  245. package/lib/browser/velocityClientConfig.d.ts +0 -8
  246. package/lib/node/accounts/basicUserAccountSubscriber.d.ts +5 -3
  247. package/lib/node/accounts/basicUserAccountSubscriber.d.ts.map +1 -1
  248. package/lib/node/accounts/basicUserAccountSubscriber.js +4 -3
  249. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts +5 -3
  250. package/lib/node/accounts/basicUserStatsAccountSubscriber.d.ts.map +1 -1
  251. package/lib/node/accounts/basicUserStatsAccountSubscriber.js +4 -3
  252. package/lib/node/accounts/bulkAccountLoader.d.ts +5 -5
  253. package/lib/node/accounts/bulkAccountLoader.d.ts.map +1 -1
  254. package/lib/node/accounts/bulkAccountLoader.js +12 -1
  255. package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -1
  256. package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
  257. package/lib/node/accounts/grpcAccountSubscriber.js +8 -2
  258. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +3 -2
  259. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  260. package/lib/node/accounts/grpcMultiAccountSubscriber.js +13 -5
  261. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -1
  262. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
  263. package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +12 -8
  264. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +2 -1
  265. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
  266. package/lib/node/accounts/grpcProgramAccountSubscriber.js +9 -3
  267. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts +0 -4
  268. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.d.ts.map +1 -1
  269. package/lib/node/accounts/grpcVelocityClientAccountSubscriber.js +19 -6
  270. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts +1 -5
  271. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  272. package/lib/node/accounts/grpcVelocityClientAccountSubscriberV2.js +44 -23
  273. package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
  274. package/lib/node/accounts/laserProgramAccountSubscriber.js +4 -1
  275. package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
  276. package/lib/node/accounts/oneShotUserAccountSubscriber.js +4 -3
  277. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
  278. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.js +7 -3
  279. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  280. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  281. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +3 -3
  282. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +0 -2
  283. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
  284. package/lib/node/accounts/pollingOracleAccountSubscriber.js +16 -5
  285. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +0 -2
  286. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
  287. package/lib/node/accounts/pollingTokenAccountSubscriber.js +16 -5
  288. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +8 -4
  289. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts.map +1 -1
  290. package/lib/node/accounts/pollingUserAccountSubscriber.js +17 -11
  291. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -2
  292. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
  293. package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +6 -6
  294. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts +7 -5
  295. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.d.ts.map +1 -1
  296. package/lib/node/accounts/pollingVelocityClientAccountSubscriber.js +69 -35
  297. package/lib/node/accounts/types.d.ts +6 -12
  298. package/lib/node/accounts/types.d.ts.map +1 -1
  299. package/lib/node/accounts/utils.d.ts +1 -0
  300. package/lib/node/accounts/utils.d.ts.map +1 -1
  301. package/lib/node/accounts/utils.js +10 -3
  302. package/lib/node/accounts/webSocketAccountSubscriber.d.ts +4 -2
  303. package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
  304. package/lib/node/accounts/webSocketAccountSubscriber.js +17 -5
  305. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +4 -2
  306. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
  307. package/lib/node/accounts/webSocketAccountSubscriberV2.js +17 -6
  308. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +4 -2
  309. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  310. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +9 -0
  311. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +3 -1
  312. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
  313. package/lib/node/accounts/webSocketProgramAccountSubscriber.js +14 -3
  314. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -1
  315. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
  316. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +15 -3
  317. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -1
  318. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
  319. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.js +14 -4
  320. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +4 -2
  321. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
  322. package/lib/node/accounts/webSocketUserAccountSubscriber.js +9 -0
  323. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +4 -2
  324. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
  325. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +9 -0
  326. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts +4 -8
  327. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.d.ts.map +1 -1
  328. package/lib/node/accounts/webSocketVelocityClientAccountSubscriber.js +52 -26
  329. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts +7 -7
  330. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.d.ts.map +1 -1
  331. package/lib/node/accounts/webSocketVelocityClientAccountSubscriberV2.js +49 -20
  332. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +1 -1
  333. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
  334. package/lib/node/accounts/websocketProgramUserAccountSubscriber.js +0 -3
  335. package/lib/node/addresses/marketAddresses.d.ts.map +1 -1
  336. package/lib/node/addresses/marketAddresses.js +3 -2
  337. package/lib/node/addresses/pda.d.ts +1 -9
  338. package/lib/node/addresses/pda.d.ts.map +1 -1
  339. package/lib/node/addresses/pda.js +4 -23
  340. package/lib/node/adminClient.d.ts +25 -29
  341. package/lib/node/adminClient.d.ts.map +1 -1
  342. package/lib/node/adminClient.js +168 -169
  343. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +2 -4
  344. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
  345. package/lib/node/auctionSubscriber/auctionSubscriber.js +8 -10
  346. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +2 -4
  347. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
  348. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +11 -10
  349. package/lib/node/auctionSubscriber/types.d.ts +3 -2
  350. package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
  351. package/lib/node/bankrun/bankrunConnection.d.ts +6 -4
  352. package/lib/node/bankrun/bankrunConnection.d.ts.map +1 -1
  353. package/lib/node/bankrun/bankrunConnection.js +69 -31
  354. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +1 -1
  355. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts.map +1 -1
  356. package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +3 -2
  357. package/lib/node/clock/clockSubscriber.d.ts +6 -6
  358. package/lib/node/clock/clockSubscriber.d.ts.map +1 -1
  359. package/lib/node/clock/clockSubscriber.js +4 -3
  360. package/lib/node/config.d.ts +11 -20
  361. package/lib/node/config.d.ts.map +1 -1
  362. package/lib/node/config.js +13 -36
  363. package/lib/node/constants/index.d.ts +1 -2
  364. package/lib/node/constants/index.d.ts.map +1 -1
  365. package/lib/node/constants/index.js +1 -2
  366. package/lib/node/constants/numericConstants.d.ts +1 -3
  367. package/lib/node/constants/numericConstants.d.ts.map +1 -1
  368. package/lib/node/constants/numericConstants.js +3 -5
  369. package/lib/node/constituentMap/constituentMap.d.ts +0 -2
  370. package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
  371. package/lib/node/constituentMap/constituentMap.js +10 -6
  372. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -1
  373. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.js +3 -2
  374. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +2 -3
  375. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -1
  376. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +10 -3
  377. package/lib/node/core/VelocityCore.d.ts +9 -15
  378. package/lib/node/core/VelocityCore.d.ts.map +1 -1
  379. package/lib/node/core/VelocityCore.js +5 -7
  380. package/lib/node/core/instructions/perpOrders.d.ts +14 -0
  381. package/lib/node/core/instructions/perpOrders.d.ts.map +1 -1
  382. package/lib/node/core/instructions/perpOrders.js +14 -0
  383. package/lib/node/core/instructions/withdraw.d.ts +1 -1
  384. package/lib/node/core/instructions/withdraw.d.ts.map +1 -1
  385. package/lib/node/core/instructions/withdraw.js +1 -1
  386. package/lib/node/core/remainingAccounts.d.ts +2 -2
  387. package/lib/node/core/remainingAccounts.d.ts.map +1 -1
  388. package/lib/node/core/remainingAccounts.js +5 -5
  389. package/lib/node/decode/user.d.ts.map +1 -1
  390. package/lib/node/decode/user.js +9 -1
  391. package/lib/node/dlob/DLOB.d.ts +7 -2
  392. package/lib/node/dlob/DLOB.d.ts.map +1 -1
  393. package/lib/node/dlob/DLOB.js +205 -142
  394. package/lib/node/dlob/DLOBNode.d.ts +5 -2
  395. package/lib/node/dlob/DLOBNode.d.ts.map +1 -1
  396. package/lib/node/dlob/DLOBNode.js +7 -0
  397. package/lib/node/dlob/DLOBSubscriber.d.ts +0 -2
  398. package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
  399. package/lib/node/dlob/DLOBSubscriber.js +39 -39
  400. package/lib/node/dlob/NodeList.d.ts.map +1 -1
  401. package/lib/node/dlob/NodeList.js +8 -7
  402. package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
  403. package/lib/node/dlob/orderBookLevels.js +24 -17
  404. package/lib/node/dlob/types.d.ts +0 -2
  405. package/lib/node/dlob/types.d.ts.map +1 -1
  406. package/lib/node/events/eventList.d.ts +3 -3
  407. package/lib/node/events/eventList.d.ts.map +1 -1
  408. package/lib/node/events/eventList.js +4 -1
  409. package/lib/node/events/eventSubscriber.d.ts +6 -3
  410. package/lib/node/events/eventSubscriber.d.ts.map +1 -1
  411. package/lib/node/events/eventSubscriber.js +75 -26
  412. package/lib/node/events/eventsServerLogProvider.d.ts +2 -2
  413. package/lib/node/events/eventsServerLogProvider.d.ts.map +1 -1
  414. package/lib/node/events/eventsServerLogProvider.js +17 -10
  415. package/lib/node/events/fetchLogs.d.ts +1 -1
  416. package/lib/node/events/fetchLogs.d.ts.map +1 -1
  417. package/lib/node/events/fetchLogs.js +4 -2
  418. package/lib/node/events/parse.d.ts.map +1 -1
  419. package/lib/node/events/parse.js +14 -14
  420. package/lib/node/events/pollingLogProvider.d.ts +2 -2
  421. package/lib/node/events/pollingLogProvider.d.ts.map +1 -1
  422. package/lib/node/events/pollingLogProvider.js +1 -0
  423. package/lib/node/events/txEventCache.d.ts +3 -3
  424. package/lib/node/events/txEventCache.d.ts.map +1 -1
  425. package/lib/node/events/txEventCache.js +6 -2
  426. package/lib/node/events/types.d.ts +3 -7
  427. package/lib/node/events/types.d.ts.map +1 -1
  428. package/lib/node/events/types.js +1 -3
  429. package/lib/node/events/webSocketLogProvider.d.ts +2 -2
  430. package/lib/node/events/webSocketLogProvider.d.ts.map +1 -1
  431. package/lib/node/events/webSocketLogProvider.js +5 -2
  432. package/lib/node/factory/bigNum.js +1 -1
  433. package/lib/{browser/idl/drift.d.ts → node/idl/velocity.d.ts} +2413 -2480
  434. package/lib/node/idl/velocity.d.ts.map +1 -0
  435. package/lib/node/idl/{drift.json → velocity.json} +2265 -2333
  436. package/lib/node/index.d.ts +1 -3
  437. package/lib/node/index.d.ts.map +1 -1
  438. package/lib/node/index.js +1 -4
  439. package/lib/node/jupiter/jupiterClient.d.ts +1 -1
  440. package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
  441. package/lib/node/jupiter/jupiterClient.js +18 -8
  442. package/lib/node/marginCalculation.d.ts.map +1 -1
  443. package/lib/node/marginCalculation.js +1 -0
  444. package/lib/node/math/amm.d.ts +31 -13
  445. package/lib/node/math/amm.d.ts.map +1 -1
  446. package/lib/node/math/amm.js +87 -31
  447. package/lib/node/math/auction.d.ts.map +1 -1
  448. package/lib/node/math/auction.js +16 -12
  449. package/lib/node/math/bankruptcy.js +1 -1
  450. package/lib/node/math/builder.d.ts +18 -1
  451. package/lib/node/math/builder.d.ts.map +1 -1
  452. package/lib/node/math/builder.js +32 -1
  453. package/lib/node/math/funding.d.ts.map +1 -1
  454. package/lib/node/math/funding.js +30 -30
  455. package/lib/node/math/insurance.d.ts +1 -1
  456. package/lib/node/math/insurance.d.ts.map +1 -1
  457. package/lib/node/math/insurance.js +4 -5
  458. package/lib/node/math/margin.d.ts +3 -11
  459. package/lib/node/math/margin.d.ts.map +1 -1
  460. package/lib/node/math/margin.js +10 -69
  461. package/lib/node/math/market.d.ts +4 -12
  462. package/lib/node/math/market.d.ts.map +1 -1
  463. package/lib/node/math/market.js +12 -46
  464. package/lib/node/math/oracles.d.ts +4 -7
  465. package/lib/node/math/oracles.d.ts.map +1 -1
  466. package/lib/node/math/oracles.js +24 -37
  467. package/lib/node/math/orders.d.ts +2 -7
  468. package/lib/node/math/orders.d.ts.map +1 -1
  469. package/lib/node/math/orders.js +9 -81
  470. package/lib/node/math/position.d.ts +1 -5
  471. package/lib/node/math/position.d.ts.map +1 -1
  472. package/lib/node/math/position.js +6 -11
  473. package/lib/node/math/repeg.d.ts +0 -1
  474. package/lib/node/math/repeg.d.ts.map +1 -1
  475. package/lib/node/math/repeg.js +1 -23
  476. package/lib/node/math/spotBalance.d.ts +4 -4
  477. package/lib/node/math/spotBalance.d.ts.map +1 -1
  478. package/lib/node/math/spotBalance.js +6 -6
  479. package/lib/node/math/spotMarket.d.ts +0 -6
  480. package/lib/node/math/spotMarket.d.ts.map +1 -1
  481. package/lib/node/math/spotMarket.js +1 -16
  482. package/lib/node/math/spotPosition.d.ts +4 -4
  483. package/lib/node/math/spotPosition.d.ts.map +1 -1
  484. package/lib/node/math/state.d.ts +0 -2
  485. package/lib/node/math/state.d.ts.map +1 -1
  486. package/lib/node/math/state.js +1 -9
  487. package/lib/node/math/superStake.d.ts +11 -63
  488. package/lib/node/math/superStake.d.ts.map +1 -1
  489. package/lib/node/math/superStake.js +29 -28
  490. package/lib/node/math/trade.d.ts +2 -2
  491. package/lib/node/math/trade.d.ts.map +1 -1
  492. package/lib/node/math/trade.js +7 -7
  493. package/lib/node/math/utils.d.ts +1 -1
  494. package/lib/node/math/utils.js +1 -1
  495. package/lib/node/memcmp.d.ts +0 -1
  496. package/lib/node/memcmp.d.ts.map +1 -1
  497. package/lib/node/memcmp.js +1 -10
  498. package/lib/node/oracles/oracleClientCache.d.ts +1 -1
  499. package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
  500. package/lib/node/oracles/prelaunchOracleClient.js +3 -2
  501. package/lib/node/oracles/pythClient.d.ts.map +1 -1
  502. package/lib/node/oracles/pythClient.js +9 -3
  503. package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
  504. package/lib/node/oracles/pythLazerClient.js +5 -4
  505. package/lib/node/oracles/utils.d.ts +4 -0
  506. package/lib/node/oracles/utils.d.ts.map +1 -1
  507. package/lib/node/oracles/utils.js +9 -1
  508. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +1 -3
  509. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  510. package/lib/node/orderSubscriber/OrderSubscriber.js +16 -14
  511. package/lib/node/orderSubscriber/WebsocketSubscription.js +1 -1
  512. package/lib/node/orderSubscriber/grpcSubscription.js +2 -2
  513. package/lib/node/orderSubscriber/types.d.ts +0 -2
  514. package/lib/node/orderSubscriber/types.d.ts.map +1 -1
  515. package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +1 -1
  516. package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts.map +1 -1
  517. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +2 -6
  518. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
  519. package/lib/node/priorityFee/priorityFeeSubscriber.js +34 -18
  520. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +0 -4
  521. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
  522. package/lib/node/priorityFee/priorityFeeSubscriberMap.js +3 -11
  523. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +1 -1
  524. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts.map +1 -1
  525. package/lib/node/priorityFee/types.d.ts +3 -8
  526. package/lib/node/priorityFee/types.d.ts.map +1 -1
  527. package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts +0 -8
  528. package/lib/node/priorityFee/velocityPriorityFeeMethod.d.ts.map +1 -1
  529. package/lib/node/priorityFee/velocityPriorityFeeMethod.js +1 -3
  530. package/lib/node/pyth/pythLazerSubscriber.d.ts +1 -1
  531. package/lib/node/pyth/pythLazerSubscriber.js +1 -1
  532. package/lib/node/pyth/types.d.ts +0 -1
  533. package/lib/node/pyth/types.d.ts.map +1 -1
  534. package/lib/node/slot/SlotSubscriber.d.ts +1 -1
  535. package/lib/node/slot/SlotSubscriber.d.ts.map +1 -1
  536. package/lib/node/slot/SlotSubscriber.js +2 -1
  537. package/lib/node/slot/SlothashSubscriber.d.ts +3 -2
  538. package/lib/node/slot/SlothashSubscriber.d.ts.map +1 -1
  539. package/lib/node/slot/SlothashSubscriber.js +11 -4
  540. package/lib/node/swap/UnifiedSwapClient.js +1 -1
  541. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +0 -3
  542. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
  543. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +5 -5
  544. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +7 -7
  545. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
  546. package/lib/node/swift/signedMsgUserAccountSubscriber.js +14 -10
  547. package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -6
  548. package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
  549. package/lib/node/swift/swiftOrderSubscriber.js +15 -16
  550. package/lib/node/testClient.js +3 -2
  551. package/lib/node/tokenFaucet.d.ts.map +1 -1
  552. package/lib/node/tokenFaucet.js +16 -2
  553. package/lib/node/tx/baseTxSender.d.ts +4 -4
  554. package/lib/node/tx/baseTxSender.d.ts.map +1 -1
  555. package/lib/node/tx/baseTxSender.js +5 -4
  556. package/lib/node/tx/fastSingleTxSender.d.ts +3 -3
  557. package/lib/node/tx/fastSingleTxSender.d.ts.map +1 -1
  558. package/lib/node/tx/fastSingleTxSender.js +9 -5
  559. package/lib/node/tx/reportTransactionError.d.ts +2 -2
  560. package/lib/node/tx/reportTransactionError.d.ts.map +1 -1
  561. package/lib/node/tx/reportTransactionError.js +5 -1
  562. package/lib/node/tx/retryTxSender.d.ts +1 -1
  563. package/lib/node/tx/retryTxSender.d.ts.map +1 -1
  564. package/lib/node/tx/retryTxSender.js +4 -2
  565. package/lib/node/tx/txHandler.d.ts +9 -3
  566. package/lib/node/tx/txHandler.d.ts.map +1 -1
  567. package/lib/node/tx/txHandler.js +54 -40
  568. package/lib/node/tx/txParamProcessor.d.ts +4 -1
  569. package/lib/node/tx/txParamProcessor.d.ts.map +1 -1
  570. package/lib/node/tx/txParamProcessor.js +6 -0
  571. package/lib/node/tx/types.d.ts +1 -1
  572. package/lib/node/tx/types.d.ts.map +1 -1
  573. package/lib/node/tx/whileValidTxSender.d.ts +1 -6
  574. package/lib/node/tx/whileValidTxSender.d.ts.map +1 -1
  575. package/lib/node/tx/whileValidTxSender.js +35 -13
  576. package/lib/node/types.d.ts +100 -155
  577. package/lib/node/types.d.ts.map +1 -1
  578. package/lib/node/types.js +6 -2
  579. package/lib/node/user.d.ts +22 -10
  580. package/lib/node/user.d.ts.map +1 -1
  581. package/lib/node/user.js +174 -154
  582. package/lib/node/userConfig.d.ts +3 -2
  583. package/lib/node/userConfig.d.ts.map +1 -1
  584. package/lib/node/userMap/WebsocketSubscription.d.ts +1 -1
  585. package/lib/node/userMap/WebsocketSubscription.d.ts.map +1 -1
  586. package/lib/node/userMap/WebsocketSubscription.js +1 -1
  587. package/lib/node/userMap/grpcSubscription.d.ts +1 -1
  588. package/lib/node/userMap/grpcSubscription.d.ts.map +1 -1
  589. package/lib/node/userMap/grpcSubscription.js +1 -1
  590. package/lib/node/userMap/referrerMap.d.ts +0 -2
  591. package/lib/node/userMap/referrerMap.d.ts.map +1 -1
  592. package/lib/node/userMap/referrerMap.js +10 -7
  593. package/lib/node/userMap/revenueShareEscrowMap.d.ts +0 -2
  594. package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
  595. package/lib/node/userMap/revenueShareEscrowMap.js +4 -4
  596. package/lib/node/userMap/userMap.d.ts +3 -5
  597. package/lib/node/userMap/userMap.d.ts.map +1 -1
  598. package/lib/node/userMap/userMap.js +39 -30
  599. package/lib/node/userMap/userMapConfig.d.ts +3 -2
  600. package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
  601. package/lib/node/userMap/userStatsMap.d.ts +1 -3
  602. package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
  603. package/lib/node/userMap/userStatsMap.js +18 -17
  604. package/lib/node/userStats.d.ts +7 -4
  605. package/lib/node/userStats.d.ts.map +1 -1
  606. package/lib/node/userStats.js +28 -18
  607. package/lib/node/userStatsConfig.d.ts +3 -2
  608. package/lib/node/userStatsConfig.d.ts.map +1 -1
  609. package/lib/node/util/TransactionConfirmationManager.d.ts.map +1 -1
  610. package/lib/node/util/TransactionConfirmationManager.js +4 -2
  611. package/lib/node/util/chainClock.d.ts +1 -1
  612. package/lib/node/util/chainClock.d.ts.map +1 -1
  613. package/lib/node/util/computeUnits.d.ts +1 -1
  614. package/lib/node/util/computeUnits.d.ts.map +1 -1
  615. package/lib/node/util/computeUnits.js +6 -1
  616. package/lib/node/util/ed25519Utils.d.ts +1 -1
  617. package/lib/node/util/ed25519Utils.js +1 -1
  618. package/lib/node/velocityClient.d.ts +145 -72
  619. package/lib/node/velocityClient.d.ts.map +1 -1
  620. package/lib/node/velocityClient.js +653 -457
  621. package/lib/node/velocityClientConfig.d.ts +0 -8
  622. package/lib/node/velocityClientConfig.d.ts.map +1 -1
  623. package/package.json +10 -9
  624. package/scripts/deposit-isolated-positions.ts +2 -2
  625. package/scripts/find-flagged-users.ts +1 -1
  626. package/scripts/grpc-client-test-comparison.ts +4 -4
  627. package/scripts/grpc-multiuser-client-test-comparison.ts +2 -2
  628. package/scripts/single-grpc-client-test.ts +3 -3
  629. package/scripts/updateVersion.js +4 -4
  630. package/scripts/withdraw-isolated-positions.ts +2 -2
  631. package/src/accounts/basicUserAccountSubscriber.ts +7 -5
  632. package/src/accounts/basicUserStatsAccountSubscriber.ts +9 -5
  633. package/src/accounts/bulkAccountLoader.ts +20 -7
  634. package/src/accounts/grpcAccountSubscriber.ts +11 -3
  635. package/src/accounts/grpcMultiAccountSubscriber.ts +24 -9
  636. package/src/accounts/grpcMultiUserAccountSubscriber.ts +16 -12
  637. package/src/accounts/grpcProgramAccountSubscriber.ts +12 -4
  638. package/src/accounts/grpcVelocityClientAccountSubscriber.ts +17 -14
  639. package/src/accounts/grpcVelocityClientAccountSubscriberV2.ts +69 -49
  640. package/src/accounts/laserProgramAccountSubscriber.ts +4 -1
  641. package/src/accounts/oneShotUserAccountSubscriber.ts +5 -3
  642. package/src/accounts/oneShotUserStatsAccountSubscriber.ts +8 -3
  643. package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +11 -5
  644. package/src/accounts/pollingOracleAccountSubscriber.ts +17 -10
  645. package/src/accounts/pollingTokenAccountSubscriber.ts +17 -10
  646. package/src/accounts/pollingUserAccountSubscriber.ts +26 -20
  647. package/src/accounts/pollingUserStatsAccountSubscriber.ts +12 -10
  648. package/src/accounts/pollingVelocityClientAccountSubscriber.ts +80 -41
  649. package/src/accounts/types.ts +8 -13
  650. package/src/accounts/utils.ts +12 -2
  651. package/src/accounts/webSocketAccountSubscriber.ts +23 -10
  652. package/src/accounts/webSocketAccountSubscriberV2.ts +23 -8
  653. package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +17 -2
  654. package/src/accounts/webSocketProgramAccountSubscriber.ts +29 -4
  655. package/src/accounts/webSocketProgramAccountSubscriberV2.ts +30 -4
  656. package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +29 -4
  657. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -2
  658. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +15 -2
  659. package/src/accounts/webSocketVelocityClientAccountSubscriber.ts +79 -58
  660. package/src/accounts/webSocketVelocityClientAccountSubscriberV2.ts +77 -45
  661. package/src/accounts/websocketProgramUserAccountSubscriber.ts +1 -6
  662. package/src/addresses/marketAddresses.ts +3 -2
  663. package/src/addresses/pda.ts +3 -38
  664. package/src/adminClient.ts +285 -315
  665. package/src/auctionSubscriber/auctionSubscriber.ts +8 -11
  666. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +13 -11
  667. package/src/auctionSubscriber/types.ts +3 -3
  668. package/src/bankrun/bankrunConnection.ts +83 -39
  669. package/src/blockhashSubscriber/BlockhashSubscriber.ts +5 -4
  670. package/src/clock/clockSubscriber.ts +10 -9
  671. package/src/config.ts +16 -70
  672. package/src/constants/index.ts +1 -2
  673. package/src/constants/numericConstants.ts +3 -3
  674. package/src/constituentMap/constituentMap.ts +10 -7
  675. package/src/constituentMap/pollingConstituentAccountSubscriber.ts +4 -2
  676. package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +13 -4
  677. package/src/core/VelocityCore.ts +11 -20
  678. package/src/core/instructions/perpOrders.ts +14 -0
  679. package/src/core/instructions/withdraw.ts +2 -2
  680. package/src/core/remainingAccounts.ts +7 -7
  681. package/src/decode/user.ts +8 -1
  682. package/src/dlob/DLOB.ts +300 -176
  683. package/src/dlob/DLOBNode.ts +23 -3
  684. package/src/dlob/DLOBSubscriber.ts +53 -42
  685. package/src/dlob/NodeList.ts +8 -7
  686. package/src/dlob/orderBookLevels.ts +51 -25
  687. package/src/dlob/types.ts +0 -2
  688. package/src/events/eventList.ts +4 -1
  689. package/src/events/eventSubscriber.ts +108 -50
  690. package/src/events/eventsServerLogProvider.ts +24 -15
  691. package/src/events/fetchLogs.ts +3 -3
  692. package/src/events/parse.ts +14 -14
  693. package/src/events/pollingLogProvider.ts +2 -2
  694. package/src/events/txEventCache.ts +8 -2
  695. package/src/events/types.ts +4 -15
  696. package/src/events/webSocketLogProvider.ts +5 -3
  697. package/src/factory/bigNum.ts +2 -2
  698. package/src/idl/{drift.json → velocity.json} +2265 -2333
  699. package/src/idl/{drift.ts → velocity.ts} +2267 -2335
  700. package/src/index.ts +1 -6
  701. package/src/jupiter/jupiterClient.ts +30 -10
  702. package/src/margin/README.md +2 -2
  703. package/src/marginCalculation.ts +1 -0
  704. package/src/math/amm.ts +217 -40
  705. package/src/math/auction.ts +16 -12
  706. package/src/math/bankruptcy.ts +1 -1
  707. package/src/math/builder.ts +45 -1
  708. package/src/math/funding.ts +51 -47
  709. package/src/math/insurance.ts +6 -8
  710. package/src/math/margin.ts +12 -119
  711. package/src/math/market.ts +16 -98
  712. package/src/math/oracles.ts +29 -43
  713. package/src/math/orders.ts +13 -109
  714. package/src/math/position.ts +6 -12
  715. package/src/math/repeg.ts +0 -29
  716. package/src/math/spotBalance.ts +14 -10
  717. package/src/math/spotMarket.ts +2 -28
  718. package/src/math/spotPosition.ts +4 -4
  719. package/src/math/state.ts +0 -8
  720. package/src/math/superStake.ts +36 -85
  721. package/src/math/trade.ts +7 -3
  722. package/src/math/utils.ts +1 -1
  723. package/src/memcmp.ts +0 -9
  724. package/src/oracles/prelaunchOracleClient.ts +7 -2
  725. package/src/oracles/pythClient.ts +12 -3
  726. package/src/oracles/pythLazerClient.ts +10 -5
  727. package/src/oracles/utils.ts +15 -0
  728. package/src/orderSubscriber/OrderSubscriber.ts +12 -12
  729. package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
  730. package/src/orderSubscriber/grpcSubscription.ts +2 -2
  731. package/src/orderSubscriber/types.ts +0 -2
  732. package/src/priorityFee/heliusPriorityFeeMethod.ts +1 -1
  733. package/src/priorityFee/priorityFeeSubscriber.ts +50 -21
  734. package/src/priorityFee/priorityFeeSubscriberMap.ts +2 -10
  735. package/src/priorityFee/solanaPriorityFeeMethod.ts +1 -1
  736. package/src/priorityFee/types.ts +3 -13
  737. package/src/priorityFee/velocityPriorityFeeMethod.ts +0 -12
  738. package/src/pyth/pythLazerSubscriber.ts +1 -1
  739. package/src/pyth/types.ts +0 -2
  740. package/src/slot/SlotSubscriber.ts +3 -3
  741. package/src/slot/SlothashSubscriber.ts +17 -6
  742. package/src/swap/UnifiedSwapClient.ts +1 -1
  743. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +5 -6
  744. package/src/swift/signedMsgUserAccountSubscriber.ts +18 -16
  745. package/src/swift/swiftOrderSubscriber.ts +17 -21
  746. package/src/testClient.ts +2 -2
  747. package/src/tokenFaucet.ts +22 -3
  748. package/src/tx/baseTxSender.ts +10 -10
  749. package/src/tx/fastSingleTxSender.ts +12 -8
  750. package/src/tx/reportTransactionError.ts +12 -7
  751. package/src/tx/retryTxSender.ts +6 -4
  752. package/src/tx/txHandler.ts +88 -43
  753. package/src/tx/txParamProcessor.ts +18 -3
  754. package/src/tx/types.ts +1 -1
  755. package/src/tx/whileValidTxSender.ts +51 -22
  756. package/src/types.ts +119 -173
  757. package/src/user.ts +208 -165
  758. package/src/userConfig.ts +1 -3
  759. package/src/userMap/WebsocketSubscription.ts +2 -2
  760. package/src/userMap/grpcSubscription.ts +2 -2
  761. package/src/userMap/referrerMap.ts +13 -13
  762. package/src/userMap/revenueShareEscrowMap.ts +6 -5
  763. package/src/userMap/userMap.ts +46 -32
  764. package/src/userMap/userMapConfig.ts +3 -3
  765. package/src/userMap/userStatsMap.ts +32 -23
  766. package/src/userStats.ts +22 -13
  767. package/src/userStatsConfig.ts +3 -3
  768. package/src/util/TransactionConfirmationManager.ts +10 -2
  769. package/src/util/chainClock.ts +1 -1
  770. package/src/util/computeUnits.ts +7 -3
  771. package/src/util/ed25519Utils.ts +1 -1
  772. package/src/velocityClient.ts +867 -600
  773. package/src/velocityClientConfig.ts +0 -10
  774. package/tests/{DriftCore → VelocityCore}/decode.test.ts +1 -1
  775. package/tests/{DriftCore → VelocityCore}/fill_trigger.test.ts +1 -1
  776. package/tests/{DriftCore → VelocityCore}/instructions.test.ts +1 -1
  777. package/tests/{DriftCore → VelocityCore}/pdas.test.ts +4 -2
  778. package/tests/amm/test.ts +138 -0
  779. package/tests/ci/verifyConstants.ts +24 -27
  780. package/tests/decode/test.ts +2 -2
  781. package/tests/dlob/helpers.ts +11 -10
  782. package/tests/events/parseLogsForCuUsage.ts +15 -15
  783. package/tests/user/helpers.ts +9 -9
  784. package/tests/user/test.ts +13 -10
  785. package/tsconfig.json +1 -0
  786. package/lib/browser/constants/insuranceFund.d.ts +0 -5
  787. package/lib/browser/constants/insuranceFund.js +0 -9
  788. package/lib/browser/tx/forwardOnlyTxSender.d.ts +0 -37
  789. package/lib/browser/tx/forwardOnlyTxSender.js +0 -92
  790. package/lib/browser/util/deprecatedAlias.d.ts +0 -26
  791. package/lib/browser/util/deprecatedAlias.js +0 -10
  792. package/lib/browser/util/tps.d.ts +0 -2
  793. package/lib/browser/util/tps.js +0 -16
  794. package/lib/node/constants/insuranceFund.d.ts +0 -6
  795. package/lib/node/constants/insuranceFund.d.ts.map +0 -1
  796. package/lib/node/constants/insuranceFund.js +0 -9
  797. package/lib/node/idl/drift.d.ts.map +0 -1
  798. package/lib/node/tx/forwardOnlyTxSender.d.ts +0 -38
  799. package/lib/node/tx/forwardOnlyTxSender.d.ts.map +0 -1
  800. package/lib/node/tx/forwardOnlyTxSender.js +0 -92
  801. package/lib/node/util/deprecatedAlias.d.ts +0 -27
  802. package/lib/node/util/deprecatedAlias.d.ts.map +0 -1
  803. package/lib/node/util/deprecatedAlias.js +0 -10
  804. package/lib/node/util/tps.d.ts +0 -3
  805. package/lib/node/util/tps.d.ts.map +0 -1
  806. package/lib/node/util/tps.js +0 -16
  807. package/src/constants/insuranceFund.ts +0 -8
  808. package/src/tx/forwardOnlyTxSender.ts +0 -145
  809. package/src/util/deprecatedAlias.ts +0 -21
  810. package/src/util/tps.ts +0 -27
  811. /package/lib/browser/idl/{drift.js → velocity.js} +0 -0
  812. /package/lib/node/idl/{drift.js → velocity.js} +0 -0
  813. /package/tests/{DriftCore → VelocityCore}/perp_orders.test.ts +0 -0
  814. /package/tests/{DriftCore → VelocityCore}/remainingAccounts.test.ts +0 -0
  815. /package/tests/{DriftCore → VelocityCore}/settlement_liquidation.test.ts +0 -0
@@ -7,6 +7,7 @@
7
7
  * pause/unpause exchange, and all ~126 admin instruction handlers in `instructions/admin.rs`.
8
8
  */
9
9
  import {
10
+ AccountMeta,
10
11
  AddressLookupTableAccount,
11
12
  Keypair,
12
13
  LAMPORTS_PER_SOL,
@@ -24,7 +25,6 @@ import {
24
25
  MarketStatus,
25
26
  ContractTier,
26
27
  AssetTier,
27
- IfRebalanceConfigParams,
28
28
  TxParams,
29
29
  AddAmmConstituentMappingDatum,
30
30
  SwapReduceOnly,
@@ -32,6 +32,8 @@ import {
32
32
  ConstituentStatus,
33
33
  LPPoolAccount,
34
34
  TransferFeeAndPnlPoolDirection,
35
+ MarketType,
36
+ SpotMarketAccount,
35
37
  } from './types';
36
38
  import { DEFAULT_MARKET_NAME, encodeName } from './userName';
37
39
  import { BN } from './isomorphic/anchor';
@@ -42,13 +44,10 @@ import {
42
44
  getSpotMarketVaultPublicKey,
43
45
  getPerpMarketPublicKey,
44
46
  getInsuranceFundVaultPublicKey,
45
- getProtocolIfSharesTransferConfigPublicKey,
46
47
  getPrelaunchOraclePublicKey,
47
48
  getUserStatsAccountPublicKey,
48
49
  getPythLazerOraclePublicKey,
49
50
  getTokenProgramForSpotMarket,
50
- getIfRebalanceConfigPublicKey,
51
- getInsuranceFundStakeAccountPublicKey,
52
51
  getLpPoolPublicKey,
53
52
  getAmmConstituentMappingPublicKey,
54
53
  getConstituentTargetBasePublicKey,
@@ -61,6 +60,7 @@ import {
61
60
  } from './addresses/pda';
62
61
  import { squareRootBN } from './math/utils';
63
62
  import {
63
+ ASSOCIATED_TOKEN_PROGRAM_ID,
64
64
  createInitializeMint2Instruction,
65
65
  createMintToInstruction,
66
66
  createTransferCheckedInstruction,
@@ -76,7 +76,6 @@ import {
76
76
  ONE,
77
77
  BASE_PRECISION,
78
78
  PRICE_PRECISION,
79
- GOV_SPOT_MARKET_INDEX,
80
79
  } from './constants/numericConstants';
81
80
  import { calculateTargetPriceTrade } from './math/trade';
82
81
  import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
@@ -95,7 +94,7 @@ export class AdminClient extends VelocityClient {
95
94
  throw new Error('Clearing house already initialized');
96
95
  }
97
96
 
98
- const [driftStatePublicKey] =
97
+ const [velocityStatePublicKey] =
99
98
  await getVelocityStateAccountPublicKeyAndNonce(this.program.programId);
100
99
 
101
100
  const initializeIx = await this.program.instruction.initialize({
@@ -103,10 +102,10 @@ export class AdminClient extends VelocityClient {
103
102
  admin: this.isSubscribed
104
103
  ? this.getStateAccount().coldAdmin
105
104
  : this.wallet.publicKey,
106
- state: driftStatePublicKey,
105
+ state: velocityStatePublicKey,
107
106
  quoteAssetMint: usdcMint,
108
107
  rent: SYSVAR_RENT_PUBKEY,
109
- driftSigner: this.getSignerPublicKey(),
108
+ velocitySigner: this.getSignerPublicKey(),
110
109
  systemProgram: anchor.web3.SystemProgram.programId,
111
110
  tokenProgram: TOKEN_PROGRAM_ID,
112
111
  },
@@ -226,7 +225,11 @@ export class AdminClient extends VelocityClient {
226
225
  spotMarketIndex
227
226
  );
228
227
 
229
- const tokenProgram = (await this.connection.getAccountInfo(mint)).owner;
228
+ const mintAccountInfo = await this.connection.getAccountInfo(mint);
229
+ if (!mintAccountInfo) {
230
+ throw new Error(`Mint account ${mint.toString()} not found`);
231
+ }
232
+ const tokenProgram = mintAccountInfo.owner;
230
233
 
231
234
  const nameBuffer = encodeName(name);
232
235
  const initializeIx = await this.program.instruction.initializeSpotMarket(
@@ -260,7 +263,7 @@ export class AdminClient extends VelocityClient {
260
263
  spotMarket,
261
264
  spotMarketVault,
262
265
  insuranceFundVault,
263
- driftSigner: this.getSignerPublicKey(),
266
+ velocitySigner: this.getSignerPublicKey(),
264
267
  spotMarketMint: mint,
265
268
  oracle,
266
269
  rent: SYSVAR_RENT_PUBKEY,
@@ -315,7 +318,7 @@ export class AdminClient extends VelocityClient {
315
318
  spotMarket: spotMarketPublicKey,
316
319
  spotMarketVault: spotMarketVaultPublicKey,
317
320
  insuranceFundVault: insuranceFundVaultPublicKey,
318
- driftSigner: this.getSignerPublicKey(),
321
+ velocitySigner: this.getSignerPublicKey(),
319
322
  tokenProgram: TOKEN_PROGRAM_ID,
320
323
  },
321
324
  }
@@ -527,13 +530,14 @@ export class AdminClient extends VelocityClient {
527
530
  public async getAddMarketToAmmCacheIx(
528
531
  perpMarketIndex: number
529
532
  ): Promise<TransactionInstruction> {
533
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
530
534
  return await this.program.instruction.addMarketToAmmCache({
531
535
  accounts: {
532
536
  state: await this.getStatePublicKey(),
533
537
  admin: this.useHotWalletAdmin
534
538
  ? this.wallet.publicKey
535
539
  : this.getStateAccount().coldAdmin,
536
- perpMarket: this.getPerpMarketAccount(perpMarketIndex).pubkey,
540
+ perpMarket: perpMarketAccount.pubkey,
537
541
  ammCache: getAmmCachePublicKey(this.program.programId),
538
542
  rent: SYSVAR_RENT_PUBKEY,
539
543
  systemProgram: anchor.web3.SystemProgram.programId,
@@ -787,6 +791,7 @@ export class AdminClient extends VelocityClient {
787
791
  perpMarketIndex: number,
788
792
  sqrtK: BN
789
793
  ): Promise<TransactionInstruction> {
794
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
790
795
  return await this.program.instruction.updateK(sqrtK, {
791
796
  accounts: {
792
797
  state: await this.getStatePublicKey(),
@@ -797,7 +802,7 @@ export class AdminClient extends VelocityClient {
797
802
  this.program.programId,
798
803
  perpMarketIndex
799
804
  ),
800
- oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
805
+ oracle: perpMarketAccount.oracle,
801
806
  },
802
807
  });
803
808
  }
@@ -863,8 +868,9 @@ export class AdminClient extends VelocityClient {
863
868
 
864
869
  public async getRecenterPerpMarketAmmCrankIx(
865
870
  perpMarketIndex: number,
866
- depth: BN
871
+ depth?: BN
867
872
  ): Promise<TransactionInstruction> {
873
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
868
874
  return await this.program.instruction.recenterPerpMarketAmmCrank(
869
875
  depth ?? null,
870
876
  {
@@ -881,7 +887,7 @@ export class AdminClient extends VelocityClient {
881
887
  this.program.programId,
882
888
  QUOTE_SPOT_MARKET_INDEX
883
889
  ),
884
- oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
890
+ oracle: perpMarketAccount.oracle,
885
891
  },
886
892
  }
887
893
  );
@@ -1015,7 +1021,7 @@ export class AdminClient extends VelocityClient {
1015
1021
  perpMarketIndex: number,
1016
1022
  targetPrice: BN
1017
1023
  ): Promise<TransactionInstruction> {
1018
- const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
1024
+ const perpMarket = this.getPerpMarketAccountOrThrow(perpMarketIndex);
1019
1025
 
1020
1026
  const [direction, tradeSize, _] = calculateTargetPriceTrade(
1021
1027
  perpMarket,
@@ -1078,7 +1084,7 @@ export class AdminClient extends VelocityClient {
1078
1084
  this.program.programId,
1079
1085
  perpMarketIndex
1080
1086
  );
1081
- const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
1087
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
1082
1088
 
1083
1089
  return await this.program.instruction.repegAmmCurve(newPeg, {
1084
1090
  accounts: {
@@ -1086,7 +1092,7 @@ export class AdminClient extends VelocityClient {
1086
1092
  admin: this.isSubscribed
1087
1093
  ? this.getStateAccount().coldAdmin
1088
1094
  : this.wallet.publicKey,
1089
- oracle: ammData.oracle,
1095
+ oracle: perpMarketAccount.oracle,
1090
1096
  perpMarket: perpMarketPublicKey,
1091
1097
  },
1092
1098
  });
@@ -1108,7 +1114,7 @@ export class AdminClient extends VelocityClient {
1108
1114
  public async getUpdatePerpMarketAmmOracleTwapIx(
1109
1115
  perpMarketIndex: number
1110
1116
  ): Promise<TransactionInstruction> {
1111
- const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
1117
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
1112
1118
  const perpMarketPublicKey = await getPerpMarketPublicKey(
1113
1119
  this.program.programId,
1114
1120
  perpMarketIndex
@@ -1120,7 +1126,7 @@ export class AdminClient extends VelocityClient {
1120
1126
  admin: this.isSubscribed
1121
1127
  ? this.getStateAccount().coldAdmin
1122
1128
  : this.wallet.publicKey,
1123
- oracle: ammData.oracle,
1129
+ oracle: perpMarketAccount.oracle,
1124
1130
  perpMarket: perpMarketPublicKey,
1125
1131
  },
1126
1132
  });
@@ -1142,7 +1148,7 @@ export class AdminClient extends VelocityClient {
1142
1148
  public async getResetPerpMarketAmmOracleTwapIx(
1143
1149
  perpMarketIndex: number
1144
1150
  ): Promise<TransactionInstruction> {
1145
- const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
1151
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
1146
1152
  const perpMarketPublicKey = await getPerpMarketPublicKey(
1147
1153
  this.program.programId,
1148
1154
  perpMarketIndex
@@ -1154,7 +1160,7 @@ export class AdminClient extends VelocityClient {
1154
1160
  admin: this.isSubscribed
1155
1161
  ? this.getStateAccount().coldAdmin
1156
1162
  : this.wallet.publicKey,
1157
- oracle: ammData.oracle,
1163
+ oracle: perpMarketAccount.oracle,
1158
1164
  perpMarket: perpMarketPublicKey,
1159
1165
  },
1160
1166
  });
@@ -1204,7 +1210,7 @@ export class AdminClient extends VelocityClient {
1204
1210
  perpMarketIndex
1205
1211
  ),
1206
1212
  sourceVault,
1207
- driftSigner: this.getSignerPublicKey(),
1213
+ velocitySigner: this.getSignerPublicKey(),
1208
1214
  quoteSpotMarket: spotMarket.pubkey,
1209
1215
  spotMarketVault: spotMarket.vault,
1210
1216
  tokenProgram: TOKEN_PROGRAM_ID,
@@ -1273,9 +1279,9 @@ export class AdminClient extends VelocityClient {
1273
1279
  amount: BN,
1274
1280
  sourceVault: PublicKey
1275
1281
  ): Promise<TransactionInstruction> {
1276
- const spotMarket = this.getSpotMarketAccount(spotMarketIndex);
1282
+ const spotMarket = this.getSpotMarketAccountOrThrow(spotMarketIndex);
1277
1283
 
1278
- const remainingAccounts = [];
1284
+ const remainingAccounts: AccountMeta[] = [];
1279
1285
  this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
1280
1286
  if (this.isTransferHook(spotMarket)) {
1281
1287
  await this.addExtraAccountMetasToRemainingAccounts(
@@ -1425,15 +1431,13 @@ export class AdminClient extends VelocityClient {
1425
1431
  public async updatePerpMarketAmmSummaryStats(
1426
1432
  perpMarketIndex: number,
1427
1433
  updateAmmSummaryStats?: boolean,
1428
- netUnsettledFundingPnl?: BN,
1429
- excludeTotalLiqFee?: boolean
1434
+ netUnsettledFundingPnl?: BN
1430
1435
  ): Promise<TransactionSignature> {
1431
1436
  const updatePerpMarketMarginRatioIx =
1432
1437
  await this.getUpdatePerpMarketAmmSummaryStatsIx(
1433
1438
  perpMarketIndex,
1434
1439
  updateAmmSummaryStats,
1435
- netUnsettledFundingPnl,
1436
- excludeTotalLiqFee
1440
+ netUnsettledFundingPnl
1437
1441
  );
1438
1442
 
1439
1443
  const tx = await this.buildTransaction(updatePerpMarketMarginRatioIx);
@@ -1446,14 +1450,13 @@ export class AdminClient extends VelocityClient {
1446
1450
  public async getUpdatePerpMarketAmmSummaryStatsIx(
1447
1451
  perpMarketIndex: number,
1448
1452
  updateAmmSummaryStats?: boolean,
1449
- netUnsettledFundingPnl?: BN,
1450
- excludeTotalLiqFee?: boolean
1453
+ netUnsettledFundingPnl?: BN
1451
1454
  ): Promise<TransactionInstruction> {
1455
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
1452
1456
  return await this.program.instruction.updatePerpMarketAmmSummaryStats(
1453
1457
  {
1454
1458
  updateAmmSummaryStats: updateAmmSummaryStats ?? null,
1455
1459
  netUnsettledFundingPnl: netUnsettledFundingPnl ?? null,
1456
- excludeTotalLiqFee: excludeTotalLiqFee ?? null,
1457
1460
  },
1458
1461
  {
1459
1462
  accounts: {
@@ -1469,7 +1472,7 @@ export class AdminClient extends VelocityClient {
1469
1472
  this.program.programId,
1470
1473
  QUOTE_SPOT_MARKET_INDEX
1471
1474
  ),
1472
- oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
1475
+ oracle: perpMarketAccount.oracle,
1473
1476
  },
1474
1477
  }
1475
1478
  );
@@ -2053,12 +2056,14 @@ export class AdminClient extends VelocityClient {
2053
2056
 
2054
2057
  public async updateWithdrawGuardThreshold(
2055
2058
  spotMarketIndex: number,
2056
- withdrawGuardThreshold: BN
2059
+ withdrawGuardThreshold: BN,
2060
+ oracle?: PublicKey
2057
2061
  ): Promise<TransactionSignature> {
2058
2062
  const updateWithdrawGuardThresholdIx =
2059
2063
  await this.getUpdateWithdrawGuardThresholdIx(
2060
2064
  spotMarketIndex,
2061
- withdrawGuardThreshold
2065
+ withdrawGuardThreshold,
2066
+ oracle
2062
2067
  );
2063
2068
 
2064
2069
  const tx = await this.buildTransaction(updateWithdrawGuardThresholdIx);
@@ -2070,8 +2075,39 @@ export class AdminClient extends VelocityClient {
2070
2075
 
2071
2076
  public async getUpdateWithdrawGuardThresholdIx(
2072
2077
  spotMarketIndex: number,
2073
- withdrawGuardThreshold: BN
2078
+ withdrawGuardThreshold: BN,
2079
+ oracle?: PublicKey
2074
2080
  ): Promise<TransactionInstruction> {
2081
+ const spotMarketPublicKey = await getSpotMarketPublicKey(
2082
+ this.program.programId,
2083
+ spotMarketIndex
2084
+ );
2085
+
2086
+ if (!oracle) {
2087
+ const cachedSpotMarket = this.isSubscribed
2088
+ ? this.getSpotMarketAccount(spotMarketIndex)
2089
+ : undefined;
2090
+ if (cachedSpotMarket) {
2091
+ oracle = cachedSpotMarket.oracle;
2092
+ } else {
2093
+ const accountInfo = await this.connection.getAccountInfo(
2094
+ spotMarketPublicKey
2095
+ );
2096
+ if (!accountInfo) {
2097
+ throw new Error(
2098
+ `Spot market account not found: ${spotMarketPublicKey.toString()}`
2099
+ );
2100
+ }
2101
+ const spotMarket = (
2102
+ this.program.account as any
2103
+ ).spotMarket.coder.accounts.decodeUnchecked(
2104
+ 'spotMarket',
2105
+ accountInfo.data
2106
+ ) as SpotMarketAccount;
2107
+ oracle = spotMarket.oracle;
2108
+ }
2109
+ }
2110
+
2075
2111
  return await this.program.instruction.updateWithdrawGuardThreshold(
2076
2112
  withdrawGuardThreshold,
2077
2113
  {
@@ -2080,10 +2116,8 @@ export class AdminClient extends VelocityClient {
2080
2116
  ? this.getStateAccount().coldAdmin
2081
2117
  : this.wallet.publicKey,
2082
2118
  state: await this.getStatePublicKey(),
2083
- spotMarket: await getSpotMarketPublicKey(
2084
- this.program.programId,
2085
- spotMarketIndex
2086
- ),
2119
+ spotMarket: spotMarketPublicKey,
2120
+ oracle,
2087
2121
  },
2088
2122
  }
2089
2123
  );
@@ -2091,13 +2125,13 @@ export class AdminClient extends VelocityClient {
2091
2125
 
2092
2126
  public async updateSpotMarketIfFactor(
2093
2127
  spotMarketIndex: number,
2094
- userIfFactor: BN,
2095
- totalIfFactor: BN
2128
+ ifFeeFactor: number,
2129
+ protocolFeeFactor: number
2096
2130
  ): Promise<TransactionSignature> {
2097
2131
  const updateSpotMarketIfFactorIx = await this.getUpdateSpotMarketIfFactorIx(
2098
2132
  spotMarketIndex,
2099
- userIfFactor,
2100
- totalIfFactor
2133
+ ifFeeFactor,
2134
+ protocolFeeFactor
2101
2135
  );
2102
2136
 
2103
2137
  const tx = await this.buildTransaction(updateSpotMarketIfFactorIx);
@@ -2109,13 +2143,13 @@ export class AdminClient extends VelocityClient {
2109
2143
 
2110
2144
  public async getUpdateSpotMarketIfFactorIx(
2111
2145
  spotMarketIndex: number,
2112
- userIfFactor: BN,
2113
- totalIfFactor: BN
2146
+ ifFeeFactor: number,
2147
+ protocolFeeFactor: number
2114
2148
  ): Promise<TransactionInstruction> {
2115
2149
  return await this.program.instruction.updateSpotMarketIfFactor(
2116
2150
  spotMarketIndex,
2117
- userIfFactor,
2118
- totalIfFactor,
2151
+ ifFeeFactor,
2152
+ protocolFeeFactor,
2119
2153
  {
2120
2154
  accounts: {
2121
2155
  admin: this.isSubscribed
@@ -2353,6 +2387,7 @@ export class AdminClient extends VelocityClient {
2353
2387
  oracleSource: OracleSource,
2354
2388
  skipInvaraintCheck = false
2355
2389
  ): Promise<TransactionInstruction> {
2390
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
2356
2391
  return await this.program.instruction.updatePerpMarketOracle(
2357
2392
  oracle,
2358
2393
  oracleSource,
@@ -2368,7 +2403,7 @@ export class AdminClient extends VelocityClient {
2368
2403
  perpMarketIndex
2369
2404
  ),
2370
2405
  oracle: oracle,
2371
- oldOracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
2406
+ oldOracle: perpMarketAccount.oracle,
2372
2407
  ammCache: getAmmCachePublicKey(this.program.programId),
2373
2408
  },
2374
2409
  }
@@ -2603,6 +2638,7 @@ export class AdminClient extends VelocityClient {
2603
2638
  oracleSource: OracleSource,
2604
2639
  skipInvaraintCheck = false
2605
2640
  ): Promise<TransactionInstruction> {
2641
+ const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
2606
2642
  return await this.program.instruction.updateSpotMarketOracle(
2607
2643
  oracle,
2608
2644
  oracleSource,
@@ -2618,7 +2654,7 @@ export class AdminClient extends VelocityClient {
2618
2654
  spotMarketIndex
2619
2655
  ),
2620
2656
  oracle: oracle,
2621
- oldOracle: this.getSpotMarketAccount(spotMarketIndex).oracle,
2657
+ oldOracle: spotMarketAccount.oracle,
2622
2658
  },
2623
2659
  }
2624
2660
  );
@@ -3255,6 +3291,7 @@ export class AdminClient extends VelocityClient {
3255
3291
  perpMarketIndex: number,
3256
3292
  maxSlippageRatio: number
3257
3293
  ): Promise<TransactionInstruction> {
3294
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(perpMarketIndex);
3258
3295
  return await (this.program.instruction as any).updateMaxSlippageRatio(
3259
3296
  maxSlippageRatio,
3260
3297
  {
@@ -3263,7 +3300,7 @@ export class AdminClient extends VelocityClient {
3263
3300
  ? this.getStateAccount().coldAdmin
3264
3301
  : this.wallet.publicKey,
3265
3302
  state: await this.getStatePublicKey(),
3266
- perpMarket: this.getPerpMarketAccount(perpMarketIndex).pubkey,
3303
+ perpMarket: perpMarketAccount.pubkey,
3267
3304
  },
3268
3305
  }
3269
3306
  );
@@ -3477,6 +3514,46 @@ export class AdminClient extends VelocityClient {
3477
3514
  );
3478
3515
  }
3479
3516
 
3517
+ public async updatePerpMarketFeePoolBufferTarget(
3518
+ perpMarketIndex: number,
3519
+ feePoolBufferTarget: BN
3520
+ ): Promise<TransactionSignature> {
3521
+ const updatePerpMarketFeePoolBufferTargetIx =
3522
+ await this.getUpdatePerpMarketFeePoolBufferTargetIx(
3523
+ perpMarketIndex,
3524
+ feePoolBufferTarget
3525
+ );
3526
+
3527
+ const tx = await this.buildTransaction(
3528
+ updatePerpMarketFeePoolBufferTargetIx
3529
+ );
3530
+
3531
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3532
+
3533
+ return txSig;
3534
+ }
3535
+
3536
+ public async getUpdatePerpMarketFeePoolBufferTargetIx(
3537
+ perpMarketIndex: number,
3538
+ feePoolBufferTarget: BN
3539
+ ): Promise<TransactionInstruction> {
3540
+ return await this.program.instruction.updatePerpMarketFeePoolBufferTarget(
3541
+ feePoolBufferTarget,
3542
+ {
3543
+ accounts: {
3544
+ admin: this.isSubscribed
3545
+ ? this.getStateAccount().coldAdmin
3546
+ : this.wallet.publicKey,
3547
+ state: await this.getStatePublicKey(),
3548
+ perpMarket: await getPerpMarketPublicKey(
3549
+ this.program.programId,
3550
+ perpMarketIndex
3551
+ ),
3552
+ },
3553
+ }
3554
+ );
3555
+ }
3556
+
3480
3557
  public async updateSpotMarketFeeAdjustment(
3481
3558
  perpMarketIndex: number,
3482
3559
  feeAdjustment: number
@@ -3518,13 +3595,15 @@ export class AdminClient extends VelocityClient {
3518
3595
  public async updatePerpMarketLiquidationFee(
3519
3596
  perpMarketIndex: number,
3520
3597
  liquidatorFee: number,
3521
- ifLiquidationFee: number
3598
+ ifLiquidationFee: number,
3599
+ protocolLiquidationFee = 0
3522
3600
  ): Promise<TransactionSignature> {
3523
3601
  const updatePerpMarketLiquidationFeeIx =
3524
3602
  await this.getUpdatePerpMarketLiquidationFeeIx(
3525
3603
  perpMarketIndex,
3526
3604
  liquidatorFee,
3527
- ifLiquidationFee
3605
+ ifLiquidationFee,
3606
+ protocolLiquidationFee
3528
3607
  );
3529
3608
 
3530
3609
  const tx = await this.buildTransaction(updatePerpMarketLiquidationFeeIx);
@@ -3537,11 +3616,13 @@ export class AdminClient extends VelocityClient {
3537
3616
  public async getUpdatePerpMarketLiquidationFeeIx(
3538
3617
  perpMarketIndex: number,
3539
3618
  liquidatorFee: number,
3540
- ifLiquidationFee: number
3619
+ ifLiquidationFee: number,
3620
+ protocolLiquidationFee = 0
3541
3621
  ): Promise<TransactionInstruction> {
3542
3622
  return await this.program.instruction.updatePerpMarketLiquidationFee(
3543
3623
  liquidatorFee,
3544
3624
  ifLiquidationFee,
3625
+ protocolLiquidationFee,
3545
3626
  {
3546
3627
  accounts: {
3547
3628
  admin: this.isSubscribed
@@ -3560,13 +3641,15 @@ export class AdminClient extends VelocityClient {
3560
3641
  public async updateSpotMarketLiquidationFee(
3561
3642
  spotMarketIndex: number,
3562
3643
  liquidatorFee: number,
3563
- ifLiquidationFee: number
3644
+ ifLiquidationFee: number,
3645
+ protocolLiquidationFee = 0
3564
3646
  ): Promise<TransactionSignature> {
3565
3647
  const updateSpotMarketLiquidationFeeIx =
3566
3648
  await this.getUpdateSpotMarketLiquidationFeeIx(
3567
3649
  spotMarketIndex,
3568
3650
  liquidatorFee,
3569
- ifLiquidationFee
3651
+ ifLiquidationFee,
3652
+ protocolLiquidationFee
3570
3653
  );
3571
3654
 
3572
3655
  const tx = await this.buildTransaction(updateSpotMarketLiquidationFeeIx);
@@ -3579,11 +3662,13 @@ export class AdminClient extends VelocityClient {
3579
3662
  public async getUpdateSpotMarketLiquidationFeeIx(
3580
3663
  spotMarketIndex: number,
3581
3664
  liquidatorFee: number,
3582
- ifLiquidationFee: number
3665
+ ifLiquidationFee: number,
3666
+ protocolLiquidationFee = 0
3583
3667
  ): Promise<TransactionInstruction> {
3584
3668
  return await this.program.instruction.updateSpotMarketLiquidationFee(
3585
3669
  liquidatorFee,
3586
3670
  ifLiquidationFee,
3671
+ protocolLiquidationFee,
3587
3672
  {
3588
3673
  accounts: {
3589
3674
  admin: this.isSubscribed
@@ -3599,187 +3684,155 @@ export class AdminClient extends VelocityClient {
3599
3684
  );
3600
3685
  }
3601
3686
 
3602
- public async initializeProtocolIfSharesTransferConfig(): Promise<TransactionSignature> {
3603
- const initializeProtocolIfSharesTransferConfigIx =
3604
- await this.getInitializeProtocolIfSharesTransferConfigIx();
3605
-
3606
- const tx = await this.buildTransaction(
3607
- initializeProtocolIfSharesTransferConfigIx
3608
- );
3609
-
3610
- const { txSig } = await this.sendTransaction(tx, [], this.opts);
3611
-
3612
- return txSig;
3613
- }
3614
-
3615
- public async getInitializeProtocolIfSharesTransferConfigIx(): Promise<TransactionInstruction> {
3616
- return await (
3617
- this.program.instruction as any
3618
- ).initializeProtocolIfSharesTransferConfig({
3619
- accounts: {
3620
- admin: this.isSubscribed
3621
- ? this.getStateAccount().coldAdmin
3622
- : this.wallet.publicKey,
3623
- state: await this.getStatePublicKey(),
3624
- rent: SYSVAR_RENT_PUBKEY,
3625
- systemProgram: anchor.web3.SystemProgram.programId,
3626
- protocolIfSharesTransferConfig:
3627
- getProtocolIfSharesTransferConfigPublicKey(this.program.programId),
3628
- },
3629
- });
3630
- }
3631
-
3632
- public async updateProtocolIfSharesTransferConfig(
3633
- whitelistedSigners?: PublicKey[],
3634
- maxTransferPerEpoch?: BN
3687
+ public async updateProtocolFeeRecipient(
3688
+ protocolFeeRecipient: PublicKey,
3689
+ marketType: MarketType
3635
3690
  ): Promise<TransactionSignature> {
3636
- const updateProtocolIfSharesTransferConfigIx =
3637
- await this.getUpdateProtocolIfSharesTransferConfigIx(
3638
- whitelistedSigners,
3639
- maxTransferPerEpoch
3640
- );
3641
-
3642
- const tx = await this.buildTransaction(
3643
- updateProtocolIfSharesTransferConfigIx
3691
+ const ix = await this.getUpdateProtocolFeeRecipientIx(
3692
+ protocolFeeRecipient,
3693
+ marketType
3644
3694
  );
3645
-
3695
+ const tx = await this.buildTransaction(ix);
3646
3696
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
3647
-
3648
3697
  return txSig;
3649
3698
  }
3650
3699
 
3651
- public async getUpdateProtocolIfSharesTransferConfigIx(
3652
- whitelistedSigners?: PublicKey[],
3653
- maxTransferPerEpoch?: BN
3700
+ public async getUpdateProtocolFeeRecipientIx(
3701
+ protocolFeeRecipient: PublicKey,
3702
+ marketType: MarketType
3654
3703
  ): Promise<TransactionInstruction> {
3655
- return await (
3656
- this.program.instruction as any
3657
- ).updateProtocolIfSharesTransferConfig(
3658
- whitelistedSigners || null,
3659
- maxTransferPerEpoch,
3704
+ return await this.program.instruction.updateProtocolFeeRecipient(
3705
+ protocolFeeRecipient,
3706
+ marketType,
3660
3707
  {
3661
3708
  accounts: {
3662
3709
  admin: this.isSubscribed
3663
3710
  ? this.getStateAccount().coldAdmin
3664
3711
  : this.wallet.publicKey,
3665
3712
  state: await this.getStatePublicKey(),
3666
- protocolIfSharesTransferConfig:
3667
- getProtocolIfSharesTransferConfigPublicKey(this.program.programId),
3668
3713
  },
3669
3714
  }
3670
3715
  );
3671
3716
  }
3672
3717
 
3673
- public async transferProtocolIfSharesToRevenuePool(
3674
- outMarketIndex: number,
3675
- inMarketIndex: number,
3676
- amount: BN
3718
+ public async withdrawProtocolFeesSpot(
3719
+ marketIndex: number,
3720
+ amount: BN,
3721
+ txParams?: TxParams
3677
3722
  ): Promise<TransactionSignature> {
3678
- const transferProtocolIfSharesToRevenuePoolIx =
3679
- await this.getTransferProtocolIfSharesToRevenuePoolIx(
3680
- outMarketIndex,
3681
- inMarketIndex,
3682
- amount
3683
- );
3684
-
3685
- const tx = await this.buildTransaction(
3686
- transferProtocolIfSharesToRevenuePoolIx
3687
- );
3688
-
3723
+ const ix = await this.getWithdrawProtocolFeesSpotIx(marketIndex, amount);
3724
+ const tx = await this.buildTransaction(ix, txParams);
3689
3725
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
3690
-
3691
3726
  return txSig;
3692
3727
  }
3693
3728
 
3694
- public async getTransferProtocolIfSharesToRevenuePoolIx(
3695
- outMarketIndex: number,
3696
- inMarketIndex: number,
3729
+ public async getWithdrawProtocolFeesSpotIx(
3730
+ marketIndex: number,
3697
3731
  amount: BN
3698
3732
  ): Promise<TransactionInstruction> {
3699
- const remainingAccounts = await this.getRemainingAccounts({
3700
- userAccounts: [],
3701
- writableSpotMarketIndexes: [outMarketIndex],
3702
- });
3733
+ const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
3734
+ const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
3735
+ const recipient = this.getStateAccount().protocolFeeRecipientSpot;
3736
+ const recipientTokenAccount = getAssociatedTokenAddressSync(
3737
+ spotMarket.mint,
3738
+ recipient,
3739
+ true,
3740
+ tokenProgramId
3741
+ );
3703
3742
 
3704
- return await this.program.instruction.transferProtocolIfSharesToRevenuePool(
3705
- outMarketIndex,
3743
+ const remainingAccounts: {
3744
+ pubkey: PublicKey;
3745
+ isSigner: boolean;
3746
+ isWritable: boolean;
3747
+ }[] = [];
3748
+ if (this.isTransferHook(spotMarket)) {
3749
+ await this.addExtraAccountMetasToRemainingAccounts(
3750
+ spotMarket.mint,
3751
+ remainingAccounts
3752
+ );
3753
+ }
3754
+
3755
+ return await this.program.instruction.withdrawProtocolFeesSpot(
3756
+ marketIndex,
3706
3757
  amount,
3707
3758
  {
3708
3759
  accounts: {
3709
- authority: this.wallet.publicKey,
3710
3760
  state: await this.getStatePublicKey(),
3711
- insuranceFundVault: await getInsuranceFundVaultPublicKey(
3712
- this.program.programId,
3713
- outMarketIndex
3714
- ),
3715
- spotMarketVault: await getSpotMarketVaultPublicKey(
3716
- this.program.programId,
3717
- outMarketIndex
3718
- ),
3719
- ifRebalanceConfig: await getIfRebalanceConfigPublicKey(
3720
- this.program.programId,
3721
- inMarketIndex,
3722
- outMarketIndex
3723
- ),
3724
- tokenProgram: TOKEN_PROGRAM_ID,
3725
- driftSigner: this.getStateAccount().signer,
3761
+ payer: this.wallet.publicKey,
3762
+ authority: this.wallet.publicKey,
3763
+ spotMarket: spotMarket.pubkey,
3764
+ spotMarketVault: spotMarket.vault,
3765
+ mint: spotMarket.mint,
3766
+ recipient,
3767
+ recipientTokenAccount,
3768
+ tokenProgram: tokenProgramId,
3769
+ velocitySigner: this.getSignerPublicKey(),
3770
+ systemProgram: SystemProgram.programId,
3771
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
3726
3772
  },
3727
3773
  remainingAccounts,
3728
3774
  }
3729
3775
  );
3730
3776
  }
3731
3777
 
3732
- public async adminWithdrawFromInsuranceFundVault(
3778
+ public async withdrawProtocolFeesPerp(
3733
3779
  marketIndex: number,
3734
3780
  amount: BN,
3735
- recipientTokenAccount: PublicKey,
3736
3781
  txParams?: TxParams
3737
3782
  ): Promise<TransactionSignature> {
3738
- const ix = await this.getAdminWithdrawFromInsuranceFundVaultIx(
3739
- marketIndex,
3740
- amount,
3741
- recipientTokenAccount
3742
- );
3783
+ const ix = await this.getWithdrawProtocolFeesPerpIx(marketIndex, amount);
3743
3784
  const tx = await this.buildTransaction(ix, txParams);
3744
3785
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
3745
3786
  return txSig;
3746
3787
  }
3747
3788
 
3748
- public async getAdminWithdrawFromInsuranceFundVaultIx(
3789
+ public async getWithdrawProtocolFeesPerpIx(
3749
3790
  marketIndex: number,
3750
- amount: BN,
3751
- recipientTokenAccount: PublicKey
3791
+ amount: BN
3752
3792
  ): Promise<TransactionInstruction> {
3753
- const spotMarket = this.getSpotMarketAccount(marketIndex);
3754
- const tokenProgramId = this.getTokenProgramForSpotMarket(spotMarket);
3793
+ const perpMarket = this.getPerpMarketAccountOrThrow(marketIndex);
3794
+ const quoteSpotMarket = this.getSpotMarketAccountOrThrow(
3795
+ perpMarket.quoteSpotMarketIndex
3796
+ );
3797
+ const tokenProgramId = this.getTokenProgramForSpotMarket(quoteSpotMarket);
3798
+ const recipient = this.getStateAccount().protocolFeeRecipientPerp;
3799
+ const recipientTokenAccount = getAssociatedTokenAddressSync(
3800
+ quoteSpotMarket.mint,
3801
+ recipient,
3802
+ true,
3803
+ tokenProgramId
3804
+ );
3755
3805
 
3756
3806
  const remainingAccounts: {
3757
3807
  pubkey: PublicKey;
3758
3808
  isSigner: boolean;
3759
3809
  isWritable: boolean;
3760
3810
  }[] = [];
3761
- this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
3762
- if (this.isTransferHook(spotMarket)) {
3811
+ if (this.isTransferHook(quoteSpotMarket)) {
3763
3812
  await this.addExtraAccountMetasToRemainingAccounts(
3764
- spotMarket.mint,
3813
+ quoteSpotMarket.mint,
3765
3814
  remainingAccounts
3766
3815
  );
3767
3816
  }
3768
3817
 
3769
- return await this.program.instruction.adminWithdrawFromInsuranceFundVault(
3818
+ return await this.program.instruction.withdrawProtocolFeesPerp(
3770
3819
  marketIndex,
3771
3820
  amount,
3772
3821
  {
3773
3822
  accounts: {
3774
3823
  state: await this.getStatePublicKey(),
3775
- authority: this.isSubscribed
3776
- ? this.getStateAccount().coldAdmin
3777
- : this.wallet.publicKey,
3778
- spotMarket: spotMarket.pubkey,
3779
- insuranceFundVault: spotMarket.insuranceFund.vault,
3824
+ payer: this.wallet.publicKey,
3825
+ authority: this.wallet.publicKey,
3826
+ perpMarket: perpMarket.pubkey,
3827
+ quoteSpotMarket: quoteSpotMarket.pubkey,
3828
+ spotMarketVault: quoteSpotMarket.vault,
3829
+ mint: quoteSpotMarket.mint,
3830
+ recipient,
3780
3831
  recipientTokenAccount,
3781
3832
  tokenProgram: tokenProgramId,
3782
- driftSigner: this.getSignerPublicKey(),
3833
+ velocitySigner: this.getSignerPublicKey(),
3834
+ systemProgram: SystemProgram.programId,
3835
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
3783
3836
  },
3784
3837
  remainingAccounts,
3785
3838
  }
@@ -4055,36 +4108,44 @@ export class AdminClient extends VelocityClient {
4055
4108
  );
4056
4109
  }
4057
4110
 
4058
- public async initializeIfRebalanceConfig(
4059
- params: IfRebalanceConfigParams
4111
+ public async updatePerpMarketFundingBiasSensitivity(
4112
+ perpMarketIndex: number,
4113
+ fundingBiasSensitivity: number
4060
4114
  ): Promise<TransactionSignature> {
4061
- const initializeIfRebalanceConfigIx =
4062
- await this.getInitializeIfRebalanceConfigIx(params);
4063
-
4064
- const tx = await this.buildTransaction(initializeIfRebalanceConfigIx);
4115
+ const updatePerpMarketFundingBiasSensitivityIx =
4116
+ await this.getUpdatePerpMarketFundingBiasSensitivityIx(
4117
+ perpMarketIndex,
4118
+ fundingBiasSensitivity
4119
+ );
4120
+ const tx = await this.buildTransaction(
4121
+ updatePerpMarketFundingBiasSensitivityIx
4122
+ );
4065
4123
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
4066
4124
 
4067
4125
  return txSig;
4068
4126
  }
4069
4127
 
4070
- public async getInitializeIfRebalanceConfigIx(
4071
- params: IfRebalanceConfigParams
4128
+ public async getUpdatePerpMarketFundingBiasSensitivityIx(
4129
+ perpMarketIndex: number,
4130
+ fundingBiasSensitivity: number
4072
4131
  ): Promise<TransactionInstruction> {
4073
- return await this.program.instruction.initializeIfRebalanceConfig(params, {
4074
- accounts: {
4075
- admin: this.isSubscribed
4076
- ? this.getStateAccount().coldAdmin
4077
- : this.wallet.publicKey,
4078
- state: await this.getStatePublicKey(),
4079
- ifRebalanceConfig: await getIfRebalanceConfigPublicKey(
4080
- this.program.programId,
4081
- params.inMarketIndex,
4082
- params.outMarketIndex
4083
- ),
4084
- rent: SYSVAR_RENT_PUBKEY,
4085
- systemProgram: anchor.web3.SystemProgram.programId,
4086
- },
4087
- });
4132
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
4133
+ this.program.programId,
4134
+ perpMarketIndex
4135
+ );
4136
+
4137
+ return await this.program.instruction.updatePerpMarketFundingBiasSensitivity(
4138
+ fundingBiasSensitivity,
4139
+ {
4140
+ accounts: {
4141
+ admin: this.useHotWalletAdmin
4142
+ ? this.wallet.publicKey
4143
+ : this.getStateAccount().coldAdmin,
4144
+ state: await this.getStatePublicKey(),
4145
+ perpMarket: perpMarketPublicKey,
4146
+ },
4147
+ }
4148
+ );
4088
4149
  }
4089
4150
 
4090
4151
  public async initializePythLazerOracle(
@@ -4141,7 +4202,7 @@ export class AdminClient extends VelocityClient {
4141
4202
  adminTokenAccount?: PublicKey
4142
4203
  ): Promise<TransactionInstruction> {
4143
4204
  const state = await this.getStatePublicKey();
4144
- const spotMarket = this.getSpotMarketAccount(marketIndex);
4205
+ const spotMarket = this.getSpotMarketAccountOrThrow(marketIndex);
4145
4206
 
4146
4207
  const remainingAccounts = this.getRemainingAccounts({
4147
4208
  userAccounts: [],
@@ -4311,106 +4372,6 @@ export class AdminClient extends VelocityClient {
4311
4372
  );
4312
4373
  }
4313
4374
 
4314
- public async updateDelegateUserGovTokenInsuranceStake(
4315
- authority: PublicKey,
4316
- delegate: PublicKey
4317
- ): Promise<TransactionSignature> {
4318
- const updateDelegateUserGovTokenInsuranceStakeIx =
4319
- await this.getUpdateDelegateUserGovTokenInsuranceStakeIx(
4320
- authority,
4321
- delegate
4322
- );
4323
-
4324
- const tx = await this.buildTransaction(
4325
- updateDelegateUserGovTokenInsuranceStakeIx
4326
- );
4327
- const { txSig } = await this.sendTransaction(tx, [], this.opts);
4328
-
4329
- return txSig;
4330
- }
4331
-
4332
- public async getUpdateDelegateUserGovTokenInsuranceStakeIx(
4333
- authority: PublicKey,
4334
- delegate: PublicKey
4335
- ): Promise<TransactionInstruction> {
4336
- const marketIndex = GOV_SPOT_MARKET_INDEX;
4337
- const spotMarket = this.getSpotMarketAccount(marketIndex);
4338
- const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
4339
- this.program.programId,
4340
- delegate,
4341
- marketIndex
4342
- );
4343
- const userStatsPublicKey = getUserStatsAccountPublicKey(
4344
- this.program.programId,
4345
- authority
4346
- );
4347
-
4348
- const ix = (
4349
- this.program.instruction as any
4350
- ).getUpdateDelegateUserGovTokenInsuranceStakeIx({
4351
- accounts: {
4352
- state: await this.getStatePublicKey(),
4353
- spotMarket: spotMarket.pubkey,
4354
- insuranceFundStake: ifStakeAccountPublicKey,
4355
- userStats: userStatsPublicKey,
4356
- signer: this.wallet.publicKey,
4357
- insuranceFundVault: spotMarket.insuranceFund.vault,
4358
- },
4359
- });
4360
-
4361
- return ix;
4362
- }
4363
-
4364
- public async depositIntoInsuranceFundStake(
4365
- marketIndex: number,
4366
- amount: BN,
4367
- userStatsPublicKey: PublicKey,
4368
- insuranceFundStakePublicKey: PublicKey,
4369
- userTokenAccountPublicKey: PublicKey,
4370
- txParams?: TxParams
4371
- ): Promise<TransactionSignature> {
4372
- const tx = await this.buildTransaction(
4373
- await this.getDepositIntoInsuranceFundStakeIx(
4374
- marketIndex,
4375
- amount,
4376
- userStatsPublicKey,
4377
- insuranceFundStakePublicKey,
4378
- userTokenAccountPublicKey
4379
- ),
4380
- txParams
4381
- );
4382
- const { txSig } = await this.sendTransaction(tx, [], this.opts);
4383
- return txSig;
4384
- }
4385
-
4386
- public async getDepositIntoInsuranceFundStakeIx(
4387
- marketIndex: number,
4388
- amount: BN,
4389
- userStatsPublicKey: PublicKey,
4390
- insuranceFundStakePublicKey: PublicKey,
4391
- userTokenAccountPublicKey: PublicKey
4392
- ): Promise<TransactionInstruction> {
4393
- const spotMarket = this.getSpotMarketAccount(marketIndex);
4394
- return await this.program.instruction.depositIntoInsuranceFundStake(
4395
- marketIndex,
4396
- amount,
4397
- {
4398
- accounts: {
4399
- signer: this.wallet.publicKey,
4400
- state: await this.getStatePublicKey(),
4401
- spotMarket: spotMarket.pubkey,
4402
- insuranceFundStake: insuranceFundStakePublicKey,
4403
- userStats: userStatsPublicKey,
4404
- spotMarketVault: spotMarket.vault,
4405
- insuranceFundVault: spotMarket.insuranceFund.vault,
4406
- userTokenAccount: userTokenAccountPublicKey,
4407
- tokenProgram: this.getTokenProgramForSpotMarket(spotMarket),
4408
- driftSigner: this.getSignerPublicKey(),
4409
- },
4410
- }
4411
- );
4412
- }
4413
-
4414
4375
  public async updateFeatureBitFlagsSettleLpPool(
4415
4376
  enable: boolean
4416
4377
  ): Promise<TransactionSignature> {
@@ -4653,7 +4614,7 @@ export class AdminClient extends VelocityClient {
4653
4614
  lpPool,
4654
4615
  spotMarketIndex
4655
4616
  );
4656
- const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
4617
+ const spotMarketAccount = this.getSpotMarketAccountOrThrow(spotMarketIndex);
4657
4618
 
4658
4619
  return [
4659
4620
  this.program.instruction.initializeConstituent(
@@ -5094,7 +5055,7 @@ export class AdminClient extends VelocityClient {
5094
5055
  }
5095
5056
 
5096
5057
  /**
5097
- * Get the drift begin_swap and end_swap instructions
5058
+ * Get the velocity begin_swap and end_swap instructions
5098
5059
  *
5099
5060
  * @param outMarketIndex the market index of the token you're buying
5100
5061
  * @param inMarketIndex the market index of the token you're selling
@@ -5144,8 +5105,8 @@ export class AdminClient extends VelocityClient {
5144
5105
  userAccountPublicKey,
5145
5106
  });
5146
5107
  }
5147
- const outSpotMarket = this.getSpotMarketAccount(outMarketIndex);
5148
- const inSpotMarket = this.getSpotMarketAccount(inMarketIndex);
5108
+ const outSpotMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
5109
+ const inSpotMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
5149
5110
 
5150
5111
  const outTokenProgram = this.getTokenProgramForSpotMarket(outSpotMarket);
5151
5112
  const inTokenProgram = this.getTokenProgramForSpotMarket(inSpotMarket);
@@ -5194,7 +5155,7 @@ export class AdminClient extends VelocityClient {
5194
5155
  }
5195
5156
  );
5196
5157
 
5197
- const remainingAccounts = [];
5158
+ const remainingAccounts: AccountMeta[] = [];
5198
5159
  remainingAccounts.push({
5199
5160
  pubkey: outTokenProgram,
5200
5161
  isWritable: false,
@@ -5251,8 +5212,8 @@ export class AdminClient extends VelocityClient {
5251
5212
  ixs: TransactionInstruction[];
5252
5213
  lookupTables: AddressLookupTableAccount[];
5253
5214
  }> {
5254
- const outMarket = this.getSpotMarketAccount(outMarketIndex);
5255
- const inMarket = this.getSpotMarketAccount(inMarketIndex);
5215
+ const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
5216
+ const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
5256
5217
 
5257
5218
  if (!quote) {
5258
5219
  const fetchedQuote = await jupiterClient.getQuote({
@@ -5368,8 +5329,10 @@ export class AdminClient extends VelocityClient {
5368
5329
  inSpotMarketIndex: number,
5369
5330
  outSpotMarketIndex: number
5370
5331
  ): Promise<TransactionInstruction[]> {
5371
- const inSpotMarketAccount = this.getSpotMarketAccount(inSpotMarketIndex);
5372
- const outSpotMarketAccount = this.getSpotMarketAccount(outSpotMarketIndex);
5332
+ const inSpotMarketAccount =
5333
+ this.getSpotMarketAccountOrThrow(inSpotMarketIndex);
5334
+ const outSpotMarketAccount =
5335
+ this.getSpotMarketAccountOrThrow(outSpotMarketIndex);
5373
5336
 
5374
5337
  const outTokenAccount = await this.getAssociatedTokenAccount(
5375
5338
  outSpotMarketAccount.marketIndex,
@@ -5437,6 +5400,8 @@ export class AdminClient extends VelocityClient {
5437
5400
  minOutAmount: BN,
5438
5401
  externalUserAuthority: PublicKey
5439
5402
  ) {
5403
+ const inMarket = this.getSpotMarketAccountOrThrow(inMarketIndex);
5404
+ const outMarket = this.getSpotMarketAccountOrThrow(outMarketIndex);
5440
5405
  const { beginSwapIx, endSwapIx } = await this.getSwapIx(
5441
5406
  {
5442
5407
  lpPoolId,
@@ -5462,13 +5427,13 @@ export class AdminClient extends VelocityClient {
5462
5427
  await this.getAssociatedTokenAccount(
5463
5428
  inMarketIndex,
5464
5429
  false,
5465
- getTokenProgramForSpotMarket(this.getSpotMarketAccount(inMarketIndex)),
5430
+ getTokenProgramForSpotMarket(inMarket),
5466
5431
  externalUserAuthority
5467
5432
  ),
5468
5433
  await this.getAssociatedTokenAccount(
5469
5434
  outMarketIndex,
5470
5435
  false,
5471
- getTokenProgramForSpotMarket(this.getSpotMarketAccount(outMarketIndex)),
5436
+ getTokenProgramForSpotMarket(outMarket),
5472
5437
  externalUserAuthority
5473
5438
  ),
5474
5439
  inMarketIndex,
@@ -5514,8 +5479,10 @@ export class AdminClient extends VelocityClient {
5514
5479
  withdrawIx: TransactionInstruction;
5515
5480
  }> {
5516
5481
  const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolId);
5517
- const depositSpotMarket = this.getSpotMarketAccount(depositMarketIndex);
5518
- const withdrawSpotMarket = this.getSpotMarketAccount(borrowMarketIndex);
5482
+ const depositSpotMarket =
5483
+ this.getSpotMarketAccountOrThrow(depositMarketIndex);
5484
+ const withdrawSpotMarket =
5485
+ this.getSpotMarketAccountOrThrow(borrowMarketIndex);
5519
5486
 
5520
5487
  const depositTokenProgram =
5521
5488
  this.getTokenProgramForSpotMarket(depositSpotMarket);
@@ -5573,7 +5540,7 @@ export class AdminClient extends VelocityClient {
5573
5540
  spotMarketVault: withdrawSpotMarket.vault,
5574
5541
  tokenProgram: withdrawTokenProgram,
5575
5542
  mint: withdrawSpotMarket.mint,
5576
- driftSigner: getVelocitySignerPublicKey(this.program.programId),
5543
+ velocitySigner: getVelocitySignerPublicKey(this.program.programId),
5577
5544
  oracle: withdrawSpotMarket.oracle,
5578
5545
  },
5579
5546
  }
@@ -5663,6 +5630,7 @@ export class AdminClient extends VelocityClient {
5663
5630
  lpFeeTransferScalar?: number,
5664
5631
  lpExchangeFeeExcluscionScalar?: number
5665
5632
  ): Promise<TransactionInstruction> {
5633
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
5666
5634
  return this.program.instruction.updatePerpMarketLpPoolFeeTransferScalar(
5667
5635
  lpFeeTransferScalar ?? null,
5668
5636
  lpExchangeFeeExcluscionScalar ?? null,
@@ -5672,7 +5640,7 @@ export class AdminClient extends VelocityClient {
5672
5640
  ? this.wallet.publicKey
5673
5641
  : this.getStateAccount().coldAdmin,
5674
5642
  state: await this.getStatePublicKey(),
5675
- perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
5643
+ perpMarket: perpMarketAccount.pubkey,
5676
5644
  },
5677
5645
  }
5678
5646
  );
@@ -5695,6 +5663,7 @@ export class AdminClient extends VelocityClient {
5695
5663
  marketIndex: number,
5696
5664
  pausedOperations: number
5697
5665
  ): Promise<TransactionInstruction> {
5666
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
5698
5667
  return this.program.instruction.updatePerpMarketLpPoolPausedOperations(
5699
5668
  pausedOperations,
5700
5669
  {
@@ -5703,7 +5672,7 @@ export class AdminClient extends VelocityClient {
5703
5672
  ? this.wallet.publicKey
5704
5673
  : this.getStateAccount().coldAdmin,
5705
5674
  state: await this.getStatePublicKey(),
5706
- perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
5675
+ perpMarket: perpMarketAccount.pubkey,
5707
5676
  },
5708
5677
  }
5709
5678
  );
@@ -5768,13 +5737,14 @@ export class AdminClient extends VelocityClient {
5768
5737
  marketIndex: number,
5769
5738
  marketConfig: number
5770
5739
  ): Promise<TransactionInstruction> {
5740
+ const perpMarketAccount = this.getPerpMarketAccountOrThrow(marketIndex);
5771
5741
  return this.program.instruction.updatePerpMarketConfig(marketConfig, {
5772
5742
  accounts: {
5773
5743
  admin: this.useHotWalletAdmin
5774
5744
  ? this.wallet.publicKey
5775
5745
  : this.getStateAccount().coldAdmin,
5776
5746
  state: await this.getStatePublicKey(),
5777
- perpMarket: this.getPerpMarketAccount(marketIndex).pubkey,
5747
+ perpMarket: perpMarketAccount.pubkey,
5778
5748
  },
5779
5749
  });
5780
5750
  }
@@ -5921,13 +5891,13 @@ export enum HotRole {
5921
5891
  LpCache = 'lpCache',
5922
5892
  LpSwap = 'lpSwap',
5923
5893
  LpSettle = 'lpSettle',
5924
- IfRebalance = 'ifRebalance',
5925
5894
  FeatureFlag = 'featureFlag',
5926
5895
  Fuel = 'fuel',
5927
5896
  UserFlag = 'userFlag',
5928
5897
  VaultDeposit = 'vaultDeposit',
5929
5898
  MmOracleCrank = 'mmOracleCrank',
5930
5899
  AmmSpreadAdjust = 'ammSpreadAdjust',
5900
+ FeeWithdraw = 'feeWithdraw',
5931
5901
  }
5932
5902
 
5933
5903
  /** Anchor encodes Rust enums as `{ <variant>: {} }`. */