@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,68 @@
1
+ import { Subscription } from 'rxjs';
2
+ import { MarketId } from '../../../../types';
3
+ import { L2WithOracleAndMarketData } from '../../../../utils/orderbook';
4
+ import { OrderbookGrouping } from '../../../../utils/dlob-server/DlobServerWebsocketUtils';
5
+ interface DriftL2OrderbookSubscription {
6
+ marketId: MarketId;
7
+ channel: 'orderbook_indicative' | 'orderbook';
8
+ grouping: OrderbookGrouping;
9
+ }
10
+ export interface DriftL2OrderbookManagerConfig {
11
+ wsUrl: string;
12
+ subscriptionConfig?: DriftL2OrderbookSubscription;
13
+ }
14
+ export declare class DriftL2OrderbookManager {
15
+ private _orderbook;
16
+ private wsUrl;
17
+ private _subscriptionConfig?;
18
+ private updatesSubject$;
19
+ private websocketSubscription;
20
+ constructor(config: DriftL2OrderbookManagerConfig);
21
+ get store(): {
22
+ marketSlot: number;
23
+ marketIndex: number;
24
+ marketName: string;
25
+ marketType?: import("../../../../../../protocol/sdk/lib/node").MarketType;
26
+ oracleData: import("../../../../../../protocol/sdk/lib/node").OraclePriceData;
27
+ markPrice: import("bn.js");
28
+ bestBidPrice: import("bn.js");
29
+ bestAskPrice: import("bn.js");
30
+ spreadPct: import("bn.js");
31
+ spreadQuote: import("bn.js");
32
+ mmOracleData?: import("../../../../../../protocol/sdk/lib/node").MMOraclePriceData;
33
+ asks: import("../../../../../../protocol/sdk/lib/node").L2Level[];
34
+ bids: import("../../../../../../protocol/sdk/lib/node").L2Level[];
35
+ slot?: number;
36
+ };
37
+ get subscriptionConfig(): DriftL2OrderbookSubscription;
38
+ /**
39
+ * Subscribe to orderbook updates via websocket
40
+ */
41
+ subscribe(): Promise<void>;
42
+ /**
43
+ * Unsubscribe from orderbook updates
44
+ */
45
+ unsubscribe(): void;
46
+ /**
47
+ * Update market keys for subscription
48
+ */
49
+ updateSubscription(orderbookSubscription: Pick<DriftL2OrderbookSubscription, 'marketId'> & Partial<DriftL2OrderbookSubscription>): void;
50
+ private tryParse;
51
+ /**
52
+ * Handle incoming websocket messages
53
+ */
54
+ private handleWebSocketMessage;
55
+ /**
56
+ * Get orderbook data for a specific market
57
+ */
58
+ getOrderbookData(): L2WithOracleAndMarketData | null;
59
+ /**
60
+ * Subscribe to orderbook updates
61
+ */
62
+ onUpdate(callback: (orderbookLookup: L2WithOracleAndMarketData) => void): Subscription;
63
+ /**
64
+ * Destroy the manager and clean up resources
65
+ */
66
+ destroy(): void;
67
+ }
68
+ export {};
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DriftL2OrderbookManager = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const orderbook_1 = require("../../../../utils/orderbook");
6
+ const MultiplexWebSocket_1 = require("../../../../utils/MultiplexWebSocket");
7
+ const DlobServerWebsocketUtils_1 = require("../../../../utils/dlob-server/DlobServerWebsocketUtils");
8
+ class DriftL2OrderbookManager {
9
+ constructor(config) {
10
+ this._orderbook = null;
11
+ this.updatesSubject$ = new rxjs_1.Subject();
12
+ this.websocketSubscription = null;
13
+ this.wsUrl = config.wsUrl;
14
+ this._subscriptionConfig = config.subscriptionConfig;
15
+ }
16
+ get store() {
17
+ return this._orderbook ? { ...this._orderbook } : null;
18
+ }
19
+ get subscriptionConfig() {
20
+ return this._subscriptionConfig;
21
+ }
22
+ /**
23
+ * Subscribe to orderbook updates via websocket
24
+ */
25
+ async subscribe() {
26
+ if (this.websocketSubscription) {
27
+ console.error('There is already a subscription to the orderbook');
28
+ return;
29
+ }
30
+ if (!this._subscriptionConfig) {
31
+ return;
32
+ }
33
+ const subscriptionId = `orderbook-${Date.now()}`;
34
+ const grouping = this._subscriptionConfig.grouping;
35
+ const subscribeMessage = JSON.stringify(DlobServerWebsocketUtils_1.DLOB_SERVER_WEBSOCKET_UTILS.getSubscriptionProps({
36
+ type: 'orderbook_indicative',
37
+ market: this._subscriptionConfig.marketId,
38
+ grouping,
39
+ }));
40
+ const unsubscribeMessage = JSON.stringify(DlobServerWebsocketUtils_1.DLOB_SERVER_WEBSOCKET_UTILS.getUnsubscriptionProps({
41
+ type: 'orderbook_indicative',
42
+ market: this._subscriptionConfig.marketId,
43
+ grouping,
44
+ }));
45
+ const messageFilter = DlobServerWebsocketUtils_1.DLOB_SERVER_WEBSOCKET_UTILS.getMessageFilter({
46
+ type: this._subscriptionConfig.channel,
47
+ market: this._subscriptionConfig.marketId,
48
+ grouping,
49
+ });
50
+ this.websocketSubscription = MultiplexWebSocket_1.MultiplexWebSocket.createWebSocketSubscription({
51
+ wsUrl: this.wsUrl,
52
+ subscriptionId,
53
+ subscribeMessage,
54
+ unsubscribeMessage,
55
+ onMessage: (message) => {
56
+ this.handleWebSocketMessage(message);
57
+ },
58
+ onError: (error) => {
59
+ console.error('OrderbookManager WebSocket error:', error);
60
+ },
61
+ messageFilter: (message) => {
62
+ return messageFilter(message);
63
+ },
64
+ errorMessageFilter: (message) => {
65
+ return !!message.error;
66
+ },
67
+ onClose: () => {
68
+ console.log('OrderbookManager WebSocket connection closed');
69
+ },
70
+ enableHeartbeatMonitoring: true,
71
+ });
72
+ }
73
+ /**
74
+ * Unsubscribe from orderbook updates
75
+ */
76
+ unsubscribe() {
77
+ if (this.websocketSubscription) {
78
+ this.websocketSubscription.unsubscribe();
79
+ this.websocketSubscription = null;
80
+ }
81
+ }
82
+ /**
83
+ * Update market keys for subscription
84
+ */
85
+ updateSubscription(orderbookSubscription) {
86
+ // check if subscription config is changing
87
+ this._subscriptionConfig = {
88
+ ...this._subscriptionConfig,
89
+ ...orderbookSubscription,
90
+ };
91
+ this.unsubscribe();
92
+ this.subscribe();
93
+ }
94
+ tryParse(data) {
95
+ try {
96
+ return JSON.parse(data, (key, value) => {
97
+ // If the value is a number and it's too large to be safely represented as a JavaScript number,
98
+ // convert it to a string to prevent precision loss
99
+ if (typeof value === 'number' && !Number.isSafeInteger(value)) {
100
+ return value.toString();
101
+ }
102
+ return value;
103
+ });
104
+ }
105
+ catch (e) {
106
+ return data;
107
+ }
108
+ }
109
+ /**
110
+ * Handle incoming websocket messages
111
+ */
112
+ handleWebSocketMessage({ data }) {
113
+ try {
114
+ const parsedData = this.tryParse(data);
115
+ // TODO: result slot incrementer
116
+ const deserializedOrderbook = (0, orderbook_1.deserializeL2Response)(parsedData);
117
+ this._orderbook = deserializedOrderbook;
118
+ this.updatesSubject$.next(deserializedOrderbook);
119
+ }
120
+ catch (error) {
121
+ console.error('Error processing orderbook websocket message:', error);
122
+ }
123
+ }
124
+ /**
125
+ * Get orderbook data for a specific market
126
+ */
127
+ getOrderbookData() {
128
+ return this._orderbook || null;
129
+ }
130
+ /**
131
+ * Subscribe to orderbook updates
132
+ */
133
+ onUpdate(callback) {
134
+ return this.updatesSubject$.subscribe(callback);
135
+ }
136
+ /**
137
+ * Destroy the manager and clean up resources
138
+ */
139
+ destroy() {
140
+ this.unsubscribe();
141
+ this.updatesSubject$.complete();
142
+ this._orderbook = null;
143
+ }
144
+ }
145
+ exports.DriftL2OrderbookManager = DriftL2OrderbookManager;
146
+ //# sourceMappingURL=DriftL2OrderbookManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DriftL2OrderbookManager.js","sourceRoot":"","sources":["../../../../../src/drift/Drift/clients/AuthorityDrift/DriftL2OrderbookManager.ts"],"names":[],"mappings":";;;AAAA,+BAA6C;AAE7C,2DAIqC;AACrC,6EAA0E;AAC1E,qGAGgE;AAmBhE,MAAa,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,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACxB,CAAC;CACD;AAxKD,0DAwKC","sourcesContent":["import { Subject, Subscription } from 'rxjs';\nimport { MarketId } from '../../../../types';\nimport {\n\tL2WithOracleAndMarketData,\n\tRawL2Output,\n\tdeserializeL2Response,\n} from '../../../../utils/orderbook';\nimport { MultiplexWebSocket } from '../../../../utils/MultiplexWebSocket';\nimport {\n\tDLOB_SERVER_WEBSOCKET_UTILS,\n\tOrderbookGrouping,\n} from '../../../../utils/dlob-server/DlobServerWebsocketUtils';\n\ninterface DriftL2OrderbookSubscription {\n\tmarketId: MarketId;\n\tchannel: 'orderbook_indicative' | 'orderbook';\n\tgrouping: OrderbookGrouping;\n}\n\ninterface DlobMessage {\n\tchannel: string;\n\tdata: string;\n\terror?: any;\n}\n\nexport interface DriftL2OrderbookManagerConfig {\n\twsUrl: string;\n\tsubscriptionConfig?: DriftL2OrderbookSubscription;\n}\n\nexport class DriftL2OrderbookManager {\n\tprivate _orderbook: L2WithOracleAndMarketData | null = null;\n\tprivate wsUrl: string;\n\tprivate _subscriptionConfig?: DriftL2OrderbookSubscription;\n\tprivate updatesSubject$ = new Subject<L2WithOracleAndMarketData>();\n\tprivate websocketSubscription: { unsubscribe: () => void } | null = null;\n\n\tconstructor(config: DriftL2OrderbookManagerConfig) {\n\t\tthis.wsUrl = config.wsUrl;\n\t\tthis._subscriptionConfig = config.subscriptionConfig;\n\t}\n\n\tget store() {\n\t\treturn this._orderbook ? { ...this._orderbook } : null;\n\t}\n\n\tget subscriptionConfig() {\n\t\treturn this._subscriptionConfig;\n\t}\n\n\t/**\n\t * Subscribe to orderbook updates via websocket\n\t */\n\tpublic async subscribe(): Promise<void> {\n\t\tif (this.websocketSubscription) {\n\t\t\tconsole.error('There is already a subscription to the orderbook');\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this._subscriptionConfig) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst subscriptionId = `orderbook-${Date.now()}`;\n\t\tconst grouping = this._subscriptionConfig.grouping;\n\n\t\tconst subscribeMessage = JSON.stringify(\n\t\t\tDLOB_SERVER_WEBSOCKET_UTILS.getSubscriptionProps({\n\t\t\t\ttype: 'orderbook_indicative',\n\t\t\t\tmarket: this._subscriptionConfig.marketId,\n\t\t\t\tgrouping,\n\t\t\t})\n\t\t);\n\n\t\tconst unsubscribeMessage = JSON.stringify(\n\t\t\tDLOB_SERVER_WEBSOCKET_UTILS.getUnsubscriptionProps({\n\t\t\t\ttype: 'orderbook_indicative',\n\t\t\t\tmarket: this._subscriptionConfig.marketId,\n\t\t\t\tgrouping,\n\t\t\t})\n\t\t);\n\n\t\tconst messageFilter = DLOB_SERVER_WEBSOCKET_UTILS.getMessageFilter({\n\t\t\ttype: this._subscriptionConfig.channel,\n\t\t\tmarket: this._subscriptionConfig.marketId,\n\t\t\tgrouping,\n\t\t});\n\n\t\tthis.websocketSubscription = MultiplexWebSocket.createWebSocketSubscription(\n\t\t\t{\n\t\t\t\twsUrl: this.wsUrl,\n\t\t\t\tsubscriptionId,\n\t\t\t\tsubscribeMessage,\n\t\t\t\tunsubscribeMessage,\n\t\t\t\tonMessage: (message: DlobMessage) => {\n\t\t\t\t\tthis.handleWebSocketMessage(message);\n\t\t\t\t},\n\t\t\t\tonError: (error) => {\n\t\t\t\t\tconsole.error('OrderbookManager WebSocket error:', error);\n\t\t\t\t},\n\t\t\t\tmessageFilter: (message: DlobMessage) => {\n\t\t\t\t\treturn messageFilter(message);\n\t\t\t\t},\n\t\t\t\terrorMessageFilter: (message: DlobMessage) => {\n\t\t\t\t\treturn !!message.error;\n\t\t\t\t},\n\t\t\t\tonClose: () => {\n\t\t\t\t\tconsole.log('OrderbookManager WebSocket connection closed');\n\t\t\t\t},\n\t\t\t\tenableHeartbeatMonitoring: true,\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Unsubscribe from orderbook updates\n\t */\n\tpublic unsubscribe(): void {\n\t\tif (this.websocketSubscription) {\n\t\t\tthis.websocketSubscription.unsubscribe();\n\t\t\tthis.websocketSubscription = null;\n\t\t}\n\t}\n\n\t/**\n\t * Update market keys for subscription\n\t */\n\tpublic updateSubscription(\n\t\torderbookSubscription: Pick<DriftL2OrderbookSubscription, 'marketId'> &\n\t\t\tPartial<DriftL2OrderbookSubscription>\n\t): void {\n\t\t// check if subscription config is changing\n\n\t\tthis._subscriptionConfig = {\n\t\t\t...this._subscriptionConfig,\n\t\t\t...orderbookSubscription,\n\t\t};\n\n\t\tthis.unsubscribe();\n\t\tthis.subscribe();\n\t}\n\n\tprivate tryParse(data: unknown): unknown {\n\t\ttry {\n\t\t\treturn JSON.parse(data as string, (key, value) => {\n\t\t\t\t// If the value is a number and it's too large to be safely represented as a JavaScript number,\n\t\t\t\t// convert it to a string to prevent precision loss\n\t\t\t\tif (typeof value === 'number' && !Number.isSafeInteger(value)) {\n\t\t\t\t\treturn value.toString();\n\t\t\t\t}\n\t\t\t\treturn value;\n\t\t\t});\n\t\t} catch (e) {\n\t\t\treturn data;\n\t\t}\n\t}\n\n\t/**\n\t * Handle incoming websocket messages\n\t */\n\tprivate handleWebSocketMessage({ data }: DlobMessage): void {\n\t\ttry {\n\t\t\tconst parsedData = this.tryParse(data) as RawL2Output;\n\n\t\t\t// TODO: result slot incrementer\n\n\t\t\tconst deserializedOrderbook = deserializeL2Response(parsedData);\n\t\t\tthis._orderbook = deserializedOrderbook;\n\t\t\tthis.updatesSubject$.next(deserializedOrderbook);\n\t\t} catch (error) {\n\t\t\tconsole.error('Error processing orderbook websocket message:', error);\n\t\t}\n\t}\n\n\t/**\n\t * Get orderbook data for a specific market\n\t */\n\tpublic getOrderbookData(): L2WithOracleAndMarketData | null {\n\t\treturn this._orderbook || null;\n\t}\n\n\t/**\n\t * Subscribe to orderbook updates\n\t */\n\tpublic onUpdate(\n\t\tcallback: (orderbookLookup: L2WithOracleAndMarketData) => void\n\t): Subscription {\n\t\treturn this.updatesSubject$.subscribe(callback);\n\t}\n\n\t/**\n\t * Destroy the manager and clean up resources\n\t */\n\tpublic destroy(): void {\n\t\tthis.unsubscribe();\n\t\tthis.updatesSubject$.complete();\n\t\tthis._orderbook = null;\n\t}\n}\n"]}
@@ -0,0 +1,204 @@
1
+ import { DriftClient, QuoteResponse, SwapMode, TxParams, User } from '@drift-labs/sdk';
2
+ import { TransactionSignature } from '@solana/web3.js';
3
+ import { UserAccountCache } from '../../../stores/UserAccountCache';
4
+ import { CreateUserAndDepositParams, DepositParams, WithdrawParams, PerpOrderParams, SwapParams, SettleAccountPnlParams, CancelOrdersParams } from './types';
5
+ import { SwiftOrderResult } from 'src/drift/base/actions/trade/openPerpOrder/openSwiftOrder';
6
+ /**
7
+ * Handles majority of the relevant operations on the Drift program including deposits,
8
+ * withdrawals, position management, and trading operations.
9
+ *
10
+ * This class encapsulates the trading logic and provides a clean API for
11
+ * executing various trading operations while handling common patterns like
12
+ * token address resolution and transaction preparation.
13
+ */
14
+ export declare class DriftOperations {
15
+ private driftClient;
16
+ private getUserAccountCache;
17
+ private dlobServerHttpUrl;
18
+ private swiftServerUrl;
19
+ private getPriorityFee;
20
+ static readonly DEFAULT_TX_PARAMS: TxParams;
21
+ static readonly MAX_COMPUTE_UNITS_PRICE: number;
22
+ /**
23
+ * Creates a new DriftOperations instance.
24
+ *
25
+ * @param driftClient - The DriftClient instance for executing transactions
26
+ * @param getUserAccountCache - Function to get the user account cache. We lazily load the user account cache, so that we always get the latest user account data.
27
+ * @param getPriorityFee - Function to get current priority fee in micro lamports
28
+ */
29
+ constructor(driftClient: DriftClient, getUserAccountCache: () => UserAccountCache, dlobServerHttpUrl: string, swiftServerUrl: string, getPriorityFee: () => number);
30
+ /**
31
+ * Gets transaction parameters with dynamic priority fees.
32
+ * Falls back to default if priority fee function is not available.
33
+ */
34
+ private getTxParams;
35
+ /**
36
+ * Creates a new user account and deposits initial collateral.
37
+ *
38
+ * This method handles the complete onboarding flow for new users including:
39
+ * - Validating that the subaccount doesn't already exist
40
+ * - Resolving referrer information if provided
41
+ * - Getting the correct token address for deposits
42
+ * - Creating the user account with custom leverage settings
43
+ * - Subscribing to the new user's account updates
44
+ *
45
+ * @param params - The parameters for user creation and initial deposit
46
+ * @returns Promise resolving to transaction signature and user account public key
47
+ *
48
+ * @throws Error if subaccount already exists
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const result = await tradingOps.createUserAndDeposit({
53
+ * depositAmount: new BigNum(100),
54
+ * depositSpotMarketIndex: 0, // USDC
55
+ * name: "Trading Account",
56
+ * maxLeverage: 5,
57
+ * subAccountId: 0
58
+ * });
59
+ * ```
60
+ */
61
+ createUserAndDeposit(params: CreateUserAndDepositParams): Promise<{
62
+ txSig: TransactionSignature;
63
+ user: User;
64
+ }>;
65
+ /**
66
+ * Deletes a user account.
67
+ *
68
+ * This method removes a user's sub-account from the Drift.
69
+ *
70
+ * @param subAccountId - The ID of the sub-account to delete
71
+ * @returns A promise that resolves to the transaction signature of the deletion
72
+ *
73
+ * @throws {Error} When the user account is not found in the cache
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Delete user sub-account with ID 0
78
+ * const txSignature = await tradingOps.deleteUser(0);
79
+ * console.log('User deleted with transaction:', txSignature);
80
+ * ```
81
+ */
82
+ deleteUser(subAccountId: number): Promise<TransactionSignature>;
83
+ /**
84
+ * Deposits collateral into a user's spot market position.
85
+ *
86
+ * This method handles depositing tokens into a user's account, with optional
87
+ * support for max borrow repayment scenarios where the deposit amount may be
88
+ * over-estimated to ensure complete repayment of borrowed funds.
89
+ *
90
+ * @param params - The deposit parameters
91
+ * @returns Promise resolving to the transaction signature
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const txSig = await tradingOps.deposit({
96
+ * subAccountId: 0,
97
+ * amount: new BigNum(50),
98
+ * spotMarketIndex: 0, // USDC
99
+ * isMaxBorrowRepayment: false
100
+ * });
101
+ * ```
102
+ */
103
+ deposit(params: DepositParams): Promise<TransactionSignature>;
104
+ /**
105
+ * Withdraws collateral from a user's spot market position.
106
+ *
107
+ * This method handles withdrawing tokens from a user's account with options
108
+ * for borrowing (if allowBorrow is true) or reduce-only withdrawals. For max
109
+ * withdrawals with reduce-only, the amount is over-estimated to ensure
110
+ * complete withdrawal.
111
+ *
112
+ * @param params - The withdrawal parameters
113
+ * @returns Promise resolving to the transaction signature
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const txSig = await tradingOps.withdraw({
118
+ * subAccountId: 0,
119
+ * amount: new BigNum(25),
120
+ * spotMarketIndex: 0, // USDC
121
+ * allowBorrow: false,
122
+ * isMax: false
123
+ * });
124
+ * ```
125
+ */
126
+ withdraw(params: WithdrawParams): Promise<TransactionSignature>;
127
+ /**
128
+ * Opens a perpetual market order (placeholder for future implementation).
129
+ *
130
+ * This method will handle opening long or short positions in perpetual markets
131
+ * with support for market and limit orders, reduce-only orders, and post-only orders.
132
+ *
133
+ * @param params - The perp order parameters
134
+ * @returns Promise resolving to the transaction signature
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const txSig = await tradingOps.openPerpMarketOrder({
139
+ * marketIndex: 0, // SOL-PERP
140
+ * direction: 'long',
141
+ * baseAssetAmount: new BigNum(1), // 1 SOL
142
+ * orderType: 'market',
143
+ * subAccountId: 0
144
+ * });
145
+ * ```
146
+ */
147
+ openPerpOrder(params: PerpOrderParams): Promise<TransactionSignature | SwiftOrderResult>;
148
+ getSwapQuote(params: Omit<SwapParams, 'jupiterQuote'> & {
149
+ slippageBps?: number;
150
+ swapMode?: SwapMode;
151
+ onlyDirectRoutes?: boolean;
152
+ }): Promise<QuoteResponse>;
153
+ /**
154
+ * Executes a swap between two spot markets (placeholder for future implementation).
155
+ *
156
+ * This method will handle swapping between different spot markets through
157
+ * the Drift protocol's swap functionality.
158
+ *
159
+ * @param params - The swap parameters
160
+ * @returns Promise resolving to the transaction signature
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const txSig = await tradingOps.executeSwap({
165
+ * fromMarketIndex: 0, // USDC
166
+ * toMarketIndex: 1, // SOL
167
+ * amount: new BigNum(100),
168
+ * subAccountId: 0,
169
+ * minReceiveAmount: new BigNum(0.5)
170
+ * });
171
+ * ```
172
+ */
173
+ swap(params: SwapParams): Promise<TransactionSignature>;
174
+ /**
175
+ * Settles P&L and funding for all perp position.
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const txSig = await tradingOps.settlePnl({
180
+ * subAccountId: 0,
181
+ * marketIndex: 0, // SOL-PERP
182
+ * counterpartySubAccountId: 1
183
+ * });
184
+ * ```
185
+ */
186
+ settleAccountPnl(params: SettleAccountPnlParams): Promise<TransactionSignature>;
187
+ cancelOrders(params: CancelOrdersParams): Promise<TransactionSignature>;
188
+ }
189
+ /**
190
+ * TODO:
191
+ * - priority fees / tx params
192
+ * - open non-market perp order
193
+ * - open market non-swift perp order
194
+ * - open non-market non-swift perp order
195
+ * - transfer between subaccounts
196
+ * - close position?
197
+ * - close multiple positions
198
+ * - edit open order
199
+ * - create user only
200
+ *
201
+ * - open spot order
202
+ * - rename subaccount
203
+ * - withdraw dust positions
204
+ */