@drift-labs/common 1.0.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 (400) hide show
  1. package/lib/Config.d.ts +26 -0
  2. package/lib/Config.js +29 -0
  3. package/lib/Config.js.map +1 -0
  4. package/lib/EnvironmentConstants.d.ts +40 -0
  5. package/lib/EnvironmentConstants.js +64 -0
  6. package/lib/EnvironmentConstants.js.map +1 -0
  7. package/lib/actions/actionHelpers/accountDeletionHelpers.d.ts +16 -0
  8. package/lib/actions/actionHelpers/accountDeletionHelpers.js +151 -0
  9. package/lib/actions/actionHelpers/accountDeletionHelpers.js.map +1 -0
  10. package/lib/actions/actionHelpers/actionHelpers.d.ts +13 -0
  11. package/lib/actions/actionHelpers/actionHelpers.js +8 -0
  12. package/lib/actions/actionHelpers/actionHelpers.js.map +1 -0
  13. package/lib/chartConstants.d.ts +2 -0
  14. package/lib/chartConstants.js +14 -0
  15. package/lib/chartConstants.js.map +1 -0
  16. package/lib/clients/candleClient.d.ts +74 -0
  17. package/lib/clients/candleClient.js +364 -0
  18. package/lib/clients/candleClient.js.map +1 -0
  19. package/lib/clients/dataApiWsClient.d.ts +33 -0
  20. package/lib/clients/dataApiWsClient.js +118 -0
  21. package/lib/clients/dataApiWsClient.js.map +1 -0
  22. package/lib/clients/index.d.ts +1 -0
  23. package/lib/clients/index.js +19 -0
  24. package/lib/clients/index.js.map +1 -0
  25. package/lib/clients/marketDataFeed.d.ts +42 -0
  26. package/lib/clients/marketDataFeed.js +422 -0
  27. package/lib/clients/marketDataFeed.js.map +1 -0
  28. package/lib/clients/redisClient.d.ts +89 -0
  29. package/lib/clients/redisClient.js +647 -0
  30. package/lib/clients/redisClient.js.map +1 -0
  31. package/lib/clients/swiftClient.d.ts +57 -0
  32. package/lib/clients/swiftClient.js +289 -0
  33. package/lib/clients/swiftClient.js.map +1 -0
  34. package/lib/clients/tvFeed.d.ts +63 -0
  35. package/lib/clients/tvFeed.js +351 -0
  36. package/lib/clients/tvFeed.js.map +1 -0
  37. package/lib/common-ui-utils/commonUiUtils.d.ts +211 -0
  38. package/lib/common-ui-utils/commonUiUtils.js +624 -0
  39. package/lib/common-ui-utils/commonUiUtils.js.map +1 -0
  40. package/lib/common-ui-utils/index.d.ts +6 -0
  41. package/lib/common-ui-utils/index.js +23 -0
  42. package/lib/common-ui-utils/index.js.map +1 -0
  43. package/lib/common-ui-utils/market.d.ts +27 -0
  44. package/lib/common-ui-utils/market.js +80 -0
  45. package/lib/common-ui-utils/market.js.map +1 -0
  46. package/lib/common-ui-utils/order.d.ts +11 -0
  47. package/lib/common-ui-utils/order.js +161 -0
  48. package/lib/common-ui-utils/order.js.map +1 -0
  49. package/lib/common-ui-utils/settings/settings.d.ts +51 -0
  50. package/lib/common-ui-utils/settings/settings.js +84 -0
  51. package/lib/common-ui-utils/settings/settings.js.map +1 -0
  52. package/lib/common-ui-utils/trading.d.ts +56 -0
  53. package/lib/common-ui-utils/trading.js +200 -0
  54. package/lib/common-ui-utils/trading.js.map +1 -0
  55. package/lib/common-ui-utils/user.d.ts +13 -0
  56. package/lib/common-ui-utils/user.js +124 -0
  57. package/lib/common-ui-utils/user.js.map +1 -0
  58. package/lib/constants/autogenerated/driftErrors.json +1787 -0
  59. package/lib/constants/autogenerated/jup-v4-error-codes.json +67 -0
  60. package/lib/constants/autogenerated/jup-v6-error-codes.json +115 -0
  61. package/lib/constants/dev.d.ts +15 -0
  62. package/lib/constants/dev.js +19 -0
  63. package/lib/constants/dev.js.map +1 -0
  64. package/lib/constants/geoblockList.d.ts +4 -0
  65. package/lib/constants/geoblockList.js +32 -0
  66. package/lib/constants/geoblockList.js.map +1 -0
  67. package/lib/constants/index.d.ts +9 -0
  68. package/lib/constants/index.js +26 -0
  69. package/lib/constants/index.js.map +1 -0
  70. package/lib/constants/markets.d.ts +1 -0
  71. package/lib/constants/markets.js +5 -0
  72. package/lib/constants/markets.js.map +1 -0
  73. package/lib/constants/misc.d.ts +23 -0
  74. package/lib/constants/misc.js +27 -0
  75. package/lib/constants/misc.js.map +1 -0
  76. package/lib/constants/orders.d.ts +12 -0
  77. package/lib/constants/orders.js +79 -0
  78. package/lib/constants/orders.js.map +1 -0
  79. package/lib/constants/pools.d.ts +5 -0
  80. package/lib/constants/pools.js +9 -0
  81. package/lib/constants/pools.js.map +1 -0
  82. package/lib/constants/predictionMarket.d.ts +3 -0
  83. package/lib/constants/predictionMarket.js +7 -0
  84. package/lib/constants/predictionMarket.js.map +1 -0
  85. package/lib/constants/superstake.d.ts +22 -0
  86. package/lib/constants/superstake.js +45 -0
  87. package/lib/constants/superstake.js.map +1 -0
  88. package/lib/constants/trade.d.ts +2 -0
  89. package/lib/constants/trade.js +9 -0
  90. package/lib/constants/trade.js.map +1 -0
  91. package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.d.ts +68 -0
  92. package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.js +146 -0
  93. package/lib/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.js.map +1 -0
  94. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.d.ts +204 -0
  95. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +530 -0
  96. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -0
  97. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +90 -0
  98. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js +3 -0
  99. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -0
  100. package/lib/drift/Drift/clients/AuthorityDrift/SubscriptionManager.d.ts +139 -0
  101. package/lib/drift/Drift/clients/AuthorityDrift/SubscriptionManager.js +287 -0
  102. package/lib/drift/Drift/clients/AuthorityDrift/SubscriptionManager.js.map +1 -0
  103. package/lib/drift/Drift/clients/AuthorityDrift/index.d.ts +242 -0
  104. package/lib/drift/Drift/clients/AuthorityDrift/index.js +503 -0
  105. package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -0
  106. package/lib/drift/Drift/clients/CentralServerDrift.d.ts +91 -0
  107. package/lib/drift/Drift/clients/CentralServerDrift.js +326 -0
  108. package/lib/drift/Drift/clients/CentralServerDrift.js.map +1 -0
  109. package/lib/drift/Drift/clients/index.d.ts +3 -0
  110. package/lib/drift/Drift/clients/index.js +20 -0
  111. package/lib/drift/Drift/clients/index.js.map +1 -0
  112. package/lib/drift/Drift/constants/blockchain.d.ts +24 -0
  113. package/lib/drift/Drift/constants/blockchain.js +32 -0
  114. package/lib/drift/Drift/constants/blockchain.js.map +1 -0
  115. package/lib/drift/Drift/constants/errors.d.ts +6 -0
  116. package/lib/drift/Drift/constants/errors.js +14 -0
  117. package/lib/drift/Drift/constants/errors.js.map +1 -0
  118. package/lib/drift/Drift/constants/index.d.ts +3 -0
  119. package/lib/drift/Drift/constants/index.js +20 -0
  120. package/lib/drift/Drift/constants/index.js.map +1 -0
  121. package/lib/drift/Drift/constants/orderbook.d.ts +7 -0
  122. package/lib/drift/Drift/constants/orderbook.js +10 -0
  123. package/lib/drift/Drift/constants/orderbook.js.map +1 -0
  124. package/lib/drift/Drift/data/PollingDlob.d.ts +154 -0
  125. package/lib/drift/Drift/data/PollingDlob.js +387 -0
  126. package/lib/drift/Drift/data/PollingDlob.js.map +1 -0
  127. package/lib/drift/Drift/data/index.d.ts +1 -0
  128. package/lib/drift/Drift/data/index.js +18 -0
  129. package/lib/drift/Drift/data/index.js.map +1 -0
  130. package/lib/drift/Drift/index.d.ts +4 -0
  131. package/lib/drift/Drift/index.js +21 -0
  132. package/lib/drift/Drift/index.js.map +1 -0
  133. package/lib/drift/Drift/stores/MarkPriceCache.d.ts +27 -0
  134. package/lib/drift/Drift/stores/MarkPriceCache.js +59 -0
  135. package/lib/drift/Drift/stores/MarkPriceCache.js.map +1 -0
  136. package/lib/drift/Drift/stores/OraclePriceCache.d.ts +21 -0
  137. package/lib/drift/Drift/stores/OraclePriceCache.js +57 -0
  138. package/lib/drift/Drift/stores/OraclePriceCache.js.map +1 -0
  139. package/lib/drift/Drift/stores/UserAccountCache.d.ts +49 -0
  140. package/lib/drift/Drift/stores/UserAccountCache.js +107 -0
  141. package/lib/drift/Drift/stores/UserAccountCache.js.map +1 -0
  142. package/lib/drift/Drift/stores/index.d.ts +3 -0
  143. package/lib/drift/Drift/stores/index.js +20 -0
  144. package/lib/drift/Drift/stores/index.js.map +1 -0
  145. package/lib/drift/base/actions/index.d.ts +4 -0
  146. package/lib/drift/base/actions/index.js +21 -0
  147. package/lib/drift/base/actions/index.js.map +1 -0
  148. package/lib/drift/base/actions/perp/index.d.ts +2 -0
  149. package/lib/drift/base/actions/perp/index.js +19 -0
  150. package/lib/drift/base/actions/perp/index.js.map +1 -0
  151. package/lib/drift/base/actions/perp/settleFunding.d.ts +25 -0
  152. package/lib/drift/base/actions/perp/settleFunding.js +41 -0
  153. package/lib/drift/base/actions/perp/settleFunding.js.map +1 -0
  154. package/lib/drift/base/actions/perp/settlePnl.d.ts +35 -0
  155. package/lib/drift/base/actions/perp/settlePnl.js +44 -0
  156. package/lib/drift/base/actions/perp/settlePnl.js.map +1 -0
  157. package/lib/drift/base/actions/spot/borrow.d.ts +1 -0
  158. package/lib/drift/base/actions/spot/borrow.js +8 -0
  159. package/lib/drift/base/actions/spot/borrow.js.map +1 -0
  160. package/lib/drift/base/actions/spot/deposit.d.ts +40 -0
  161. package/lib/drift/base/actions/spot/deposit.js +82 -0
  162. package/lib/drift/base/actions/spot/deposit.js.map +1 -0
  163. package/lib/drift/base/actions/spot/index.d.ts +3 -0
  164. package/lib/drift/base/actions/spot/index.js +20 -0
  165. package/lib/drift/base/actions/spot/index.js.map +1 -0
  166. package/lib/drift/base/actions/spot/withdraw.d.ts +16 -0
  167. package/lib/drift/base/actions/spot/withdraw.js +39 -0
  168. package/lib/drift/base/actions/spot/withdraw.js.map +1 -0
  169. package/lib/drift/base/actions/trade/cancelOrder.d.ts +47 -0
  170. package/lib/drift/base/actions/trade/cancelOrder.js +55 -0
  171. package/lib/drift/base/actions/trade/cancelOrder.js.map +1 -0
  172. package/lib/drift/base/actions/trade/editOrder.d.ts +55 -0
  173. package/lib/drift/base/actions/trade/editOrder.js +35 -0
  174. package/lib/drift/base/actions/trade/editOrder.js.map +1 -0
  175. package/lib/drift/base/actions/trade/index.d.ts +4 -0
  176. package/lib/drift/base/actions/trade/index.js +21 -0
  177. package/lib/drift/base/actions/trade/index.js.map +1 -0
  178. package/lib/drift/base/actions/trade/openPerpOrder/index.d.ts +3 -0
  179. package/lib/drift/base/actions/trade/openPerpOrder/index.js +20 -0
  180. package/lib/drift/base/actions/trade/openPerpOrder/index.js.map +1 -0
  181. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +84 -0
  182. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +293 -0
  183. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -0
  184. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +19 -0
  185. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +161 -0
  186. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -0
  187. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.d.ts +166 -0
  188. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +156 -0
  189. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -0
  190. package/lib/drift/base/actions/trade/swap.d.ts +62 -0
  191. package/lib/drift/base/actions/trade/swap.js +60 -0
  192. package/lib/drift/base/actions/trade/swap.js.map +1 -0
  193. package/lib/drift/base/actions/user/create.d.ts +75 -0
  194. package/lib/drift/base/actions/user/create.js +104 -0
  195. package/lib/drift/base/actions/user/create.js.map +1 -0
  196. package/lib/drift/base/actions/user/delete.d.ts +47 -0
  197. package/lib/drift/base/actions/user/delete.js +39 -0
  198. package/lib/drift/base/actions/user/delete.js.map +1 -0
  199. package/lib/drift/base/actions/user/index.d.ts +1 -0
  200. package/lib/drift/base/actions/user/index.js +18 -0
  201. package/lib/drift/base/actions/user/index.js.map +1 -0
  202. package/lib/drift/base/constants/accountNames.d.ts +1 -0
  203. package/lib/drift/base/constants/accountNames.js +13 -0
  204. package/lib/drift/base/constants/accountNames.js.map +1 -0
  205. package/lib/drift/base/details/index.d.ts +2 -0
  206. package/lib/drift/base/details/index.js +19 -0
  207. package/lib/drift/base/details/index.js.map +1 -0
  208. package/lib/drift/base/details/market/funding.d.ts +9 -0
  209. package/lib/drift/base/details/market/funding.js +50 -0
  210. package/lib/drift/base/details/market/funding.js.map +1 -0
  211. package/lib/drift/base/details/market/index.d.ts +2 -0
  212. package/lib/drift/base/details/market/index.js +19 -0
  213. package/lib/drift/base/details/market/index.js.map +1 -0
  214. package/lib/drift/base/details/market/openInterest.d.ts +5 -0
  215. package/lib/drift/base/details/market/openInterest.js +12 -0
  216. package/lib/drift/base/details/market/openInterest.js.map +1 -0
  217. package/lib/drift/base/details/user/balances.d.ts +40 -0
  218. package/lib/drift/base/details/user/balances.js +39 -0
  219. package/lib/drift/base/details/user/balances.js.map +1 -0
  220. package/lib/drift/base/details/user/index.d.ts +4 -0
  221. package/lib/drift/base/details/user/index.js +21 -0
  222. package/lib/drift/base/details/user/index.js.map +1 -0
  223. package/lib/drift/base/details/user/marginInfo.d.ts +29 -0
  224. package/lib/drift/base/details/user/marginInfo.js +49 -0
  225. package/lib/drift/base/details/user/marginInfo.js.map +1 -0
  226. package/lib/drift/base/details/user/orders.d.ts +3 -0
  227. package/lib/drift/base/details/user/orders.js +11 -0
  228. package/lib/drift/base/details/user/orders.js.map +1 -0
  229. package/lib/drift/base/details/user/positions.d.ts +70 -0
  230. package/lib/drift/base/details/user/positions.js +146 -0
  231. package/lib/drift/base/details/user/positions.js.map +1 -0
  232. package/lib/drift/cli.d.ts +25 -0
  233. package/lib/drift/cli.js +900 -0
  234. package/lib/drift/cli.js.map +1 -0
  235. package/lib/drift/constants/apiUrls.d.ts +27 -0
  236. package/lib/drift/constants/apiUrls.js +31 -0
  237. package/lib/drift/constants/apiUrls.js.map +1 -0
  238. package/lib/drift/example.d.ts +19 -0
  239. package/lib/drift/example.js +249 -0
  240. package/lib/drift/example.js.map +1 -0
  241. package/lib/drift/index.d.ts +3 -0
  242. package/lib/drift/index.js +20 -0
  243. package/lib/drift/index.js.map +1 -0
  244. package/lib/drift/utils/auctionParamsResponseMapper.d.ts +45 -0
  245. package/lib/drift/utils/auctionParamsResponseMapper.js +148 -0
  246. package/lib/drift/utils/auctionParamsResponseMapper.js.map +1 -0
  247. package/lib/drift/utils/funding.d.ts +2 -0
  248. package/lib/drift/utils/funding.js +9 -0
  249. package/lib/drift/utils/funding.js.map +1 -0
  250. package/lib/drift/utils/index.d.ts +3 -0
  251. package/lib/drift/utils/index.js +23 -0
  252. package/lib/drift/utils/index.js.map +1 -0
  253. package/lib/drift/utils/orderParams.d.ts +48 -0
  254. package/lib/drift/utils/orderParams.js +140 -0
  255. package/lib/drift/utils/orderParams.js.map +1 -0
  256. package/lib/index.d.ts +45 -0
  257. package/lib/index.js +68 -0
  258. package/lib/index.js.map +1 -0
  259. package/lib/serializableTypes.d.ts +961 -0
  260. package/lib/serializableTypes.js +3887 -0
  261. package/lib/serializableTypes.js.map +1 -0
  262. package/lib/types/MarketId.d.ts +26 -0
  263. package/lib/types/MarketId.js +64 -0
  264. package/lib/types/MarketId.js.map +1 -0
  265. package/lib/types/Superstake.d.ts +7 -0
  266. package/lib/types/Superstake.js +3 -0
  267. package/lib/types/Superstake.js.map +1 -0
  268. package/lib/types/UIEnv.d.ts +26 -0
  269. package/lib/types/UIEnv.js +49 -0
  270. package/lib/types/UIEnv.js.map +1 -0
  271. package/lib/types/UIMarket.d.ts +94 -0
  272. package/lib/types/UIMarket.js +224 -0
  273. package/lib/types/UIMarket.js.map +1 -0
  274. package/lib/types/candles.d.ts +4 -0
  275. package/lib/types/candles.js +9 -0
  276. package/lib/types/candles.js.map +1 -0
  277. package/lib/types/dataServer.d.ts +53 -0
  278. package/lib/types/dataServer.js +3 -0
  279. package/lib/types/dataServer.js.map +1 -0
  280. package/lib/types/historyServer.d.ts +38 -0
  281. package/lib/types/historyServer.js +11 -0
  282. package/lib/types/historyServer.js.map +1 -0
  283. package/lib/types/index.d.ts +12 -0
  284. package/lib/types/index.js +29 -0
  285. package/lib/types/index.js.map +1 -0
  286. package/lib/types/leaderboard.d.ts +80 -0
  287. package/lib/types/leaderboard.js +11 -0
  288. package/lib/types/leaderboard.js.map +1 -0
  289. package/lib/types/remote-configs.d.ts +61 -0
  290. package/lib/types/remote-configs.js +3 -0
  291. package/lib/types/remote-configs.js.map +1 -0
  292. package/lib/types/trade.d.ts +18 -0
  293. package/lib/types/trade.js +3 -0
  294. package/lib/types/trade.js.map +1 -0
  295. package/lib/types/user.d.ts +40 -0
  296. package/lib/types/user.js +3 -0
  297. package/lib/types/user.js.map +1 -0
  298. package/lib/types/utility.d.ts +15 -0
  299. package/lib/types/utility.js +3 -0
  300. package/lib/types/utility.js.map +1 -0
  301. package/lib/utils/CircularBuffers/CircularBuffer.d.ts +22 -0
  302. package/lib/utils/CircularBuffers/CircularBuffer.js +73 -0
  303. package/lib/utils/CircularBuffers/CircularBuffer.js.map +1 -0
  304. package/lib/utils/CircularBuffers/UniqueCircularBuffer.d.ts +19 -0
  305. package/lib/utils/CircularBuffers/UniqueCircularBuffer.js +78 -0
  306. package/lib/utils/CircularBuffers/UniqueCircularBuffer.js.map +1 -0
  307. package/lib/utils/CircularBuffers/index.d.ts +2 -0
  308. package/lib/utils/CircularBuffers/index.js +19 -0
  309. package/lib/utils/CircularBuffers/index.js.map +1 -0
  310. package/lib/utils/MultiplexWebSocket.d.ts +95 -0
  311. package/lib/utils/MultiplexWebSocket.js +416 -0
  312. package/lib/utils/MultiplexWebSocket.js.map +1 -0
  313. package/lib/utils/NumLib.d.ts +106 -0
  314. package/lib/utils/NumLib.js +300 -0
  315. package/lib/utils/NumLib.js.map +1 -0
  316. package/lib/utils/SharedInterval.d.ts +21 -0
  317. package/lib/utils/SharedInterval.js +47 -0
  318. package/lib/utils/SharedInterval.js.map +1 -0
  319. package/lib/utils/SlotBasedResultValidator.d.ts +9 -0
  320. package/lib/utils/SlotBasedResultValidator.js +27 -0
  321. package/lib/utils/SlotBasedResultValidator.js.map +1 -0
  322. package/lib/utils/Stopwatch.d.ts +15 -0
  323. package/lib/utils/Stopwatch.js +31 -0
  324. package/lib/utils/Stopwatch.js.map +1 -0
  325. package/lib/utils/StrictEventEmitter.d.ts +15 -0
  326. package/lib/utils/StrictEventEmitter.js +55 -0
  327. package/lib/utils/StrictEventEmitter.js.map +1 -0
  328. package/lib/utils/WalletConnectionState.d.ts +31 -0
  329. package/lib/utils/WalletConnectionState.js +83 -0
  330. package/lib/utils/WalletConnectionState.js.map +1 -0
  331. package/lib/utils/assert.d.ts +1 -0
  332. package/lib/utils/assert.js +10 -0
  333. package/lib/utils/assert.js.map +1 -0
  334. package/lib/utils/candles/Candle.d.ts +94 -0
  335. package/lib/utils/candles/Candle.js +580 -0
  336. package/lib/utils/candles/Candle.js.map +1 -0
  337. package/lib/utils/candles/types.d.ts +8 -0
  338. package/lib/utils/candles/types.js +3 -0
  339. package/lib/utils/candles/types.js.map +1 -0
  340. package/lib/utils/dlob-server/DlobServerWebsocketUtils.d.ts +57 -0
  341. package/lib/utils/dlob-server/DlobServerWebsocketUtils.js +137 -0
  342. package/lib/utils/dlob-server/DlobServerWebsocketUtils.js.map +1 -0
  343. package/lib/utils/driftEvents.d.ts +10 -0
  344. package/lib/utils/driftEvents.js +123 -0
  345. package/lib/utils/driftEvents.js.map +1 -0
  346. package/lib/utils/equalityChecks.d.ts +12 -0
  347. package/lib/utils/equalityChecks.js +71 -0
  348. package/lib/utils/equalityChecks.js.map +1 -0
  349. package/lib/utils/featureFlags.d.ts +3 -0
  350. package/lib/utils/featureFlags.js +7 -0
  351. package/lib/utils/featureFlags.js.map +1 -0
  352. package/lib/utils/geoblock/index.d.ts +4 -0
  353. package/lib/utils/geoblock/index.js +20 -0
  354. package/lib/utils/geoblock/index.js.map +1 -0
  355. package/lib/utils/index.d.ts +181 -0
  356. package/lib/utils/index.js +608 -0
  357. package/lib/utils/index.js.map +1 -0
  358. package/lib/utils/insuranceFund.d.ts +15 -0
  359. package/lib/utils/insuranceFund.js +84 -0
  360. package/lib/utils/insuranceFund.js.map +1 -0
  361. package/lib/utils/logger.d.ts +5 -0
  362. package/lib/utils/logger.js +53 -0
  363. package/lib/utils/logger.js.map +1 -0
  364. package/lib/utils/math.d.ts +10 -0
  365. package/lib/utils/math.js +89 -0
  366. package/lib/utils/math.js.map +1 -0
  367. package/lib/utils/orderbook/index.d.ts +65 -0
  368. package/lib/utils/orderbook/index.js +80 -0
  369. package/lib/utils/orderbook/index.js.map +1 -0
  370. package/lib/utils/pollingSequenceGuard.d.ts +9 -0
  371. package/lib/utils/pollingSequenceGuard.js +24 -0
  372. package/lib/utils/pollingSequenceGuard.js.map +1 -0
  373. package/lib/utils/priority-fees/PriorityFeeCalculator.d.ts +24 -0
  374. package/lib/utils/priority-fees/PriorityFeeCalculator.js +53 -0
  375. package/lib/utils/priority-fees/PriorityFeeCalculator.js.map +1 -0
  376. package/lib/utils/priority-fees/PriorityFeeStrategies.d.ts +5 -0
  377. package/lib/utils/priority-fees/PriorityFeeStrategies.js +43 -0
  378. package/lib/utils/priority-fees/PriorityFeeStrategies.js.map +1 -0
  379. package/lib/utils/priority-fees/index.d.ts +2 -0
  380. package/lib/utils/priority-fees/index.js +19 -0
  381. package/lib/utils/priority-fees/index.js.map +1 -0
  382. package/lib/utils/priorityFees.d.ts +14 -0
  383. package/lib/utils/priorityFees.js +68 -0
  384. package/lib/utils/priorityFees.js.map +1 -0
  385. package/lib/utils/rpcLatency.d.ts +7 -0
  386. package/lib/utils/rpcLatency.js +49 -0
  387. package/lib/utils/rpcLatency.js.map +1 -0
  388. package/lib/utils/rxjs.d.ts +11 -0
  389. package/lib/utils/rxjs.js +24 -0
  390. package/lib/utils/rxjs.js.map +1 -0
  391. package/lib/utils/s3Buckets.d.ts +43 -0
  392. package/lib/utils/s3Buckets.js +108 -0
  393. package/lib/utils/s3Buckets.js.map +1 -0
  394. package/lib/utils/superstake.d.ts +86 -0
  395. package/lib/utils/superstake.js +224 -0
  396. package/lib/utils/superstake.js.map +1 -0
  397. package/lib/utils/token.d.ts +16 -0
  398. package/lib/utils/token.js +44 -0
  399. package/lib/utils/token.js.map +1 -0
  400. package/package.json +87 -0
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSwiftPerpMarketOrder = exports.createOpenPerpMarketOrderTxn = exports.createOpenPerpMarketOrderIx = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ const utils_1 = require("../../../../../../utils");
6
+ const auctionParamsResponseMapper_1 = require("../../../../../utils/auctionParamsResponseMapper");
7
+ const openSwiftOrder_1 = require("../openSwiftOrder");
8
+ const types_1 = require("../../../../../../types");
9
+ const swiftClient_1 = require("../../../../../../clients/swiftClient");
10
+ const orderParams_1 = require("../../../../../utils/orderParams");
11
+ /**
12
+ * Fetches order parameters from the auction params server
13
+ */
14
+ async function fetchOrderParamsFromServer({ assetType, marketIndex, marketType = sdk_1.MarketType.PERP, direction, amount, dlobServerHttpUrl, auctionParamsOptions = {}, }) {
15
+ var _a;
16
+ // Extract optional parameters (no defaults except for what's required by server)
17
+ const { maxLeverageSelected, maxLeverageOrderSize, reduceOnly, auctionDuration, auctionStartPriceOffset, auctionEndPriceOffset, auctionStartPriceOffsetFrom, auctionEndPriceOffsetFrom, slippageTolerance, isOracleOrder, orderType, ...restOptions } = auctionParamsOptions;
18
+ // Build URL parameters for server request
19
+ const urlParamsObject = {
20
+ // Required fields
21
+ assetType,
22
+ marketType: utils_1.ENUM_UTILS.toStr(marketType),
23
+ marketIndex: marketIndex.toString(),
24
+ direction: utils_1.ENUM_UTILS.toStr(direction),
25
+ amount: amount.toString(),
26
+ };
27
+ // Add optional parameters only if they are provided
28
+ const optionalParams = {
29
+ maxLeverageSelected,
30
+ maxLeverageOrderSize,
31
+ reduceOnly,
32
+ auctionDuration,
33
+ auctionStartPriceOffset,
34
+ auctionEndPriceOffset,
35
+ auctionStartPriceOffsetFrom,
36
+ auctionEndPriceOffsetFrom,
37
+ slippageTolerance,
38
+ isOracleOrder,
39
+ orderType,
40
+ additionalEndPriceBuffer: restOptions.additionalEndPriceBuffer,
41
+ forceUpToSlippage: restOptions.forceUpToSlippage,
42
+ };
43
+ // Add defined optional parameters
44
+ Object.entries(optionalParams).forEach(([key, value]) => {
45
+ if (value !== undefined) {
46
+ urlParamsObject[key] = value.toString();
47
+ }
48
+ });
49
+ const urlParams = new URLSearchParams(urlParamsObject);
50
+ // Get order params from server
51
+ const requestUrl = `${dlobServerHttpUrl}/auctionParams?${urlParams.toString()}`;
52
+ const response = await fetch(requestUrl);
53
+ if (!response.ok) {
54
+ throw new Error(`Server responded with ${response.status}: ${response.statusText}`);
55
+ }
56
+ const serverResponse = await response.json();
57
+ const mappedParams = (0, auctionParamsResponseMapper_1.mapAuctionParamsResponse)(serverResponse);
58
+ // Convert MappedAuctionParams to OptionalOrderParams
59
+ return {
60
+ orderType: mappedParams.orderType,
61
+ marketType: mappedParams.marketType,
62
+ userOrderId: mappedParams.userOrderId,
63
+ direction: mappedParams.direction,
64
+ baseAssetAmount: mappedParams.baseAssetAmount,
65
+ marketIndex: mappedParams.marketIndex,
66
+ reduceOnly: mappedParams.reduceOnly,
67
+ postOnly: mappedParams.postOnly,
68
+ triggerPrice: mappedParams.triggerPrice,
69
+ triggerCondition: mappedParams.triggerCondition,
70
+ oraclePriceOffset: ((_a = mappedParams.oraclePriceOffset) === null || _a === void 0 ? void 0 : _a.toNumber()) || null,
71
+ auctionDuration: mappedParams.auctionDuration,
72
+ maxTs: mappedParams.maxTs,
73
+ auctionStartPrice: mappedParams.auctionStartPrice,
74
+ auctionEndPrice: mappedParams.auctionEndPrice,
75
+ };
76
+ }
77
+ /**
78
+ * Creates and submits a Swift (signed message) order. Only available for perp orders.
79
+ */
80
+ async function createSwiftOrder({ driftClient, user, assetType, marketIndex, direction, amount, bracketOrders, dlobServerHttpUrl, auctionParamsOptions, swiftOptions, }) {
81
+ // Get order parameters from server
82
+ const orderParams = await fetchOrderParamsFromServer({
83
+ driftClient,
84
+ user,
85
+ assetType,
86
+ marketIndex,
87
+ marketType: sdk_1.MarketType.PERP,
88
+ direction,
89
+ amount,
90
+ dlobServerHttpUrl,
91
+ auctionParamsOptions,
92
+ });
93
+ // Fetch current slot programmatically
94
+ const currentSlot = await driftClient.connection.getSlot();
95
+ const userAccount = user.getUserAccount();
96
+ // Use the existing prepSwiftOrder helper function
97
+ const { hexEncodedSwiftOrderMessage, signedMsgOrderUuid } = (0, openSwiftOrder_1.prepSwiftOrder)({
98
+ driftClient,
99
+ takerUserAccount: {
100
+ pubKey: swiftOptions.wallet.publicKey,
101
+ subAccountId: userAccount.subAccountId,
102
+ },
103
+ currentSlot,
104
+ isDelegate: swiftOptions.isDelegate || false,
105
+ orderParams: {
106
+ main: orderParams,
107
+ takeProfit: bracketOrders === null || bracketOrders === void 0 ? void 0 : bracketOrders.takeProfit,
108
+ stopLoss: bracketOrders === null || bracketOrders === void 0 ? void 0 : bracketOrders.stopLoss,
109
+ },
110
+ slotBuffer: swiftOptions.signedMessageOrderSlotBuffer || 30,
111
+ });
112
+ // Sign the message
113
+ const signedMessage = await swiftOptions.wallet.signMessage(hexEncodedSwiftOrderMessage.uInt8Array);
114
+ // Initialize SwiftClient (required before using sendSwiftOrder)
115
+ swiftClient_1.SwiftClient.init(swiftOptions.swiftServerUrl);
116
+ const swiftOrderResult = (0, openSwiftOrder_1.sendSwiftOrder)({
117
+ driftClient,
118
+ marketId: types_1.MarketId.createPerpMarket(marketIndex),
119
+ hexEncodedSwiftOrderMessageString: hexEncodedSwiftOrderMessage.string,
120
+ signedMessage,
121
+ signedMsgOrderUuid,
122
+ takerAuthority: swiftOptions.wallet.publicKey,
123
+ signingAuthority: swiftOptions.wallet.publicKey,
124
+ auctionDurationSlot: orderParams.auctionDuration || undefined,
125
+ swiftConfirmationSlotBuffer: 15,
126
+ });
127
+ return swiftOrderResult;
128
+ }
129
+ /**
130
+ * Creates transaction instructions for opening a perp market order.
131
+ * If swiftOptions is provided, it will create a Swift (signed message) order instead.
132
+ *
133
+ * @param driftClient - The Drift client instance for interacting with the protocol
134
+ * @param user - The user account that will place the order
135
+ * @param assetType - Whether the amount is in base or quote units
136
+ * @param marketIndex - The perp market index to trade
137
+ * @param direction - The direction of the trade (long/short)
138
+ * @param amount - The amount to trade
139
+ * @param dlobServerHttpUrl - Server URL for the auction params endpoint
140
+ * @param auctionParamsOptions - Optional parameters for auction params endpoint and order configuration
141
+ * @param useSwift - Whether to use Swift (signed message) orders instead of regular transactions
142
+ * @param swiftOptions - Options for Swift (signed message) orders. Required if useSwift is true
143
+ *
144
+ * @returns Promise resolving to an array of transaction instructions for regular orders, or empty array for Swift orders
145
+ */
146
+ const createOpenPerpMarketOrderIx = async ({ driftClient, user, assetType, marketIndex, direction, amount, dlobServerHttpUrl, auctionParamsOptions = {}, useSwift = false, swiftOptions, }) => {
147
+ if (!amount || amount.isZero()) {
148
+ throw new Error('Amount must be greater than zero');
149
+ }
150
+ // First, get order parameters from server (same for both Swift and regular orders)
151
+ const orderParams = await fetchOrderParamsFromServer({
152
+ driftClient,
153
+ user,
154
+ assetType,
155
+ marketIndex,
156
+ marketType: sdk_1.MarketType.PERP,
157
+ direction,
158
+ amount,
159
+ dlobServerHttpUrl,
160
+ auctionParamsOptions,
161
+ });
162
+ // If useSwift is true, use prepSwiftOrder and return empty array
163
+ if (useSwift) {
164
+ if (!swiftOptions) {
165
+ throw new Error('swiftOptions is required when useSwift is true');
166
+ }
167
+ const currentSlot = await driftClient.connection.getSlot();
168
+ const userAccount = user.getUserAccount();
169
+ // Use the existing prepSwiftOrder helper function
170
+ (0, openSwiftOrder_1.prepSwiftOrder)({
171
+ driftClient,
172
+ takerUserAccount: {
173
+ pubKey: swiftOptions.wallet.publicKey,
174
+ subAccountId: userAccount.subAccountId,
175
+ },
176
+ currentSlot,
177
+ isDelegate: swiftOptions.isDelegate || false,
178
+ orderParams: {
179
+ main: orderParams,
180
+ // TODO: Add support for stopLoss and takeProfit
181
+ },
182
+ slotBuffer: swiftOptions.signedMessageOrderSlotBuffer || 30,
183
+ });
184
+ // Swift orders don't return transaction instructions
185
+ return [];
186
+ }
187
+ // Regular order flow - create transaction instruction
188
+ const placeOrderIx = await driftClient.getPlaceOrdersIx([orderParams]);
189
+ return [placeOrderIx];
190
+ };
191
+ exports.createOpenPerpMarketOrderIx = createOpenPerpMarketOrderIx;
192
+ /**
193
+ * Creates a complete transaction for opening a perp market order.
194
+ *
195
+ * @param driftClient - The Drift client instance for interacting with the protocol
196
+ * @param user - The user account that will place the order
197
+ * @param marketIndex - The perp market index to trade
198
+ * @param direction - The direction of the trade (long/short)
199
+ * @param amount - The amount to trade
200
+ * @param auctionParamsOptions - Optional parameters for auction params endpoint and order configuration
201
+ * @param dlobServerHttpUrl - Server URL for the auction params endpoint
202
+ *
203
+ * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)
204
+ */
205
+ const createOpenPerpMarketOrderTxn = async ({ driftClient, user, assetType, marketIndex, direction, amount, dlobServerHttpUrl, auctionParamsOptions, bracketOrders, useSwift, swiftOptions, }) => {
206
+ if (!amount || amount.isZero()) {
207
+ throw new Error('Amount must be greater than zero');
208
+ }
209
+ // First, get order parameters from server (same for both Swift and regular orders)
210
+ const orderParams = await fetchOrderParamsFromServer({
211
+ driftClient,
212
+ user,
213
+ assetType,
214
+ marketIndex,
215
+ marketType: sdk_1.MarketType.PERP,
216
+ direction,
217
+ amount,
218
+ dlobServerHttpUrl,
219
+ auctionParamsOptions,
220
+ });
221
+ // If useSwift is true, return the Swift result directly
222
+ if (useSwift) {
223
+ if (!swiftOptions) {
224
+ throw new Error('swiftOptions is required when useSwift is true');
225
+ }
226
+ return (await createSwiftOrder({
227
+ driftClient,
228
+ user,
229
+ assetType,
230
+ marketIndex,
231
+ direction,
232
+ amount,
233
+ dlobServerHttpUrl,
234
+ bracketOrders,
235
+ auctionParamsOptions,
236
+ swiftOptions,
237
+ }));
238
+ }
239
+ const allOrders = [orderParams];
240
+ if (bracketOrders === null || bracketOrders === void 0 ? void 0 : bracketOrders.takeProfit) {
241
+ const takeProfitParams = (0, orderParams_1.buildNonMarketOrderParams)({
242
+ marketIndex,
243
+ marketType: sdk_1.MarketType.PERP,
244
+ direction: bracketOrders.takeProfit.direction,
245
+ baseAssetAmount: amount,
246
+ orderConfig: {
247
+ orderType: 'takeProfit',
248
+ triggerPrice: bracketOrders.takeProfit.triggerPrice,
249
+ },
250
+ reduceOnly: true,
251
+ });
252
+ allOrders.push(takeProfitParams);
253
+ }
254
+ if (bracketOrders === null || bracketOrders === void 0 ? void 0 : bracketOrders.stopLoss) {
255
+ const stopLossParams = (0, orderParams_1.buildNonMarketOrderParams)({
256
+ marketIndex,
257
+ marketType: sdk_1.MarketType.PERP,
258
+ direction: bracketOrders.stopLoss.direction,
259
+ baseAssetAmount: amount,
260
+ orderConfig: {
261
+ orderType: 'stopLoss',
262
+ triggerPrice: bracketOrders.stopLoss.triggerPrice,
263
+ },
264
+ reduceOnly: true,
265
+ });
266
+ allOrders.push(stopLossParams);
267
+ }
268
+ // Regular order flow - create transaction instruction and build transaction
269
+ const placeOrderIx = await driftClient.getPlaceOrdersIx(allOrders);
270
+ const openPerpMarketOrderTxn = await driftClient.txHandler.buildTransaction({
271
+ instructions: [placeOrderIx],
272
+ txVersion: 0,
273
+ connection: driftClient.connection,
274
+ preFlightCommitment: 'confirmed',
275
+ fetchAllMarketLookupTableAccounts: driftClient.fetchAllLookupTableAccounts.bind(driftClient),
276
+ });
277
+ return openPerpMarketOrderTxn;
278
+ };
279
+ exports.createOpenPerpMarketOrderTxn = createOpenPerpMarketOrderTxn;
280
+ /**
281
+ * Creates a Swift (signed message) order directly.
282
+ * This is a convenience function for when you only want to create Swift orders.
283
+ *
284
+ * @param params - All the parameters needed for creating a Swift order
285
+ * @returns Promise resolving to SwiftOrderResult with observable and order UUID
286
+ */
287
+ const createSwiftPerpMarketOrder = async (params) => {
288
+ return await createSwiftOrder({
289
+ ...params,
290
+ });
291
+ };
292
+ exports.createSwiftPerpMarketOrder = createSwiftPerpMarketOrder;
293
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.ts"],"names":[],"mappings":";;;AAAA,yCAOyB;AAMzB,mDAAqD;AACrD,kGAI0D;AAC1D,sDAM2B;AAC3B,mDAAmD;AACnD,uEAAoE;AACpE,kEAA6E;AAsD7E;;GAEG;AACH,KAAK,UAAU,0BAA0B,CAAC,EACzC,SAAS,EACT,WAAW,EACX,UAAU,GAAG,gBAAU,CAAC,IAAI,EAC5B,SAAS,EACT,MAAM,EACN,iBAAiB,EACjB,oBAAoB,GAAG,EAAE,GACL;;IACpB,iFAAiF;IACjF,MAAM,EACL,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,GAAG,WAAW,EACd,GAAG,oBAAoB,CAAC;IAEzB,0CAA0C;IAC1C,MAAM,eAAe,GAA2B;QAC/C,kBAAkB;QAClB,SAAS;QACT,UAAU,EAAE,kBAAU,CAAC,KAAK,CAAC,UAAU,CAAC;QACxC,WAAW,EAAE,WAAW,CAAC,QAAQ,EAAE;QACnC,SAAS,EAAE,kBAAU,CAAC,KAAK,CAAC,SAAS,CAAC;QACtC,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;KACzB,CAAC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;IAED,IAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,QAAQ,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAG,IAAA,uCAAyB,EAAC;YAChD,WAAW;YACX,UAAU,EAAE,gBAAU,CAAC,IAAI;YAC3B,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,SAAS;YAC3C,eAAe,EAAE,MAAM;YACvB,WAAW,EAAE;gBACZ,SAAS,EAAE,UAAU;gBACrB,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,YAAY;aACjD;YACD,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAChC,CAAC;IAED,4EAA4E;IAC5E,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACnE,MAAM,sBAAsB,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC;QAC3E,YAAY,EAAE,CAAC,YAAY,CAAC;QAC5B,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAChC,WAAW,CAAC,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;KAC1D,CAAC,CAAC;IAEH,OAAO,sBAE8B,CAAC;AACvC,CAAC,CAAC;AAnGW,QAAA,4BAA4B,gCAmGvC;AAEF;;;;;;GAMG;AACI,MAAM,0BAA0B,GAAG,KAAK,EAC9C,MAEC,EAC2B,EAAE;IAC9B,OAAO,MAAM,gBAAgB,CAAC;QAC7B,GAAG,MAAM;KACT,CAAC,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,0BAA0B,8BAQrC","sourcesContent":["import {\n\tDriftClient,\n\tUser,\n\tBN,\n\tPositionDirection,\n\tOptionalOrderParams,\n\tMarketType,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { ENUM_UTILS } from '../../../../../../utils';\nimport {\n\tmapAuctionParamsResponse,\n\tServerAuctionParamsResponse,\n\tMappedAuctionParams,\n} from '../../../../../utils/auctionParamsResponseMapper';\nimport {\n\tOptionalTriggerOrderParams,\n\tprepSwiftOrder,\n\tsendSwiftOrder,\n\tSwiftOrderOptions,\n\tSwiftOrderResult,\n} from '../openSwiftOrder';\nimport { MarketId } from '../../../../../../types';\nimport { SwiftClient } from '../../../../../../clients/swiftClient';\nimport { buildNonMarketOrderParams } from '../../../../../utils/orderParams';\n\nexport interface AuctionParamsRequestOptions {\n\t// Optional parameters that can override defaults or provide additional configuration\n\tmaxLeverageSelected?: boolean;\n\tmaxLeverageOrderSize?: BN;\n\treduceOnly?: boolean;\n\tauctionDuration?: number;\n\tauctionStartPriceOffset?: number;\n\tauctionEndPriceOffset?: number;\n\tauctionStartPriceOffsetFrom?: string; // TradeOffsetPrice\n\tauctionEndPriceOffsetFrom?: string; // TradeOffsetPrice\n\tslippageTolerance?: number | 'dynamic';\n\tauctionPriceCaps?: {\n\t\tmin: BN;\n\t\tmax: BN;\n\t};\n\tisOracleOrder?: boolean;\n\tadditionalEndPriceBuffer?: BN;\n\tforceUpToSlippage?: boolean;\n\torderType?: 'market' | 'oracle';\n}\n\nexport type OpenPerpMarketOrderParams<T extends boolean = boolean> = {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tassetType: 'base' | 'quote';\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tamount: BN;\n\tauctionParamsOptions?: AuctionParamsRequestOptions;\n\tdlobServerHttpUrl: string;\n\tbracketOrders?: {\n\t\ttakeProfit?: OptionalTriggerOrderParams;\n\t\tstopLoss?: OptionalTriggerOrderParams;\n\t};\n\tmarketType?: MarketType;\n\tuseSwift: T;\n} & (T extends true\n\t? { swiftOptions: SwiftOrderOptions }\n\t: { swiftOptions?: never });\n\ninterface RegularOrderParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tassetType: 'base' | 'quote';\n\tmarketType?: MarketType;\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tamount: BN;\n\tauctionParamsOptions?: AuctionParamsRequestOptions;\n\tdlobServerHttpUrl: string;\n}\n\n/**\n * Fetches order parameters from the auction params server\n */\nasync function fetchOrderParamsFromServer({\n\tassetType,\n\tmarketIndex,\n\tmarketType = MarketType.PERP,\n\tdirection,\n\tamount,\n\tdlobServerHttpUrl,\n\tauctionParamsOptions = {},\n}: RegularOrderParams): Promise<OptionalOrderParams> {\n\t// Extract optional parameters (no defaults except for what's required by server)\n\tconst {\n\t\tmaxLeverageSelected,\n\t\tmaxLeverageOrderSize,\n\t\treduceOnly,\n\t\tauctionDuration,\n\t\tauctionStartPriceOffset,\n\t\tauctionEndPriceOffset,\n\t\tauctionStartPriceOffsetFrom,\n\t\tauctionEndPriceOffsetFrom,\n\t\tslippageTolerance,\n\t\tisOracleOrder,\n\t\torderType,\n\t\t...restOptions\n\t} = auctionParamsOptions;\n\n\t// Build URL parameters for server request\n\tconst urlParamsObject: Record<string, string> = {\n\t\t// Required fields\n\t\tassetType,\n\t\tmarketType: ENUM_UTILS.toStr(marketType),\n\t\tmarketIndex: marketIndex.toString(),\n\t\tdirection: ENUM_UTILS.toStr(direction),\n\t\tamount: amount.toString(),\n\t};\n\n\t// Add optional parameters only if they are provided\n\tconst optionalParams = {\n\t\tmaxLeverageSelected,\n\t\tmaxLeverageOrderSize,\n\t\treduceOnly,\n\t\tauctionDuration,\n\t\tauctionStartPriceOffset,\n\t\tauctionEndPriceOffset,\n\t\tauctionStartPriceOffsetFrom,\n\t\tauctionEndPriceOffsetFrom,\n\t\tslippageTolerance,\n\t\tisOracleOrder,\n\t\torderType,\n\t\tadditionalEndPriceBuffer: restOptions.additionalEndPriceBuffer,\n\t\tforceUpToSlippage: restOptions.forceUpToSlippage,\n\t};\n\n\t// Add defined optional parameters\n\tObject.entries(optionalParams).forEach(([key, value]) => {\n\t\tif (value !== undefined) {\n\t\t\turlParamsObject[key] = value.toString();\n\t\t}\n\t});\n\n\tconst urlParams = new URLSearchParams(urlParamsObject);\n\n\t// Get order params from server\n\tconst requestUrl = `${dlobServerHttpUrl}/auctionParams?${urlParams.toString()}`;\n\tconst response = await fetch(requestUrl);\n\n\tif (!response.ok) {\n\t\tthrow new Error(\n\t\t\t`Server responded with ${response.status}: ${response.statusText}`\n\t\t);\n\t}\n\n\tconst serverResponse: ServerAuctionParamsResponse = await response.json();\n\tconst mappedParams: MappedAuctionParams =\n\t\tmapAuctionParamsResponse(serverResponse);\n\n\t// Convert MappedAuctionParams to OptionalOrderParams\n\treturn {\n\t\torderType: mappedParams.orderType,\n\t\tmarketType: mappedParams.marketType,\n\t\tuserOrderId: mappedParams.userOrderId,\n\t\tdirection: mappedParams.direction,\n\t\tbaseAssetAmount: mappedParams.baseAssetAmount,\n\t\tmarketIndex: mappedParams.marketIndex,\n\t\treduceOnly: mappedParams.reduceOnly,\n\t\tpostOnly: mappedParams.postOnly,\n\t\ttriggerPrice: mappedParams.triggerPrice,\n\t\ttriggerCondition: mappedParams.triggerCondition,\n\t\toraclePriceOffset: mappedParams.oraclePriceOffset?.toNumber() || null,\n\t\tauctionDuration: mappedParams.auctionDuration,\n\t\tmaxTs: mappedParams.maxTs,\n\t\tauctionStartPrice: mappedParams.auctionStartPrice,\n\t\tauctionEndPrice: mappedParams.auctionEndPrice,\n\t};\n}\n\n/**\n * Creates and submits a Swift (signed message) order. Only available for perp orders.\n */\nasync function createSwiftOrder({\n\tdriftClient,\n\tuser,\n\tassetType,\n\tmarketIndex,\n\tdirection,\n\tamount,\n\tbracketOrders,\n\tdlobServerHttpUrl,\n\tauctionParamsOptions,\n\tswiftOptions,\n}: Omit<OpenPerpMarketOrderParams, 'useSwift'> & {\n\tswiftOptions: SwiftOrderOptions;\n}): Promise<SwiftOrderResult> {\n\t// Get order parameters from server\n\tconst orderParams = await fetchOrderParamsFromServer({\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType,\n\t\tmarketIndex,\n\t\tmarketType: MarketType.PERP,\n\t\tdirection,\n\t\tamount,\n\t\tdlobServerHttpUrl,\n\t\tauctionParamsOptions,\n\t});\n\n\t// Fetch current slot programmatically\n\tconst currentSlot = await driftClient.connection.getSlot();\n\tconst userAccount = user.getUserAccount();\n\n\t// Use the existing prepSwiftOrder helper function\n\tconst { hexEncodedSwiftOrderMessage, signedMsgOrderUuid } = prepSwiftOrder({\n\t\tdriftClient,\n\t\ttakerUserAccount: {\n\t\t\tpubKey: swiftOptions.wallet.publicKey,\n\t\t\tsubAccountId: userAccount.subAccountId,\n\t\t},\n\t\tcurrentSlot,\n\t\tisDelegate: swiftOptions.isDelegate || false,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: bracketOrders?.takeProfit,\n\t\t\tstopLoss: bracketOrders?.stopLoss,\n\t\t},\n\t\tslotBuffer: swiftOptions.signedMessageOrderSlotBuffer || 30,\n\t});\n\n\t// Sign the message\n\tconst signedMessage = await swiftOptions.wallet.signMessage(\n\t\thexEncodedSwiftOrderMessage.uInt8Array\n\t);\n\n\t// Initialize SwiftClient (required before using sendSwiftOrder)\n\tSwiftClient.init(swiftOptions.swiftServerUrl);\n\n\tconst swiftOrderResult = sendSwiftOrder({\n\t\tdriftClient,\n\t\tmarketId: MarketId.createPerpMarket(marketIndex),\n\t\thexEncodedSwiftOrderMessageString: hexEncodedSwiftOrderMessage.string,\n\t\tsignedMessage,\n\t\tsignedMsgOrderUuid,\n\t\ttakerAuthority: swiftOptions.wallet.publicKey,\n\t\tsigningAuthority: swiftOptions.wallet.publicKey,\n\t\tauctionDurationSlot: orderParams.auctionDuration || undefined,\n\t\tswiftConfirmationSlotBuffer: 15,\n\t});\n\n\treturn swiftOrderResult;\n}\n\n/**\n * Creates transaction instructions for opening a perp market order.\n * If swiftOptions is provided, it will create a Swift (signed message) order instead.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param assetType - Whether the amount is in base or quote units\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n * @param auctionParamsOptions - Optional parameters for auction params endpoint and order configuration\n * @param useSwift - Whether to use Swift (signed message) orders instead of regular transactions\n * @param swiftOptions - Options for Swift (signed message) orders. Required if useSwift is true\n *\n * @returns Promise resolving to an array of transaction instructions for regular orders, or empty array for Swift orders\n */\nexport const createOpenPerpMarketOrderIx = async ({\n\tdriftClient,\n\tuser,\n\tassetType,\n\tmarketIndex,\n\tdirection,\n\tamount,\n\tdlobServerHttpUrl,\n\tauctionParamsOptions = {},\n\tuseSwift = false,\n\tswiftOptions,\n}: OpenPerpMarketOrderParams): Promise<TransactionInstruction[]> => {\n\tif (!amount || amount.isZero()) {\n\t\tthrow new Error('Amount must be greater than zero');\n\t}\n\n\t// First, get order parameters from server (same for both Swift and regular orders)\n\tconst orderParams = await fetchOrderParamsFromServer({\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType,\n\t\tmarketIndex,\n\t\tmarketType: MarketType.PERP,\n\t\tdirection,\n\t\tamount,\n\t\tdlobServerHttpUrl,\n\t\tauctionParamsOptions,\n\t});\n\n\t// If useSwift is true, use prepSwiftOrder and return empty array\n\tif (useSwift) {\n\t\tif (!swiftOptions) {\n\t\t\tthrow new Error('swiftOptions is required when useSwift is true');\n\t\t}\n\n\t\tconst currentSlot = await driftClient.connection.getSlot();\n\t\tconst userAccount = user.getUserAccount();\n\n\t\t// Use the existing prepSwiftOrder helper function\n\t\tprepSwiftOrder({\n\t\t\tdriftClient,\n\t\t\ttakerUserAccount: {\n\t\t\t\tpubKey: swiftOptions.wallet.publicKey,\n\t\t\t\tsubAccountId: userAccount.subAccountId,\n\t\t\t},\n\t\t\tcurrentSlot,\n\t\t\tisDelegate: swiftOptions.isDelegate || false,\n\t\t\torderParams: {\n\t\t\t\tmain: orderParams,\n\t\t\t\t// TODO: Add support for stopLoss and takeProfit\n\t\t\t},\n\t\t\tslotBuffer: swiftOptions.signedMessageOrderSlotBuffer || 30,\n\t\t});\n\n\t\t// Swift orders don't return transaction instructions\n\t\treturn [];\n\t}\n\n\t// Regular order flow - create transaction instruction\n\tconst placeOrderIx = await driftClient.getPlaceOrdersIx([orderParams]);\n\treturn [placeOrderIx];\n};\n\n/**\n * Creates a complete transaction for opening a perp market order.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param auctionParamsOptions - Optional parameters for auction params endpoint and order configuration\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createOpenPerpMarketOrderTxn = async <T extends boolean>({\n\tdriftClient,\n\tuser,\n\tassetType,\n\tmarketIndex,\n\tdirection,\n\tamount,\n\tdlobServerHttpUrl,\n\tauctionParamsOptions,\n\tbracketOrders,\n\tuseSwift,\n\tswiftOptions,\n}: OpenPerpMarketOrderParams<T>): Promise<\n\tT extends true ? SwiftOrderResult : Transaction | VersionedTransaction\n> => {\n\tif (!amount || amount.isZero()) {\n\t\tthrow new Error('Amount must be greater than zero');\n\t}\n\n\t// First, get order parameters from server (same for both Swift and regular orders)\n\tconst orderParams = await fetchOrderParamsFromServer({\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType,\n\t\tmarketIndex,\n\t\tmarketType: MarketType.PERP,\n\t\tdirection,\n\t\tamount,\n\t\tdlobServerHttpUrl,\n\t\tauctionParamsOptions,\n\t});\n\n\t// If useSwift is true, return the Swift result directly\n\tif (useSwift) {\n\t\tif (!swiftOptions) {\n\t\t\tthrow new Error('swiftOptions is required when useSwift is true');\n\t\t}\n\t\treturn (await createSwiftOrder({\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tassetType,\n\t\t\tmarketIndex,\n\t\t\tdirection,\n\t\t\tamount,\n\t\t\tdlobServerHttpUrl,\n\t\t\tbracketOrders,\n\t\t\tauctionParamsOptions,\n\t\t\tswiftOptions,\n\t\t})) as T extends true\n\t\t\t? SwiftOrderResult\n\t\t\t: Transaction | VersionedTransaction;\n\t}\n\n\tconst allOrders: OptionalOrderParams[] = [orderParams];\n\n\tif (bracketOrders?.takeProfit) {\n\t\tconst takeProfitParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrders.takeProfit.direction,\n\t\t\tbaseAssetAmount: amount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'takeProfit',\n\t\t\t\ttriggerPrice: bracketOrders.takeProfit.triggerPrice,\n\t\t\t},\n\t\t\treduceOnly: true,\n\t\t});\n\t\tallOrders.push(takeProfitParams);\n\t}\n\n\tif (bracketOrders?.stopLoss) {\n\t\tconst stopLossParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrders.stopLoss.direction,\n\t\t\tbaseAssetAmount: amount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'stopLoss',\n\t\t\t\ttriggerPrice: bracketOrders.stopLoss.triggerPrice,\n\t\t\t},\n\t\t\treduceOnly: true,\n\t\t});\n\t\tallOrders.push(stopLossParams);\n\t}\n\n\t// Regular order flow - create transaction instruction and build transaction\n\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(allOrders);\n\tconst openPerpMarketOrderTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: [placeOrderIx],\n\t\ttxVersion: 0,\n\t\tconnection: driftClient.connection,\n\t\tpreFlightCommitment: 'confirmed',\n\t\tfetchAllMarketLookupTableAccounts:\n\t\t\tdriftClient.fetchAllLookupTableAccounts.bind(driftClient),\n\t});\n\n\treturn openPerpMarketOrderTxn as T extends true\n\t\t? SwiftOrderResult\n\t\t: Transaction | VersionedTransaction;\n};\n\n/**\n * Creates a Swift (signed message) order directly.\n * This is a convenience function for when you only want to create Swift orders.\n *\n * @param params - All the parameters needed for creating a Swift order\n * @returns Promise resolving to SwiftOrderResult with observable and order UUID\n */\nexport const createSwiftPerpMarketOrder = async (\n\tparams: Omit<OpenPerpMarketOrderParams, 'useSwift'> & {\n\t\tswiftOptions: SwiftOrderOptions;\n\t}\n): Promise<SwiftOrderResult> => {\n\treturn await createSwiftOrder({\n\t\t...params,\n\t});\n};\n"]}
@@ -0,0 +1,19 @@
1
+ import { DriftClient, User, BN, PostOnlyParams, TxParams } from '@drift-labs/sdk';
2
+ import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
3
+ import { SwiftOrderOptions, SwiftOrderResult } from '../openSwiftOrder';
4
+ import { NonMarketOrderParamsConfig } from '../../../../../utils/orderParams';
5
+ export interface OpenPerpNonMarketOrderParams<T extends boolean = boolean> extends Omit<NonMarketOrderParamsConfig, 'marketType' | 'baseAssetAmount'> {
6
+ driftClient: DriftClient;
7
+ user: User;
8
+ amount?: BN;
9
+ assetType?: 'base' | 'quote';
10
+ baseAssetAmount?: BN;
11
+ reduceOnly?: boolean;
12
+ postOnly?: PostOnlyParams;
13
+ useSwift?: T;
14
+ swiftOptions?: T extends true ? SwiftOrderOptions : never;
15
+ }
16
+ export declare const createOpenPerpNonMarketOrderIx: (params: Omit<OpenPerpNonMarketOrderParams, 'useSwift' | 'swiftOptions'>) => Promise<TransactionInstruction>;
17
+ export declare const createOpenPerpNonMarketOrderTxn: <T extends boolean>(params: OpenPerpNonMarketOrderParams<T> & {
18
+ txParams?: TxParams;
19
+ }) => Promise<T extends true ? SwiftOrderResult : Transaction | VersionedTransaction>;
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createOpenPerpNonMarketOrderTxn = exports.createOpenPerpNonMarketOrderIx = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ const openSwiftOrder_1 = require("../openSwiftOrder");
6
+ const types_1 = require("../../../../../../types");
7
+ const swiftClient_1 = require("../../../../../../clients/swiftClient");
8
+ const orderParams_1 = require("../../../../../utils/orderParams");
9
+ const utils_1 = require("../../../../../../utils");
10
+ const createOpenPerpNonMarketOrderIx = async (params) => {
11
+ var _a, _b;
12
+ const { driftClient, user: _user, marketIndex, direction, reduceOnly = false, postOnly = sdk_1.PostOnlyParams.NONE, orderConfig, } = params;
13
+ // Support both new (amount + assetType) and legacy (baseAssetAmount) approaches
14
+ const finalBaseAssetAmount = (0, orderParams_1.resolveBaseAssetAmount)({
15
+ amount: 'amount' in params ? params.amount : undefined,
16
+ assetType: 'assetType' in params ? params.assetType : undefined,
17
+ baseAssetAmount: 'baseAssetAmount' in params ? params.baseAssetAmount : undefined,
18
+ limitPrice: 'limitPrice' in params.orderConfig && params.orderConfig.limitPrice,
19
+ });
20
+ if (!finalBaseAssetAmount || finalBaseAssetAmount.isZero()) {
21
+ throw new Error('Final base asset amount must be greater than zero');
22
+ }
23
+ const allOrders = [];
24
+ const orderParams = (0, orderParams_1.buildNonMarketOrderParams)({
25
+ marketIndex,
26
+ marketType: sdk_1.MarketType.PERP,
27
+ direction,
28
+ baseAssetAmount: finalBaseAssetAmount,
29
+ orderConfig,
30
+ reduceOnly,
31
+ postOnly,
32
+ });
33
+ allOrders.push(orderParams);
34
+ if ('bracketOrders' in orderConfig && ((_a = orderConfig.bracketOrders) === null || _a === void 0 ? void 0 : _a.takeProfit)) {
35
+ const takeProfitParams = (0, orderParams_1.buildNonMarketOrderParams)({
36
+ marketIndex,
37
+ marketType: sdk_1.MarketType.PERP,
38
+ direction: orderConfig.bracketOrders.takeProfit.direction,
39
+ baseAssetAmount: finalBaseAssetAmount,
40
+ orderConfig: {
41
+ orderType: 'takeProfit',
42
+ triggerPrice: orderConfig.bracketOrders.takeProfit.triggerPrice,
43
+ },
44
+ reduceOnly: true,
45
+ });
46
+ allOrders.push(takeProfitParams);
47
+ }
48
+ if ('bracketOrders' in orderConfig && ((_b = orderConfig.bracketOrders) === null || _b === void 0 ? void 0 : _b.stopLoss)) {
49
+ const stopLossParams = (0, orderParams_1.buildNonMarketOrderParams)({
50
+ marketIndex,
51
+ marketType: sdk_1.MarketType.PERP,
52
+ direction: orderConfig.bracketOrders.stopLoss.direction,
53
+ baseAssetAmount: finalBaseAssetAmount,
54
+ orderConfig: {
55
+ orderType: 'stopLoss',
56
+ triggerPrice: orderConfig.bracketOrders.stopLoss.triggerPrice,
57
+ },
58
+ reduceOnly: true,
59
+ });
60
+ allOrders.push(stopLossParams);
61
+ }
62
+ const placeOrderIx = await driftClient.getPlaceOrdersIx(allOrders);
63
+ return placeOrderIx;
64
+ };
65
+ exports.createOpenPerpNonMarketOrderIx = createOpenPerpNonMarketOrderIx;
66
+ const createSwiftOrder = async (params) => {
67
+ var _a, _b;
68
+ const { driftClient, user, marketIndex, direction, reduceOnly = false, swiftOptions, orderConfig, } = params;
69
+ const limitPrice = orderConfig.limitPrice;
70
+ if (limitPrice.isZero()) {
71
+ throw new Error('LIMIT orders require limitPrice');
72
+ }
73
+ // Support both new (amount + assetType) and legacy (baseAssetAmount) approaches
74
+ const finalBaseAssetAmount = (0, orderParams_1.resolveBaseAssetAmount)({
75
+ amount: 'amount' in params ? params.amount : undefined,
76
+ assetType: 'assetType' in params ? params.assetType : undefined,
77
+ baseAssetAmount: 'baseAssetAmount' in params ? params.baseAssetAmount : undefined,
78
+ limitPrice,
79
+ });
80
+ // Build limit order parameters directly like the UI does
81
+ const orderParams = (0, sdk_1.getLimitOrderParams)({
82
+ marketIndex,
83
+ marketType: sdk_1.MarketType.PERP,
84
+ direction,
85
+ baseAssetAmount: finalBaseAssetAmount,
86
+ price: limitPrice,
87
+ reduceOnly,
88
+ postOnly: sdk_1.PostOnlyParams.NONE, // we don't allow post only orders for SWIFT
89
+ });
90
+ console.log('🔧 Order params:', JSON.stringify(orderParams, null, 2));
91
+ // Fetch current slot programmatically
92
+ const currentSlot = await driftClient.connection.getSlot();
93
+ const userAccount = user.getUserAccount();
94
+ // Use the existing prepSwiftOrder helper function
95
+ const { hexEncodedSwiftOrderMessage, signedMsgOrderUuid } = (0, openSwiftOrder_1.prepSwiftOrder)({
96
+ driftClient,
97
+ takerUserAccount: {
98
+ pubKey: swiftOptions.wallet.publicKey,
99
+ subAccountId: userAccount.subAccountId,
100
+ },
101
+ currentSlot,
102
+ isDelegate: swiftOptions.isDelegate || false,
103
+ orderParams: {
104
+ main: orderParams,
105
+ takeProfit: (_a = orderConfig.bracketOrders) === null || _a === void 0 ? void 0 : _a.takeProfit,
106
+ stopLoss: (_b = orderConfig.bracketOrders) === null || _b === void 0 ? void 0 : _b.stopLoss,
107
+ },
108
+ slotBuffer: swiftOptions.signedMessageOrderSlotBuffer || 50,
109
+ });
110
+ // Sign the message
111
+ const signedMessage = await swiftOptions.wallet.signMessage(hexEncodedSwiftOrderMessage.uInt8Array);
112
+ // Initialize SwiftClient (required before using sendSwiftOrder)
113
+ swiftClient_1.SwiftClient.init(swiftOptions.swiftServerUrl);
114
+ // Create a promise-based wrapper for the sendSwiftOrder callback-based API
115
+ const swiftOrderResult = (0, openSwiftOrder_1.sendSwiftOrder)({
116
+ driftClient,
117
+ marketId: types_1.MarketId.createPerpMarket(marketIndex),
118
+ hexEncodedSwiftOrderMessageString: hexEncodedSwiftOrderMessage.string,
119
+ signedMessage,
120
+ signedMsgOrderUuid,
121
+ takerAuthority: swiftOptions.wallet.publicKey,
122
+ signingAuthority: swiftOptions.wallet.publicKey,
123
+ auctionDurationSlot: orderParams.auctionDuration || undefined,
124
+ swiftConfirmationSlotBuffer: 30,
125
+ });
126
+ return swiftOrderResult;
127
+ };
128
+ const createOpenPerpNonMarketOrderTxn = async (params) => {
129
+ const { driftClient, swiftOptions, useSwift, orderConfig } = params;
130
+ // If useSwift is true, return the Swift result directly
131
+ if (useSwift) {
132
+ if (!swiftOptions) {
133
+ throw new Error('swiftOptions is required when useSwift is true');
134
+ }
135
+ if (orderConfig.orderType !== 'limit') {
136
+ throw new Error('Only limit orders are supported with Swift');
137
+ }
138
+ if (params.postOnly &&
139
+ !utils_1.ENUM_UTILS.match(params.postOnly, sdk_1.PostOnlyParams.NONE)) {
140
+ throw new Error('Post only orders are not supported with Swift');
141
+ }
142
+ const swiftOrderResult = await createSwiftOrder({
143
+ ...params,
144
+ swiftOptions,
145
+ orderConfig,
146
+ });
147
+ return swiftOrderResult;
148
+ }
149
+ const instructions = await (0, exports.createOpenPerpNonMarketOrderIx)(params);
150
+ const openPerpNonMarketOrderTxn = await driftClient.txHandler.buildTransaction({
151
+ instructions,
152
+ txVersion: 0,
153
+ connection: driftClient.connection,
154
+ preFlightCommitment: 'confirmed',
155
+ fetchAllMarketLookupTableAccounts: driftClient.fetchAllLookupTableAccounts.bind(driftClient),
156
+ txParams: params.txParams,
157
+ });
158
+ return openPerpNonMarketOrderTxn;
159
+ };
160
+ exports.createOpenPerpNonMarketOrderTxn = createOpenPerpNonMarketOrderTxn;
161
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.ts"],"names":[],"mappings":";;;AAAA,yCASyB;AAMzB,sDAK2B;AAC3B,mDAAmD;AACnD,uEAAoE;AACpE,kEAI0C;AAC1C,mDAAqD;AAmB9C,MAAM,8BAA8B,GAAG,KAAK,EAClD,MAAuE,EACrC,EAAE;;IACpC,MAAM,EACL,WAAW,EACX,IAAI,EAAE,KAAK,EACX,WAAW,EACX,SAAS,EACT,UAAU,GAAG,KAAK,EAClB,QAAQ,GAAG,oBAAc,CAAC,IAAI,EAC9B,WAAW,GACX,GAAG,MAAM,CAAC;IACX,gFAAgF;IAChF,MAAM,oBAAoB,GAAG,IAAA,oCAAsB,EAAC;QACnD,MAAM,EAAE,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QACtD,SAAS,EAAE,WAAW,IAAI,MAAM,C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AAA,sCAA8B,EAAC,MAAM,CAAC,CAAC;IAElE,MAAM,yBAAyB,GAC9B,MAAM,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC;QAC5C,YAAY;QACZ,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAChC,WAAW,CAAC,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;QAC1D,QAAQ,EAAE,MAAM,CAAC,QAAQ;KACzB,CAAC,CAAC;IAEJ,OAAO,yBAE8B,CAAC;AACvC,CAAC,CAAC;AAnDW,QAAA,+BAA+B,mCAmD1C","sourcesContent":["import {\n\tDriftClient,\n\tUser,\n\tBN,\n\tMarketType,\n\tPostOnlyParams,\n\tgetLimitOrderParams,\n\tTxParams,\n\tOptionalOrderParams,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport {\n\tprepSwiftOrder,\n\tsendSwiftOrder,\n\tSwiftOrderOptions,\n\tSwiftOrderResult,\n} from '../openSwiftOrder';\nimport { MarketId } from '../../../../../../types';\nimport { SwiftClient } from '../../../../../../clients/swiftClient';\nimport {\n\tbuildNonMarketOrderParams,\n\tNonMarketOrderParamsConfig,\n\tresolveBaseAssetAmount,\n} from '../../../../../utils/orderParams';\nimport { ENUM_UTILS } from '../../../../../../utils';\n\nexport interface OpenPerpNonMarketOrderParams<T extends boolean = boolean>\n\textends Omit<NonMarketOrderParamsConfig, 'marketType' | 'baseAssetAmount'> {\n\tdriftClient: DriftClient;\n\tuser: User;\n\t// Either new approach\n\tamount?: BN;\n\tassetType?: 'base' | 'quote';\n\t// Or legacy approach\n\tbaseAssetAmount?: BN;\n\t// Common optional params\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\t// Swift\n\tuseSwift?: T;\n\tswiftOptions?: T extends true ? SwiftOrderOptions : never;\n}\n\nexport const createOpenPerpNonMarketOrderIx = async (\n\tparams: Omit<OpenPerpNonMarketOrderParams, 'useSwift' | 'swiftOptions'>\n): Promise<TransactionInstruction> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser: _user,\n\t\tmarketIndex,\n\t\tdirection,\n\t\treduceOnly = false,\n\t\tpostOnly = PostOnlyParams.NONE,\n\t\torderConfig,\n\t} = params;\n\t// Support both new (amount + assetType) and legacy (baseAssetAmount) approaches\n\tconst finalBaseAssetAmount = resolveBaseAssetAmount({\n\t\tamount: 'amount' in params ? params.amount : undefined,\n\t\tassetType: 'assetType' in params ? params.assetType : undefined,\n\t\tbaseAssetAmount:\n\t\t\t'baseAssetAmount' in params ? params.baseAssetAmount : undefined,\n\t\tlimitPrice:\n\t\t\t'limitPrice' in params.orderConfig && params.orderConfig.limitPrice,\n\t});\n\n\tif (!finalBaseAssetAmount || finalBaseAssetAmount.isZero()) {\n\t\tthrow new Error('Final base asset amount must be greater than zero');\n\t}\n\n\tconst allOrders: OptionalOrderParams[] = [];\n\n\tconst orderParams = buildNonMarketOrderParams({\n\t\tmarketIndex,\n\t\tmarketType: MarketType.PERP,\n\t\tdirection,\n\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\torderConfig,\n\t\treduceOnly,\n\t\tpostOnly,\n\t});\n\tallOrders.push(orderParams);\n\n\tif ('bracketOrders' in orderConfig && orderConfig.bracketOrders?.takeProfit) {\n\t\tconst takeProfitParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: orderConfig.bracketOrders.takeProfit.direction,\n\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'takeProfit',\n\t\t\t\ttriggerPrice: orderConfig.bracketOrders.takeProfit.triggerPrice,\n\t\t\t},\n\t\t\treduceOnly: true,\n\t\t});\n\t\tallOrders.push(takeProfitParams);\n\t}\n\n\tif ('bracketOrders' in orderConfig && orderConfig.bracketOrders?.stopLoss) {\n\t\tconst stopLossParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: orderConfig.bracketOrders.stopLoss.direction,\n\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'stopLoss',\n\t\t\t\ttriggerPrice: orderConfig.bracketOrders.stopLoss.triggerPrice,\n\t\t\t},\n\t\t\treduceOnly: true,\n\t\t});\n\t\tallOrders.push(stopLossParams);\n\t}\n\n\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(allOrders);\n\treturn placeOrderIx;\n};\n\nconst createSwiftOrder = async (\n\tparams: OpenPerpNonMarketOrderParams & {\n\t\tswiftOptions: SwiftOrderOptions;\n\t} & {\n\t\torderConfig: {\n\t\t\torderType: 'limit';\n\t\t\tlimitPrice: BN;\n\t\t};\n\t}\n): Promise<SwiftOrderResult> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tdirection,\n\t\treduceOnly = false,\n\t\tswiftOptions,\n\t\torderConfig,\n\t} = params;\n\n\tconst limitPrice = orderConfig.limitPrice;\n\n\tif (limitPrice.isZero()) {\n\t\tthrow new Error('LIMIT orders require limitPrice');\n\t}\n\n\t// Support both new (amount + assetType) and legacy (baseAssetAmount) approaches\n\tconst finalBaseAssetAmount = resolveBaseAssetAmount({\n\t\tamount: 'amount' in params ? params.amount : undefined,\n\t\tassetType: 'assetType' in params ? params.assetType : undefined,\n\t\tbaseAssetAmount:\n\t\t\t'baseAssetAmount' in params ? params.baseAssetAmount : undefined,\n\t\tlimitPrice,\n\t});\n\n\t// Build limit order parameters directly like the UI does\n\tconst orderParams = getLimitOrderParams({\n\t\tmarketIndex,\n\t\tmarketType: MarketType.PERP,\n\t\tdirection,\n\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\tprice: limitPrice,\n\t\treduceOnly,\n\t\tpostOnly: PostOnlyParams.NONE, // we don't allow post only orders for SWIFT\n\t});\n\n\tconsole.log('🔧 Order params:', JSON.stringify(orderParams, null, 2));\n\n\t// Fetch current slot programmatically\n\tconst currentSlot = await driftClient.connection.getSlot();\n\tconst userAccount = user.getUserAccount();\n\n\t// Use the existing prepSwiftOrder helper function\n\tconst { hexEncodedSwiftOrderMessage, signedMsgOrderUuid } = prepSwiftOrder({\n\t\tdriftClient,\n\t\ttakerUserAccount: {\n\t\t\tpubKey: swiftOptions.wallet.publicKey,\n\t\t\tsubAccountId: userAccount.subAccountId,\n\t\t},\n\t\tcurrentSlot,\n\t\tisDelegate: swiftOptions.isDelegate || false,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: orderConfig.bracketOrders?.takeProfit,\n\t\t\tstopLoss: orderConfig.bracketOrders?.stopLoss,\n\t\t},\n\t\tslotBuffer: swiftOptions.signedMessageOrderSlotBuffer || 50,\n\t});\n\n\t// Sign the message\n\tconst signedMessage = await swiftOptions.wallet.signMessage(\n\t\thexEncodedSwiftOrderMessage.uInt8Array\n\t);\n\n\t// Initialize SwiftClient (required before using sendSwiftOrder)\n\tSwiftClient.init(swiftOptions.swiftServerUrl);\n\n\t// Create a promise-based wrapper for the sendSwiftOrder callback-based API\n\tconst swiftOrderResult = sendSwiftOrder({\n\t\tdriftClient,\n\t\tmarketId: MarketId.createPerpMarket(marketIndex),\n\t\thexEncodedSwiftOrderMessageString: hexEncodedSwiftOrderMessage.string,\n\t\tsignedMessage,\n\t\tsignedMsgOrderUuid,\n\t\ttakerAuthority: swiftOptions.wallet.publicKey,\n\t\tsigningAuthority: swiftOptions.wallet.publicKey,\n\t\tauctionDurationSlot: orderParams.auctionDuration || undefined,\n\t\tswiftConfirmationSlotBuffer: 30,\n\t});\n\n\treturn swiftOrderResult;\n};\n\nexport const createOpenPerpNonMarketOrderTxn = async <T extends boolean>(\n\tparams: OpenPerpNonMarketOrderParams<T> & { txParams?: TxParams }\n): Promise<\n\tT extends true ? SwiftOrderResult : Transaction | VersionedTransaction\n> => {\n\tconst { driftClient, swiftOptions, useSwift, orderConfig } = params;\n\n\t// If useSwift is true, return the Swift result directly\n\tif (useSwift) {\n\t\tif (!swiftOptions) {\n\t\t\tthrow new Error('swiftOptions is required when useSwift is true');\n\t\t}\n\n\t\tif (orderConfig.orderType !== 'limit') {\n\t\t\tthrow new Error('Only limit orders are supported with Swift');\n\t\t}\n\n\t\tif (\n\t\t\tparams.postOnly &&\n\t\t\t!ENUM_UTILS.match(params.postOnly, PostOnlyParams.NONE)\n\t\t) {\n\t\t\tthrow new Error('Post only orders are not supported with Swift');\n\t\t}\n\n\t\tconst swiftOrderResult = await createSwiftOrder({\n\t\t\t...params,\n\t\t\tswiftOptions,\n\t\t\torderConfig,\n\t\t});\n\n\t\treturn swiftOrderResult as T extends true\n\t\t\t? SwiftOrderResult\n\t\t\t: Transaction | VersionedTransaction;\n\t}\n\n\tconst instructions = await createOpenPerpNonMarketOrderIx(params);\n\n\tconst openPerpNonMarketOrderTxn =\n\t\tawait driftClient.txHandler.buildTransaction({\n\t\t\tinstructions,\n\t\t\ttxVersion: 0,\n\t\t\tconnection: driftClient.connection,\n\t\t\tpreFlightCommitment: 'confirmed',\n\t\t\tfetchAllMarketLookupTableAccounts:\n\t\t\t\tdriftClient.fetchAllLookupTableAccounts.bind(driftClient),\n\t\t\ttxParams: params.txParams,\n\t\t});\n\n\treturn openPerpNonMarketOrderTxn as T extends true\n\t\t? SwiftOrderResult\n\t\t: Transaction | VersionedTransaction;\n};\n"]}