@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,300 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.NumLib = void 0;
5
+ const sdk_1 = require("@drift-labs/sdk");
6
+ /**
7
+ * Utilities to convert numbers and BigNumbers (BN) to different formats for the UI.
8
+ */
9
+ class NumLib {
10
+ }
11
+ exports.NumLib = NumLib;
12
+ _a = NumLib;
13
+ NumLib.locale = 'en';
14
+ NumLib.setLocale = (locale) => {
15
+ _a.locale = locale;
16
+ };
17
+ /**
18
+ * Converts a Big Number to its regular number representation.
19
+ *
20
+ * This won't work when the precision, or bn/precision is larger than MAX_SAFE_INTEGER .. This shouldn't happen though unless using extremely large numbers
21
+ * */
22
+ NumLib.toRawNum = (bn, precision, fixedAccuracity) => {
23
+ if (!bn)
24
+ return 0;
25
+ if (bn.lt(precision)) {
26
+ try {
27
+ return bn.toNumber() / precision.toNumber();
28
+ }
29
+ catch {
30
+ const numScale = new sdk_1.BN(1000);
31
+ return bn.div(precision.div(numScale)).toNumber() / numScale.toNumber();
32
+ }
33
+ }
34
+ let rawValue = bn.div(precision).toNumber() +
35
+ bn.mod(precision).toNumber() / precision.toNumber();
36
+ if (fixedAccuracity) {
37
+ rawValue = parseFloat(rawValue.toFixed(fixedAccuracity));
38
+ }
39
+ return rawValue;
40
+ };
41
+ NumLib.formatNum = {
42
+ /**
43
+ * Converts a number to a precision suitable to trade with
44
+ * @param num
45
+ * @returns
46
+ */
47
+ toTradePrecision: (num) => {
48
+ return parseFloat(num.toPrecision(6));
49
+ },
50
+ toTradePrecisionString: (num, toLocaleString) => {
51
+ if (num === 0)
52
+ return Number(0).toLocaleString(_a.locale, {
53
+ minimumSignificantDigits: 6,
54
+ maximumSignificantDigits: 6,
55
+ });
56
+ // slice numbers which have leading 0s so that numbers are only 6 digits long.
57
+ //// trimAmount will be 1 for 0.1 -> 0.999, 2 for 0.01 -> 0.0999, etc.
58
+ //// Handle num = 0 edge case .. (log10(0) = infinity)
59
+ const trimAmount = Math.abs(num >= 1 || num == 0
60
+ ? 0
61
+ : Math.min(0, Math.floor(Math.log10(Math.abs(num)))));
62
+ // max sigFigs = 6, min = 1
63
+ const sigFigs = Math.max(Math.min(6 - trimAmount, 6), 1);
64
+ const tradePrecisionString = num.toPrecision(sigFigs);
65
+ if (toLocaleString)
66
+ return _a.formatNum
67
+ .toTradePrecision(num)
68
+ .toLocaleString(_a.locale, {
69
+ minimumSignificantDigits: sigFigs,
70
+ maximumSignificantDigits: sigFigs,
71
+ });
72
+ return tradePrecisionString;
73
+ },
74
+ /**
75
+ * Formats a notional dollar value for UI. Goes to max. 2 decimals (accurate to 1 cent)
76
+ * @param num
77
+ * @returns
78
+ */
79
+ toNotionalDisplay: (num) => {
80
+ return `${num < 0 ? `-` : ``}$${(Math.round(Math.abs(num) * 100) / 100).toLocaleString(_a.locale, {
81
+ maximumFractionDigits: 2,
82
+ minimumFractionDigits: 2,
83
+ })}`;
84
+ },
85
+ /**
86
+ * Formats a notional dollar value. Goes to max. 2 decimals (accurate to 1 cent)
87
+ * @param num
88
+ * @returns
89
+ */
90
+ toNotionalNum: (num) => {
91
+ return parseFloat((Math.round(num * 100) / 100).toFixed(2));
92
+ },
93
+ /**
94
+ * This function prints the base amount of an asset with a number of decimals relative to the price of the asset, because for high priced assets we care about more accuracy in the base amount. Number of decimals corresponds to accuracy to ~ 1 cent
95
+ * @param baseAmount
96
+ * @param assetPrice in dollars
97
+ * @param skipLocaleFormatting Format using toFixed rather than localeString, which can't be parsed with regular number parsing
98
+ * @returns
99
+ */
100
+ toBaseDisplay: (baseAmount, _assetPrice, _skipLocaleFormatting = false, customSigFigs = 5) => {
101
+ if (baseAmount < 1) {
102
+ if (baseAmount === 0)
103
+ return '0.0000';
104
+ if (baseAmount < 0.00001) {
105
+ return '<0.00001';
106
+ }
107
+ return baseAmount.toFixed(4);
108
+ }
109
+ if (_skipLocaleFormatting) {
110
+ return baseAmount.toFixed(Math.min(Math.max(0, Math.floor(Math.log10(_assetPrice + 1))) + 2, 6));
111
+ }
112
+ return baseAmount.toLocaleString(_a.locale, {
113
+ minimumSignificantDigits: customSigFigs,
114
+ maximumSignificantDigits: customSigFigs,
115
+ });
116
+ },
117
+ /**
118
+ * This function prints the base amount of an asset with a number of decimals relative to the price of the asset, because for high priced assets we care about more accuracy in the base amount. Number of decimals corresponds to accuracy to ~ 1 cent
119
+ * @param baseAmount
120
+ * @param assetPrice in dollars
121
+ * @param skipLocaleFormatting Format using toFixed rather than localeString, which can't be parsed with regular number parsing
122
+ * @returns
123
+ */
124
+ toBase: (baseAmount, assetPrice) => {
125
+ if (assetPrice === 0 ||
126
+ assetPrice === undefined ||
127
+ Number(assetPrice) === undefined) {
128
+ return parseFloat(baseAmount.toFixed(6));
129
+ }
130
+ const decimalDigits = Math.min(Math.max(0, Math.floor(Math.log10(assetPrice))) + 2, 6);
131
+ return parseFloat(baseAmount.toFixed(decimalDigits));
132
+ },
133
+ toBaseBN: (baseAmount) => _a.formatNum.toRawBn(baseAmount, sdk_1.AMM_RESERVE_PRECISION),
134
+ toQuoteBN: (quoteAmount) => _a.formatNum.toRawBn(quoteAmount, sdk_1.QUOTE_PRECISION),
135
+ /**
136
+ * Formats to price in locale style
137
+ * @param assetPrice
138
+ * @returns
139
+ */
140
+ toDisplayPrice: (assetPrice) => {
141
+ if (assetPrice === undefined)
142
+ return '';
143
+ if (assetPrice === 0)
144
+ return assetPrice.toFixed(2);
145
+ return assetPrice.toLocaleString(_a.locale, {
146
+ maximumSignificantDigits: 6,
147
+ minimumSignificantDigits: 6,
148
+ });
149
+ },
150
+ /**
151
+ * Formats a price
152
+ * @param assetPrice
153
+ * @returns
154
+ */
155
+ toPrice: (assetPrice) => {
156
+ if (assetPrice === undefined)
157
+ return 0;
158
+ if (assetPrice === 0)
159
+ return parseFloat(assetPrice.toFixed(2));
160
+ // const numFractionDigits = 6 - Math.floor(Math.log10(assetPrice));
161
+ return parseFloat(assetPrice.toFixed(6));
162
+ },
163
+ /**
164
+ * Convert a number to a BN based on the required precision
165
+ * @param num
166
+ * @param precision
167
+ * @returns
168
+ */
169
+ toRawBn: (num, precision) => {
170
+ let numericalAsBn;
171
+ try {
172
+ numericalAsBn = new sdk_1.BN(num * precision.toNumber());
173
+ }
174
+ catch (e) {
175
+ // Integer part
176
+ if (Math.abs(num) < Number.MAX_SAFE_INTEGER) {
177
+ numericalAsBn = new sdk_1.BN(num).mul(precision);
178
+ // Decimal part
179
+ //// BN Strips the decimal value when constructing one directly. Need to add it manually
180
+ const mantissaSize = Math.log10(precision.toNumber());
181
+ const decimalValue = parseFloat((num % 1).toFixed(mantissaSize));
182
+ numericalAsBn.add(new sdk_1.BN(decimalValue * 10 ** mantissaSize));
183
+ }
184
+ else {
185
+ numericalAsBn = new sdk_1.BN(Number.MAX_SAFE_INTEGER).mul(precision);
186
+ }
187
+ }
188
+ return numericalAsBn;
189
+ },
190
+ /**
191
+ * Truncates a number to a certain number of decimal places. This differs from .toFixed() in that it rounds down, whereas .toFixed() rounds to the nearest number.
192
+ * @param num
193
+ * @param decimalPlaces
194
+ * @returns
195
+ */
196
+ toDecimalPlaces: (num, decimalPlaces, noPadding) => {
197
+ const truncatedNum = Math.floor(num * Math.pow(10, decimalPlaces)) /
198
+ Math.pow(10, decimalPlaces);
199
+ if (noPadding) {
200
+ return truncatedNum.toString();
201
+ }
202
+ const paddedNum = truncatedNum.toString();
203
+ const [integerPart, decimalPart = ''] = paddedNum.split('.');
204
+ const paddedDecimal = decimalPart.padEnd(decimalPlaces, '0');
205
+ return `${integerPart}.${paddedDecimal}`;
206
+ },
207
+ };
208
+ NumLib.formatBn = {
209
+ toRawNum: _a.toRawNum,
210
+ fromQuote: (bn) => {
211
+ return _a.toRawNum(bn, sdk_1.QUOTE_PRECISION);
212
+ },
213
+ fromBase: (bn) => {
214
+ return _a.toRawNum(bn, sdk_1.AMM_RESERVE_PRECISION);
215
+ },
216
+ };
217
+ /**
218
+ * Outputs information and formatted string for UI based on its log10 value
219
+ * @param value
220
+ * @returns
221
+ */
222
+ NumLib.millify = (value) => {
223
+ if (!value)
224
+ return {
225
+ mantissa: 0,
226
+ symbol: '',
227
+ sigFigs: 1,
228
+ displayValue: 0,
229
+ displayString: '0',
230
+ };
231
+ const valueLog10 = Math.log10(value === 0 ? 1 : value);
232
+ const metricAmount = Math.floor(valueLog10 / 3);
233
+ const sigFigs = Math.max(3 + (valueLog10 % 3), 1);
234
+ let symbol = '';
235
+ let mantissa = 1;
236
+ switch (metricAmount) {
237
+ case 1:
238
+ mantissa = 10 ** 3;
239
+ symbol = 'K';
240
+ break;
241
+ case 2:
242
+ mantissa = 10 ** 6;
243
+ symbol = 'M';
244
+ break;
245
+ case 3:
246
+ mantissa = 10 ** 9;
247
+ symbol = 'B';
248
+ break;
249
+ case 4:
250
+ mantissa = 10 ** 12;
251
+ symbol = 'T';
252
+ break;
253
+ case 0:
254
+ default:
255
+ mantissa = 1;
256
+ symbol = '';
257
+ break;
258
+ }
259
+ const displayValue = parseFloat((value / mantissa).toLocaleString(_a.locale, {
260
+ maximumSignificantDigits: sigFigs,
261
+ }));
262
+ const displayString = `${(value / mantissa).toLocaleString(_a.locale, {
263
+ maximumSignificantDigits: sigFigs,
264
+ })}${symbol}`;
265
+ return {
266
+ mantissa,
267
+ symbol,
268
+ sigFigs,
269
+ displayValue,
270
+ displayString,
271
+ };
272
+ };
273
+ /**
274
+ * Get the precision to use for an asset so that base asset amounts are on the same scale as USD cents
275
+ * @param assetPrice
276
+ * @returns
277
+ */
278
+ NumLib.getDisplayPrecision = (assetPrice) => {
279
+ if (assetPrice.eqZero() || !assetPrice) {
280
+ return 6;
281
+ }
282
+ const exponent = assetPrice.toString().length - 1 - assetPrice.precision.toNumber();
283
+ if (exponent < 1)
284
+ return 2;
285
+ return exponent + 2;
286
+ };
287
+ NumLib.bp = (num) => num * 10 ** -4;
288
+ NumLib.isInvalid = (num) => !isFinite(num) || typeof num !== 'number';
289
+ NumLib.sumBigNums = (nums, precision) => {
290
+ return nums.reduce((previousValue, currentValue) => {
291
+ return previousValue.add(currentValue);
292
+ }, sdk_1.BigNum.zero(precision));
293
+ };
294
+ NumLib.averageBigNums = (nums, precision) => {
295
+ if (!nums || !nums.length)
296
+ return;
297
+ const total = _a.sumBigNums(nums, precision);
298
+ return total.scale(1, nums.length);
299
+ };
300
+ //# sourceMappingURL=NumLib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NumLib.js","sourceRoot":"","sources":["../../src/utils/NumLib.ts"],"names":[],"mappings":";;;;AAAA,yCAKyB;AAEzB;;GAEG;AACH,MAAa,MAAM;;AAAnB,wBAuWC;;AAtWe,aAAM,GAAG,IAAI,AAAP,CAAQ;AAEtB,gBAAS,GAAG,CAAC,MAAc,EAAE,EAAE;IACrC,EAAI,CAAC,MAAM,GAAG,MAAM,CAAC;AACtB,CAAC,AAFe,CAEd;AAEF;;;;KAIK;AACU,eAAQ,GAAG,CACzB,EAAM,EACN,SAAa,EACb,eAAwB,EACvB,EAAE;IACH,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,CAAC;IAElB,IAAI,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;QACtB,IAAI,CAAC;YACJ,OAAO,EAAE,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC7C,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,QAAQ,GAAG,IA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AO,GAAG,KAAK,QAAQ,AAA7D,CAA8D;AAEvE,iBAAU,GAAG,CAAC,IAAc,EAAE,SAAa,EAAE,EAAE;IACrD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,EAAE;QAClD,OAAO,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC,EAAE,YAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AAC5B,CAAC,AAJgB,CAIf;AAEK,qBAAc,GAAG,CAAC,IAAc,EAAE,SAAa,EAAE,EAAE;IACzD,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,OAAO;IAClC,MAAM,KAAK,GAAG,EAAI,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,AAJoB,CAInB","sourcesContent":["import {\n\tBN,\n\tQUOTE_PRECISION,\n\tAMM_RESERVE_PRECISION,\n\tBigNum,\n} from '@drift-labs/sdk';\n\n/**\n * Utilities to convert numbers and BigNumbers (BN) to different formats for the UI.\n */\nexport class NumLib {\n\tprivate static locale = 'en';\n\n\tstatic setLocale = (locale: string) => {\n\t\tthis.locale = locale;\n\t};\n\n\t/**\n\t * Converts a Big Number to its regular number representation.\n\t *\n\t * This won't work when the precision, or bn/precision is larger than MAX_SAFE_INTEGER .. This shouldn't happen though unless using extremely large numbers\n\t * */\n\tprivate static toRawNum = (\n\t\tbn: BN,\n\t\tprecision: BN,\n\t\tfixedAccuracity?: number\n\t) => {\n\t\tif (!bn) return 0;\n\n\t\tif (bn.lt(precision)) {\n\t\t\ttry {\n\t\t\t\treturn bn.toNumber() / precision.toNumber();\n\t\t\t} catch {\n\t\t\t\tconst numScale = new BN(1000);\n\t\t\t\treturn bn.div(precision.div(numScale)).toNumber() / numScale.toNumber();\n\t\t\t}\n\t\t}\n\n\t\tlet rawValue =\n\t\t\tbn.div(precision).toNumber() +\n\t\t\tbn.mod(precision).toNumber() / precision.toNumber();\n\n\t\tif (fixedAccuracity) {\n\t\t\trawValue = parseFloat(rawValue.toFixed(fixedAccuracity));\n\t\t}\n\n\t\treturn rawValue;\n\t};\n\n\tstatic formatNum = {\n\t\t/**\n\t\t * Converts a number to a precision suitable to trade with\n\t\t * @param num\n\t\t * @returns\n\t\t */\n\t\ttoTradePrecision: (num: number) => {\n\t\t\treturn parseFloat(num.toPrecision(6));\n\t\t},\n\t\ttoTradePrecisionString: (num: number, toLocaleString?: boolean) => {\n\t\t\tif (num === 0)\n\t\t\t\treturn Number(0).toLocaleString(this.locale, {\n\t\t\t\t\tminimumSignificantDigits: 6,\n\t\t\t\t\tmaximumSignificantDigits: 6,\n\t\t\t\t});\n\n\t\t\t// slice numbers which have leading 0s so that numbers are only 6 digits long.\n\t\t\t//// trimAmount will be 1 for 0.1 -> 0.999, 2 for 0.01 -> 0.0999, etc.\n\t\t\t//// Handle num = 0 edge case .. (log10(0) = infinity)\n\t\t\tconst trimAmount = Math.abs(\n\t\t\t\tnum >= 1 || num == 0\n\t\t\t\t\t? 0\n\t\t\t\t\t: Math.min(0, Math.floor(Math.log10(Math.abs(num))))\n\t\t\t);\n\n\t\t\t// max sigFigs = 6, min = 1\n\t\t\tconst sigFigs = Math.max(Math.min(6 - trimAmount, 6), 1);\n\n\t\t\tconst tradePrecisionString = num.toPrecision(sigFigs);\n\n\t\t\tif (toLocaleString)\n\t\t\t\treturn NumLib.formatNum\n\t\t\t\t\t.toTradePrecision(num)\n\t\t\t\t\t.toLocaleString(this.locale, {\n\t\t\t\t\t\tminimumSignificantDigits: sigFigs,\n\t\t\t\t\t\tmaximumSignificantDigits: sigFigs,\n\t\t\t\t\t});\n\n\t\t\treturn tradePrecisionString;\n\t\t},\n\t\t/**\n\t\t * Formats a notional dollar value for UI. Goes to max. 2 decimals (accurate to 1 cent)\n\t\t * @param num\n\t\t * @returns\n\t\t */\n\t\ttoNotionalDisplay: (num: number) => {\n\t\t\treturn `${num < 0 ? `-` : ``}$${(\n\t\t\t\tMath.round(Math.abs(num) * 100) / 100\n\t\t\t).toLocaleString(this.locale, {\n\t\t\t\tmaximumFractionDigits: 2,\n\t\t\t\tminimumFractionDigits: 2,\n\t\t\t})}`;\n\t\t},\n\t\t/**\n\t\t * Formats a notional dollar value. Goes to max. 2 decimals (accurate to 1 cent)\n\t\t * @param num\n\t\t * @returns\n\t\t */\n\t\ttoNotionalNum: (num: number) => {\n\t\t\treturn parseFloat((Math.round(num * 100) / 100).toFixed(2));\n\t\t},\n\t\t/**\n\t\t * This function prints the base amount of an asset with a number of decimals relative to the price of the asset, because for high priced assets we care about more accuracy in the base amount. Number of decimals corresponds to accuracy to ~ 1 cent\n\t\t * @param baseAmount\n\t\t * @param assetPrice in dollars\n\t\t * @param skipLocaleFormatting Format using toFixed rather than localeString, which can't be parsed with regular number parsing\n\t\t * @returns\n\t\t */\n\t\ttoBaseDisplay: (\n\t\t\tbaseAmount: number,\n\t\t\t_assetPrice?: number,\n\t\t\t_skipLocaleFormatting = false,\n\t\t\tcustomSigFigs = 5\n\t\t): string => {\n\t\t\tif (baseAmount < 1) {\n\t\t\t\tif (baseAmount === 0) return '0.0000';\n\n\t\t\t\tif (baseAmount < 0.00001) {\n\t\t\t\t\treturn '<0.00001';\n\t\t\t\t}\n\n\t\t\t\treturn baseAmount.toFixed(4);\n\t\t\t}\n\t\t\tif (_skipLocaleFormatting) {\n\t\t\t\treturn baseAmount.toFixed(\n\t\t\t\t\tMath.min(Math.max(0, Math.floor(Math.log10(_assetPrice + 1))) + 2, 6)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn baseAmount.toLocaleString(this.locale, {\n\t\t\t\tminimumSignificantDigits: customSigFigs,\n\t\t\t\tmaximumSignificantDigits: customSigFigs,\n\t\t\t});\n\t\t},\n\t\t/**\n\t\t * This function prints the base amount of an asset with a number of decimals relative to the price of the asset, because for high priced assets we care about more accuracy in the base amount. Number of decimals corresponds to accuracy to ~ 1 cent\n\t\t * @param baseAmount\n\t\t * @param assetPrice in dollars\n\t\t * @param skipLocaleFormatting Format using toFixed rather than localeString, which can't be parsed with regular number parsing\n\t\t * @returns\n\t\t */\n\t\ttoBase: (baseAmount: number, assetPrice?: number): number => {\n\t\t\tif (\n\t\t\t\tassetPrice === 0 ||\n\t\t\t\tassetPrice === undefined ||\n\t\t\t\tNumber(assetPrice) === undefined\n\t\t\t) {\n\t\t\t\treturn parseFloat(baseAmount.toFixed(6));\n\t\t\t}\n\n\t\t\tconst decimalDigits = Math.min(\n\t\t\t\tMath.max(0, Math.floor(Math.log10(assetPrice))) + 2,\n\t\t\t\t6\n\t\t\t);\n\n\t\t\treturn parseFloat(baseAmount.toFixed(decimalDigits));\n\t\t},\n\t\ttoBaseBN: (baseAmount: number) =>\n\t\t\tthis.formatNum.toRawBn(baseAmount, AMM_RESERVE_PRECISION),\n\t\ttoQuoteBN: (quoteAmount: number) =>\n\t\t\tthis.formatNum.toRawBn(quoteAmount, QUOTE_PRECISION),\n\t\t/**\n\t\t * Formats to price in locale style\n\t\t * @param assetPrice\n\t\t * @returns\n\t\t */\n\t\ttoDisplayPrice: (assetPrice: number): string => {\n\t\t\tif (assetPrice === undefined) return '';\n\t\t\tif (assetPrice === 0) return assetPrice.toFixed(2);\n\n\t\t\treturn assetPrice.toLocaleString(this.locale, {\n\t\t\t\tmaximumSignificantDigits: 6,\n\t\t\t\tminimumSignificantDigits: 6,\n\t\t\t});\n\t\t},\n\t\t/**\n\t\t * Formats a price\n\t\t * @param assetPrice\n\t\t * @returns\n\t\t */\n\t\ttoPrice: (assetPrice: number): number => {\n\t\t\tif (assetPrice === undefined) return 0;\n\t\t\tif (assetPrice === 0) return parseFloat(assetPrice.toFixed(2));\n\n\t\t\t// const numFractionDigits = 6 - Math.floor(Math.log10(assetPrice));\n\n\t\t\treturn parseFloat(assetPrice.toFixed(6));\n\t\t},\n\t\t/**\n\t\t * Convert a number to a BN based on the required precision\n\t\t * @param num\n\t\t * @param precision\n\t\t * @returns\n\t\t */\n\t\ttoRawBn: (num: number, precision: BN) => {\n\t\t\tlet numericalAsBn: BN;\n\n\t\t\ttry {\n\t\t\t\tnumericalAsBn = new BN(num * precision.toNumber());\n\t\t\t} catch (e) {\n\t\t\t\t// Integer part\n\t\t\t\tif (Math.abs(num) < Number.MAX_SAFE_INTEGER) {\n\t\t\t\t\tnumericalAsBn = new BN(num).mul(precision);\n\n\t\t\t\t\t// Decimal part\n\t\t\t\t\t//// BN Strips the decimal value when constructing one directly. Need to add it manually\n\t\t\t\t\tconst mantissaSize = Math.log10(precision.toNumber());\n\t\t\t\t\tconst decimalValue = parseFloat((num % 1).toFixed(mantissaSize));\n\n\t\t\t\t\tnumericalAsBn.add(new BN(decimalValue * 10 ** mantissaSize));\n\t\t\t\t} else {\n\t\t\t\t\tnumericalAsBn = new BN(Number.MAX_SAFE_INTEGER).mul(precision);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn numericalAsBn;\n\t\t},\n\t\t/**\n\t\t * Truncates a number to a certain number of decimal places. This differs from .toFixed() in that it rounds down, whereas .toFixed() rounds to the nearest number.\n\t\t * @param num\n\t\t * @param decimalPlaces\n\t\t * @returns\n\t\t */\n\t\ttoDecimalPlaces: (\n\t\t\tnum: number,\n\t\t\tdecimalPlaces: number,\n\t\t\tnoPadding?: boolean\n\t\t): string => {\n\t\t\tconst truncatedNum =\n\t\t\t\tMath.floor(num * Math.pow(10, decimalPlaces)) /\n\t\t\t\tMath.pow(10, decimalPlaces);\n\t\t\tif (noPadding) {\n\t\t\t\treturn truncatedNum.toString();\n\t\t\t}\n\n\t\t\tconst paddedNum = truncatedNum.toString();\n\t\t\tconst [integerPart, decimalPart = ''] = paddedNum.split('.');\n\t\t\tconst paddedDecimal = decimalPart.padEnd(decimalPlaces, '0');\n\t\t\treturn `${integerPart}.${paddedDecimal}`;\n\t\t},\n\t};\n\n\tstatic formatBn = {\n\t\ttoRawNum: NumLib.toRawNum,\n\t\tfromQuote: (bn: BN) => {\n\t\t\treturn NumLib.toRawNum(bn, QUOTE_PRECISION);\n\t\t},\n\t\tfromBase: (bn: BN) => {\n\t\t\treturn NumLib.toRawNum(bn, AMM_RESERVE_PRECISION);\n\t\t},\n\t};\n\n\t/**\n\t * Outputs information and formatted string for UI based on its log10 value\n\t * @param value\n\t * @returns\n\t */\n\tstatic millify = (\n\t\tvalue: number\n\t): {\n\t\tmantissa: number;\n\t\tsymbol: string;\n\t\tsigFigs: number;\n\t\tdisplayValue: number;\n\t\tdisplayString: string;\n\t} => {\n\t\tif (!value)\n\t\t\treturn {\n\t\t\t\tmantissa: 0,\n\t\t\t\tsymbol: '',\n\t\t\t\tsigFigs: 1,\n\t\t\t\tdisplayValue: 0,\n\t\t\t\tdisplayString: '0',\n\t\t\t};\n\n\t\tconst valueLog10 = Math.log10(value === 0 ? 1 : value);\n\n\t\tconst metricAmount = Math.floor(valueLog10 / 3);\n\n\t\tconst sigFigs = Math.max(3 + (valueLog10 % 3), 1);\n\n\t\tlet symbol = '';\n\t\tlet mantissa = 1;\n\n\t\tswitch (metricAmount) {\n\t\t\tcase 1:\n\t\t\t\tmantissa = 10 ** 3;\n\t\t\t\tsymbol = 'K';\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tmantissa = 10 ** 6;\n\t\t\t\tsymbol = 'M';\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tmantissa = 10 ** 9;\n\t\t\t\tsymbol = 'B';\n\t\t\t\tbreak;\n\t\t\tcase 4:\n\t\t\t\tmantissa = 10 ** 12;\n\t\t\t\tsymbol = 'T';\n\t\t\t\tbreak;\n\t\t\tcase 0:\n\t\t\tdefault:\n\t\t\t\tmantissa = 1;\n\t\t\t\tsymbol = '';\n\t\t\t\tbreak;\n\t\t}\n\n\t\tconst displayValue = parseFloat(\n\t\t\t(value / mantissa).toLocaleString(this.locale, {\n\t\t\t\tmaximumSignificantDigits: sigFigs,\n\t\t\t})\n\t\t);\n\n\t\tconst displayString = `${(value / mantissa).toLocaleString(this.locale, {\n\t\t\tmaximumSignificantDigits: sigFigs,\n\t\t})}${symbol}`;\n\n\t\treturn {\n\t\t\tmantissa,\n\t\t\tsymbol,\n\t\t\tsigFigs,\n\t\t\tdisplayValue,\n\t\t\tdisplayString,\n\t\t};\n\t};\n\n\t/**\n\t * Get the precision to use for an asset so that base asset amounts are on the same scale as USD cents\n\t * @param assetPrice\n\t * @returns\n\t */\n\tstatic getDisplayPrecision = (assetPrice: BigNum) => {\n\t\tif (assetPrice.eqZero() || !assetPrice) {\n\t\t\treturn 6;\n\t\t}\n\n\t\tconst exponent =\n\t\t\tassetPrice.toString().length - 1 - assetPrice.precision.toNumber();\n\n\t\tif (exponent < 1) return 2;\n\n\t\treturn exponent + 2;\n\t};\n\n\tstatic bp = (num: number) => num * 10 ** -4;\n\n\tstatic isInvalid = (num: number) => !isFinite(num) || typeof num !== 'number';\n\n\tstatic sumBigNums = (nums: BigNum[], precision: BN) => {\n\t\treturn nums.reduce((previousValue, currentValue) => {\n\t\t\treturn previousValue.add(currentValue);\n\t\t}, BigNum.zero(precision));\n\t};\n\n\tstatic averageBigNums = (nums: BigNum[], precision: BN) => {\n\t\tif (!nums || !nums.length) return;\n\t\tconst total = this.sumBigNums(nums, precision);\n\t\treturn total.scale(1, nums.length);\n\t};\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { Observable } from 'rxjs';
2
+ /**
3
+ * This class creates an interval which multiple "subscribers" can add their "props" to.
4
+ *
5
+ * The interval has a base tick rate, and the subscribers add their tick multiple and props to the interval.
6
+ *
7
+ * The interval will tick at the base rate, and for each tick it will the props of any subscribers whose tick multiple is a factor of the current tick.
8
+ */
9
+ export declare class SharedInterval<SubscriberProps> {
10
+ private tickRate;
11
+ private interval;
12
+ private tickCount;
13
+ private subscription;
14
+ private subscribers;
15
+ constructor(tickRate: number);
16
+ addSubscriber(tickMultiple: number, id: string, props: SubscriberProps): void;
17
+ removeSubscriber(id: string): void;
18
+ start(): void;
19
+ stop(): void;
20
+ subscribe(): Observable<SubscriberProps[]>;
21
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedInterval = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ /**
6
+ * This class creates an interval which multiple "subscribers" can add their "props" to.
7
+ *
8
+ * The interval has a base tick rate, and the subscribers add their tick multiple and props to the interval.
9
+ *
10
+ * The interval will tick at the base rate, and for each tick it will the props of any subscribers whose tick multiple is a factor of the current tick.
11
+ */
12
+ class SharedInterval {
13
+ constructor(tickRate) {
14
+ this.tickCount = 0;
15
+ this.subscription = new rxjs_1.Subject();
16
+ this.subscribers = new Map();
17
+ this.tickRate = tickRate;
18
+ }
19
+ addSubscriber(tickMultiple, id, props) {
20
+ this.subscribers.set(id, {
21
+ tickMultiple,
22
+ props,
23
+ });
24
+ }
25
+ removeSubscriber(id) {
26
+ this.subscribers.delete(id);
27
+ }
28
+ start() {
29
+ this.interval = setInterval(() => {
30
+ this.tickCount++;
31
+ const propsForTick = Array.from(this.subscribers.values()).map((subscriber) => {
32
+ if (this.tickCount % subscriber.tickMultiple === 0) {
33
+ return subscriber.props;
34
+ }
35
+ });
36
+ this.subscription.next(propsForTick);
37
+ }, this.tickRate);
38
+ }
39
+ stop() {
40
+ clearInterval(this.interval);
41
+ }
42
+ subscribe() {
43
+ return this.subscription.asObservable();
44
+ }
45
+ }
46
+ exports.SharedInterval = SharedInterval;
47
+ //# sourceMappingURL=SharedInterval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedInterval.js","sourceRoot":"","sources":["../../src/utils/SharedInterval.ts"],"names":[],"mappings":";;;AAAA,+BAA2C;AAE3C;;;;;;GAMG;AACH,MAAa,cAAc;IAgB1B,YAAY,QAAgB;QAbpB,cAAS,GAAG,CAAC,CAAC;QACd,iBAAY,GAA+B,IAAI,cAAO,EAE3D,CAAC;QAEI,gBAAW,GAAG,IAAI,GAAG,EAM1B,CAAC;QAGH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,aAAa,CAAC,YAAoB,EAAE,EAAU,EAAE,KAAsB;QACrE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE;YACxB,YAAY;YACZ,KAAK;SACL,CAAC,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAC,EAAU;QAC1B,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE;YAChC,IAAI,CAAC,SAAS,EAAE,CAAC;YAEjB,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAC7D,CAAC,UAAU,EAAE,EAAE;gBACd,IAAI,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;oBACpD,OAAO,UAAU,CAAC,KAAK,CAAC;gBACzB,CAAC;YACF,CAAC,CACD,CAAC;YAEF,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnB,CAAC;IAED,IAAI;QACH,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;IACzC,CAAC;CACD;AAtDD,wCAsDC","sourcesContent":["import { Observable, Subject } from 'rxjs';\n\n/**\n * This class creates an interval which multiple \"subscribers\" can add their \"props\" to.\n *\n * The interval has a base tick rate, and the subscribers add their tick multiple and props to the interval.\n *\n * The interval will tick at the base rate, and for each tick it will the props of any subscribers whose tick multiple is a factor of the current tick.\n */\nexport class SharedInterval<SubscriberProps> {\n\tprivate tickRate: number;\n\tprivate interval: ReturnType<typeof setInterval>;\n\tprivate tickCount = 0;\n\tprivate subscription: Subject<SubscriberProps[]> = new Subject<\n\t\tSubscriberProps[]\n\t>();\n\n\tprivate subscribers = new Map<\n\t\tstring,\n\t\t{\n\t\t\ttickMultiple: number;\n\t\t\tprops: SubscriberProps;\n\t\t}\n\t>();\n\n\tconstructor(tickRate: number) {\n\t\tthis.tickRate = tickRate;\n\t}\n\n\taddSubscriber(tickMultiple: number, id: string, props: SubscriberProps) {\n\t\tthis.subscribers.set(id, {\n\t\t\ttickMultiple,\n\t\t\tprops,\n\t\t});\n\t}\n\n\tremoveSubscriber(id: string) {\n\t\tthis.subscribers.delete(id);\n\t}\n\n\tstart() {\n\t\tthis.interval = setInterval(() => {\n\t\t\tthis.tickCount++;\n\n\t\t\tconst propsForTick = Array.from(this.subscribers.values()).map(\n\t\t\t\t(subscriber) => {\n\t\t\t\t\tif (this.tickCount % subscriber.tickMultiple === 0) {\n\t\t\t\t\t\treturn subscriber.props;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tthis.subscription.next(propsForTick);\n\t\t}, this.tickRate);\n\t}\n\n\tstop() {\n\t\tclearInterval(this.interval);\n\t}\n\n\tsubscribe(): Observable<SubscriberProps[]> {\n\t\treturn this.subscription.asObservable();\n\t}\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Utility class which makes sure that all results with a slot are only accepted if the slot is higher than the previous result
3
+ */
4
+ export declare class SlotBasedResultValidator {
5
+ private resultIncrements;
6
+ private allowUndefined;
7
+ constructor(allowUndefined?: boolean);
8
+ handleResult(key: string, slot: number | undefined): boolean;
9
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SlotBasedResultValidator = void 0;
4
+ /**
5
+ * Utility class which makes sure that all results with a slot are only accepted if the slot is higher than the previous result
6
+ */
7
+ class SlotBasedResultValidator {
8
+ constructor(allowUndefined = true) {
9
+ this.resultIncrements = new Map();
10
+ this.allowUndefined = allowUndefined;
11
+ }
12
+ handleResult(key, slot) {
13
+ if (slot === undefined) {
14
+ return this.allowUndefined;
15
+ }
16
+ const previous = this.resultIncrements.get(key);
17
+ if (!previous || slot >= previous) {
18
+ this.resultIncrements.set(key, slot);
19
+ return true;
20
+ }
21
+ else {
22
+ return false;
23
+ }
24
+ }
25
+ }
26
+ exports.SlotBasedResultValidator = SlotBasedResultValidator;
27
+ //# sourceMappingURL=SlotBasedResultValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SlotBasedResultValidator.js","sourceRoot":"","sources":["../../src/utils/SlotBasedResultValidator.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,wBAAwB;IAIpC,YAAY,cAAc,GAAG,IAAI;QAHzB,qBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAIpD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACtC,CAAC;IAED,YAAY,CAAC,GAAW,EAAE,IAAwB;QACjD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,cAAc,CAAC;QAC5B,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEhD,IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,QAAQ,EAAE,CAAC;YACnC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACrC,OAAO,IAAI,CAAC;QACb,CAAC;aAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;CACD;AAtBD,4DAsBC","sourcesContent":["/**\n * Utility class which makes sure that all results with a slot are only accepted if the slot is higher than the previous result\n */\nexport class SlotBasedResultValidator {\n\tprivate resultIncrements = new Map<string, number>();\n\tprivate allowUndefined: boolean;\n\n\tconstructor(allowUndefined = true) {\n\t\tthis.allowUndefined = allowUndefined;\n\t}\n\n\thandleResult(key: string, slot: number | undefined) {\n\t\tif (slot === undefined) {\n\t\t\treturn this.allowUndefined;\n\t\t}\n\n\t\tconst previous = this.resultIncrements.get(key);\n\n\t\tif (!previous || slot >= previous) {\n\t\t\tthis.resultIncrements.set(key, slot);\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A Dev Tool to help with performance analysis.
3
+ *
4
+ * The stopwatch class should function as a "timer" for a variety of unique keys. Any time a caller calls the "tick" method, with a key, the stopwatch will log the time since the last tick for that key.
5
+ */
6
+ export declare class Stopwatch {
7
+ private _lastTick;
8
+ constructor();
9
+ /**
10
+ * Logs the time since the last tick for the given key.
11
+ * @param key The key to log the time for.
12
+ */
13
+ tick(key: string, message?: string): void;
14
+ blankTick(key: string): void;
15
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stopwatch = void 0;
4
+ /**
5
+ * A Dev Tool to help with performance analysis.
6
+ *
7
+ * The stopwatch class should function as a "timer" for a variety of unique keys. Any time a caller calls the "tick" method, with a key, the stopwatch will log the time since the last tick for that key.
8
+ */
9
+ class Stopwatch {
10
+ constructor() {
11
+ this._lastTick = {};
12
+ }
13
+ /**
14
+ * Logs the time since the last tick for the given key.
15
+ * @param key The key to log the time for.
16
+ */
17
+ tick(key, message) {
18
+ const now = Date.now();
19
+ const lastTick = this._lastTick[key];
20
+ if (lastTick) {
21
+ console.log(`⏱️ :: ${message ? ` ${message} ` : ''} \n${key} => ${now - lastTick}ms`);
22
+ }
23
+ this._lastTick[key] = now;
24
+ }
25
+ blankTick(key) {
26
+ const now = Date.now();
27
+ this._lastTick[key] = now;
28
+ }
29
+ }
30
+ exports.Stopwatch = Stopwatch;
31
+ //# sourceMappingURL=Stopwatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stopwatch.js","sourceRoot":"","sources":["../../src/utils/Stopwatch.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,SAAS;IAErB;QADQ,cAAS,GAA8B,EAAE,CAAC;IACnC,CAAC;IAEhB;;;OAGG;IACI,IAAI,CAAC,GAAW,EAAE,OAAgB;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CACV,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,GAAG,QAAQ,IAAI,CACxE,CAAC;QACH,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,GAAW;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAC3B,CAAC;CACD;AAvBD,8BAuBC","sourcesContent":["/**\n * A Dev Tool to help with performance analysis.\n *\n * The stopwatch class should function as a \"timer\" for a variety of unique keys. Any time a caller calls the \"tick\" method, with a key, the stopwatch will log the time since the last tick for that key.\n */\nexport class Stopwatch {\n\tprivate _lastTick: { [key: string]: number } = {};\n\tconstructor() {}\n\n\t/**\n\t * Logs the time since the last tick for the given key.\n\t * @param key The key to log the time for.\n\t */\n\tpublic tick(key: string, message?: string) {\n\t\tconst now = Date.now();\n\t\tconst lastTick = this._lastTick[key];\n\t\tif (lastTick) {\n\t\t\tconsole.log(\n\t\t\t\t`⏱️ :: ${message ? ` ${message} ` : ''} \\n${key} => ${now - lastTick}ms`\n\t\t\t);\n\t\t}\n\t\tthis._lastTick[key] = now;\n\t}\n\n\tblankTick(key: string) {\n\t\tconst now = Date.now();\n\t\tthis._lastTick[key] = now;\n\t}\n}\n"]}
@@ -0,0 +1,15 @@
1
+ type EventMap = {
2
+ [K: string]: any;
3
+ };
4
+ type EventKey<T extends EventMap> = string & keyof T;
5
+ type EventListener<T> = (params: T) => void;
6
+ export declare class StrictEventEmitter<T extends EventMap> {
7
+ private listeners;
8
+ on<K extends EventKey<T>>(event: K, listener: EventListener<T[K]>): void;
9
+ off<K extends EventKey<T>>(event: K, listener: EventListener<T[K]>): void;
10
+ once<K extends EventKey<T>>(event: K, listener: EventListener<T[K]>): void;
11
+ emit<K extends EventKey<T>>(event: K, params: T[K]): void;
12
+ removeAllListeners<K extends EventKey<T>>(event?: K): void;
13
+ listenerCount<K extends EventKey<T>>(event: K): number;
14
+ }
15
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StrictEventEmitter = void 0;
4
+ class StrictEventEmitter {
5
+ constructor() {
6
+ this.listeners = {};
7
+ }
8
+ on(event, listener) {
9
+ if (!this.listeners[event]) {
10
+ this.listeners[event] = [];
11
+ }
12
+ this.listeners[event].push(listener);
13
+ }
14
+ off(event, listener) {
15
+ const eventListeners = this.listeners[event];
16
+ if (!eventListeners)
17
+ return;
18
+ const index = eventListeners.indexOf(listener);
19
+ if (index > -1) {
20
+ eventListeners.splice(index, 1);
21
+ }
22
+ if (eventListeners.length === 0) {
23
+ delete this.listeners[event];
24
+ }
25
+ }
26
+ once(event, listener) {
27
+ const onceWrapper = (params) => {
28
+ listener(params);
29
+ this.off(event, onceWrapper);
30
+ };
31
+ this.on(event, onceWrapper);
32
+ }
33
+ emit(event, params) {
34
+ const eventListeners = this.listeners[event];
35
+ if (!eventListeners)
36
+ return;
37
+ eventListeners.forEach((listener) => {
38
+ listener(params);
39
+ });
40
+ }
41
+ removeAllListeners(event) {
42
+ if (event) {
43
+ delete this.listeners[event];
44
+ }
45
+ else {
46
+ this.listeners = {};
47
+ }
48
+ }
49
+ listenerCount(event) {
50
+ const eventListeners = this.listeners[event];
51
+ return eventListeners ? eventListeners.length : 0;
52
+ }
53
+ }
54
+ exports.StrictEventEmitter = StrictEventEmitter;
55
+ //# sourceMappingURL=StrictEventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StrictEventEmitter.js","sourceRoot":"","sources":["../../src/utils/StrictEventEmitter.ts"],"names":[],"mappings":";;;AAOA,MAAa,kBAAkB;IAA/B;QACS,cAAS,GAEb,EAAE,CAAC;IAoDR,CAAC;IAlDA,EAAE,CAAwB,KAAQ,EAAE,QAA6B;QAChE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED,GAAG,CAAwB,KAAQ,EAAE,QAA6B;QACjE,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,cAAc;YAAE,OAAO;QAE5B,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;YAChB,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,IAAI,CAAwB,KAAQ,EAAE,QAA6B;QAClE,MAAM,WAAW,GAAG,CAAC,MAAY,EAAE,EAAE;YACpC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACjB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAC9B,CAAC,CAAC;QACF,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,CAAwB,KAAQ,EAAE,MAAY;QACjD,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,cAAc;YAAE,OAAO;QAE5B,cAAc,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACnC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,kBAAkB,CAAwB,KAAS;QAClD,IAAI,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACrB,CAAC;IACF,CAAC;IAED,aAAa,CAAwB,KAAQ;QAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC7C,OAAO,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;CACD;AAvDD,gDAuDC","sourcesContent":["type EventMap = {\n\t[K: string]: any;\n};\n\ntype EventKey<T extends EventMap> = string & keyof T;\ntype EventListener<T> = (params: T) => void;\n\nexport class StrictEventEmitter<T extends EventMap> {\n\tprivate listeners: {\n\t\t[K in EventKey<T>]?: Array<EventListener<T[K]>>;\n\t} = {};\n\n\ton<K extends EventKey<T>>(event: K, listener: EventListener<T[K]>): void {\n\t\tif (!this.listeners[event]) {\n\t\t\tthis.listeners[event] = [];\n\t\t}\n\t\tthis.listeners[event]!.push(listener);\n\t}\n\n\toff<K extends EventKey<T>>(event: K, listener: EventListener<T[K]>): void {\n\t\tconst eventListeners = this.listeners[event];\n\t\tif (!eventListeners) return;\n\n\t\tconst index = eventListeners.indexOf(listener);\n\t\tif (index > -1) {\n\t\t\teventListeners.splice(index, 1);\n\t\t}\n\n\t\tif (eventListeners.length === 0) {\n\t\t\tdelete this.listeners[event];\n\t\t}\n\t}\n\n\tonce<K extends EventKey<T>>(event: K, listener: EventListener<T[K]>): void {\n\t\tconst onceWrapper = (params: T[K]) => {\n\t\t\tlistener(params);\n\t\t\tthis.off(event, onceWrapper);\n\t\t};\n\t\tthis.on(event, onceWrapper);\n\t}\n\n\temit<K extends EventKey<T>>(event: K, params: T[K]): void {\n\t\tconst eventListeners = this.listeners[event];\n\t\tif (!eventListeners) return;\n\n\t\teventListeners.forEach((listener) => {\n\t\t\tlistener(params);\n\t\t});\n\t}\n\n\tremoveAllListeners<K extends EventKey<T>>(event?: K): void {\n\t\tif (event) {\n\t\t\tdelete this.listeners[event];\n\t\t} else {\n\t\t\tthis.listeners = {};\n\t\t}\n\t}\n\n\tlistenerCount<K extends EventKey<T>>(event: K): number {\n\t\tconst eventListeners = this.listeners[event];\n\t\treturn eventListeners ? eventListeners.length : 0;\n\t}\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { PublicKey } from '@drift-labs/sdk';
2
+ export declare enum ConnectionStateSteps {
3
+ NotConnected = 0,
4
+ AdapterConnected = 1,
5
+ ClientConnected = 2,
6
+ BalanceLoaded = 4,
7
+ SubaccountsSubscribed = 8
8
+ }
9
+ export declare enum ConnectionStates {
10
+ NotConnected = 0,
11
+ AdapterConnected = 1,
12
+ ClientConnected = 2,
13
+ BalanceLoaded = 4,
14
+ SubaccountsSubscribed = 8,
15
+ FullyConnected = 15
16
+ }
17
+ export type ConnectionStepString = keyof typeof ConnectionStateSteps;
18
+ export type ConnectionStateString = keyof typeof ConnectionStates;
19
+ export declare class WalletConnectionState {
20
+ state: number;
21
+ authority: PublicKey;
22
+ constructor(authority: PublicKey);
23
+ is(stateQuery: ConnectionStateString): boolean;
24
+ update(updateStep: ConnectionStepString, authorityGate?: PublicKey): void;
25
+ get NotConnected(): boolean;
26
+ get AdapterConnected(): boolean;
27
+ get ClientConnected(): boolean;
28
+ get BalanceLoaded(): boolean;
29
+ get FullyConnected(): boolean;
30
+ get SubaccountsSubscribed(): boolean;
31
+ }