@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,26 @@
1
+ import { SpotMarketConfig, DriftEnv, initialize, PerpMarketConfig } from '@drift-labs/sdk';
2
+ export declare const Config: {
3
+ initialized: boolean;
4
+ spotMarketsLookup: SpotMarketConfig[];
5
+ perpMarketsLookup: PerpMarketConfig[];
6
+ sdkConfig: ReturnType<typeof initialize>;
7
+ };
8
+ export declare const Initialize: (env: DriftEnv) => {
9
+ ENV: DriftEnv;
10
+ PYTH_ORACLE_MAPPING_ADDRESS: string;
11
+ DRIFT_PROGRAM_ID: string;
12
+ JIT_PROXY_PROGRAM_ID?: string;
13
+ DRIFT_ORACLE_RECEIVER_ID: string;
14
+ USDC_MINT_ADDRESS: string;
15
+ SERUM_V3: string;
16
+ PHOENIX: string;
17
+ OPENBOOK: string;
18
+ V2_ALPHA_TICKET_MINT_ADDRESS: string;
19
+ PERP_MARKETS: PerpMarketConfig[];
20
+ SPOT_MARKETS: SpotMarketConfig[];
21
+ MARKET_LOOKUP_TABLE: string;
22
+ MARKET_LOOKUP_TABLES: string[];
23
+ SERUM_LOOKUP_TABLE?: string;
24
+ PYTH_PULL_ORACLE_LOOKUP_TABLE?: string;
25
+ SB_ON_DEMAND_PID: import("@solana/web3.js").PublicKey;
26
+ };
package/lib/Config.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Initialize = exports.Config = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ exports.Config = {
6
+ initialized: false,
7
+ spotMarketsLookup: [],
8
+ perpMarketsLookup: [],
9
+ sdkConfig: undefined,
10
+ };
11
+ const Initialize = (env) => {
12
+ const SDKConfig = (0, sdk_1.initialize)({ env });
13
+ const maxSpotMarketIndex = Math.max(...SDKConfig.SPOT_MARKETS.map((market) => market.marketIndex));
14
+ const maxPerpMarketIndex = Math.max(...SDKConfig.PERP_MARKETS.map((market) => market.marketIndex));
15
+ const spotMarkets = new Array(maxSpotMarketIndex);
16
+ const markets = new Array(maxPerpMarketIndex);
17
+ SDKConfig.SPOT_MARKETS.forEach((spotMarket) => {
18
+ spotMarkets[spotMarket.marketIndex] = spotMarket;
19
+ });
20
+ SDKConfig.PERP_MARKETS.forEach((perpMarket) => {
21
+ markets[perpMarket.marketIndex] = perpMarket;
22
+ });
23
+ exports.Config.spotMarketsLookup = spotMarkets;
24
+ exports.Config.perpMarketsLookup = markets;
25
+ exports.Config.initialized = true;
26
+ return SDKConfig;
27
+ };
28
+ exports.Initialize = Initialize;
29
+ //# sourceMappingURL=Config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Config.js","sourceRoot":"","sources":["../src/Config.ts"],"names":[],"mappings":";;;AAAA,yCAKyB;AAEZ,QAAA,MAAM,GAKf;IACH,WAAW,EAAE,KAAK;IAClB,iBAAiB,EAAE,EAAE;IACrB,iBAAiB,EAAE,EAAE;IACrB,SAAS,EAAE,SAAS;CACpB,CAAC;AAEK,MAAM,UAAU,GAAG,CAAC,GAAa,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,IAAA,gBAAU,EAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAEtC,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAClC,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAC7D,CAAC;IAEF,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAClC,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAC7D,CAAC;IAEF,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAE9C,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7C,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7C,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,cAAM,CAAC,iBAAiB,GAAG,WAAW,CAAC;IACvC,cAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC;IAEnC,cAAM,CAAC,WAAW,GAAG,IAAI,CAAC;IAE1B,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AA5BW,QAAA,UAAU,cA4BrB","sourcesContent":["import {\n\tSpotMarketConfig,\n\tDriftEnv,\n\tinitialize,\n\tPerpMarketConfig,\n} from '@drift-labs/sdk';\n\nexport const Config: {\n\tinitialized: boolean;\n\tspotMarketsLookup: SpotMarketConfig[];\n\tperpMarketsLookup: PerpMarketConfig[];\n\tsdkConfig: ReturnType<typeof initialize>;\n} = {\n\tinitialized: false,\n\tspotMarketsLookup: [],\n\tperpMarketsLookup: [],\n\tsdkConfig: undefined,\n};\n\nexport const Initialize = (env: DriftEnv) => {\n\tconst SDKConfig = initialize({ env });\n\n\tconst maxSpotMarketIndex = Math.max(\n\t\t...SDKConfig.SPOT_MARKETS.map((market) => market.marketIndex)\n\t);\n\n\tconst maxPerpMarketIndex = Math.max(\n\t\t...SDKConfig.PERP_MARKETS.map((market) => market.marketIndex)\n\t);\n\n\tconst spotMarkets = new Array(maxSpotMarketIndex);\n\tconst markets = new Array(maxPerpMarketIndex);\n\n\tSDKConfig.SPOT_MARKETS.forEach((spotMarket) => {\n\t\tspotMarkets[spotMarket.marketIndex] = spotMarket;\n\t});\n\n\tSDKConfig.PERP_MARKETS.forEach((perpMarket) => {\n\t\tmarkets[perpMarket.marketIndex] = perpMarket;\n\t});\n\n\tConfig.spotMarketsLookup = spotMarkets;\n\tConfig.perpMarketsLookup = markets;\n\n\tConfig.initialized = true;\n\n\treturn SDKConfig;\n};\n"]}
@@ -0,0 +1,40 @@
1
+ export interface RpcEndpoint {
2
+ label: string;
3
+ value: string;
4
+ wsValue?: string;
5
+ allowAdditionalConnection: boolean;
6
+ }
7
+ export declare const EnvironmentConstants: {
8
+ rpcs: {
9
+ dev: RpcEndpoint[];
10
+ mainnet: RpcEndpoint[];
11
+ };
12
+ historyServerUrl: {
13
+ dev: string;
14
+ mainnet: string;
15
+ staging: string;
16
+ };
17
+ dataServerUrl: {
18
+ dev: string;
19
+ mainnet: string;
20
+ staging: string;
21
+ };
22
+ dlobServerHttpUrl: {
23
+ dev: string;
24
+ mainnet: string;
25
+ staging: string;
26
+ };
27
+ dlobServerWsUrl: {
28
+ dev: string;
29
+ mainnet: string;
30
+ staging: string;
31
+ };
32
+ eventsServerUrl: {
33
+ mainnet: string;
34
+ staging: string;
35
+ };
36
+ swiftServerUrl: {
37
+ mainnet: string;
38
+ staging: string;
39
+ };
40
+ };
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnvironmentConstants = void 0;
4
+ exports.EnvironmentConstants = {
5
+ rpcs: {
6
+ dev: [
7
+ {
8
+ label: 'Helius',
9
+ value: 'https://detailed-sharleen-fast-devnet.helius-rpc.com',
10
+ wsValue: 'wss://detailed-sharleen-fast-devnet.helius-rpc.com',
11
+ allowAdditionalConnection: true,
12
+ },
13
+ {
14
+ label: 'RPC Pool',
15
+ value: 'https://drift-drift-a827.devnet.rpcpool.com/3639271b-6f0e-47c6-a643-1aaa0e498f58',
16
+ wsValue: 'wss://drift-drift-a827.devnet.rpcpool.com/3639271b-6f0e-47c6-a643-1aaa0e498f58/whirligig',
17
+ allowAdditionalConnection: false,
18
+ },
19
+ ],
20
+ mainnet: [
21
+ {
22
+ label: 'Triton RPC Pool 1',
23
+ value: 'https://drift-drift-951a.mainnet.rpcpool.com',
24
+ wsValue: 'wss://drift-drift-951a.mainnet.rpcpool.com/whirligig',
25
+ allowAdditionalConnection: true,
26
+ },
27
+ {
28
+ label: 'Helius 1',
29
+ value: 'https://kora-8cwrc2-fast-mainnet.helius-rpc.com/',
30
+ wsValue: 'wss://kora-8cwrc2-fast-mainnet.helius-rpc.com/',
31
+ allowAdditionalConnection: true,
32
+ },
33
+ ],
34
+ },
35
+ historyServerUrl: {
36
+ dev: 'https://master.api.drift.trade',
37
+ mainnet: 'https://mainnet-beta.api.drift.trade',
38
+ staging: 'https://staging.api.drift.trade',
39
+ },
40
+ dataServerUrl: {
41
+ dev: 'https://data-master.api.drift.trade',
42
+ mainnet: 'https://data.api.drift.trade',
43
+ staging: 'https://data-staging.api.drift.trade',
44
+ },
45
+ dlobServerHttpUrl: {
46
+ dev: 'https://master.dlob.drift.trade',
47
+ mainnet: 'https://dlob.drift.trade',
48
+ staging: 'https://staging.dlob.drift.trade',
49
+ },
50
+ dlobServerWsUrl: {
51
+ dev: 'wss://master.dlob.drift.trade/ws',
52
+ mainnet: 'wss://dlob.drift.trade/ws',
53
+ staging: 'wss://staging.dlob.drift.trade/ws',
54
+ },
55
+ eventsServerUrl: {
56
+ mainnet: 'wss://events.drift.trade/ws',
57
+ staging: 'wss://events.drift.trade/ws',
58
+ },
59
+ swiftServerUrl: {
60
+ mainnet: 'https://swift.drift.trade',
61
+ staging: 'https://master.swift.drift.trade',
62
+ },
63
+ };
64
+ //# sourceMappingURL=EnvironmentConstants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvironmentConstants.js","sourceRoot":"","sources":["../src/EnvironmentConstants.ts"],"names":[],"mappings":";;;AAOa,QAAA,oBAAoB,GAAG;IACnC,IAAI,EAAE;QACL,GAAG,EAAE;YACJ;gBACC,KAAK,EAAE,QAAQ;gBACf,KAAK,EAAE,sDAAsD;gBAC7D,OAAO,EAAE,oDAAoD;gBAC7D,yBAAyB,EAAE,IAAI;aAC/B;YACD;gBACC,KAAK,EAAE,UAAU;gBACjB,KAAK,EACJ,kFAAkF;gBACnF,OAAO,EACN,0FAA0F;gBAC3F,yBAAyB,EAAE,KAAK;aAChC;SACgB;QAClB,OAAO,EAAE;YACR;gBACC,KAAK,EAAE,mBAAmB;gBAC1B,KAAK,EAAE,8CAA8C;gBACrD,OAAO,EAAE,sDAAsD;gBAC/D,yBAAyB,EAAE,IAAI;aAC/B;YACD;gBACC,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,kDAAkD;gBACzD,OAAO,EAAE,gDAAgD;gBACzD,yBAAyB,EAAE,IAAI;aAC/B;SACgB;KAClB;IACD,gBAAgB,EAAE;QACjB,GAAG,EAAE,gCAAgC;QACrC,OAAO,EAAE,sCAAsC;QAC/C,OAAO,EAAE,iCAAiC;KAC1C;IACD,aAAa,EAAE;QACd,GAAG,EAAE,qCAAqC;QAC1C,OAAO,EAAE,8BAA8B;QACvC,OAAO,EAAE,sCAAsC;KAC/C;IACD,iBAAiB,EAAE;QAClB,GAAG,EAAE,iCAAiC;QACtC,OAAO,EAAE,0BAA0B;QACnC,OAAO,EAAE,kCAAkC;KAC3C;IACD,eAAe,EAAE;QAChB,GAAG,EAAE,kCAAkC;QACvC,OAAO,EAAE,2BAA2B;QACpC,OAAO,EAAE,mCAAmC;KAC5C;IACD,eAAe,EAAE;QAChB,OAAO,EAAE,6BAA6B;QACtC,OAAO,EAAE,6BAA6B;KACtC;IACD,cAAc,EAAE;QACf,OAAO,EAAE,2BAA2B;QACpC,OAAO,EAAE,kCAAkC;KAC3C;CACD,CAAC","sourcesContent":["export interface RpcEndpoint {\n\tlabel: string;\n\tvalue: string;\n\twsValue?: string;\n\tallowAdditionalConnection: boolean;\n}\n\nexport const EnvironmentConstants = {\n\trpcs: {\n\t\tdev: [\n\t\t\t{\n\t\t\t\tlabel: 'Helius',\n\t\t\t\tvalue: 'https://detailed-sharleen-fast-devnet.helius-rpc.com',\n\t\t\t\twsValue: 'wss://detailed-sharleen-fast-devnet.helius-rpc.com',\n\t\t\t\tallowAdditionalConnection: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tlabel: 'RPC Pool',\n\t\t\t\tvalue:\n\t\t\t\t\t'https://drift-drift-a827.devnet.rpcpool.com/3639271b-6f0e-47c6-a643-1aaa0e498f58',\n\t\t\t\twsValue:\n\t\t\t\t\t'wss://drift-drift-a827.devnet.rpcpool.com/3639271b-6f0e-47c6-a643-1aaa0e498f58/whirligig',\n\t\t\t\tallowAdditionalConnection: false,\n\t\t\t},\n\t\t] as RpcEndpoint[],\n\t\tmainnet: [\n\t\t\t{\n\t\t\t\tlabel: 'Triton RPC Pool 1',\n\t\t\t\tvalue: 'https://drift-drift-951a.mainnet.rpcpool.com',\n\t\t\t\twsValue: 'wss://drift-drift-951a.mainnet.rpcpool.com/whirligig',\n\t\t\t\tallowAdditionalConnection: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tlabel: 'Helius 1',\n\t\t\t\tvalue: 'https://kora-8cwrc2-fast-mainnet.helius-rpc.com/',\n\t\t\t\twsValue: 'wss://kora-8cwrc2-fast-mainnet.helius-rpc.com/',\n\t\t\t\tallowAdditionalConnection: true,\n\t\t\t},\n\t\t] as RpcEndpoint[],\n\t},\n\thistoryServerUrl: {\n\t\tdev: 'https://master.api.drift.trade',\n\t\tmainnet: 'https://mainnet-beta.api.drift.trade',\n\t\tstaging: 'https://staging.api.drift.trade',\n\t},\n\tdataServerUrl: {\n\t\tdev: 'https://data-master.api.drift.trade',\n\t\tmainnet: 'https://data.api.drift.trade',\n\t\tstaging: 'https://data-staging.api.drift.trade',\n\t},\n\tdlobServerHttpUrl: {\n\t\tdev: 'https://master.dlob.drift.trade',\n\t\tmainnet: 'https://dlob.drift.trade',\n\t\tstaging: 'https://staging.dlob.drift.trade',\n\t},\n\tdlobServerWsUrl: {\n\t\tdev: 'wss://master.dlob.drift.trade/ws',\n\t\tmainnet: 'wss://dlob.drift.trade/ws',\n\t\tstaging: 'wss://staging.dlob.drift.trade/ws',\n\t},\n\teventsServerUrl: {\n\t\tmainnet: 'wss://events.drift.trade/ws',\n\t\tstaging: 'wss://events.drift.trade/ws',\n\t},\n\tswiftServerUrl: {\n\t\tmainnet: 'https://swift.drift.trade',\n\t\tstaging: 'https://master.swift.drift.trade',\n\t},\n};\n"]}
@@ -0,0 +1,16 @@
1
+ import { DriftClient, User, UserStatsAccount } from '@drift-labs/sdk';
2
+ type AccountDeletionStep = 'askToCloseAllPositionsOrdersBorrows' | 'sendAccountDeletionIx' | 'sendBalanceWithdrawalIx' | 'sendTriggerAccountIdleIx' | 'askToWait';
3
+ type CanBeDeletedState = 'no' | 'yes' | 'no-wait-for-idle' | 'yes-after-making-idle';
4
+ export declare const getIdleWaitTimeMinutes: (user: User, currentSlot: number) => number;
5
+ export declare const ACCOUNT_DELETION_HELPERS: {
6
+ accountHasOpenOrders: (user: User) => boolean;
7
+ accountHasOpenPerpPositions: (user: User) => boolean;
8
+ accountHasOpenSpotPositions: (user: User) => boolean;
9
+ getAccountDeletionStepsToTake: (user: User, userStatsAccount: UserStatsAccount, currentSlot: number) => AccountDeletionStep[];
10
+ getAccountCanBeDeletedInstantly: (user: User, userStatsAccount: UserStatsAccount, currentSlot: number) => CanBeDeletedState;
11
+ getStatsAccountIsPastDeletionCutoff: (userStatsAccount: UserStatsAccount) => boolean;
12
+ tryDeleteUserAccount: (driftClient: DriftClient, user: User, userStatsAccount: UserStatsAccount, latestSlot: number) => Promise<string>;
13
+ getIdleWaitTimeMinutes: (user: User, currentSlot: number) => number;
14
+ getStatsAccountDeletionWaitTime: (userStatsAccount: UserStatsAccount) => number;
15
+ };
16
+ export {};
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACCOUNT_DELETION_HELPERS = exports.getIdleWaitTimeMinutes = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ const getStatsAccountDeletionWaitTime = (userStatsAccount) => {
6
+ const estimatedAgeSeconds = Math.round(Date.now() / 1000) -
7
+ sdk_1.UserStats.getOldestActionTs(userStatsAccount);
8
+ return Math.max(sdk_1.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS - estimatedAgeSeconds, 0);
9
+ };
10
+ const getStatsAccountIsPastDeletionCutoff = (userStatsAccount) => {
11
+ const estimatedAgeSeconds = Math.round(Date.now() / 1000) -
12
+ sdk_1.UserStats.getOldestActionTs(userStatsAccount);
13
+ return estimatedAgeSeconds >= sdk_1.ACCOUNT_AGE_DELETION_CUTOFF_SECONDS;
14
+ };
15
+ const accountHasOpenPerpPositions = (user) => {
16
+ const userAccount = user.getUserAccount();
17
+ for (const perpPosition of userAccount.perpPositions) {
18
+ if (!(0, sdk_1.positionIsAvailable)(perpPosition)) {
19
+ return true;
20
+ }
21
+ }
22
+ return false;
23
+ };
24
+ const accountHasOpenSpotPositions = (user) => {
25
+ const userAccount = user.getUserAccount();
26
+ for (const spotPosition of userAccount.spotPositions) {
27
+ if (spotPosition.scaledBalance.gt(sdk_1.ZERO)) {
28
+ return true;
29
+ }
30
+ }
31
+ return false;
32
+ };
33
+ const accountHasOpenOrders = (user) => {
34
+ const userAccount = user.getUserAccount();
35
+ return userAccount.orders.some((order) => (0, sdk_1.isVariant)(order.status, 'open'));
36
+ };
37
+ const accountHasOpenPositionsOrOrders = (user) => {
38
+ if (accountHasOpenPerpPositions(user)) {
39
+ return true;
40
+ }
41
+ if (accountHasOpenSpotPositions(user)) {
42
+ return true;
43
+ }
44
+ if (accountHasOpenOrders(user)) {
45
+ return true;
46
+ }
47
+ return false;
48
+ };
49
+ const getAccountCanBeDeletedInstantly = (user, userStatsAccount, currentSlot) => {
50
+ const statsAccountIsPastDeletionCutoff = getStatsAccountIsPastDeletionCutoff(userStatsAccount);
51
+ const userIsIdle = user.getUserAccount().idle;
52
+ const userCanBeMarkedIdle = user.canMakeIdle(new sdk_1.BN(currentSlot));
53
+ const accountHasNoOpenPositionsOrOrders = !accountHasOpenPositionsOrOrders(user);
54
+ if (!accountHasNoOpenPositionsOrOrders) {
55
+ return 'no';
56
+ }
57
+ if (statsAccountIsPastDeletionCutoff || userIsIdle) {
58
+ return 'yes';
59
+ }
60
+ if (!userCanBeMarkedIdle) {
61
+ return 'no-wait-for-idle';
62
+ }
63
+ return 'yes-after-making-idle';
64
+ };
65
+ /**
66
+ * To try improve the UX we want to abstract away the different account states and deletion compliance. This method returns the steps required to give the best UX for account deletion depending on the incoming account state. A short explanation of the logic:
67
+ *
68
+ * States that affect whether an account can be deleted:
69
+ * - A user stats account that is older than 13 days => All accounts can be deleted
70
+ * - A user account that is idle => The user account in question can be deleted
71
+ * - A user account that can be marked idle => The user account in question can be deleted after sending a markIdle instruction
72
+ * - A user that is not/can not be idle (yet), with no stats account older than 13 days => wait until the account is idle and then try again. If the user has open perp positions, orders or borrows, they need to be closed first as well.
73
+ * @param userAccount
74
+ * @param userStatsAccount
75
+ */
76
+ const getAccountDeletionStepsToTake = (user, userStatsAccount, currentSlot) => {
77
+ const userAccount = user.getUserAccount();
78
+ const statsAccountIsPastDeletionCutoff = getStatsAccountIsPastDeletionCutoff(userStatsAccount);
79
+ // Account is past deletion cutoff
80
+ if (statsAccountIsPastDeletionCutoff) {
81
+ return ['sendAccountDeletionIx'];
82
+ }
83
+ // Account needs to be unwound first
84
+ const hasOpenPositionsOrOrders = accountHasOpenPositionsOrOrders(user);
85
+ if (hasOpenPositionsOrOrders) {
86
+ return ['askToCloseAllPositionsOrdersBorrows'];
87
+ }
88
+ // Account is idle and can be deleted
89
+ const userAccountIsIdle = userAccount.idle;
90
+ if (userAccountIsIdle) {
91
+ return ['sendAccountDeletionIx'];
92
+ }
93
+ // Account can be marked idle and then deleted
94
+ const canBeMarkedIdle = user.canMakeIdle(new sdk_1.BN(currentSlot));
95
+ if (canBeMarkedIdle) {
96
+ return ['sendTriggerAccountIdleIx', 'sendAccountDeletionIx'];
97
+ }
98
+ // Account is not idle and can not be marked idle yet, wait until it is (or can be marked) idle and then try again
99
+ return ['askToWait'];
100
+ };
101
+ /**
102
+ * Builds the necessary transaction to delete a user account. This method will throw an error if the account cannot be deleted instantly.
103
+ * @param driftClient
104
+ * @param user
105
+ * @param userStatsAccount
106
+ * @param latestSlot
107
+ * @returns
108
+ */
109
+ const tryDeleteUserAccount = async (driftClient, user, userStatsAccount, latestSlot) => {
110
+ var _a;
111
+ const canBeDeleted = getAccountCanBeDeletedInstantly(user, userStatsAccount, latestSlot);
112
+ if (canBeDeleted === 'no' || canBeDeleted === 'no-wait-for-idle') {
113
+ throw new Error('Account cannot be deleted');
114
+ }
115
+ const Ixs = [];
116
+ if (canBeDeleted === 'yes-after-making-idle') {
117
+ // Create the make idle instruction
118
+ Ixs.push(await driftClient.getUpdateUserIdleIx(user.userAccountPublicKey, user.getUserAccount()));
119
+ }
120
+ // Create the delete account instruction
121
+ Ixs.push(await driftClient.getUserDeletionIx(user.userAccountPublicKey));
122
+ // Create a transaction from the instructions
123
+ const tx = await driftClient.buildTransaction(Ixs);
124
+ const { txSig } = await driftClient.sendTransaction(tx);
125
+ const userMapKey = driftClient.getUserMapKey(user.getUserAccount().subAccountId, driftClient.wallet.publicKey);
126
+ await ((_a = driftClient.users.get(userMapKey)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
127
+ driftClient.users.delete(userMapKey);
128
+ return txSig;
129
+ };
130
+ const getIdleWaitTimeMinutes = (user, currentSlot) => {
131
+ const lastActiveSlot = user.getUserAccount().lastActiveSlot;
132
+ const inactiveAccountTime = Math.max(currentSlot - lastActiveSlot.toNumber(), 0);
133
+ const slotsToWait = sdk_1.IDLE_TIME_SLOTS - inactiveAccountTime;
134
+ const secondsPerSlot = sdk_1.SLOT_TIME_ESTIMATE_MS / 1000;
135
+ const timeEstimateSeconds = slotsToWait * secondsPerSlot;
136
+ const minutesEstimate = Math.ceil(timeEstimateSeconds / 60);
137
+ return minutesEstimate;
138
+ };
139
+ exports.getIdleWaitTimeMinutes = getIdleWaitTimeMinutes;
140
+ exports.ACCOUNT_DELETION_HELPERS = {
141
+ accountHasOpenOrders,
142
+ accountHasOpenPerpPositions,
143
+ accountHasOpenSpotPositions,
144
+ getAccountDeletionStepsToTake,
145
+ getAccountCanBeDeletedInstantly,
146
+ getStatsAccountIsPastDeletionCutoff,
147
+ tryDeleteUserAccount,
148
+ getIdleWaitTimeMinutes: exports.getIdleWaitTimeMinutes,
149
+ getStatsAccountDeletionWaitTime,
150
+ };
151
+ //# sourceMappingURL=accountDeletionHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountDeletionHelpers.js","sourceRoot":"","sources":["../../../src/actions/actionHelpers/accountDeletionHelpers.ts"],"names":[],"mappings":";;;AAAA,yCAYyB;AAUzB,MAAM,+BAA+B,GAAG,CACvC,gBAAkC,EACjC,EAAE;IACH,MAAM,mBAAmB,GACxB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAC7B,eAAS,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAE/C,OAAO,IAAI,CAAC,GAAG,CAAC,yCAAmC,GAAG,mBAAmB,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,mCAAmC,GAAG,CAC3C,gBAAkC,EACjC,EAAE;IACH,MAAM,mBAAmB,GACxB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAC7B,eAAS,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAA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serStatsAccount,\n\tZERO,\n\tisVariant,\n\tpositionIsAvailable,\n} from '@drift-labs/sdk';\nimport { TransactionInstruction } from '@solana/web3.js';\n\ntype AccountDeletionStep =\n\t| 'askToCloseAllPositionsOrdersBorrows'\n\t| 'sendAccountDeletionIx'\n\t| 'sendBalanceWithdrawalIx'\n\t| 'sendTriggerAccountIdleIx'\n\t| 'askToWait';\n\nconst getStatsAccountDeletionWaitTime = (\n\tuserStatsAccount: UserStatsAccount\n) => {\n\tconst estimatedAgeSeconds =\n\t\tMath.round(Date.now() / 1000) -\n\t\tUserStats.getOldestActionTs(userStatsAccount);\n\n\treturn Math.max(ACCOUNT_AGE_DELETION_CUTOFF_SECONDS - estimatedAgeSeconds, 0);\n};\n\nconst getStatsAccountIsPastDeletionCutoff = (\n\tuserStatsAccount: UserStatsAccount\n) => {\n\tconst estimatedAgeSeconds =\n\t\tMath.round(Date.now() / 1000) -\n\t\tUserStats.getOldestActionTs(userStatsAccount);\n\n\treturn estimatedAgeSeconds >= ACCOUNT_AGE_DELETION_CUTOFF_SECONDS;\n};\n\nconst accountHasOpenPerpPositions = (user: User) => {\n\tconst userAccount = user.getUserAccount();\n\tfor (const perpPosition of userAccount.perpPositions) {\n\t\tif (!positionIsAvailable(perpPosition)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n};\n\nconst accountHasOpenSpotPositions = (user: User) => {\n\tconst userAccount = user.getUserAccount();\n\tfor (const spotPosition of userAccount.spotPositions) {\n\t\tif (spotPosition.scaledBalance.gt(ZERO)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n};\n\nconst accountHasOpenOrders = (user: User) => {\n\tconst userAccount = user.getUserAccount();\n\treturn userAccount.orders.some((order) => isVariant(order.status, 'open'));\n};\n\nconst accountHasOpenPositionsOrOrders = (user: User) => {\n\tif (accountHasOpenPerpPositions(user)) {\n\t\treturn true;\n\t}\n\n\tif (accountHasOpenSpotPositions(user)) {\n\t\treturn true;\n\t}\n\n\tif (accountHasOpenOrders(user)) {\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n\ntype CanBeDeletedState =\n\t| 'no'\n\t| 'yes'\n\t| 'no-wait-for-idle'\n\t| 'yes-after-making-idle';\n\nconst getAccountCanBeDeletedInstantly = (\n\tuser: User,\n\tuserStatsAccount: UserStatsAccount,\n\tcurrentSlot: number\n): CanBeDeletedState => {\n\tconst statsAccountIsPastDeletionCutoff =\n\t\tgetStatsAccountIsPastDeletionCutoff(userStatsAccount);\n\n\tconst userIsIdle = user.getUserAccount().idle;\n\n\tconst userCanBeMarkedIdle = user.canMakeIdle(new BN(currentSlot));\n\n\tconst accountHasNoOpenPositionsOrOrders =\n\t\t!accountHasOpenPositionsOrOrders(user);\n\n\tif (!accountHasNoOpenPositionsOrOrders) {\n\t\treturn 'no';\n\t}\n\n\tif (statsAccountIsPastDeletionCutoff || userIsIdle) {\n\t\treturn 'yes';\n\t}\n\n\tif (!userCanBeMarkedIdle) {\n\t\treturn 'no-wait-for-idle';\n\t}\n\n\treturn 'yes-after-making-idle';\n};\n\n/**\n * To try improve the UX we want to abstract away the different account states and deletion compliance. This method returns the steps required to give the best UX for account deletion depending on the incoming account state. A short explanation of the logic:\n *\n * States that affect whether an account can be deleted:\n * - A user stats account that is older than 13 days => All accounts can be deleted\n * - A user account that is idle => The user account in question can be deleted\n * - A user account that can be marked idle => The user account in question can be deleted after sending a markIdle instruction\n * - A user that is not/can not be idle (yet), with no stats account older than 13 days => wait until the account is idle and then try again. If the user has open perp positions, orders or borrows, they need to be closed first as well.\n * @param userAccount\n * @param userStatsAccount\n */\nconst getAccountDeletionStepsToTake = (\n\tuser: User,\n\tuserStatsAccount: UserStatsAccount,\n\tcurrentSlot: number\n): AccountDeletionStep[] => {\n\tconst userAccount = user.getUserAccount();\n\tconst statsAccountIsPastDeletionCutoff =\n\t\tgetStatsAccountIsPastDeletionCutoff(userStatsAccount);\n\n\t// Account is past deletion cutoff\n\tif (statsAccountIsPastDeletionCutoff) {\n\t\treturn ['sendAccountDeletionIx'];\n\t}\n\n\t// Account needs to be unwound first\n\tconst hasOpenPositionsOrOrders = accountHasOpenPositionsOrOrders(user);\n\n\tif (hasOpenPositionsOrOrders) {\n\t\treturn ['askToCloseAllPositionsOrdersBorrows'];\n\t}\n\n\t// Account is idle and can be deleted\n\tconst userAccountIsIdle = userAccount.idle;\n\n\tif (userAccountIsIdle) {\n\t\treturn ['sendAccountDeletionIx'];\n\t}\n\n\t// Account can be marked idle and then deleted\n\tconst canBeMarkedIdle = user.canMakeIdle(new BN(currentSlot));\n\n\tif (canBeMarkedIdle) {\n\t\treturn ['sendTriggerAccountIdleIx', 'sendAccountDeletionIx'];\n\t}\n\n\t// Account is not idle and can not be marked idle yet, wait until it is (or can be marked) idle and then try again\n\treturn ['askToWait'];\n};\n\n/**\n * Builds the necessary transaction to delete a user account. This method will throw an error if the account cannot be deleted instantly.\n * @param driftClient\n * @param user\n * @param userStatsAccount\n * @param latestSlot\n * @returns\n */\nconst tryDeleteUserAccount = async (\n\tdriftClient: DriftClient,\n\tuser: User,\n\tuserStatsAccount: UserStatsAccount,\n\tlatestSlot: number\n) => {\n\tconst canBeDeleted = getAccountCanBeDeletedInstantly(\n\t\tuser,\n\t\tuserStatsAccount,\n\t\tlatestSlot\n\t);\n\n\tif (canBeDeleted === 'no' || canBeDeleted === 'no-wait-for-idle') {\n\t\tthrow new Error('Account cannot be deleted');\n\t}\n\n\tconst Ixs: TransactionInstruction[] = [];\n\n\tif (canBeDeleted === 'yes-after-making-idle') {\n\t\t// Create the make idle instruction\n\t\tIxs.push(\n\t\t\tawait driftClient.getUpdateUserIdleIx(\n\t\t\t\tuser.userAccountPublicKey,\n\t\t\t\tuser.getUserAccount()\n\t\t\t)\n\t\t);\n\t}\n\n\t// Create the delete account instruction\n\tIxs.push(await driftClient.getUserDeletionIx(user.userAccountPublicKey));\n\n\t// Create a transaction from the instructions\n\tconst tx = await driftClient.buildTransaction(Ixs);\n\n\tconst { txSig } = await driftClient.sendTransaction(tx);\n\n\tconst userMapKey = driftClient.getUserMapKey(\n\t\tuser.getUserAccount().subAccountId,\n\t\tdriftClient.wallet.publicKey\n\t);\n\tawait driftClient.users.get(userMapKey)?.unsubscribe();\n\tdriftClient.users.delete(userMapKey);\n\n\treturn txSig;\n};\n\nexport const getIdleWaitTimeMinutes = (user: User, currentSlot: number) => {\n\tconst lastActiveSlot = user.getUserAccount().lastActiveSlot;\n\n\tconst inactiveAccountTime = Math.max(\n\t\tcurrentSlot - lastActiveSlot.toNumber(),\n\t\t0\n\t);\n\n\tconst slotsToWait = IDLE_TIME_SLOTS - inactiveAccountTime;\n\n\tconst secondsPerSlot = SLOT_TIME_ESTIMATE_MS / 1000;\n\n\tconst timeEstimateSeconds = slotsToWait * secondsPerSlot;\n\n\tconst minutesEstimate = Math.ceil(timeEstimateSeconds / 60);\n\n\treturn minutesEstimate;\n};\n\nexport const ACCOUNT_DELETION_HELPERS = {\n\taccountHasOpenOrders,\n\taccountHasOpenPerpPositions,\n\taccountHasOpenSpotPositions,\n\tgetAccountDeletionStepsToTake,\n\tgetAccountCanBeDeletedInstantly,\n\tgetStatsAccountIsPastDeletionCutoff,\n\ttryDeleteUserAccount,\n\tgetIdleWaitTimeMinutes,\n\tgetStatsAccountDeletionWaitTime,\n};\n"]}
@@ -0,0 +1,13 @@
1
+ export declare const ACTION_HELPERS: {
2
+ ACCOUNT_DELETION_HELPERS: {
3
+ accountHasOpenOrders: (user: import("../../../../protocol/sdk/lib/node").User) => boolean;
4
+ accountHasOpenPerpPositions: (user: import("../../../../protocol/sdk/lib/node").User) => boolean;
5
+ accountHasOpenSpotPositions: (user: import("../../../../protocol/sdk/lib/node").User) => boolean;
6
+ getAccountDeletionStepsToTake: (user: import("../../../../protocol/sdk/lib/node").User, userStatsAccount: import("../../../../protocol/sdk/lib/node").UserStatsAccount, currentSlot: number) => ("askToCloseAllPositionsOrdersBorrows" | "sendAccountDeletionIx" | "sendBalanceWithdrawalIx" | "sendTriggerAccountIdleIx" | "askToWait")[];
7
+ getAccountCanBeDeletedInstantly: (user: import("../../../../protocol/sdk/lib/node").User, userStatsAccount: import("../../../../protocol/sdk/lib/node").UserStatsAccount, currentSlot: number) => "no" | "yes" | "no-wait-for-idle" | "yes-after-making-idle";
8
+ getStatsAccountIsPastDeletionCutoff: (userStatsAccount: import("../../../../protocol/sdk/lib/node").UserStatsAccount) => boolean;
9
+ tryDeleteUserAccount: (driftClient: import("../../../../protocol/sdk/lib/node").DriftClient, user: import("../../../../protocol/sdk/lib/node").User, userStatsAccount: import("../../../../protocol/sdk/lib/node").UserStatsAccount, latestSlot: number) => Promise<string>;
10
+ getIdleWaitTimeMinutes: (user: import("../../../../protocol/sdk/lib/node").User, currentSlot: number) => number;
11
+ getStatsAccountDeletionWaitTime: (userStatsAccount: import("../../../../protocol/sdk/lib/node").UserStatsAccount) => number;
12
+ };
13
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACTION_HELPERS = void 0;
4
+ const accountDeletionHelpers_1 = require("./accountDeletionHelpers");
5
+ exports.ACTION_HELPERS = {
6
+ ACCOUNT_DELETION_HELPERS: accountDeletionHelpers_1.ACCOUNT_DELETION_HELPERS,
7
+ };
8
+ //# sourceMappingURL=actionHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionHelpers.js","sourceRoot":"","sources":["../../../src/actions/actionHelpers/actionHelpers.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AAEvD,QAAA,cAAc,GAAG;IAC7B,wBAAwB,EAAxB,iDAAwB;CACxB,CAAC","sourcesContent":["import { ACCOUNT_DELETION_HELPERS } from './accountDeletionHelpers';\n\nexport const ACTION_HELPERS = {\n\tACCOUNT_DELETION_HELPERS,\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import { CandleResolution } from '@drift-labs/sdk';
2
+ export declare const CandleResolutions: CandleResolution[];
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CandleResolutions = void 0;
4
+ exports.CandleResolutions = [
5
+ '1',
6
+ '5',
7
+ '15',
8
+ '60',
9
+ '240',
10
+ 'D',
11
+ 'W',
12
+ 'M',
13
+ ];
14
+ //# sourceMappingURL=chartConstants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chartConstants.js","sourceRoot":"","sources":["../src/chartConstants.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAuB;IACpD,GAAG;IACH,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,GAAG;IACH,GAAG;IACH,GAAG;CACH,CAAC","sourcesContent":["import { CandleResolution } from '@drift-labs/sdk';\n\nexport const CandleResolutions: CandleResolution[] = [\n\t'1',\n\t'5',\n\t'15',\n\t'60',\n\t'240',\n\t'D',\n\t'W',\n\t'M',\n];\n"]}
@@ -0,0 +1,74 @@
1
+ import { CandleResolution } from '@drift-labs/sdk';
2
+ import { JsonCandle, MarketId } from '../types';
3
+ import { UIEnv } from '../types/UIEnv';
4
+ /**
5
+ * # CANDLE CLIENT HIGH LEVEL EXPLANATION:
6
+ * The Candle Client uses the Data API (see https://data.api.drift.trade/playground) to source candles to display.
7
+ *
8
+ * There are two key parts of the client:
9
+ * - Fetching Candles
10
+ * - Subscribing to Candles
11
+ *
12
+ * ## Fetching Candles:
13
+ * - We can fetch candles between any timestamp range.
14
+ * - The maximum number of candles we can fetch in a single request is 1000 (see CANDLE_FETCH_LIMIT).
15
+ * - We define "recent history" to be the last 1000 candles .. basically whatever comes back from the infra when we don't use a startTs and use the maximum fetch limit.
16
+ * - We want to avoid using high cardinality parameters in the fetch because otherwise we will miss the cache in the infra.
17
+ * - A concrete example of this is that we don't attach a startTs parameter when we are fetching candles within recent history (past 1000 candles)
18
+ * - We cache the recent candles in memory so that any subsequent fetches within recent history after the first one will be served from cache.
19
+ * - e.g. moving back to a further timeframe on TradingView - the required candles could potentially be in the cache, so we don't need to refetch them.
20
+ *
21
+ * ## Subscribing to Candles:
22
+ * - We subscribe to a websocket endpoint for a given market and resolution.
23
+ * - We allow the client to support multiple concurrent subscriptions, because the TradingView comopnent will sometimes do this when switching between markets.
24
+ *
25
+ * ## Possible Improvements:
26
+ * - Create a more advanced cache which can store more than the most recent 1000 candles, dynamically growing as more candles are added (for now seems unnecessary, rare for someone to go back further than 1000 candles)
27
+ */
28
+ type CandleFetchConfig = {
29
+ env: UIEnv;
30
+ marketId: MarketId;
31
+ resolution: CandleResolution;
32
+ fromTs: number;
33
+ toTs: number;
34
+ };
35
+ type CandleSubscriptionConfig = {
36
+ resolution: CandleResolution;
37
+ marketId: MarketId;
38
+ env: UIEnv;
39
+ };
40
+ type CandleSubscriberEvents = {
41
+ 'candle-update': JsonCandle;
42
+ };
43
+ /**
44
+ * This class will subscribe to candles from the Drift Data API.
45
+ *
46
+ * Note: If you are using TradingView you probably want to just use the DriftTvFeed class instead.
47
+ */
48
+ export declare class CandleClient {
49
+ private activeSubscriptions;
50
+ constructor();
51
+ subscribe: (config: CandleSubscriptionConfig, subscriptionKey: string) => Promise<void>;
52
+ /**
53
+ *
54
+ * @param config {
55
+ *
56
+ * env: UIEnv;
57
+ *
58
+ * marketId: MarketId;
59
+ *
60
+ * resolution: CandleResolution;
61
+ *
62
+ * fromTs: number; // Seconds :: This should be the START (oldest) timestamp of the candles to fetch
63
+ *
64
+ * toTs: number; // Seconds :: This should be the END (newest) timestamp of the candles to fetch
65
+ *
66
+ * }
67
+ * @returns
68
+ */
69
+ fetch: (config: CandleFetchConfig) => Promise<JsonCandle[]>;
70
+ unsubscribe: (subscriptionKey: string) => void;
71
+ unsubscribeAll: () => void;
72
+ on(subscriptionKey: string, event: keyof CandleSubscriberEvents, listener: (candle: JsonCandle) => void): void;
73
+ }
74
+ export {};