@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,94 @@
1
+ import { MarketType, PerpMarketConfig, SpotMarketConfig } from '@drift-labs/sdk';
2
+ import { MarketId } from './MarketId';
3
+ import { Opaque } from './utility';
4
+ /**
5
+ * MarketSymbol will uniquely identify a market
6
+ */
7
+ export type MarketSymbol = Opaque<string, 'MarketSymbol'>;
8
+ /**
9
+ * MarketDisplaySymbol is the label for a market that we display to a user
10
+ */
11
+ export type MarketDisplaySymbol = Opaque<string, 'MarketDisplaySymbol'>;
12
+ /**
13
+ * BaseAssetSymbol is the symbol for the underlying asset for a market
14
+ */
15
+ export type BaseAssetSymbol = Opaque<string, 'BaseAssetSymbol'>;
16
+ /**
17
+ * BaseAssetDisplaySymbol is the label for the underlying asset for a market that we display to a user
18
+ */
19
+ export type BaseAssetDisplaySymbol = Opaque<string, 'BaseAssetDisplaySymbol'>;
20
+ /**
21
+ * # Examples and explanations of the symbol types:
22
+ *
23
+ * ## MarketSymbol:
24
+ * These are basically just the raw symbols in the market configs.
25
+ * - 1KWEN-PERP
26
+ * - JitoSOL-3
27
+ * - PT-fragSOL-15JUN25-3
28
+ *
29
+ * ## MarketDisplaySymbol:
30
+ * This is the symbol we use to display the market to the user. For SPOT markets it should be the exact same as the BaseAssetDisplaySymbol, but for PERP markets they might be different which is why we have this separate type.
31
+ *
32
+ * - 1KWEN-PERP => 1KWEN-PERP
33
+ * - JitoSOL-3 => JitoSOL
34
+ * - PT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25
35
+ *
36
+ * ## BaseAssetDisplaySymbol:
37
+ * This is the symbol we use to communicate "what asset they are holding". For SPOT markets it should be the same as the MarketDisplaySymbol, but for PERP markets it may be different, for example we show open interest denominated in "1KWEN", while the market is "1KWEN-PERP".
38
+ *
39
+ * - 1KWEN-PERP => 1KWEN
40
+ * - JitoSOL-3 => JitoSOL
41
+ * - PT-fragSOL-15JUN25-3 => fragSOL
42
+ *
43
+ * ## BaseAssetSymbol:
44
+ * This is the symbol for the underlying asset for a market. I don't believe we will display this anywhere but we use these for example when looking up the market icon to use.
45
+ *
46
+ * - 1KWEN-PERP => WEN
47
+ * - JitoSOL-3 => JitoSOL
48
+ * - PT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25 (note: PT-fragSOL has an icon different to regular fragSOL, otherwise we would use 'fragSOL' for the base asset symbol)
49
+ */
50
+ type UISymbols = {
51
+ marketSymbol: MarketSymbol;
52
+ marketDisplaySymbol: MarketDisplaySymbol;
53
+ baseAssetSymbol: BaseAssetSymbol;
54
+ baseAssetDisplaySymbol: BaseAssetDisplaySymbol;
55
+ };
56
+ export declare class UIMarket {
57
+ readonly marketIndex: number;
58
+ readonly marketType: MarketType;
59
+ static perpMarkets: PerpMarketConfig[];
60
+ static spotMarkets: SpotMarketConfig[];
61
+ private static cache;
62
+ readonly market: SpotMarketConfig | PerpMarketConfig;
63
+ readonly marketId: MarketId;
64
+ private _uiSymbols;
65
+ get uiSymbols(): UISymbols;
66
+ private set uiSymbols(value);
67
+ constructor(marketIndex: number, marketType: MarketType);
68
+ static setPerpMarkets(perpMarkets: PerpMarketConfig[]): void;
69
+ static setSpotMarkets(spotMarkets: SpotMarketConfig[]): void;
70
+ private static getOrCreate;
71
+ static createSpotMarket(marketIndex: number): UIMarket;
72
+ static createPerpMarket(marketIndex: number): UIMarket;
73
+ static fromMarketId(marketId: MarketId): UIMarket;
74
+ static checkIsPredictionMarket(marketConfig: PerpMarketConfig): boolean;
75
+ get isSpot(): boolean;
76
+ get isPerp(): boolean;
77
+ get marketTypeStr(): string;
78
+ get key(): import("./MarketId").MarketKey;
79
+ get marketName(): string;
80
+ get symbol(): string;
81
+ get isUsdcMarket(): boolean;
82
+ get isStableCoinMarket(): boolean;
83
+ get isPredictionMarket(): boolean;
84
+ get precision(): import("bn.js");
85
+ get precisionExp(): import("bn.js");
86
+ equals(other: UIMarket): boolean;
87
+ baseAssetSymbol(removePrefix?: boolean): string;
88
+ protected setUiSymbols(): void;
89
+ private getMarketSymbol;
90
+ private getMarketDisplaySymbol;
91
+ private getBaseAssetSymbol;
92
+ private getBaseAssetDisplaySymbol;
93
+ }
94
+ export {};
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UIMarket = void 0;
7
+ const sdk_1 = require("@drift-labs/sdk");
8
+ const MarketId_1 = require("./MarketId");
9
+ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
10
+ const pools_1 = require("../constants/pools");
11
+ const markets_1 = require("../constants/markets");
12
+ const utils_1 = require("../utils");
13
+ const Config_1 = require("../Config");
14
+ const useAsyncMarketConfigs = process.env.NEXT_PUBLIC_USE_ASYNC_MARKET_CONFIGS === 'true';
15
+ class UIMarket {
16
+ get uiSymbols() {
17
+ return this._uiSymbols;
18
+ }
19
+ set uiSymbols(uiSymbols) {
20
+ this._uiSymbols = uiSymbols;
21
+ }
22
+ constructor(marketIndex, marketType) {
23
+ this.marketIndex = marketIndex;
24
+ this.marketType = marketType;
25
+ const marketId = new MarketId_1.MarketId(marketIndex, marketType);
26
+ const perpMarkets = useAsyncMarketConfigs
27
+ ? UIMarket.perpMarkets
28
+ : Config_1.Config.perpMarketsLookup;
29
+ const spotMarkets = useAsyncMarketConfigs
30
+ ? UIMarket.spotMarkets
31
+ : Config_1.Config.spotMarketsLookup;
32
+ const markets = marketId.isPerp ? perpMarkets : spotMarkets;
33
+ //@ts-ignore
34
+ const market = markets.find((m) => m.marketIndex === marketIndex);
35
+ // TODO: should we purposely throw an error here? Or construct a default market?
36
+ (0, tiny_invariant_1.default)(market, `Market not found for type: ${marketId.marketTypeStr}, market index: ${marketIndex}`);
37
+ this.marketId = marketId;
38
+ this.market = market;
39
+ this.setUiSymbols();
40
+ }
41
+ static setPerpMarkets(perpMarkets) {
42
+ this.perpMarkets = perpMarkets;
43
+ }
44
+ static setSpotMarkets(spotMarkets) {
45
+ this.spotMarkets = spotMarkets;
46
+ }
47
+ static getOrCreate(marketIndex, marketType) {
48
+ const key = MarketId_1.MarketId.key(marketIndex, marketType);
49
+ if (UIMarket.cache.has(key)) {
50
+ return UIMarket.cache.get(key);
51
+ }
52
+ const market = new UIMarket(marketIndex, marketType);
53
+ UIMarket.cache.set(key, market);
54
+ return market;
55
+ }
56
+ static createSpotMarket(marketIndex) {
57
+ return UIMarket.getOrCreate(marketIndex, sdk_1.MarketType.SPOT);
58
+ }
59
+ static createPerpMarket(marketIndex) {
60
+ return UIMarket.getOrCreate(marketIndex, sdk_1.MarketType.PERP);
61
+ }
62
+ static fromMarketId(marketId) {
63
+ return UIMarket.getOrCreate(marketId.marketIndex, marketId.marketType);
64
+ }
65
+ static checkIsPredictionMarket(marketConfig) {
66
+ if (!marketConfig.category) {
67
+ return false;
68
+ }
69
+ return marketConfig.category.includes('Prediction');
70
+ }
71
+ get isSpot() {
72
+ return this.marketId.isSpot;
73
+ }
74
+ get isPerp() {
75
+ return this.marketId.isPerp;
76
+ }
77
+ get marketTypeStr() {
78
+ return this.marketId.marketTypeStr;
79
+ }
80
+ get key() {
81
+ return this.marketId.key;
82
+ }
83
+ // @deprecated : Use uiSymbols.marketDisplaySymbol instead
84
+ get marketName() {
85
+ return `${this.market.symbol}${this.isSpot ? '/USDC' : ''}`;
86
+ }
87
+ // @deprecated : Use uiSymbols.marketSymbol instead
88
+ get symbol() {
89
+ return this.market.symbol;
90
+ }
91
+ get isUsdcMarket() {
92
+ return this.isSpot && this.marketIndex === markets_1.USDC_SPOT_MARKET_INDEX;
93
+ }
94
+ get isStableCoinMarket() {
95
+ return (this.isSpot &&
96
+ utils_1.ENUM_UTILS.match(this.market.oracleSource, sdk_1.OracleSource.PYTH_STABLE_COIN));
97
+ }
98
+ get isPredictionMarket() {
99
+ return (this.isPerp &&
100
+ UIMarket.checkIsPredictionMarket(this.market));
101
+ }
102
+ get precision() {
103
+ if (this.marketId.isPerp) {
104
+ return sdk_1.BASE_PRECISION;
105
+ }
106
+ else {
107
+ return this.market.precision;
108
+ }
109
+ }
110
+ get precisionExp() {
111
+ if (this.marketId.isPerp) {
112
+ return sdk_1.BASE_PRECISION_EXP;
113
+ }
114
+ else {
115
+ return this.market.precisionExp;
116
+ }
117
+ }
118
+ equals(other) {
119
+ return this.marketId.equals(other.marketId);
120
+ }
121
+ // @deprecated : Use uiSymbols.baseAssetSymbol instead
122
+ baseAssetSymbol(removePrefix = false) {
123
+ let baseAssetSymbol = this.isPerp
124
+ ? this.market.baseAssetSymbol
125
+ : this.market.symbol;
126
+ if (removePrefix) {
127
+ baseAssetSymbol = baseAssetSymbol.replace('1K', '').replace('1M', '');
128
+ }
129
+ return baseAssetSymbol;
130
+ }
131
+ setUiSymbols() {
132
+ (0, tiny_invariant_1.default)(this.marketId, 'MarketId not set');
133
+ const marketSymbol = this.getMarketSymbol();
134
+ const marketDisplaySymbol = this.getMarketDisplaySymbol();
135
+ const baseAssetSymbol = this.getBaseAssetSymbol();
136
+ const baseAssetDisplaySymbol = this.getBaseAssetDisplaySymbol();
137
+ this.uiSymbols = {
138
+ marketSymbol,
139
+ marketDisplaySymbol,
140
+ baseAssetSymbol,
141
+ baseAssetDisplaySymbol,
142
+ };
143
+ }
144
+ getMarketSymbol() {
145
+ if (this.marketId.isPerp) {
146
+ return this.market.symbol;
147
+ }
148
+ else {
149
+ return this.market.symbol;
150
+ }
151
+ }
152
+ getMarketDisplaySymbol() {
153
+ if (this.marketId.isPerp) {
154
+ return this.market.symbol;
155
+ }
156
+ else {
157
+ const marketConfig = this.market;
158
+ switch (marketConfig.poolId) {
159
+ case pools_1.MAIN_POOL_ID:
160
+ return marketConfig.symbol;
161
+ case pools_1.JLP_POOL_ID:
162
+ return `${marketConfig.symbol.split('-')[0]}`;
163
+ case pools_1.LST_POOL_ID:
164
+ return `${marketConfig.symbol.split('-')[0]}`;
165
+ case pools_1.EXPONENT_POOL_ID: {
166
+ /*
167
+ Example market symbol conversions:
168
+ PT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25
169
+ PT-kySOL-10JUL25-3 => PT-kySOL-10JUL25
170
+ JitoSOL-3 => JitoSOL
171
+ JTO-3 => JTO
172
+ */
173
+ return (marketConfig.symbol.startsWith('PT-')
174
+ ? marketConfig.symbol.slice(0, marketConfig.symbol.lastIndexOf('-'))
175
+ : marketConfig.symbol.split('-')[0]);
176
+ }
177
+ case pools_1.SACRED_POOL_ID:
178
+ return `${marketConfig.symbol.split('-')[0]}`;
179
+ default:
180
+ return marketConfig.symbol;
181
+ }
182
+ }
183
+ }
184
+ getBaseAssetSymbol() {
185
+ if (this.marketId.isPerp) {
186
+ return this.market.baseAssetSymbol
187
+ .replace('1K', '')
188
+ .replace('1M', '');
189
+ }
190
+ else {
191
+ return this.getMarketDisplaySymbol(); // Currently no cases where SPOT baseAssetSymbol is different from marketDisplaySymbol
192
+ }
193
+ }
194
+ getBaseAssetDisplaySymbol() {
195
+ if (this.marketId.isPerp) {
196
+ return this.market
197
+ .baseAssetSymbol;
198
+ }
199
+ else {
200
+ const marketConfig = this.market;
201
+ switch (marketConfig.poolId) {
202
+ case pools_1.EXPONENT_POOL_ID: {
203
+ /*
204
+ Example market symbol conversions:
205
+ PT-fragSOL-15JUN25-3 => fragSOL
206
+ PT-kySOL-10JUL25-3 => kySOL
207
+ JitoSOL-3 => JitoSOL
208
+ JTO-3 => JTO
209
+ */
210
+ return (marketConfig.symbol.startsWith('PT-')
211
+ ? marketConfig.symbol.split('-')[1]
212
+ : marketConfig.symbol.split('-')[0]);
213
+ }
214
+ default:
215
+ return marketConfig.symbol;
216
+ }
217
+ }
218
+ }
219
+ }
220
+ exports.UIMarket = UIMarket;
221
+ UIMarket.perpMarkets = sdk_1.PerpMarkets['mainnet-beta'];
222
+ UIMarket.spotMarkets = sdk_1.SpotMarkets['mainnet-beta'];
223
+ UIMarket.cache = new Map();
224
+ //# sourceMappingURL=UIMarket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UIMarket.js","sourceRoot":"","sources":["../../src/types/UIMarket.ts"],"names":[],"mappings":";;;;;;AAAA,yCASyB;AACzB,yCAAsC;AACtC,oEAAuC;AACvC,8CAM4B;AAC5B,kDAA8D;AAC9D,oCAAsC;AACtC,sCAAmC;AAGnC,MAAM,qBAAqB,GAC1B,OAAO,CAAC,GAAG,CAAC,oCAAoC,KAAK,MAAM,CAAC;AAyD7D,MAAa,QAAQ;IAUpB,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED,IAAY,SAAS,CAAC,SAAoB;QACzC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,YAAqB,WAAmB,EAAW,UAAsB;QAApD,gBAAW,GAAX,WAAW,CAAQ;QAAW,eAAU,GAAV,UAAU,CAAY;QACxE,MAAM,QAAQ,GAAG,IAAI,mBAAQ,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACvD,MAAM,WAAW,GAAG,qBAAqB;YACxC,CAAC,CAAC,QAAQ,CAAC,WAAW;YACtB,CAAC,CAAC,eAAM,CAAC,iBAAiB,CAAC;QAC5B,MAAM,WAAW,GAAG,qBAAqB;YACxC,CAAC,CAAC,QAAQ,CAAC,WAAW;YACtB,CAAC,CAAC,eAAM,CAAC,iBAAiB,CAAC;QAC5B,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAA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B,CAAC;gBACD;oBACC,OAAO,YAAY,CAAC,MAAgC,CAAC;YACvD,CAAC;QACF,CAAC;IACF,CAAC;;AA9PF,4BA+PC;AA9PO,oBAAW,GAAG,iBAAW,CAAC,cAAc,CAAC,CAAC;AAC1C,oBAAW,GAAG,iBAAW,CAAC,cAAc,CAAC,CAAC;AAClC,cAAK,GAAG,IAAI,GAAG,EAAoB,CAAC","sourcesContent":["import {\n\tMarketType,\n\tOracleSource,\n\tPerpMarketConfig,\n\tPerpMarkets,\n\tSpotMarkets,\n\tSpotMarketConfig,\n\tBASE_PRECISION,\n\tBASE_PRECISION_EXP,\n} from '@drift-labs/sdk';\nimport { MarketId } from './MarketId';\nimport invariant from 'tiny-invariant';\nimport {\n\tEXPONENT_POOL_ID,\n\tJLP_POOL_ID,\n\tLST_POOL_ID,\n\tMAIN_POOL_ID,\n\tSACRED_POOL_ID,\n} from '../constants/pools';\nimport { USDC_SPOT_MARKET_INDEX } from '../constants/markets';\nimport { ENUM_UTILS } from '../utils';\nimport { Config } from '../Config';\nimport { Opaque } from './utility';\n\nconst useAsyncMarketConfigs =\n\tprocess.env.NEXT_PUBLIC_USE_ASYNC_MARKET_CONFIGS === 'true';\n\n/**\n * MarketSymbol will uniquely identify a market\n */\nexport type MarketSymbol = Opaque<string, 'MarketSymbol'>;\n/**\n * MarketDisplaySymbol is the label for a market that we display to a user\n */\nexport type MarketDisplaySymbol = Opaque<string, 'MarketDisplaySymbol'>;\n/**\n * BaseAssetSymbol is the symbol for the underlying asset for a market\n */\nexport type BaseAssetSymbol = Opaque<string, 'BaseAssetSymbol'>;\n/**\n * BaseAssetDisplaySymbol is the label for the underlying asset for a market that we display to a user\n */\nexport type BaseAssetDisplaySymbol = Opaque<string, 'BaseAssetDisplaySymbol'>;\n\n/**\n * # Examples and explanations of the symbol types:\n *\n * ## MarketSymbol:\n * These are basically just the raw symbols in the market configs.\n * - 1KWEN-PERP\n * - JitoSOL-3\n * - PT-fragSOL-15JUN25-3\n *\n * ## MarketDisplaySymbol:\n * This is the symbol we use to display the market to the user. For SPOT markets it should be the exact same as the BaseAssetDisplaySymbol, but for PERP markets they might be different which is why we have this separate type.\n *\n * - 1KWEN-PERP => 1KWEN-PERP\n * - JitoSOL-3 => JitoSOL\n * - PT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25\n *\n * ## BaseAssetDisplaySymbol:\n * This is the symbol we use to communicate \"what asset they are holding\". For SPOT markets it should be the same as the MarketDisplaySymbol, but for PERP markets it may be different, for example we show open interest denominated in \"1KWEN\", while the market is \"1KWEN-PERP\".\n *\n * - 1KWEN-PERP => 1KWEN\n * - JitoSOL-3 => JitoSOL\n * - PT-fragSOL-15JUN25-3 => fragSOL\n *\n * ## BaseAssetSymbol:\n * This is the symbol for the underlying asset for a market. I don't believe we will display this anywhere but we use these for example when looking up the market icon to use.\n *\n * - 1KWEN-PERP => WEN\n * - JitoSOL-3 => JitoSOL\n * - PT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25 (note: PT-fragSOL has an icon different to regular fragSOL, otherwise we would use 'fragSOL' for the base asset symbol)\n */\n\ntype UISymbols = {\n\tmarketSymbol: MarketSymbol;\n\tmarketDisplaySymbol: MarketDisplaySymbol;\n\tbaseAssetSymbol: BaseAssetSymbol;\n\tbaseAssetDisplaySymbol: BaseAssetDisplaySymbol;\n};\n\nexport class UIMarket {\n\tstatic perpMarkets = PerpMarkets['mainnet-beta'];\n\tstatic spotMarkets = SpotMarkets['mainnet-beta'];\n\tprivate static cache = new Map<string, UIMarket>();\n\n\treadonly market: SpotMarketConfig | PerpMarketConfig;\n\treadonly marketId: MarketId;\n\n\tprivate _uiSymbols: UISymbols;\n\n\tget uiSymbols() {\n\t\treturn this._uiSymbols;\n\t}\n\n\tprivate set uiSymbols(uiSymbols: UISymbols) {\n\t\tthis._uiSymbols = uiSymbols;\n\t}\n\n\tconstructor(readonly marketIndex: number, readonly marketType: MarketType) {\n\t\tconst marketId = new MarketId(marketIndex, marketType);\n\t\tconst perpMarkets = useAsyncMarketConfigs\n\t\t\t? UIMarket.perpMarkets\n\t\t\t: Config.perpMarketsLookup;\n\t\tconst spotMarkets = useAsyncMarketConfigs\n\t\t\t? UIMarket.spotMarkets\n\t\t\t: Config.spotMarketsLookup;\n\t\tconst markets = marketId.isPerp ? perpMarkets : spotMarkets;\n\n\t\t//@ts-ignore\n\t\tconst market = markets.find((m) => m.marketIndex === marketIndex);\n\n\t\t// TODO: should we purposely throw an error here? Or construct a default market?\n\t\tinvariant(\n\t\t\tmarket,\n\t\t\t`Market not found for type: ${marketId.marketTypeStr}, market index: ${marketIndex}`\n\t\t);\n\n\t\tthis.marketId = marketId;\n\t\tthis.market = market;\n\n\t\tthis.setUiSymbols();\n\t}\n\n\tstatic setPerpMarkets(perpMarkets: PerpMarketConfig[]) {\n\t\tthis.perpMarkets = perpMarkets;\n\t}\n\n\tstatic setSpotMarkets(spotMarkets: SpotMarketConfig[]) {\n\t\tthis.spotMarkets = spotMarkets;\n\t}\n\n\tprivate static getOrCreate(marketIndex: number, marketType: MarketType) {\n\t\tconst key = MarketId.key(marketIndex, marketType);\n\t\tif (UIMarket.cache.has(key)) {\n\t\t\treturn UIMarket.cache.get(key)!;\n\t\t}\n\t\tconst market = new UIMarket(marketIndex, marketType);\n\t\tUIMarket.cache.set(key, market);\n\t\treturn market;\n\t}\n\n\tstatic createSpotMarket(marketIndex: number) {\n\t\treturn UIMarket.getOrCreate(marketIndex, MarketType.SPOT);\n\t}\n\n\tstatic createPerpMarket(marketIndex: number) {\n\t\treturn UIMarket.getOrCreate(marketIndex, MarketType.PERP);\n\t}\n\n\tstatic fromMarketId(marketId: MarketId) {\n\t\treturn UIMarket.getOrCreate(marketId.marketIndex, marketId.marketType);\n\t}\n\n\tstatic checkIsPredictionMarket(marketConfig: PerpMarketConfig) {\n\t\tif (!(marketConfig as PerpMarketConfig).category) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn (marketConfig as PerpMarketConfig).category.includes('Prediction');\n\t}\n\n\tget isSpot() {\n\t\treturn this.marketId.isSpot;\n\t}\n\n\tget isPerp() {\n\t\treturn this.marketId.isPerp;\n\t}\n\n\tget marketTypeStr() {\n\t\treturn this.marketId.marketTypeStr;\n\t}\n\n\tget key() {\n\t\treturn this.marketId.key;\n\t}\n\n\t// @deprecated : Use uiSymbols.marketDisplaySymbol instead\n\tget marketName() {\n\t\treturn `${this.market.symbol}${this.isSpot ? '/USDC' : ''}`;\n\t}\n\n\t// @deprecated : Use uiSymbols.marketSymbol instead\n\tget symbol() {\n\t\treturn this.market.symbol;\n\t}\n\n\tget isUsdcMarket() {\n\t\treturn this.isSpot && this.marketIndex === USDC_SPOT_MARKET_INDEX;\n\t}\n\n\tget isStableCoinMarket() {\n\t\treturn (\n\t\t\tthis.isSpot &&\n\t\t\tENUM_UTILS.match(this.market.oracleSource, OracleSource.PYTH_STABLE_COIN)\n\t\t);\n\t}\n\n\tget isPredictionMarket() {\n\t\treturn (\n\t\t\tthis.isPerp &&\n\t\t\tUIMarket.checkIsPredictionMarket(this.market as PerpMarketConfig)\n\t\t);\n\t}\n\n\tget precision() {\n\t\tif (this.marketId.isPerp) {\n\t\t\treturn BASE_PRECISION;\n\t\t} else {\n\t\t\treturn (this.market as SpotMarketConfig).precision;\n\t\t}\n\t}\n\n\tget precisionExp() {\n\t\tif (this.marketId.isPerp) {\n\t\t\treturn BASE_PRECISION_EXP;\n\t\t} else {\n\t\t\treturn (this.market as SpotMarketConfig).precisionExp;\n\t\t}\n\t}\n\n\tequals(other: UIMarket) {\n\t\treturn this.marketId.equals(other.marketId);\n\t}\n\n\t// @deprecated : Use uiSymbols.baseAssetSymbol instead\n\tbaseAssetSymbol(removePrefix = false) {\n\t\tlet baseAssetSymbol = this.isPerp\n\t\t\t? (this.market as PerpMarketConfig).baseAssetSymbol\n\t\t\t: this.market.symbol;\n\n\t\tif (removePrefix) {\n\t\t\tbaseAssetSymbol = baseAssetSymbol.replace('1K', '').replace('1M', '');\n\t\t}\n\n\t\treturn baseAssetSymbol;\n\t}\n\n\tprotected setUiSymbols() {\n\t\tinvariant(this.marketId, 'MarketId not set');\n\n\t\tconst marketSymbol = this.getMarketSymbol();\n\t\tconst marketDisplaySymbol = this.getMarketDisplaySymbol();\n\t\tconst baseAssetSymbol = this.getBaseAssetSymbol();\n\t\tconst baseAssetDisplaySymbol = this.getBaseAssetDisplaySymbol();\n\n\t\tthis.uiSymbols = {\n\t\t\tmarketSymbol,\n\t\t\tmarketDisplaySymbol,\n\t\t\tbaseAssetSymbol,\n\t\t\tbaseAssetDisplaySymbol,\n\t\t};\n\t}\n\n\tprivate getMarketSymbol(): MarketSymbol {\n\t\tif (this.marketId.isPerp) {\n\t\t\treturn this.market.symbol as MarketSymbol;\n\t\t} else {\n\t\t\treturn this.market.symbol as MarketSymbol;\n\t\t}\n\t}\n\n\tprivate getMarketDisplaySymbol(): MarketDisplaySymbol {\n\t\tif (this.marketId.isPerp) {\n\t\t\treturn this.market.symbol as MarketDisplaySymbol;\n\t\t} else {\n\t\t\tconst marketConfig = this.market as SpotMarketConfig;\n\t\t\tswitch (marketConfig.poolId) {\n\t\t\t\tcase MAIN_POOL_ID:\n\t\t\t\t\treturn marketConfig.symbol as MarketDisplaySymbol;\n\t\t\t\tcase JLP_POOL_ID:\n\t\t\t\t\treturn `${marketConfig.symbol.split('-')[0]}` as MarketDisplaySymbol;\n\t\t\t\tcase LST_POOL_ID:\n\t\t\t\t\treturn `${marketConfig.symbol.split('-')[0]}` as MarketDisplaySymbol;\n\t\t\t\tcase EXPONENT_POOL_ID: {\n\t\t\t\t\t/*\n\t\t\t\t\tExample market symbol conversions:\n\t\t\t\t\tPT-fragSOL-15JUN25-3 => PT-fragSOL-15JUN25\n\t\t\t\t\tPT-kySOL-10JUL25-3 => PT-kySOL-10JUL25\n\t\t\t\t\tJitoSOL-3 => JitoSOL\n\t\t\t\t\tJTO-3 => JTO\n\t\t\t\t*/\n\t\t\t\t\treturn (\n\t\t\t\t\t\tmarketConfig.symbol.startsWith('PT-')\n\t\t\t\t\t\t\t? marketConfig.symbol.slice(\n\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\tmarketConfig.symbol.lastIndexOf('-')\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: marketConfig.symbol.split('-')[0]\n\t\t\t\t\t) as MarketDisplaySymbol;\n\t\t\t\t}\n\t\t\t\tcase SACRED_POOL_ID:\n\t\t\t\t\treturn `${marketConfig.symbol.split('-')[0]}` as MarketDisplaySymbol;\n\t\t\t\tdefault:\n\t\t\t\t\treturn marketConfig.symbol as MarketDisplaySymbol;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getBaseAssetSymbol(): BaseAssetSymbol {\n\t\tif (this.marketId.isPerp) {\n\t\t\treturn (this.market as PerpMarketConfig).baseAssetSymbol\n\t\t\t\t.replace('1K', '')\n\t\t\t\t.replace('1M', '') as BaseAssetSymbol;\n\t\t} else {\n\t\t\treturn this.getMarketDisplaySymbol() as unknown as BaseAssetSymbol; // Currently no cases where SPOT baseAssetSymbol is different from marketDisplaySymbol\n\t\t}\n\t}\n\n\tprivate getBaseAssetDisplaySymbol(): BaseAssetDisplaySymbol {\n\t\tif (this.marketId.isPerp) {\n\t\t\treturn (this.market as PerpMarketConfig)\n\t\t\t\t.baseAssetSymbol as BaseAssetDisplaySymbol;\n\t\t} else {\n\t\t\tconst marketConfig = this.market as SpotMarketConfig;\n\t\t\tswitch (marketConfig.poolId) {\n\t\t\t\tcase EXPONENT_POOL_ID: {\n\t\t\t\t\t/*\n\t\t\t\t\tExample market symbol conversions:\n\t\t\t\t\tPT-fragSOL-15JUN25-3 => fragSOL\n\t\t\t\t\tPT-kySOL-10JUL25-3 => kySOL\n\t\t\t\t\tJitoSOL-3 => JitoSOL\n\t\t\t\t\tJTO-3 => JTO\n\t\t\t\t*/\n\t\t\t\t\treturn (\n\t\t\t\t\t\tmarketConfig.symbol.startsWith('PT-')\n\t\t\t\t\t\t\t? marketConfig.symbol.split('-')[1]\n\t\t\t\t\t\t\t: marketConfig.symbol.split('-')[0]\n\t\t\t\t\t) as BaseAssetDisplaySymbol;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn marketConfig.symbol as BaseAssetDisplaySymbol;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export declare enum CandleType {
2
+ FILL_PRICE = "FILL_PRICE",
3
+ ORACLE_PRICE = "ORACLE_PRICE"
4
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CandleType = void 0;
4
+ var CandleType;
5
+ (function (CandleType) {
6
+ CandleType["FILL_PRICE"] = "FILL_PRICE";
7
+ CandleType["ORACLE_PRICE"] = "ORACLE_PRICE";
8
+ })(CandleType || (exports.CandleType = CandleType = {}));
9
+ //# sourceMappingURL=candles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"candles.js","sourceRoot":"","sources":["../../src/types/candles.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAGX;AAHD,WAAY,UAAU;IACrB,uCAAyB,CAAA;IACzB,2CAA6B,CAAA;AAC9B,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB","sourcesContent":["export enum CandleType {\n\tFILL_PRICE = 'FILL_PRICE',\n\tORACLE_PRICE = 'ORACLE_PRICE',\n}\n"]}
@@ -0,0 +1,53 @@
1
+ export type JsonTrade = {
2
+ action: string;
3
+ actionExplanation: string;
4
+ baseAssetAmountFilled: number;
5
+ bitFlags: number;
6
+ createdAt: number;
7
+ entity: string;
8
+ fillRecordId: string;
9
+ filler: string;
10
+ fillerReward: number;
11
+ maker: string;
12
+ makerFee: number;
13
+ makerOrderBaseAssetAmount: number;
14
+ makerOrderCumulativeBaseAssetAmountFilled: number;
15
+ makerOrderCumulativeQuoteAssetAmountFilled: number;
16
+ makerOrderDirection: string;
17
+ makerOrderId: number;
18
+ makerRebate: number;
19
+ marketFilter: string;
20
+ marketIndex: number;
21
+ marketType: string;
22
+ oraclePrice: number;
23
+ price: number;
24
+ quoteAssetAmountFilled: number;
25
+ quoteAssetAmountSurplus: number;
26
+ referrerReward: number;
27
+ slot: number;
28
+ spotFulfillmentMethodFee: number;
29
+ symbol: string;
30
+ taker: string;
31
+ takerFee: number;
32
+ takerOrderBaseAssetAmount: number;
33
+ takerOrderCumulativeBaseAssetAmountFilled: number;
34
+ takerOrderCumulativeQuoteAssetAmountFilled: number;
35
+ takerOrderDirection: string;
36
+ takerOrderId: number;
37
+ ts: number;
38
+ txSig: string;
39
+ txSigIndex: number;
40
+ };
41
+ export type JsonCandle = {
42
+ ts: number;
43
+ fillOpen: number;
44
+ fillHigh: number;
45
+ fillClose: number;
46
+ fillLow: number;
47
+ oracleOpen: number;
48
+ oracleHigh: number;
49
+ oracleClose: number;
50
+ oracleLow: number;
51
+ quoteVolume: number;
52
+ baseVolume: number;
53
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=dataServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataServer.js","sourceRoot":"","sources":["../../src/types/dataServer.ts"],"names":[],"mappings":"","sourcesContent":["// Type for the trades returned by the data API\nexport type JsonTrade = {\n\taction: string;\n\tactionExplanation: string;\n\tbaseAssetAmountFilled: number;\n\tbitFlags: number;\n\tcreatedAt: number;\n\tentity: string;\n\tfillRecordId: string;\n\tfiller: string;\n\tfillerReward: number;\n\tmaker: string;\n\tmakerFee: number;\n\tmakerOrderBaseAssetAmount: number;\n\tmakerOrderCumulativeBaseAssetAmountFilled: number;\n\tmakerOrderCumulativeQuoteAssetAmountFilled: number;\n\tmakerOrderDirection: string;\n\tmakerOrderId: number;\n\tmakerRebate: number;\n\tmarketFilter: string;\n\tmarketIndex: number;\n\tmarketType: string;\n\toraclePrice: number;\n\tprice: number;\n\tquoteAssetAmountFilled: number;\n\tquoteAssetAmountSurplus: number;\n\treferrerReward: number;\n\tslot: number;\n\tspotFulfillmentMethodFee: number;\n\tsymbol: string;\n\ttaker: string;\n\ttakerFee: number;\n\ttakerOrderBaseAssetAmount: number;\n\ttakerOrderCumulativeBaseAssetAmountFilled: number;\n\ttakerOrderCumulativeQuoteAssetAmountFilled: number;\n\ttakerOrderDirection: string;\n\ttakerOrderId: number;\n\tts: number;\n\ttxSig: string;\n\ttxSigIndex: number;\n};\n\n// Type for the candles returned by the data API\nexport type JsonCandle = {\n\tts: number;\n\tfillOpen: number;\n\tfillHigh: number;\n\tfillClose: number;\n\tfillLow: number;\n\toracleOpen: number;\n\toracleHigh: number;\n\toracleClose: number;\n\toracleLow: number;\n\tquoteVolume: number;\n\tbaseVolume: number;\n};\n"]}
@@ -0,0 +1,38 @@
1
+ import { MarketType } from '@drift-labs/sdk';
2
+ import { UISerializableAccountSnapshot, UISerializableAllTimePnlData } from 'src/serializableTypes';
3
+ export type MarketDetails24H = {
4
+ marketType: MarketType;
5
+ marketIndex: number;
6
+ symbol: string;
7
+ baseVolume: number;
8
+ quoteVolume: number;
9
+ baseVolume30D: number;
10
+ quoteVolume30D: number;
11
+ price24hAgo: number;
12
+ pricePercentChange: number;
13
+ priceHigh: number;
14
+ priceLow: number;
15
+ avgFunding?: number;
16
+ avgLongFunding?: number;
17
+ avgShortFunding?: number;
18
+ marketCap: number;
19
+ dailyVolumeIncreaseZScore: number;
20
+ };
21
+ export declare enum HistoryResolution {
22
+ DAY = "DAY",
23
+ WEEK = "WEEK",
24
+ MONTH = "MONTH",
25
+ ALL = "ALL"
26
+ }
27
+ export type UISnapshotHistory = {
28
+ [HistoryResolution.DAY]: UISerializableAccountSnapshot[];
29
+ [HistoryResolution.WEEK]: UISerializableAccountSnapshot[];
30
+ [HistoryResolution.MONTH]: UISerializableAccountSnapshot[];
31
+ [HistoryResolution.ALL]: UISerializableAccountSnapshot[];
32
+ dailyAllTimePnls: UISerializableAllTimePnlData[];
33
+ };
34
+ export type MarketMakerRewardRecord = {
35
+ ts: number;
36
+ amount: number;
37
+ symbol: string;
38
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HistoryResolution = void 0;
4
+ var HistoryResolution;
5
+ (function (HistoryResolution) {
6
+ HistoryResolution["DAY"] = "DAY";
7
+ HistoryResolution["WEEK"] = "WEEK";
8
+ HistoryResolution["MONTH"] = "MONTH";
9
+ HistoryResolution["ALL"] = "ALL";
10
+ })(HistoryResolution || (exports.HistoryResolution = HistoryResolution = {}));
11
+ //# sourceMappingURL=historyServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"historyServer.js","sourceRoot":"","sources":["../../src/types/historyServer.ts"],"names":[],"mappings":";;;AAyBA,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC5B,gCAAW,CAAA;IACX,kCAAa,CAAA;IACb,oCAAe,CAAA;IACf,gCAAW,CAAA;AACZ,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B","sourcesContent":["import { MarketType } from '@drift-labs/sdk';\nimport {\n\tUISerializableAccountSnapshot,\n\tUISerializableAllTimePnlData,\n} from 'src/serializableTypes';\n\nexport type MarketDetails24H = {\n\tmarketType: MarketType;\n\tmarketIndex: number;\n\tsymbol: string;\n\tbaseVolume: number;\n\tquoteVolume: number;\n\tbaseVolume30D: number;\n\tquoteVolume30D: number;\n\tprice24hAgo: number;\n\tpricePercentChange: number;\n\tpriceHigh: number;\n\tpriceLow: number;\n\tavgFunding?: number;\n\tavgLongFunding?: number;\n\tavgShortFunding?: number;\n\tmarketCap: number;\n\tdailyVolumeIncreaseZScore: number;\n};\n\nexport enum HistoryResolution {\n\tDAY = 'DAY',\n\tWEEK = 'WEEK',\n\tMONTH = 'MONTH',\n\tALL = 'ALL',\n}\n\nexport type UISnapshotHistory = {\n\t[HistoryResolution.DAY]: UISerializableAccountSnapshot[];\n\t[HistoryResolution.WEEK]: UISerializableAccountSnapshot[];\n\t[HistoryResolution.MONTH]: UISerializableAccountSnapshot[];\n\t[HistoryResolution.ALL]: UISerializableAccountSnapshot[];\n\tdailyAllTimePnls: UISerializableAllTimePnlData[];\n};\n\nexport type MarketMakerRewardRecord = {\n\tts: number;\n\tamount: number;\n\tsymbol: string;\n};\n"]}
@@ -0,0 +1,12 @@
1
+ export * from './MarketId';
2
+ export * from './UIMarket';
3
+ export * from './Superstake';
4
+ export * from './remote-configs';
5
+ export * from './UIEnv';
6
+ export * from './candles';
7
+ export * from './dataServer';
8
+ export * from './historyServer';
9
+ export * from './trade';
10
+ export * from './user';
11
+ export * from './leaderboard';
12
+ export * from './utility';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./MarketId"), exports);
18
+ __exportStar(require("./UIMarket"), exports);
19
+ __exportStar(require("./Superstake"), exports);
20
+ __exportStar(require("./remote-configs"), exports);
21
+ __exportStar(require("./UIEnv"), exports);
22
+ __exportStar(require("./candles"), exports);
23
+ __exportStar(require("./dataServer"), exports);
24
+ __exportStar(require("./historyServer"), exports);
25
+ __exportStar(require("./trade"), exports);
26
+ __exportStar(require("./user"), exports);
27
+ __exportStar(require("./leaderboard"), exports);
28
+ __exportStar(require("./utility"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,6CAA2B;AAC3B,+CAA6B;AAC7B,mDAAiC;AACjC,0CAAwB;AACxB,4CAA0B;AAC1B,+CAA6B;AAC7B,kDAAgC;AAChC,0CAAwB;AACxB,yCAAuB;AACvB,gDAA8B;AAC9B,4CAA0B","sourcesContent":["export * from './MarketId';\nexport * from './UIMarket';\nexport * from './Superstake';\nexport * from './remote-configs';\nexport * from './UIEnv';\nexport * from './candles';\nexport * from './dataServer';\nexport * from './historyServer';\nexport * from './trade';\nexport * from './user';\nexport * from './leaderboard';\nexport * from './utility';\n"]}
@@ -0,0 +1,80 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import { BigNum, BN, SpotBalanceType } from '@drift-labs/sdk';
3
+ import { SerializableUserSnapshotRecord, UISerializableUserSnapshotRecord } from 'src/serializableTypes';
4
+ export type RollingPnlData = {
5
+ totalPnlQuote: BN;
6
+ totalPnlPct: BN;
7
+ spotPnlQuote: BN;
8
+ spotPnlPct: BN;
9
+ perpPnlQuote: BN;
10
+ perpPnlPct: BN;
11
+ };
12
+ export type PnlSnapshotOrderOption = keyof Pick<RollingPnlData, 'totalPnlPct' | 'totalPnlQuote'>;
13
+ export type LeaderBoardResultRow = {
14
+ user: PublicKey;
15
+ authority: PublicKey;
16
+ subaccountId: number;
17
+ resolution: SnapshotEpochResolution;
18
+ rollingValue: number;
19
+ pnlHistoryPoints: PnlHistoryDataPoint[];
20
+ };
21
+ export type LeaderboardResult = {
22
+ lastUpdateTs: number;
23
+ results: LeaderBoardResultRow[];
24
+ ordering: PnlSnapshotOrderOption;
25
+ };
26
+ export type UserSnapshotRecord = {
27
+ programId: PublicKey;
28
+ authority: PublicKey;
29
+ user: PublicKey;
30
+ epochTs: number;
31
+ ts: number;
32
+ perpPositionUpnl: BN;
33
+ totalAccountValue: BN;
34
+ cumulativeDepositQuoteValue: BN;
35
+ cumulativeWithdrawalQuoteValue: BN;
36
+ cumulativeSettledPerpPnl: BN;
37
+ cumulativeReferralReward: BN;
38
+ cumulativeReferralVolume: BN;
39
+ cumulativeReferralCount: number;
40
+ };
41
+ export type UIAccountSnapshot = Pick<UserSnapshotRecord, 'authority' | 'user' | 'epochTs'> & Pick<UISerializableUserSnapshotRecord, 'cumulativeDepositQuoteValue' | 'cumulativeWithdrawalQuoteValue' | 'totalAccountValue' | 'cumulativeReferralReward' | 'cumulativeReferralVolume' | 'cumulativeReferralCount'> & {
42
+ allTimeTotalPnl: BigNum;
43
+ allTimeTotalPnlPct: BigNum;
44
+ };
45
+ export type AccountSnapshot = Pick<UserSnapshotRecord, 'authority' | 'user' | 'epochTs'> & Pick<SerializableUserSnapshotRecord, 'cumulativeDepositQuoteValue' | 'cumulativeWithdrawalQuoteValue' | 'totalAccountValue' | 'cumulativeReferralReward' | 'cumulativeReferralVolume' | 'cumulativeReferralCount'> & {
46
+ allTimeTotalPnl: BN;
47
+ allTimeTotalPnlPct: BN;
48
+ };
49
+ export type UserPerpPositionSnapshot = {
50
+ lpShares: BN;
51
+ quoteAssetAmount: BN;
52
+ baseAssetAmount: BN;
53
+ marketIndex: number;
54
+ };
55
+ export type UserSpotPositionSnapshot = {
56
+ tokenValue: BN;
57
+ tokenAmount: BN;
58
+ cumulativeDeposits: BN;
59
+ balanceInterestDelta: BN;
60
+ marketIndex: number;
61
+ type: SpotBalanceType;
62
+ };
63
+ export type PnlHistoryDataPoint = {
64
+ val: number;
65
+ ts: number;
66
+ };
67
+ export declare class SnapshotEpochResolution {
68
+ static readonly HOURLY: {
69
+ hourly: {};
70
+ };
71
+ static readonly DAILY: {
72
+ daily: {};
73
+ };
74
+ static readonly WEEKLY: {
75
+ weekly: {};
76
+ };
77
+ static readonly MONTHLY: {
78
+ monthly: {};
79
+ };
80
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapshotEpochResolution = void 0;
4
+ class SnapshotEpochResolution {
5
+ }
6
+ exports.SnapshotEpochResolution = SnapshotEpochResolution;
7
+ SnapshotEpochResolution.HOURLY = { hourly: {} };
8
+ SnapshotEpochResolution.DAILY = { daily: {} };
9
+ SnapshotEpochResolution.WEEKLY = { weekly: {} };
10
+ SnapshotEpochResolution.MONTHLY = { monthly: {} };
11
+ //# sourceMappingURL=leaderboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboard.js","sourceRoot":"","sources":["../../src/types/leaderboard.ts"],"names":[],"mappings":";;;AA4GA,MAAa,uBAAuB;;AAApC,0DAKC;AAJgB,8BAAM,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACxB,6BAAK,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AACtB,8BAAM,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACxB,+BAAO,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC","sourcesContent":["import { PublicKey } from '@solana/web3.js';\nimport { BigNum, BN, SpotBalanceType } from '@drift-labs/sdk';\nimport {\n\tSerializableUserSnapshotRecord,\n\tUISerializableUserSnapshotRecord,\n} from 'src/serializableTypes';\n\nexport type RollingPnlData = {\n\ttotalPnlQuote: BN;\n\ttotalPnlPct: BN;\n\tspotPnlQuote: BN;\n\tspotPnlPct: BN;\n\tperpPnlQuote: BN;\n\tperpPnlPct: BN;\n};\n\nexport type PnlSnapshotOrderOption = keyof Pick<\n\tRollingPnlData,\n\t'totalPnlPct' | 'totalPnlQuote'\n>;\n\nexport type LeaderBoardResultRow = {\n\tuser: PublicKey;\n\tauthority: PublicKey;\n\tsubaccountId: number;\n\tresolution: SnapshotEpochResolution;\n\trollingValue: number;\n\tpnlHistoryPoints: PnlHistoryDataPoint[];\n};\n\nexport type LeaderboardResult = {\n\tlastUpdateTs: number;\n\tresults: LeaderBoardResultRow[];\n\tordering: PnlSnapshotOrderOption;\n};\n\nexport type UserSnapshotRecord = {\n\tprogramId: PublicKey;\n\tauthority: PublicKey;\n\tuser: PublicKey;\n\tepochTs: number;\n\tts: number;\n\tperpPositionUpnl: BN;\n\n\ttotalAccountValue: BN;\n\tcumulativeDepositQuoteValue: BN;\n\tcumulativeWithdrawalQuoteValue: BN;\n\tcumulativeSettledPerpPnl: BN;\n\tcumulativeReferralReward: BN;\n\tcumulativeReferralVolume: BN;\n\tcumulativeReferralCount: number;\n};\n\nexport type UIAccountSnapshot = Pick<\n\tUserSnapshotRecord,\n\t'authority' | 'user' | 'epochTs'\n> &\n\tPick<\n\t\tUISerializableUserSnapshotRecord,\n\t\t| 'cumulativeDepositQuoteValue'\n\t\t| 'cumulativeWithdrawalQuoteValue'\n\t\t| 'totalAccountValue'\n\t\t| 'cumulativeReferralReward'\n\t\t| 'cumulativeReferralVolume'\n\t\t| 'cumulativeReferralCount'\n\t> & {\n\t\tallTimeTotalPnl: BigNum;\n\t\tallTimeTotalPnlPct: BigNum;\n\t};\n\nexport type AccountSnapshot = Pick<\n\tUserSnapshotRecord,\n\t'authority' | 'user' | 'epochTs'\n> &\n\tPick<\n\t\tSerializableUserSnapshotRecord,\n\t\t| 'cumulativeDepositQuoteValue'\n\t\t| 'cumulativeWithdrawalQuoteValue'\n\t\t| 'totalAccountValue'\n\t\t| 'cumulativeReferralReward'\n\t\t| 'cumulativeReferralVolume'\n\t\t| 'cumulativeReferralCount'\n\t> & {\n\t\tallTimeTotalPnl: BN;\n\t\tallTimeTotalPnlPct: BN;\n\t};\n\nexport type UserPerpPositionSnapshot = {\n\tlpShares: BN;\n\tquoteAssetAmount: BN;\n\tbaseAssetAmount: BN;\n\tmarketIndex: number;\n};\n\nexport type UserSpotPositionSnapshot = {\n\ttokenValue: BN;\n\ttokenAmount: BN;\n\tcumulativeDeposits: BN;\n\tbalanceInterestDelta: BN;\n\tmarketIndex: number;\n\ttype: SpotBalanceType;\n};\n\nexport type PnlHistoryDataPoint = {\n\tval: number;\n\tts: number;\n};\n\nexport class SnapshotEpochResolution {\n\tstatic readonly HOURLY = { hourly: {} };\n\tstatic readonly DAILY = { daily: {} };\n\tstatic readonly WEEKLY = { weekly: {} };\n\tstatic readonly MONTHLY = { monthly: {} };\n}\n"]}