@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,166 @@
1
+ import { SignedMsgOrderParamsDelegateMessage, SignedMsgOrderParamsMessage } from '@drift-labs/sdk';
2
+ import { BN, DriftClient, OptionalOrderParams, PublicKey } from '@drift-labs/sdk';
3
+ import { SwiftOrderEvent } from '../../../../../../clients/swiftClient';
4
+ import { MarketId } from '../../../../../../types';
5
+ import { Observable } from 'rxjs';
6
+ export interface SwiftOrderOptions {
7
+ wallet: {
8
+ signMessage: (message: Uint8Array) => Promise<Uint8Array>;
9
+ publicKey: PublicKey;
10
+ };
11
+ swiftServerUrl: string;
12
+ signedMessageOrderSlotBuffer?: number;
13
+ confirmDuration?: number;
14
+ isDelegate?: boolean;
15
+ }
16
+ export type SwiftOrderResult = {
17
+ swiftOrderObservable: Observable<SwiftOrderEvent>;
18
+ swiftOrderUuid: Uint8Array;
19
+ };
20
+ export interface OptionalTriggerOrderParams extends OptionalOrderParams {
21
+ /** The trigger price for the order */
22
+ triggerPrice: BN;
23
+ }
24
+ interface PrepSwiftOrderParams {
25
+ /** The Drift client instance */
26
+ driftClient: DriftClient;
27
+ /** The taker user account information */
28
+ takerUserAccount: {
29
+ /** Public key of the user account */
30
+ pubKey: PublicKey;
31
+ /** User account ID */
32
+ subAccountId: number;
33
+ };
34
+ /** Current blockchain slot number */
35
+ currentSlot: number;
36
+ /** Whether this is a delegate order */
37
+ isDelegate: boolean;
38
+ /** Order parameters including main order and optional stop loss/take profit */
39
+ orderParams: {
40
+ /** Main order parameters */
41
+ main: OptionalOrderParams;
42
+ /** Optional stop loss order parameters */
43
+ stopLoss?: OptionalTriggerOrderParams;
44
+ /** Optional take profit order parameters */
45
+ takeProfit?: OptionalTriggerOrderParams;
46
+ };
47
+ /** Buffer slots to account for signing time (default: 2 slots ~1 second). If a user is required to manually sign the message, this should be a higher number. */
48
+ slotBuffer?: number;
49
+ }
50
+ /**
51
+ * Prepares a swift order by encoding the order parameters into a message format
52
+ * suitable for signing and sending to the Swift server.
53
+ *
54
+ * @param driftClient - The Drift client instance
55
+ * @param takerUserAccount - The taker user account information
56
+ * @param currentSlot - Current blockchain slot number
57
+ * @param isDelegate - Whether this is a delegate order
58
+ * @param orderParams - Order parameters including main order and optional stop loss/take profit
59
+ * @param slotBuffer - Buffer slots to account for signing time (default: 2 slots ~1 second). If a user is required to manually sign the message, this should be a higher number.
60
+ *
61
+ * @returns An object containing:
62
+ * - `hexEncodedSwiftOrderMessage`: The encoded order message in both Uint8Array and string formats. The Uint8Array format is for a wallet to sign, while the string format is used to send to the SWIFT server.
63
+ * - `signedMsgOrderParamsMessage`: The signed message order parameters
64
+ * - `slotForSignedMsg`: The slot number for the signed message
65
+ * - `signedMsgOrderUuid`: Unique identifier for the signed message order
66
+ */
67
+ export declare const prepSwiftOrder: ({ driftClient, takerUserAccount, currentSlot, isDelegate, orderParams, slotBuffer, }: PrepSwiftOrderParams) => {
68
+ hexEncodedSwiftOrderMessage: {
69
+ uInt8Array: Uint8Array;
70
+ string: string;
71
+ };
72
+ signedMsgOrderParamsMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage;
73
+ slotForSignedMsg: BN;
74
+ signedMsgOrderUuid: Uint8Array;
75
+ };
76
+ /**
77
+ * Error thrown when an auction slot has expired
78
+ */
79
+ export declare class AuctionSlotExpiredError extends Error {
80
+ name: string;
81
+ /**
82
+ * Creates an instance of AuctionSlotExpiredError
83
+ * @param message - Error message (default: 'Auction slot expired')
84
+ */
85
+ constructor(message?: string);
86
+ }
87
+ interface SignOrderMsgParams {
88
+ /** Wallet instance with message signing capability */
89
+ wallet: {
90
+ /** Function to sign a message */
91
+ signMessage: (message: Uint8Array) => Promise<Uint8Array>;
92
+ };
93
+ /** Hex-encoded swift order message to sign */
94
+ hexEncodedSwiftOrderMessage: Uint8Array;
95
+ /** Slot number when the auction expires */
96
+ auctionExpirationSlot: BN;
97
+ /** Function to get the current blockchain slot */
98
+ getCurrentSlot: () => number;
99
+ /** Callback function called when the auction expires */
100
+ onExpired: () => void;
101
+ }
102
+ /**
103
+ * Signs a swift order message with slot expiration monitoring.
104
+ * Continuously monitors the current slot and rejects with AuctionSlotExpiredError
105
+ * if the auction slot expires before signing is complete.
106
+ *
107
+ * @param wallet - Wallet instance with message signing capability
108
+ * @param hexEncodedSwiftOrderMessage - Hex-encoded swift order message to sign
109
+ * @param auctionExpirationSlot - Slot number when the auction expires
110
+ * @param getCurrentSlot - Function to get the current blockchain slot
111
+ * @param onExpired - Callback function called when the auction expires
112
+ *
113
+ * @returns Promise resolving to the signed message as Uint8Array
114
+ * @throws {AuctionSlotExpiredError} When the auction slot expires before signing completes
115
+ */
116
+ export declare const signSwiftOrderMsg: ({ wallet, hexEncodedSwiftOrderMessage, auctionExpirationSlot, getCurrentSlot, onExpired, }: SignOrderMsgParams) => Promise<Uint8Array>;
117
+ /**
118
+ * Parameters for sending a swift order to the Swift server
119
+ * @interface SendSwiftOrderParams
120
+ */
121
+ interface SendSwiftOrderParams {
122
+ /** The Drift client instance */
123
+ driftClient: DriftClient;
124
+ /** Market identifier for the order */
125
+ marketId: MarketId;
126
+ /** Hex-encoded swift order message as string */
127
+ hexEncodedSwiftOrderMessageString: string;
128
+ /** The signed message from the wallet */
129
+ signedMessage: Uint8Array;
130
+ /** Unique identifier for the signed message order */
131
+ signedMsgOrderUuid: Uint8Array;
132
+ /** Public key of the taker authority */
133
+ takerAuthority: PublicKey;
134
+ /** Public key of the signing authority */
135
+ signingAuthority: PublicKey;
136
+ /** Duration of the auction in slots (optional) */
137
+ auctionDurationSlot?: number;
138
+ /**
139
+ * This is a slot buffer to account for the time it takes for the swift server to confirm the order.
140
+ * If there is an auction duration component, it will be added to the final confirmation delay.
141
+ * @default 15
142
+ */
143
+ swiftConfirmationSlotBuffer?: number;
144
+ }
145
+ /**
146
+ * Sends a swift order to the Swift server and handles the response.
147
+ * Monitors the order status and calls appropriate callback functions based on the response type.
148
+ *
149
+ * @param driftClient - The Drift client instance
150
+ * @param marketId - Market identifier for the order
151
+ * @param hexEncodedSwiftOrderMessageString - Hex-encoded swift order message as string
152
+ * @param signedMessage - The signed message from the wallet
153
+ * @param signedMsgOrderUuid - Unique identifier for the signed message order
154
+ * @param takerAuthority - Public key of the taker authority
155
+ * @param signingAuthority - Public key of the signing authority
156
+ * @param auctionDurationSlot - Duration of the auction in slots (optional)
157
+ * @param swiftConfirmationSlotBuffer - Slot buffer for swift server confirmation time (default: 15)
158
+ * @param onExpired - Callback function called when the order expires
159
+ * @param onErrored - Callback function called when the order encounters an error
160
+ * @param onConfirmed - Callback function called when the order is confirmed
161
+ *
162
+ * @returns Promise that resolves when the order processing is complete
163
+ *
164
+ */
165
+ export declare const sendSwiftOrder: ({ driftClient, marketId, hexEncodedSwiftOrderMessageString: hexEncodedSwiftOrderMessage, signedMessage, signedMsgOrderUuid, takerAuthority, signingAuthority, auctionDurationSlot, swiftConfirmationSlotBuffer, }: SendSwiftOrderParams) => SwiftOrderResult;
166
+ export {};
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendSwiftOrder = exports.signSwiftOrderMsg = exports.AuctionSlotExpiredError = exports.prepSwiftOrder = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ const sdk_2 = require("@drift-labs/sdk");
6
+ const swiftClient_1 = require("../../../../../../clients/swiftClient");
7
+ /**
8
+ * Prepares a swift order by encoding the order parameters into a message format
9
+ * suitable for signing and sending to the Swift server.
10
+ *
11
+ * @param driftClient - The Drift client instance
12
+ * @param takerUserAccount - The taker user account information
13
+ * @param currentSlot - Current blockchain slot number
14
+ * @param isDelegate - Whether this is a delegate order
15
+ * @param orderParams - Order parameters including main order and optional stop loss/take profit
16
+ * @param slotBuffer - Buffer slots to account for signing time (default: 2 slots ~1 second). If a user is required to manually sign the message, this should be a higher number.
17
+ *
18
+ * @returns An object containing:
19
+ * - `hexEncodedSwiftOrderMessage`: The encoded order message in both Uint8Array and string formats. The Uint8Array format is for a wallet to sign, while the string format is used to send to the SWIFT server.
20
+ * - `signedMsgOrderParamsMessage`: The signed message order parameters
21
+ * - `slotForSignedMsg`: The slot number for the signed message
22
+ * - `signedMsgOrderUuid`: Unique identifier for the signed message order
23
+ */
24
+ const prepSwiftOrder = ({ driftClient, takerUserAccount, currentSlot, isDelegate, orderParams, slotBuffer = 2, // ~1 second
25
+ }) => {
26
+ const mainOrderParams = (0, sdk_2.getOrderParams)({
27
+ ...orderParams.main,
28
+ auctionDuration: orderParams.main.auctionDuration || null, // swift server expects auctionDuration to be null if not set, won't handle 0
29
+ });
30
+ // buffer for time the user takes to sign a message and send to the swift server
31
+ const slotForSignedMsg = new sdk_2.BN(currentSlot + slotBuffer);
32
+ const signedMsgOrderUuid = (0, sdk_2.generateSignedMsgUuid)();
33
+ const baseSignedMsgOrderParamsMessage = {
34
+ signedMsgOrderParams: mainOrderParams,
35
+ uuid: signedMsgOrderUuid,
36
+ slot: slotForSignedMsg,
37
+ stopLossOrderParams: orderParams.stopLoss
38
+ ? {
39
+ baseAssetAmount: orderParams.stopLoss.baseAssetAmount,
40
+ triggerPrice: orderParams.stopLoss.triggerPrice,
41
+ }
42
+ : null,
43
+ takeProfitOrderParams: orderParams.takeProfit
44
+ ? {
45
+ baseAssetAmount: orderParams.takeProfit.baseAssetAmount,
46
+ triggerPrice: orderParams.takeProfit.triggerPrice,
47
+ }
48
+ : null,
49
+ };
50
+ const signedMsgOrderParamsMessage = isDelegate
51
+ ? {
52
+ ...baseSignedMsgOrderParamsMessage,
53
+ takerPubkey: takerUserAccount.pubKey,
54
+ }
55
+ : {
56
+ ...baseSignedMsgOrderParamsMessage,
57
+ subAccountId: takerUserAccount.subAccountId,
58
+ };
59
+ const encodedOrderMessage = driftClient.encodeSignedMsgOrderParamsMessage(signedMsgOrderParamsMessage, isDelegate);
60
+ const hexEncodedSwiftOrderMessage = Buffer.from(encodedOrderMessage.toString('hex'));
61
+ return {
62
+ hexEncodedSwiftOrderMessage: {
63
+ uInt8Array: new Uint8Array(hexEncodedSwiftOrderMessage),
64
+ string: hexEncodedSwiftOrderMessage.toString(),
65
+ },
66
+ signedMsgOrderParamsMessage,
67
+ slotForSignedMsg,
68
+ signedMsgOrderUuid,
69
+ };
70
+ };
71
+ exports.prepSwiftOrder = prepSwiftOrder;
72
+ /**
73
+ * Error thrown when an auction slot has expired
74
+ */
75
+ class AuctionSlotExpiredError extends Error {
76
+ /**
77
+ * Creates an instance of AuctionSlotExpiredError
78
+ * @param message - Error message (default: 'Auction slot expired')
79
+ */
80
+ constructor(message = 'Auction slot expired') {
81
+ super(message);
82
+ this.name = 'AuctionSlotExpiredError';
83
+ if (Error.captureStackTrace) {
84
+ Error.captureStackTrace(this, AuctionSlotExpiredError);
85
+ }
86
+ }
87
+ }
88
+ exports.AuctionSlotExpiredError = AuctionSlotExpiredError;
89
+ // TODO: Signing the swift order should be part of the Drift wrapper, not here
90
+ /**
91
+ * Signs a swift order message with slot expiration monitoring.
92
+ * Continuously monitors the current slot and rejects with AuctionSlotExpiredError
93
+ * if the auction slot expires before signing is complete.
94
+ *
95
+ * @param wallet - Wallet instance with message signing capability
96
+ * @param hexEncodedSwiftOrderMessage - Hex-encoded swift order message to sign
97
+ * @param auctionExpirationSlot - Slot number when the auction expires
98
+ * @param getCurrentSlot - Function to get the current blockchain slot
99
+ * @param onExpired - Callback function called when the auction expires
100
+ *
101
+ * @returns Promise resolving to the signed message as Uint8Array
102
+ * @throws {AuctionSlotExpiredError} When the auction slot expires before signing completes
103
+ */
104
+ const signSwiftOrderMsg = async ({ wallet, hexEncodedSwiftOrderMessage, auctionExpirationSlot, getCurrentSlot, onExpired, }) => {
105
+ return new Promise((resolve, reject) => {
106
+ const interval = setInterval(() => {
107
+ const currentSlot = getCurrentSlot();
108
+ if (currentSlot >= auctionExpirationSlot.toNumber()) {
109
+ onExpired();
110
+ clearInterval(interval);
111
+ reject(new AuctionSlotExpiredError());
112
+ }
113
+ }, sdk_1.SLOT_TIME_ESTIMATE_MS);
114
+ wallet
115
+ .signMessage(hexEncodedSwiftOrderMessage)
116
+ .then((signedMessage) => {
117
+ resolve(signedMessage);
118
+ })
119
+ .catch((error) => {
120
+ reject(error);
121
+ })
122
+ .finally(() => {
123
+ clearInterval(interval);
124
+ });
125
+ });
126
+ };
127
+ exports.signSwiftOrderMsg = signSwiftOrderMsg;
128
+ // TODO: Sending the swift order should be part of the Drift wrapper, not here
129
+ /**
130
+ * Sends a swift order to the Swift server and handles the response.
131
+ * Monitors the order status and calls appropriate callback functions based on the response type.
132
+ *
133
+ * @param driftClient - The Drift client instance
134
+ * @param marketId - Market identifier for the order
135
+ * @param hexEncodedSwiftOrderMessageString - Hex-encoded swift order message as string
136
+ * @param signedMessage - The signed message from the wallet
137
+ * @param signedMsgOrderUuid - Unique identifier for the signed message order
138
+ * @param takerAuthority - Public key of the taker authority
139
+ * @param signingAuthority - Public key of the signing authority
140
+ * @param auctionDurationSlot - Duration of the auction in slots (optional)
141
+ * @param swiftConfirmationSlotBuffer - Slot buffer for swift server confirmation time (default: 15)
142
+ * @param onExpired - Callback function called when the order expires
143
+ * @param onErrored - Callback function called when the order encounters an error
144
+ * @param onConfirmed - Callback function called when the order is confirmed
145
+ *
146
+ * @returns Promise that resolves when the order processing is complete
147
+ *
148
+ */
149
+ const sendSwiftOrder = ({ driftClient, marketId, hexEncodedSwiftOrderMessageString: hexEncodedSwiftOrderMessage, signedMessage, signedMsgOrderUuid, takerAuthority, signingAuthority, auctionDurationSlot, swiftConfirmationSlotBuffer = 15, }) => {
150
+ const signedMsgUserOrdersAccountPubkey = (0, sdk_1.getSignedMsgUserAccountPublicKey)(driftClient.program.programId, takerAuthority);
151
+ const swiftOrderObservable = swiftClient_1.SwiftClient.sendAndConfirmSwiftOrderWS(driftClient.connection, driftClient, marketId.marketIndex, marketId.marketType, hexEncodedSwiftOrderMessage.toString(), Buffer.from(signedMessage), takerAuthority, signedMsgUserOrdersAccountPubkey, signedMsgOrderUuid, ((auctionDurationSlot !== null && auctionDurationSlot !== void 0 ? auctionDurationSlot : 0) + swiftConfirmationSlotBuffer) *
152
+ sdk_1.SLOT_TIME_ESTIMATE_MS, signingAuthority);
153
+ return { swiftOrderObservable, swiftOrderUuid: signedMsgOrderUuid };
154
+ };
155
+ exports.sendSwiftOrder = sendSwiftOrder;
156
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n\tgetSignedMsgUserAccountPublicKey,\n\tSignedMsgOrderParamsDelegateMessage,\n\tSignedMsgOrderParamsMessage,\n\tSLOT_TIME_ESTIMATE_MS,\n} from '@drift-labs/sdk';\nimport {\n\tBN,\n\tDriftClient,\n\tgenerateSignedMsgUuid,\n\tgetOrderParams,\n\tOptionalOrderParams,\n\tPublicKey,\n} from '@drift-labs/sdk';\nimport {\n\tSwiftClient,\n\tSwiftOrderEvent,\n} from '../../../../../../clients/swiftClient';\nimport { MarketId } from '../../../../../../types';\nimport { Observable } from 'rxjs';\n\nexport interface SwiftOrderOptions {\n\twallet: {\n\t\tsignMessage: (message: Uint8Array) => Promise<Uint8Array>;\n\t\tpublicKey: PublicKey;\n\t};\n\tswiftServerUrl: string;\n\tsignedMessageOrderSlotBuffer?: number;\n\tconfirmDuration?: number;\n\tisDelegate?: boolean;\n}\n\nexport type SwiftOrderResult = {\n\tswiftOrderObservable: Observable<SwiftOrderEvent>;\n\tswiftOrderUuid: Uint8Array;\n};\n\nexport interface OptionalTriggerOrderParams extends OptionalOrderParams {\n\t/** The trigger price for the order */\n\ttriggerPrice: BN;\n}\n\ninterface PrepSwiftOrderParams {\n\t/** The Drift client instance */\n\tdriftClient: DriftClient;\n\t/** The taker user account information */\n\ttakerUserAccount: {\n\t\t/** Public key of the user account */\n\t\tpubKey: PublicKey;\n\t\t/** User account ID */\n\t\tsubAccountId: number;\n\t};\n\t/** Current blockchain slot number */\n\tcurrentSlot: number;\n\t/** Whether this is a delegate order */\n\tisDelegate: boolean;\n\t/** Order parameters including main order and optional stop loss/take profit */\n\torderParams: {\n\t\t/** Main order parameters */\n\t\tmain: OptionalOrderParams;\n\t\t/** Optional stop loss order parameters */\n\t\tstopLoss?: OptionalTriggerOrderParams;\n\t\t/** Optional take profit order parameters */\n\t\ttakeProfit?: OptionalTriggerOrderParams;\n\t};\n\t/** Buffer slots to account for signing time (default: 2 slots ~1 second). If a user is required to manually sign the message, this should be a higher number. */\n\tslotBuffer?: number;\n}\n\n/**\n * Prepares a swift order by encoding the order parameters into a message format\n * suitable for signing and sending to the Swift server.\n *\n * @param driftClient - The Drift client instance\n * @param takerUserAccount - The taker user account information\n * @param currentSlot - Current blockchain slot number\n * @param isDelegate - Whether this is a delegate order\n * @param orderParams - Order parameters including main order and optional stop loss/take profit\n * @param slotBuffer - Buffer slots to account for signing time (default: 2 slots ~1 second). If a user is required to manually sign the message, this should be a higher number.\n *\n * @returns An object containing:\n * - `hexEncodedSwiftOrderMessage`: The encoded order message in both Uint8Array and string formats. The Uint8Array format is for a wallet to sign, while the string format is used to send to the SWIFT server.\n * - `signedMsgOrderParamsMessage`: The signed message order parameters\n * - `slotForSignedMsg`: The slot number for the signed message\n * - `signedMsgOrderUuid`: Unique identifier for the signed message order\n */\nexport const prepSwiftOrder = ({\n\tdriftClient,\n\ttakerUserAccount,\n\tcurrentSlot,\n\tisDelegate,\n\torderParams,\n\tslotBuffer = 2, // ~1 second\n}: PrepSwiftOrderParams): {\n\thexEncodedSwiftOrderMessage: {\n\t\tuInt8Array: Uint8Array;\n\t\tstring: string;\n\t};\n\tsignedMsgOrderParamsMessage:\n\t\t| SignedMsgOrderParamsMessage\n\t\t| SignedMsgOrderParamsDelegateMessage;\n\tslotForSignedMsg: BN;\n\tsignedMsgOrderUuid: Uint8Array;\n} => {\n\tconst mainOrderParams = getOrderParams({\n\t\t...orderParams.main,\n\t\tauctionDuration: orderParams.main.auctionDuration || null, // swift server expects auctionDuration to be null if not set, won't handle 0\n\t});\n\n\t// buffer for time the user takes to sign a message and send to the swift server\n\tconst slotForSignedMsg = new BN(currentSlot + slotBuffer);\n\n\tconst signedMsgOrderUuid = generateSignedMsgUuid();\n\n\tconst baseSignedMsgOrderParamsMessage = {\n\t\tsignedMsgOrderParams: mainOrderParams,\n\t\tuuid: signedMsgOrderUuid,\n\t\tslot: slotForSignedMsg,\n\t\tstopLossOrderParams: orderParams.stopLoss\n\t\t\t? {\n\t\t\t\t\tbaseAssetAmount: orderParams.stopLoss.baseAssetAmount,\n\t\t\t\t\ttriggerPrice: orderParams.stopLoss.triggerPrice,\n\t\t\t }\n\t\t\t: null,\n\t\ttakeProfitOrderParams: orderParams.takeProfit\n\t\t\t? {\n\t\t\t\t\tbaseAssetAmount: orderParams.takeProfit.baseAssetAmount,\n\t\t\t\t\ttriggerPrice: orderParams.takeProfit.triggerPrice,\n\t\t\t }\n\t\t\t: null,\n\t};\n\n\tconst signedMsgOrderParamsMessage:\n\t\t| SignedMsgOrderParamsMessage\n\t\t| SignedMsgOrderParamsDelegateMessage = isDelegate\n\t\t? {\n\t\t\t\t...baseSignedMsgOrderParamsMessage,\n\t\t\t\ttakerPubkey: takerUserAccount.pubKey,\n\t\t }\n\t\t: {\n\t\t\t\t...baseSignedMsgOrderParamsMessage,\n\t\t\t\tsubAccountId: takerUserAccount.subAccountId,\n\t\t };\n\n\tconst encodedOrderMessage = driftClient.encodeSignedMsgOrderParamsMessage(\n\t\tsignedMsgOrderParamsMessage,\n\t\tisDelegate\n\t);\n\tconst hexEncodedSwiftOrderMessage = Buffer.from(\n\t\tencodedOrderMessage.toString('hex')\n\t);\n\n\treturn {\n\t\thexEncodedSwiftOrderMessage: {\n\t\t\tuInt8Array: new Uint8Array(hexEncodedSwiftOrderMessage),\n\t\t\tstring: hexEncodedSwiftOrderMessage.toString(),\n\t\t},\n\t\tsignedMsgOrderParamsMessage,\n\t\tslotForSignedMsg,\n\t\tsignedMsgOrderUuid,\n\t};\n};\n\n/**\n * Error thrown when an auction slot has expired\n */\nexport class AuctionSlotExpiredError extends Error {\n\tname = 'AuctionSlotExpiredError';\n\n\t/**\n\t * Creates an instance of AuctionSlotExpiredError\n\t * @param message - Error message (default: 'Auction slot expired')\n\t */\n\tconstructor(message: string = 'Auction slot expired') {\n\t\tsuper(message);\n\t\tif (Error.captureStackTrace) {\n\t\t\tError.captureStackTrace(this, AuctionSlotExpiredError);\n\t\t}\n\t}\n}\n\ninterface SignOrderMsgParams {\n\t/** Wallet instance with message signing capability */\n\twallet: {\n\t\t/** Function to sign a message */\n\t\tsignMessage: (message: Uint8Array) => Promise<Uint8Array>;\n\t};\n\t/** Hex-encoded swift order message to sign */\n\thexEncodedSwiftOrderMessage: Uint8Array;\n\t/** Slot number when the auction expires */\n\tauctionExpirationSlot: BN;\n\t/** Function to get the current blockchain slot */\n\tgetCurrentSlot: () => number;\n\t/** Callback function called when the auction expires */\n\tonExpired: () => void;\n}\n\n// TODO: Signing the swift order should be part of the Drift wrapper, not here\n/**\n * Signs a swift order message with slot expiration monitoring.\n * Continuously monitors the current slot and rejects with AuctionSlotExpiredError\n * if the auction slot expires before signing is complete.\n *\n * @param wallet - Wallet instance with message signing capability\n * @param hexEncodedSwiftOrderMessage - Hex-encoded swift order message to sign\n * @param auctionExpirationSlot - Slot number when the auction expires\n * @param getCurrentSlot - Function to get the current blockchain slot\n * @param onExpired - Callback function called when the auction expires\n *\n * @returns Promise resolving to the signed message as Uint8Array\n * @throws {AuctionSlotExpiredError} When the auction slot expires before signing completes\n */\nexport const signSwiftOrderMsg = async ({\n\twallet,\n\thexEncodedSwiftOrderMessage,\n\tauctionExpirationSlot,\n\tgetCurrentSlot,\n\tonExpired,\n}: SignOrderMsgParams): Promise<Uint8Array> => {\n\treturn new Promise((resolve, reject) => {\n\t\tconst interval = setInterval(() => {\n\t\t\tconst currentSlot = getCurrentSlot();\n\t\t\tif (currentSlot >= auctionExpirationSlot.toNumber()) {\n\t\t\t\tonExpired();\n\t\t\t\tclearInterval(interval);\n\t\t\t\treject(new AuctionSlotExpiredError());\n\t\t\t}\n\t\t}, SLOT_TIME_ESTIMATE_MS);\n\n\t\twallet\n\t\t\t.signMessage(hexEncodedSwiftOrderMessage)\n\t\t\t.then((signedMessage) => {\n\t\t\t\tresolve(signedMessage);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\treject(error);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tclearInterval(interval);\n\t\t\t});\n\t});\n};\n\n/**\n * Parameters for sending a swift order to the Swift server\n * @interface SendSwiftOrderParams\n */\ninterface SendSwiftOrderParams {\n\t/** The Drift client instance */\n\tdriftClient: DriftClient;\n\t/** Market identifier for the order */\n\tmarketId: MarketId;\n\t/** Hex-encoded swift order message as string */\n\thexEncodedSwiftOrderMessageString: string;\n\t/** The signed message from the wallet */\n\tsignedMessage: Uint8Array;\n\t/** Unique identifier for the signed message order */\n\tsignedMsgOrderUuid: Uint8Array;\n\t/** Public key of the taker authority */\n\ttakerAuthority: PublicKey;\n\t/** Public key of the signing authority */\n\tsigningAuthority: PublicKey;\n\t/** Duration of the auction in slots (optional) */\n\tauctionDurationSlot?: number;\n\n\t/**\n\t * This is a slot buffer to account for the time it takes for the swift server to confirm the order.\n\t * If there is an auction duration component, it will be added to the final confirmation delay.\n\t * @default 15\n\t */\n\tswiftConfirmationSlotBuffer?: number;\n}\n\n// TODO: Sending the swift order should be part of the Drift wrapper, not here\n/**\n * Sends a swift order to the Swift server and handles the response.\n * Monitors the order status and calls appropriate callback functions based on the response type.\n *\n * @param driftClient - The Drift client instance\n * @param marketId - Market identifier for the order\n * @param hexEncodedSwiftOrderMessageString - Hex-encoded swift order message as string\n * @param signedMessage - The signed message from the wallet\n * @param signedMsgOrderUuid - Unique identifier for the signed message order\n * @param takerAuthority - Public key of the taker authority\n * @param signingAuthority - Public key of the signing authority\n * @param auctionDurationSlot - Duration of the auction in slots (optional)\n * @param swiftConfirmationSlotBuffer - Slot buffer for swift server confirmation time (default: 15)\n * @param onExpired - Callback function called when the order expires\n * @param onErrored - Callback function called when the order encounters an error\n * @param onConfirmed - Callback function called when the order is confirmed\n *\n * @returns Promise that resolves when the order processing is complete\n *\n */\nexport const sendSwiftOrder = ({\n\tdriftClient,\n\tmarketId,\n\thexEncodedSwiftOrderMessageString: hexEncodedSwiftOrderMessage,\n\tsignedMessage,\n\tsignedMsgOrderUuid,\n\ttakerAuthority,\n\tsigningAuthority,\n\tauctionDurationSlot,\n\tswiftConfirmationSlotBuffer = 15,\n}: SendSwiftOrderParams): SwiftOrderResult => {\n\tconst signedMsgUserOrdersAccountPubkey = getSignedMsgUserAccountPublicKey(\n\t\tdriftClient.program.programId,\n\t\ttakerAuthority\n\t);\n\n\tconst swiftOrderObservable = SwiftClient.sendAndConfirmSwiftOrderWS(\n\t\tdriftClient.connection,\n\t\tdriftClient,\n\t\tmarketId.marketIndex,\n\t\tmarketId.marketType,\n\t\thexEncodedSwiftOrderMessage.toString(),\n\t\tBuffer.from(signedMessage),\n\t\ttakerAuthority,\n\t\tsignedMsgUserOrdersAccountPubkey,\n\t\tsignedMsgOrderUuid,\n\t\t((auctionDurationSlot ?? 0) + swiftConfirmationSlotBuffer) *\n\t\t\tSLOT_TIME_ESTIMATE_MS,\n\t\tsigningAuthority\n\t);\n\n\treturn { swiftOrderObservable, swiftOrderUuid: signedMsgOrderUuid };\n};\n"]}
@@ -0,0 +1,62 @@
1
+ import { BN, DriftClient, JupiterClient, QuoteResponse, TxParams, User } from '@drift-labs/sdk';
2
+ import { AddressLookupTableAccount, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
3
+ /**
4
+ * Parameters for creating swap instruction details
5
+ */
6
+ interface CreateSwapIxDetailsParams {
7
+ /** The Drift client instance for interacting with the Drift protocol */
8
+ driftClient: DriftClient;
9
+ /** Quote response from Jupiter containing swap route information */
10
+ quote: QuoteResponse;
11
+ /** Jupiter client instance for performing the swap */
12
+ jupiterClient: JupiterClient;
13
+ /** Market index of the token being swapped from */
14
+ swapFromMarketIndex: number;
15
+ /** Market index of the token being swapped to */
16
+ swapToMarketIndex: number;
17
+ /** Amount to swap in base units */
18
+ amount: BN;
19
+ /** User instance containing account information */
20
+ user: User;
21
+ }
22
+ /**
23
+ * Creates swap instruction details for a Jupiter swap through Drift
24
+ *
25
+ * @param driftClient - The Drift client instance
26
+ * @param jupiterClient - The Jupiter client instance
27
+ * @param quote - Quote response from Jupiter with routing information
28
+ * @param swapFromMarketIndex - Source token market index
29
+ * @param swapToMarketIndex - Destination token market index
30
+ * @param amount - Amount to swap in base units
31
+ * @param user - User account instance
32
+ * @returns Promise resolving to an object containing transaction instructions and lookup tables
33
+ * @returns ixs - Array of Solana transaction instructions for the swap
34
+ * @returns lookupTables - Address lookup table accounts for transaction compression
35
+ */
36
+ export declare const createSwapIxDetails: ({ driftClient, jupiterClient, quote, swapFromMarketIndex, swapToMarketIndex, amount, user, }: CreateSwapIxDetailsParams) => Promise<{
37
+ ixs: TransactionInstruction[];
38
+ lookupTables: AddressLookupTableAccount[];
39
+ }>;
40
+ /**
41
+ * Parameters for creating a complete swap transaction
42
+ * Extends CreateSwapIxDetailsParams with additional transaction parameters
43
+ */
44
+ interface CreateSwapTxnParams extends CreateSwapIxDetailsParams {
45
+ /** Transaction parameters including compute units, priority fees, and other options */
46
+ txParams?: TxParams;
47
+ }
48
+ /**
49
+ * Creates a complete swap transaction ready for signing and submission
50
+ *
51
+ * @param driftClient - The Drift client instance
52
+ * @param jupiterClient - The Jupiter client instance
53
+ * @param quote - Quote response from Jupiter with routing information
54
+ * @param swapFromMarketIndex - Source token market index
55
+ * @param swapToMarketIndex - Destination token market index
56
+ * @param amount - Amount to swap in base units
57
+ * @param user - User account instance
58
+ * @param txParams - Transaction parameters for fees and compute units
59
+ * @returns Promise resolving to either a legacy Transaction or VersionedTransaction ready for signing
60
+ */
61
+ export declare const createSwapTxn: ({ driftClient, jupiterClient, quote, swapFromMarketIndex, swapToMarketIndex, amount, user, txParams, }: CreateSwapTxnParams) => Promise<Transaction | VersionedTransaction>;
62
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSwapTxn = exports.createSwapIxDetails = void 0;
4
+ /**
5
+ * Creates swap instruction details for a Jupiter swap through Drift
6
+ *
7
+ * @param driftClient - The Drift client instance
8
+ * @param jupiterClient - The Jupiter client instance
9
+ * @param quote - Quote response from Jupiter with routing information
10
+ * @param swapFromMarketIndex - Source token market index
11
+ * @param swapToMarketIndex - Destination token market index
12
+ * @param amount - Amount to swap in base units
13
+ * @param user - User account instance
14
+ * @returns Promise resolving to an object containing transaction instructions and lookup tables
15
+ * @returns ixs - Array of Solana transaction instructions for the swap
16
+ * @returns lookupTables - Address lookup table accounts for transaction compression
17
+ */
18
+ const createSwapIxDetails = async ({ driftClient, jupiterClient, quote, swapFromMarketIndex, swapToMarketIndex, amount, user, }) => {
19
+ const userPublicKey = user.getUserAccountPublicKey();
20
+ const swapIxsDetails = await driftClient.getJupiterSwapIxV6({
21
+ jupiterClient,
22
+ outMarketIndex: swapToMarketIndex,
23
+ inMarketIndex: swapFromMarketIndex,
24
+ amount,
25
+ quote,
26
+ userAccountPublicKey: userPublicKey,
27
+ // we skip passing in the associated token accounts and have getJupiterSwapIxV6 derive them instead.
28
+ // getJupiterSwapIxV6 will also add the ixs to create the associated token accounts if they don't exist.
29
+ });
30
+ return swapIxsDetails;
31
+ };
32
+ exports.createSwapIxDetails = createSwapIxDetails;
33
+ /**
34
+ * Creates a complete swap transaction ready for signing and submission
35
+ *
36
+ * @param driftClient - The Drift client instance
37
+ * @param jupiterClient - The Jupiter client instance
38
+ * @param quote - Quote response from Jupiter with routing information
39
+ * @param swapFromMarketIndex - Source token market index
40
+ * @param swapToMarketIndex - Destination token market index
41
+ * @param amount - Amount to swap in base units
42
+ * @param user - User account instance
43
+ * @param txParams - Transaction parameters for fees and compute units
44
+ * @returns Promise resolving to either a legacy Transaction or VersionedTransaction ready for signing
45
+ */
46
+ const createSwapTxn = async ({ driftClient, jupiterClient, quote, swapFromMarketIndex, swapToMarketIndex, amount, user, txParams, }) => {
47
+ const swapIxsDetails = await (0, exports.createSwapIxDetails)({
48
+ driftClient,
49
+ jupiterClient,
50
+ quote,
51
+ swapFromMarketIndex,
52
+ swapToMarketIndex,
53
+ amount,
54
+ user,
55
+ });
56
+ const tx = await driftClient.buildTransaction(swapIxsDetails.ixs, txParams, 0, swapIxsDetails.lookupTables);
57
+ return tx;
58
+ };
59
+ exports.createSwapTxn = createSwapTxn;
60
+ //# sourceMappingURL=swap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swap.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/trade/swap.ts"],"names":[],"mappings":";;;AAmCA;;;;;;;;;;;;;GAaG;AACI,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACzC,WAAW,EACX,aAAa,EACb,KAAK,EACL,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,EACN,IAAI,GACuB,EAGzB,EAAE;IACJ,MAAM,aAAa,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;IAErD,MAAM,cAAc,GAAG,MAAM,WAAW,CAAC,kBAAkB,CAAC;QAC3D,aAAa;QACb,cAAc,EAAE,iBAAiB;QACjC,aAAa,EAAE,mBAAmB;QAClC,MAAM;QACN,KAAK;QACL,oBAAoB,EAAE,aAAa;QACnC,oGAAoG;QACpG,wGAAwG;KACxG,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC;AACvB,CAAC,CAAC;AA1BW,QAAA,mBAAmB,uBA0B9B;AAWF;;;;;;;;;;;;GAYG;AACI,MAAM,aAAa,GAAG,KAAK,EAAE,EACnC,WAAW,EACX,aAAa,EACb,KAAK,EACL,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,EACN,IAAI,EACJ,QAAQ,GACa,EAA+C,EAAE;IACtE,MAAM,cAAc,GAAG,MAAM,IAAA,2BAAmB,EAAC;QAChD,WAAW;QACX,aAAa;QACb,KAAK;QACL,mBAAmB;QACnB,iBAAiB;QACjB,MAAM;QACN,IAAI;KACJ,CAAC,CAAC;IAEH,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,gBAAgB,CAC5C,cAAc,CAAC,GAAG,EAClB,QAAQ,EACR,CAAC,EACD,cAAc,CAAC,YAAY,CAC3B,CAAC;IAEF,OAAO,EAAE,CAAC;AACX,CAAC,CAAC;AA5BW,QAAA,aAAa,iBA4BxB","sourcesContent":["import {\n\tBN,\n\tDriftClient,\n\tJupiterClient,\n\tQuoteResponse,\n\tTxParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tAddressLookupTableAccount,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\n\n/**\n * Parameters for creating swap instruction details\n */\ninterface CreateSwapIxDetailsParams {\n\t/** The Drift client instance for interacting with the Drift protocol */\n\tdriftClient: DriftClient;\n\t/** Quote response from Jupiter containing swap route information */\n\tquote: QuoteResponse;\n\t/** Jupiter client instance for performing the swap */\n\tjupiterClient: JupiterClient;\n\t/** Market index of the token being swapped from */\n\tswapFromMarketIndex: number;\n\t/** Market index of the token being swapped to */\n\tswapToMarketIndex: number;\n\t/** Amount to swap in base units */\n\tamount: BN;\n\t/** User instance containing account information */\n\tuser: User;\n}\n\n/**\n * Creates swap instruction details for a Jupiter swap through Drift\n *\n * @param driftClient - The Drift client instance\n * @param jupiterClient - The Jupiter client instance\n * @param quote - Quote response from Jupiter with routing information\n * @param swapFromMarketIndex - Source token market index\n * @param swapToMarketIndex - Destination token market index\n * @param amount - Amount to swap in base units\n * @param user - User account instance\n * @returns Promise resolving to an object containing transaction instructions and lookup tables\n * @returns ixs - Array of Solana transaction instructions for the swap\n * @returns lookupTables - Address lookup table accounts for transaction compression\n */\nexport const createSwapIxDetails = async ({\n\tdriftClient,\n\tjupiterClient,\n\tquote,\n\tswapFromMarketIndex,\n\tswapToMarketIndex,\n\tamount,\n\tuser,\n}: CreateSwapIxDetailsParams): Promise<{\n\tixs: TransactionInstruction[];\n\tlookupTables: AddressLookupTableAccount[];\n}> => {\n\tconst userPublicKey = user.getUserAccountPublicKey();\n\n\tconst swapIxsDetails = await driftClient.getJupiterSwapIxV6({\n\t\tjupiterClient,\n\t\toutMarketIndex: swapToMarketIndex,\n\t\tinMarketIndex: swapFromMarketIndex,\n\t\tamount,\n\t\tquote,\n\t\tuserAccountPublicKey: userPublicKey,\n\t\t// we skip passing in the associated token accounts and have getJupiterSwapIxV6 derive them instead.\n\t\t// getJupiterSwapIxV6 will also add the ixs to create the associated token accounts if they don't exist.\n\t});\n\n\treturn swapIxsDetails;\n};\n\n/**\n * Parameters for creating a complete swap transaction\n * Extends CreateSwapIxDetailsParams with additional transaction parameters\n */\ninterface CreateSwapTxnParams extends CreateSwapIxDetailsParams {\n\t/** Transaction parameters including compute units, priority fees, and other options */\n\ttxParams?: TxParams;\n}\n\n/**\n * Creates a complete swap transaction ready for signing and submission\n *\n * @param driftClient - The Drift client instance\n * @param jupiterClient - The Jupiter client instance\n * @param quote - Quote response from Jupiter with routing information\n * @param swapFromMarketIndex - Source token market index\n * @param swapToMarketIndex - Destination token market index\n * @param amount - Amount to swap in base units\n * @param user - User account instance\n * @param txParams - Transaction parameters for fees and compute units\n * @returns Promise resolving to either a legacy Transaction or VersionedTransaction ready for signing\n */\nexport const createSwapTxn = async ({\n\tdriftClient,\n\tjupiterClient,\n\tquote,\n\tswapFromMarketIndex,\n\tswapToMarketIndex,\n\tamount,\n\tuser,\n\ttxParams,\n}: CreateSwapTxnParams): Promise<Transaction | VersionedTransaction> => {\n\tconst swapIxsDetails = await createSwapIxDetails({\n\t\tdriftClient,\n\t\tjupiterClient,\n\t\tquote,\n\t\tswapFromMarketIndex,\n\t\tswapToMarketIndex,\n\t\tamount,\n\t\tuser,\n\t});\n\n\tconst tx = await driftClient.buildTransaction(\n\t\tswapIxsDetails.ixs,\n\t\ttxParams,\n\t\t0,\n\t\tswapIxsDetails.lookupTables\n\t);\n\n\treturn tx;\n};\n"]}
@@ -0,0 +1,75 @@
1
+ import { BN, DriftClient, PublicKey, SpotMarketConfig, TxParams, UserStatsAccount } from '@drift-labs/sdk';
2
+ import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
3
+ interface CreateUserAndDepositCollateralBaseIxsParams {
4
+ driftClient: DriftClient;
5
+ amount: BN;
6
+ spotMarketConfig: SpotMarketConfig;
7
+ authority: PublicKey;
8
+ userStatsAccount: UserStatsAccount | undefined;
9
+ referrerName?: string;
10
+ accountName?: string;
11
+ poolId?: number;
12
+ fromSubAccountId?: number;
13
+ customMaxMarginRatio?: number;
14
+ }
15
+ /**
16
+ * Creates transaction instructions for initializing a new user account and depositing collateral.
17
+ *
18
+ * This function generates the necessary transaction instructions to:
19
+ * 1. Initialize a new user account in the Drift protocol
20
+ * 2. Deposit collateral into the newly created account
21
+ *
22
+ * @param driftClient - The Drift client instance for interacting with the protocol
23
+ * @param amount - The amount of collateral to deposit (in base units)
24
+ * @param spotMarketConfig - The spot market config of the deposit collateral
25
+ * @param authority - The public key of the account authority (wallet owner)
26
+ * @param userStatsAccount - Existing user stats account, used to determine next sub-account ID
27
+ * @param referrerName - Optional name of the referrer for referral tracking
28
+ * @param accountName - Optional custom name for the account (defaults to pool-specific name)
29
+ * @param poolId - The pool ID to associate the account with (defaults to MAIN_POOL_ID)
30
+ * @param fromSubAccountId - Optional sub-account ID to transfer funds from
31
+ * @param customMaxMarginRatio - Optional custom maximum margin ratio for the account
32
+ *
33
+ * @returns Promise resolving to an object containing:
34
+ * - subAccountId: The ID of the newly created sub-account
35
+ * - userAccountPublicKey: The public key of the created user account
36
+ * - ixs: Array of transaction instructions to execute
37
+ */
38
+ export declare const createUserAndDepositCollateralBaseIxs: ({ driftClient, amount, spotMarketConfig, authority, userStatsAccount, referrerName, accountName, poolId, fromSubAccountId, customMaxMarginRatio, }: CreateUserAndDepositCollateralBaseIxsParams) => Promise<{
39
+ subAccountId: number;
40
+ userAccountPublicKey: PublicKey;
41
+ ixs: TransactionInstruction[];
42
+ }>;
43
+ interface CreateUserAndDepositCollateralBaseTxnParams extends CreateUserAndDepositCollateralBaseIxsParams {
44
+ txParams?: TxParams;
45
+ }
46
+ /**
47
+ * Creates a complete transaction for initializing a new user account and depositing collateral.
48
+ *
49
+ * This function is a higher-level wrapper around `createUserAndDepositCollateralBaseIxs` that:
50
+ * 1. Generates the necessary transaction instructions
51
+ * 2. Builds a complete transaction ready for signing and submission
52
+ *
53
+ * @param driftClient - The Drift client instance for interacting with the protocol
54
+ * @param amount - The amount of collateral to deposit (in base units)
55
+ * @param spotMarketConfig - The spot market config of the deposit collateral
56
+ * @param authority - The public key of the account authority (wallet owner)
57
+ * @param userStatsAccount - Existing user stats account, used to determine next sub-account ID
58
+ * @param referrerName - Optional name of the referrer for referral tracking
59
+ * @param accountName - Optional custom name for the account (defaults to pool-specific name)
60
+ * @param poolId - The pool ID to associate the account with (defaults to MAIN_POOL_ID)
61
+ * @param fromSubAccountId - Optional sub-account ID to transfer funds from
62
+ * @param customMaxMarginRatio - Optional custom maximum margin ratio for the account
63
+ * @param txParams - Transaction parameters for building the transaction (compute units, priority fees, etc.)
64
+ *
65
+ * @returns Promise resolving to an object containing:
66
+ * - transaction: The built transaction ready for signing (Transaction or VersionedTransaction)
67
+ * - userAccountPublicKey: The public key of the created user account
68
+ * - subAccountId: The ID of the newly created sub-account
69
+ */
70
+ export declare const createUserAndDepositCollateralBaseTxn: ({ driftClient, amount, spotMarketConfig, authority, userStatsAccount, referrerName, accountName, poolId, fromSubAccountId, customMaxMarginRatio, txParams, }: CreateUserAndDepositCollateralBaseTxnParams) => Promise<{
71
+ transaction: Transaction | VersionedTransaction;
72
+ userAccountPublicKey: PublicKey;
73
+ subAccountId: number;
74
+ }>;
75
+ export {};