@metamask-previews/perps-controller 0.0.0-preview-b0148922a → 0.0.0-preview-ee1fa5d01

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 (482) hide show
  1. package/CHANGELOG.md +0 -25
  2. package/dist/PerpsController.cjs +65 -3077
  3. package/dist/PerpsController.cjs.map +1 -1
  4. package/dist/PerpsController.d.cts +82 -969
  5. package/dist/PerpsController.d.cts.map +1 -1
  6. package/dist/PerpsController.d.mts +82 -969
  7. package/dist/PerpsController.d.mts.map +1 -1
  8. package/dist/PerpsController.mjs +62 -3073
  9. package/dist/PerpsController.mjs.map +1 -1
  10. package/dist/index.cjs +1 -63
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +2 -38
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +2 -38
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +1 -46
  17. package/dist/index.mjs.map +1 -1
  18. package/package.json +2 -16
  19. package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -441
  20. package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
  21. package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -171
  22. package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
  23. package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -171
  24. package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
  25. package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -437
  26. package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
  27. package/dist/aggregation/index.cjs +0 -9
  28. package/dist/aggregation/index.cjs.map +0 -1
  29. package/dist/aggregation/index.d.cts +0 -6
  30. package/dist/aggregation/index.d.cts.map +0 -1
  31. package/dist/aggregation/index.d.mts +0 -6
  32. package/dist/aggregation/index.d.mts.map +0 -1
  33. package/dist/aggregation/index.mjs +0 -5
  34. package/dist/aggregation/index.mjs.map +0 -1
  35. package/dist/constants/chartConfig.cjs +0 -227
  36. package/dist/constants/chartConfig.cjs.map +0 -1
  37. package/dist/constants/chartConfig.d.cts +0 -216
  38. package/dist/constants/chartConfig.d.cts.map +0 -1
  39. package/dist/constants/chartConfig.d.mts +0 -216
  40. package/dist/constants/chartConfig.d.mts.map +0 -1
  41. package/dist/constants/chartConfig.mjs +0 -221
  42. package/dist/constants/chartConfig.mjs.map +0 -1
  43. package/dist/constants/eventNames.cjs +0 -436
  44. package/dist/constants/eventNames.cjs.map +0 -1
  45. package/dist/constants/eventNames.d.cts +0 -387
  46. package/dist/constants/eventNames.d.cts.map +0 -1
  47. package/dist/constants/eventNames.d.mts +0 -387
  48. package/dist/constants/eventNames.d.mts.map +0 -1
  49. package/dist/constants/eventNames.mjs +0 -433
  50. package/dist/constants/eventNames.mjs.map +0 -1
  51. package/dist/constants/hyperLiquidConfig.cjs +0 -380
  52. package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
  53. package/dist/constants/hyperLiquidConfig.d.cts +0 -236
  54. package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
  55. package/dist/constants/hyperLiquidConfig.d.mts +0 -236
  56. package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
  57. package/dist/constants/hyperLiquidConfig.mjs +0 -371
  58. package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
  59. package/dist/constants/index.cjs +0 -28
  60. package/dist/constants/index.cjs.map +0 -1
  61. package/dist/constants/index.d.cts +0 -12
  62. package/dist/constants/index.d.cts.map +0 -1
  63. package/dist/constants/index.d.mts +0 -12
  64. package/dist/constants/index.d.mts.map +0 -1
  65. package/dist/constants/index.mjs +0 -12
  66. package/dist/constants/index.mjs.map +0 -1
  67. package/dist/constants/myxConfig.cjs +0 -229
  68. package/dist/constants/myxConfig.cjs.map +0 -1
  69. package/dist/constants/myxConfig.d.cts +0 -106
  70. package/dist/constants/myxConfig.d.cts.map +0 -1
  71. package/dist/constants/myxConfig.d.mts +0 -106
  72. package/dist/constants/myxConfig.d.mts.map +0 -1
  73. package/dist/constants/myxConfig.mjs +0 -219
  74. package/dist/constants/myxConfig.mjs.map +0 -1
  75. package/dist/constants/orderTypes.cjs +0 -31
  76. package/dist/constants/orderTypes.cjs.map +0 -1
  77. package/dist/constants/orderTypes.d.cts +0 -19
  78. package/dist/constants/orderTypes.d.cts.map +0 -1
  79. package/dist/constants/orderTypes.d.mts +0 -19
  80. package/dist/constants/orderTypes.d.mts.map +0 -1
  81. package/dist/constants/orderTypes.mjs +0 -27
  82. package/dist/constants/orderTypes.mjs.map +0 -1
  83. package/dist/constants/performanceMetrics.cjs +0 -63
  84. package/dist/constants/performanceMetrics.cjs.map +0 -1
  85. package/dist/constants/performanceMetrics.d.cts +0 -46
  86. package/dist/constants/performanceMetrics.d.cts.map +0 -1
  87. package/dist/constants/performanceMetrics.d.mts +0 -46
  88. package/dist/constants/performanceMetrics.d.mts.map +0 -1
  89. package/dist/constants/performanceMetrics.mjs +0 -60
  90. package/dist/constants/performanceMetrics.mjs.map +0 -1
  91. package/dist/constants/perpsConfig.cjs +0 -295
  92. package/dist/constants/perpsConfig.cjs.map +0 -1
  93. package/dist/constants/perpsConfig.d.cts +0 -221
  94. package/dist/constants/perpsConfig.d.cts.map +0 -1
  95. package/dist/constants/perpsConfig.d.mts +0 -221
  96. package/dist/constants/perpsConfig.d.mts.map +0 -1
  97. package/dist/constants/perpsConfig.mjs +0 -292
  98. package/dist/constants/perpsConfig.mjs.map +0 -1
  99. package/dist/constants/transactionsHistoryConfig.cjs +0 -19
  100. package/dist/constants/transactionsHistoryConfig.cjs.map +0 -1
  101. package/dist/constants/transactionsHistoryConfig.d.cts +0 -16
  102. package/dist/constants/transactionsHistoryConfig.d.cts.map +0 -1
  103. package/dist/constants/transactionsHistoryConfig.d.mts +0 -16
  104. package/dist/constants/transactionsHistoryConfig.d.mts.map +0 -1
  105. package/dist/constants/transactionsHistoryConfig.mjs +0 -16
  106. package/dist/constants/transactionsHistoryConfig.mjs.map +0 -1
  107. package/dist/perpsErrorCodes.cjs +0 -80
  108. package/dist/perpsErrorCodes.cjs.map +0 -1
  109. package/dist/perpsErrorCodes.d.cts +0 -65
  110. package/dist/perpsErrorCodes.d.cts.map +0 -1
  111. package/dist/perpsErrorCodes.d.mts +0 -65
  112. package/dist/perpsErrorCodes.d.mts.map +0 -1
  113. package/dist/perpsErrorCodes.mjs +0 -77
  114. package/dist/perpsErrorCodes.mjs.map +0 -1
  115. package/dist/providers/AggregatedPerpsProvider.cjs +0 -508
  116. package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
  117. package/dist/providers/AggregatedPerpsProvider.d.cts +0 -171
  118. package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
  119. package/dist/providers/AggregatedPerpsProvider.d.mts +0 -171
  120. package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
  121. package/dist/providers/AggregatedPerpsProvider.mjs +0 -504
  122. package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
  123. package/dist/providers/HyperLiquidProvider.cjs +0 -5679
  124. package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
  125. package/dist/providers/HyperLiquidProvider.d.cts +0 -516
  126. package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
  127. package/dist/providers/HyperLiquidProvider.d.mts +0 -516
  128. package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
  129. package/dist/providers/HyperLiquidProvider.mjs +0 -5675
  130. package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
  131. package/dist/providers/MYXProvider.cjs +0 -514
  132. package/dist/providers/MYXProvider.cjs.map +0 -1
  133. package/dist/providers/MYXProvider.d.cts +0 -105
  134. package/dist/providers/MYXProvider.d.cts.map +0 -1
  135. package/dist/providers/MYXProvider.d.mts +0 -105
  136. package/dist/providers/MYXProvider.d.mts.map +0 -1
  137. package/dist/providers/MYXProvider.mjs +0 -510
  138. package/dist/providers/MYXProvider.mjs.map +0 -1
  139. package/dist/routing/ProviderRouter.cjs +0 -154
  140. package/dist/routing/ProviderRouter.cjs.map +0 -1
  141. package/dist/routing/ProviderRouter.d.cts +0 -112
  142. package/dist/routing/ProviderRouter.d.cts.map +0 -1
  143. package/dist/routing/ProviderRouter.d.mts +0 -112
  144. package/dist/routing/ProviderRouter.d.mts.map +0 -1
  145. package/dist/routing/ProviderRouter.mjs +0 -150
  146. package/dist/routing/ProviderRouter.mjs.map +0 -1
  147. package/dist/routing/index.cjs +0 -9
  148. package/dist/routing/index.cjs.map +0 -1
  149. package/dist/routing/index.d.cts +0 -6
  150. package/dist/routing/index.d.cts.map +0 -1
  151. package/dist/routing/index.d.mts +0 -6
  152. package/dist/routing/index.d.mts.map +0 -1
  153. package/dist/routing/index.mjs +0 -5
  154. package/dist/routing/index.mjs.map +0 -1
  155. package/dist/selectors.cjs +0 -166
  156. package/dist/selectors.cjs.map +0 -1
  157. package/dist/selectors.d.cts +0 -362
  158. package/dist/selectors.d.cts.map +0 -1
  159. package/dist/selectors.d.mts +0 -362
  160. package/dist/selectors.d.mts.map +0 -1
  161. package/dist/selectors.mjs +0 -158
  162. package/dist/selectors.mjs.map +0 -1
  163. package/dist/services/AccountService.cjs +0 -324
  164. package/dist/services/AccountService.cjs.map +0 -1
  165. package/dist/services/AccountService.d.cts +0 -56
  166. package/dist/services/AccountService.d.cts.map +0 -1
  167. package/dist/services/AccountService.d.mts +0 -56
  168. package/dist/services/AccountService.d.mts.map +0 -1
  169. package/dist/services/AccountService.mjs +0 -320
  170. package/dist/services/AccountService.mjs.map +0 -1
  171. package/dist/services/DataLakeService.cjs +0 -233
  172. package/dist/services/DataLakeService.cjs.map +0 -1
  173. package/dist/services/DataLakeService.d.cts +0 -51
  174. package/dist/services/DataLakeService.d.cts.map +0 -1
  175. package/dist/services/DataLakeService.d.mts +0 -51
  176. package/dist/services/DataLakeService.d.mts.map +0 -1
  177. package/dist/services/DataLakeService.mjs +0 -229
  178. package/dist/services/DataLakeService.mjs.map +0 -1
  179. package/dist/services/DepositService.cjs +0 -98
  180. package/dist/services/DepositService.cjs.map +0 -1
  181. package/dist/services/DepositService.d.cts +0 -39
  182. package/dist/services/DepositService.d.cts.map +0 -1
  183. package/dist/services/DepositService.d.mts +0 -39
  184. package/dist/services/DepositService.d.mts.map +0 -1
  185. package/dist/services/DepositService.mjs +0 -94
  186. package/dist/services/DepositService.mjs.map +0 -1
  187. package/dist/services/EligibilityService.cjs +0 -173
  188. package/dist/services/EligibilityService.cjs.map +0 -1
  189. package/dist/services/EligibilityService.d.cts +0 -39
  190. package/dist/services/EligibilityService.d.cts.map +0 -1
  191. package/dist/services/EligibilityService.d.mts +0 -39
  192. package/dist/services/EligibilityService.d.mts.map +0 -1
  193. package/dist/services/EligibilityService.mjs +0 -169
  194. package/dist/services/EligibilityService.mjs.map +0 -1
  195. package/dist/services/FeatureFlagConfigurationService.cjs +0 -257
  196. package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
  197. package/dist/services/FeatureFlagConfigurationService.d.cts +0 -73
  198. package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
  199. package/dist/services/FeatureFlagConfigurationService.d.mts +0 -73
  200. package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
  201. package/dist/services/FeatureFlagConfigurationService.mjs +0 -253
  202. package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
  203. package/dist/services/HyperLiquidClientService.cjs +0 -867
  204. package/dist/services/HyperLiquidClientService.cjs.map +0 -1
  205. package/dist/services/HyperLiquidClientService.d.cts +0 -214
  206. package/dist/services/HyperLiquidClientService.d.cts.map +0 -1
  207. package/dist/services/HyperLiquidClientService.d.mts +0 -214
  208. package/dist/services/HyperLiquidClientService.d.mts.map +0 -1
  209. package/dist/services/HyperLiquidClientService.mjs +0 -862
  210. package/dist/services/HyperLiquidClientService.mjs.map +0 -1
  211. package/dist/services/HyperLiquidSubscriptionService.cjs +0 -2199
  212. package/dist/services/HyperLiquidSubscriptionService.cjs.map +0 -1
  213. package/dist/services/HyperLiquidSubscriptionService.d.cts +0 -187
  214. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +0 -1
  215. package/dist/services/HyperLiquidSubscriptionService.d.mts +0 -187
  216. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +0 -1
  217. package/dist/services/HyperLiquidSubscriptionService.mjs +0 -2195
  218. package/dist/services/HyperLiquidSubscriptionService.mjs.map +0 -1
  219. package/dist/services/HyperLiquidWalletService.cjs +0 -163
  220. package/dist/services/HyperLiquidWalletService.cjs.map +0 -1
  221. package/dist/services/HyperLiquidWalletService.d.cts +0 -78
  222. package/dist/services/HyperLiquidWalletService.d.cts.map +0 -1
  223. package/dist/services/HyperLiquidWalletService.d.mts +0 -78
  224. package/dist/services/HyperLiquidWalletService.d.mts.map +0 -1
  225. package/dist/services/HyperLiquidWalletService.mjs +0 -159
  226. package/dist/services/HyperLiquidWalletService.mjs.map +0 -1
  227. package/dist/services/MYXClientService.cjs +0 -304
  228. package/dist/services/MYXClientService.cjs.map +0 -1
  229. package/dist/services/MYXClientService.d.cts +0 -81
  230. package/dist/services/MYXClientService.d.cts.map +0 -1
  231. package/dist/services/MYXClientService.d.mts +0 -81
  232. package/dist/services/MYXClientService.d.mts.map +0 -1
  233. package/dist/services/MYXClientService.mjs +0 -300
  234. package/dist/services/MYXClientService.mjs.map +0 -1
  235. package/dist/services/MarketDataService.cjs +0 -848
  236. package/dist/services/MarketDataService.cjs.map +0 -1
  237. package/dist/services/MarketDataService.d.cts +0 -291
  238. package/dist/services/MarketDataService.d.cts.map +0 -1
  239. package/dist/services/MarketDataService.d.mts +0 -291
  240. package/dist/services/MarketDataService.d.mts.map +0 -1
  241. package/dist/services/MarketDataService.mjs +0 -844
  242. package/dist/services/MarketDataService.mjs.map +0 -1
  243. package/dist/services/RewardsIntegrationService.cjs +0 -120
  244. package/dist/services/RewardsIntegrationService.cjs.map +0 -1
  245. package/dist/services/RewardsIntegrationService.d.cts +0 -28
  246. package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
  247. package/dist/services/RewardsIntegrationService.d.mts +0 -28
  248. package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
  249. package/dist/services/RewardsIntegrationService.mjs +0 -116
  250. package/dist/services/RewardsIntegrationService.mjs.map +0 -1
  251. package/dist/services/ServiceContext.cjs +0 -3
  252. package/dist/services/ServiceContext.cjs.map +0 -1
  253. package/dist/services/ServiceContext.d.cts +0 -86
  254. package/dist/services/ServiceContext.d.cts.map +0 -1
  255. package/dist/services/ServiceContext.d.mts +0 -86
  256. package/dist/services/ServiceContext.d.mts.map +0 -1
  257. package/dist/services/ServiceContext.mjs +0 -2
  258. package/dist/services/ServiceContext.mjs.map +0 -1
  259. package/dist/services/TradingReadinessCache.cjs +0 -288
  260. package/dist/services/TradingReadinessCache.cjs.map +0 -1
  261. package/dist/services/TradingReadinessCache.d.cts +0 -174
  262. package/dist/services/TradingReadinessCache.d.cts.map +0 -1
  263. package/dist/services/TradingReadinessCache.d.mts +0 -174
  264. package/dist/services/TradingReadinessCache.d.mts.map +0 -1
  265. package/dist/services/TradingReadinessCache.mjs +0 -285
  266. package/dist/services/TradingReadinessCache.mjs.map +0 -1
  267. package/dist/services/TradingService.cjs +0 -1457
  268. package/dist/services/TradingService.cjs.map +0 -1
  269. package/dist/services/TradingService.d.cts +0 -195
  270. package/dist/services/TradingService.d.cts.map +0 -1
  271. package/dist/services/TradingService.d.mts +0 -195
  272. package/dist/services/TradingService.d.mts.map +0 -1
  273. package/dist/services/TradingService.mjs +0 -1453
  274. package/dist/services/TradingService.mjs.map +0 -1
  275. package/dist/types/config.cjs +0 -3
  276. package/dist/types/config.cjs.map +0 -1
  277. package/dist/types/config.d.cts +0 -49
  278. package/dist/types/config.d.cts.map +0 -1
  279. package/dist/types/config.d.mts +0 -49
  280. package/dist/types/config.d.mts.map +0 -1
  281. package/dist/types/config.mjs +0 -2
  282. package/dist/types/config.mjs.map +0 -1
  283. package/dist/types/hyperliquid-types.cjs +0 -3
  284. package/dist/types/hyperliquid-types.cjs.map +0 -1
  285. package/dist/types/hyperliquid-types.d.cts +0 -20
  286. package/dist/types/hyperliquid-types.d.cts.map +0 -1
  287. package/dist/types/hyperliquid-types.d.mts +0 -20
  288. package/dist/types/hyperliquid-types.d.mts.map +0 -1
  289. package/dist/types/hyperliquid-types.mjs +0 -2
  290. package/dist/types/hyperliquid-types.mjs.map +0 -1
  291. package/dist/types/index.cjs +0 -115
  292. package/dist/types/index.cjs.map +0 -1
  293. package/dist/types/index.d.cts +0 -1262
  294. package/dist/types/index.d.cts.map +0 -1
  295. package/dist/types/index.d.mts +0 -1262
  296. package/dist/types/index.d.mts.map +0 -1
  297. package/dist/types/index.mjs +0 -97
  298. package/dist/types/index.mjs.map +0 -1
  299. package/dist/types/messenger.cjs +0 -3
  300. package/dist/types/messenger.cjs.map +0 -1
  301. package/dist/types/messenger.d.cts +0 -27
  302. package/dist/types/messenger.d.cts.map +0 -1
  303. package/dist/types/messenger.d.mts +0 -27
  304. package/dist/types/messenger.d.mts.map +0 -1
  305. package/dist/types/messenger.mjs +0 -2
  306. package/dist/types/messenger.mjs.map +0 -1
  307. package/dist/types/myx-types.cjs +0 -25
  308. package/dist/types/myx-types.cjs.map +0 -1
  309. package/dist/types/myx-types.d.cts +0 -63
  310. package/dist/types/myx-types.d.cts.map +0 -1
  311. package/dist/types/myx-types.d.mts +0 -63
  312. package/dist/types/myx-types.d.mts.map +0 -1
  313. package/dist/types/myx-types.mjs +0 -22
  314. package/dist/types/myx-types.mjs.map +0 -1
  315. package/dist/types/perps-types.cjs +0 -4
  316. package/dist/types/perps-types.cjs.map +0 -1
  317. package/dist/types/perps-types.d.cts +0 -105
  318. package/dist/types/perps-types.d.cts.map +0 -1
  319. package/dist/types/perps-types.d.mts +0 -105
  320. package/dist/types/perps-types.d.mts.map +0 -1
  321. package/dist/types/perps-types.mjs +0 -2
  322. package/dist/types/perps-types.mjs.map +0 -1
  323. package/dist/types/token.cjs +0 -3
  324. package/dist/types/token.cjs.map +0 -1
  325. package/dist/types/token.d.cts +0 -25
  326. package/dist/types/token.d.cts.map +0 -1
  327. package/dist/types/token.d.mts +0 -25
  328. package/dist/types/token.d.mts.map +0 -1
  329. package/dist/types/token.mjs +0 -2
  330. package/dist/types/token.mjs.map +0 -1
  331. package/dist/types/transactionTypes.cjs +0 -28
  332. package/dist/types/transactionTypes.cjs.map +0 -1
  333. package/dist/types/transactionTypes.d.cts +0 -64
  334. package/dist/types/transactionTypes.d.cts.map +0 -1
  335. package/dist/types/transactionTypes.d.mts +0 -64
  336. package/dist/types/transactionTypes.d.mts.map +0 -1
  337. package/dist/types/transactionTypes.mjs +0 -23
  338. package/dist/types/transactionTypes.mjs.map +0 -1
  339. package/dist/utils/accountUtils.cjs +0 -100
  340. package/dist/utils/accountUtils.cjs.map +0 -1
  341. package/dist/utils/accountUtils.d.cts +0 -30
  342. package/dist/utils/accountUtils.d.cts.map +0 -1
  343. package/dist/utils/accountUtils.d.mts +0 -30
  344. package/dist/utils/accountUtils.d.mts.map +0 -1
  345. package/dist/utils/accountUtils.mjs +0 -92
  346. package/dist/utils/accountUtils.mjs.map +0 -1
  347. package/dist/utils/errorUtils.cjs +0 -35
  348. package/dist/utils/errorUtils.cjs.map +0 -1
  349. package/dist/utils/errorUtils.d.cts +0 -15
  350. package/dist/utils/errorUtils.d.cts.map +0 -1
  351. package/dist/utils/errorUtils.d.mts +0 -15
  352. package/dist/utils/errorUtils.d.mts.map +0 -1
  353. package/dist/utils/errorUtils.mjs +0 -31
  354. package/dist/utils/errorUtils.mjs.map +0 -1
  355. package/dist/utils/hyperLiquidAdapter.cjs +0 -331
  356. package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
  357. package/dist/utils/hyperLiquidAdapter.d.cts +0 -42
  358. package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
  359. package/dist/utils/hyperLiquidAdapter.d.mts +0 -42
  360. package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
  361. package/dist/utils/hyperLiquidAdapter.mjs +0 -316
  362. package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
  363. package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -83
  364. package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
  365. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -55
  366. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
  367. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -55
  368. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
  369. package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -78
  370. package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
  371. package/dist/utils/hyperLiquidValidation.cjs +0 -426
  372. package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
  373. package/dist/utils/hyperLiquidValidation.d.cts +0 -143
  374. package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
  375. package/dist/utils/hyperLiquidValidation.d.mts +0 -143
  376. package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
  377. package/dist/utils/hyperLiquidValidation.mjs +0 -413
  378. package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
  379. package/dist/utils/idUtils.cjs +0 -18
  380. package/dist/utils/idUtils.cjs.map +0 -1
  381. package/dist/utils/idUtils.d.cts +0 -6
  382. package/dist/utils/idUtils.d.cts.map +0 -1
  383. package/dist/utils/idUtils.d.mts +0 -6
  384. package/dist/utils/idUtils.d.mts.map +0 -1
  385. package/dist/utils/idUtils.mjs +0 -10
  386. package/dist/utils/idUtils.mjs.map +0 -1
  387. package/dist/utils/index.cjs +0 -59
  388. package/dist/utils/index.cjs.map +0 -1
  389. package/dist/utils/index.d.cts +0 -25
  390. package/dist/utils/index.d.cts.map +0 -1
  391. package/dist/utils/index.d.mts +0 -25
  392. package/dist/utils/index.d.mts.map +0 -1
  393. package/dist/utils/index.mjs +0 -30
  394. package/dist/utils/index.mjs.map +0 -1
  395. package/dist/utils/marketDataTransform.cjs +0 -211
  396. package/dist/utils/marketDataTransform.cjs.map +0 -1
  397. package/dist/utils/marketDataTransform.d.cts +0 -40
  398. package/dist/utils/marketDataTransform.d.cts.map +0 -1
  399. package/dist/utils/marketDataTransform.d.mts +0 -40
  400. package/dist/utils/marketDataTransform.d.mts.map +0 -1
  401. package/dist/utils/marketDataTransform.mjs +0 -205
  402. package/dist/utils/marketDataTransform.mjs.map +0 -1
  403. package/dist/utils/marketUtils.cjs +0 -151
  404. package/dist/utils/marketUtils.cjs.map +0 -1
  405. package/dist/utils/marketUtils.d.cts +0 -30
  406. package/dist/utils/marketUtils.d.cts.map +0 -1
  407. package/dist/utils/marketUtils.d.mts +0 -30
  408. package/dist/utils/marketUtils.d.mts.map +0 -1
  409. package/dist/utils/marketUtils.mjs +0 -138
  410. package/dist/utils/marketUtils.mjs.map +0 -1
  411. package/dist/utils/myxAdapter.cjs +0 -224
  412. package/dist/utils/myxAdapter.cjs.map +0 -1
  413. package/dist/utils/myxAdapter.d.cts +0 -81
  414. package/dist/utils/myxAdapter.d.cts.map +0 -1
  415. package/dist/utils/myxAdapter.d.mts +0 -81
  416. package/dist/utils/myxAdapter.d.mts.map +0 -1
  417. package/dist/utils/myxAdapter.mjs +0 -213
  418. package/dist/utils/myxAdapter.mjs.map +0 -1
  419. package/dist/utils/orderCalculations.cjs +0 -283
  420. package/dist/utils/orderCalculations.cjs.map +0 -1
  421. package/dist/utils/orderCalculations.d.cts +0 -107
  422. package/dist/utils/orderCalculations.d.cts.map +0 -1
  423. package/dist/utils/orderCalculations.d.mts +0 -107
  424. package/dist/utils/orderCalculations.d.mts.map +0 -1
  425. package/dist/utils/orderCalculations.mjs +0 -274
  426. package/dist/utils/orderCalculations.mjs.map +0 -1
  427. package/dist/utils/rewardsUtils.cjs +0 -98
  428. package/dist/utils/rewardsUtils.cjs.map +0 -1
  429. package/dist/utils/rewardsUtils.d.cts +0 -33
  430. package/dist/utils/rewardsUtils.d.cts.map +0 -1
  431. package/dist/utils/rewardsUtils.d.mts +0 -33
  432. package/dist/utils/rewardsUtils.d.mts.map +0 -1
  433. package/dist/utils/rewardsUtils.mjs +0 -92
  434. package/dist/utils/rewardsUtils.mjs.map +0 -1
  435. package/dist/utils/significantFigures.cjs +0 -88
  436. package/dist/utils/significantFigures.cjs.map +0 -1
  437. package/dist/utils/significantFigures.d.cts +0 -25
  438. package/dist/utils/significantFigures.d.cts.map +0 -1
  439. package/dist/utils/significantFigures.d.mts +0 -25
  440. package/dist/utils/significantFigures.d.mts.map +0 -1
  441. package/dist/utils/significantFigures.mjs +0 -82
  442. package/dist/utils/significantFigures.mjs.map +0 -1
  443. package/dist/utils/sortMarkets.cjs +0 -93
  444. package/dist/utils/sortMarkets.cjs.map +0 -1
  445. package/dist/utils/sortMarkets.d.cts +0 -27
  446. package/dist/utils/sortMarkets.d.cts.map +0 -1
  447. package/dist/utils/sortMarkets.d.mts +0 -27
  448. package/dist/utils/sortMarkets.d.mts.map +0 -1
  449. package/dist/utils/sortMarkets.mjs +0 -88
  450. package/dist/utils/sortMarkets.mjs.map +0 -1
  451. package/dist/utils/standaloneInfoClient.cjs +0 -70
  452. package/dist/utils/standaloneInfoClient.cjs.map +0 -1
  453. package/dist/utils/standaloneInfoClient.d.cts +0 -37
  454. package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
  455. package/dist/utils/standaloneInfoClient.d.mts +0 -37
  456. package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
  457. package/dist/utils/standaloneInfoClient.mjs +0 -64
  458. package/dist/utils/standaloneInfoClient.mjs.map +0 -1
  459. package/dist/utils/stringParseUtils.cjs +0 -18
  460. package/dist/utils/stringParseUtils.cjs.map +0 -1
  461. package/dist/utils/stringParseUtils.d.cts +0 -3
  462. package/dist/utils/stringParseUtils.d.cts.map +0 -1
  463. package/dist/utils/stringParseUtils.d.mts +0 -3
  464. package/dist/utils/stringParseUtils.d.mts.map +0 -1
  465. package/dist/utils/stringParseUtils.mjs +0 -13
  466. package/dist/utils/stringParseUtils.mjs.map +0 -1
  467. package/dist/utils/transferData.cjs +0 -33
  468. package/dist/utils/transferData.cjs.map +0 -1
  469. package/dist/utils/transferData.d.cts +0 -9
  470. package/dist/utils/transferData.d.cts.map +0 -1
  471. package/dist/utils/transferData.d.mts +0 -9
  472. package/dist/utils/transferData.d.mts.map +0 -1
  473. package/dist/utils/transferData.mjs +0 -29
  474. package/dist/utils/transferData.mjs.map +0 -1
  475. package/dist/utils/wait.cjs +0 -6
  476. package/dist/utils/wait.cjs.map +0 -1
  477. package/dist/utils/wait.d.cts +0 -2
  478. package/dist/utils/wait.d.cts.map +0 -1
  479. package/dist/utils/wait.d.mts +0 -2
  480. package/dist/utils/wait.d.mts.map +0 -1
  481. package/dist/utils/wait.mjs +0 -2
  482. package/dist/utils/wait.mjs.map +0 -1
@@ -1,94 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _DepositService_deps, _DepositService_messenger;
13
- import { toHex } from "@metamask/controller-utils";
14
- import { parseCaipAssetId } from "@metamask/utils";
15
- import { getSelectedEvmAccount } from "../utils/accountUtils.mjs";
16
- import { generateDepositId } from "../utils/idUtils.mjs";
17
- import { generateERC20TransferData } from "../utils/transferData.mjs";
18
- // Temporary to avoid estimation failures due to insufficient balance
19
- const DEPOSIT_GAS_LIMIT = toHex(100000);
20
- /**
21
- * DepositService
22
- *
23
- * Handles deposit transaction preparation and validation.
24
- * Stateless service that prepares transaction data for TransactionController.
25
- * Controller handles TransactionController integration and promise lifecycle.
26
- *
27
- * Instance-based service with constructor injection of platform dependencies
28
- * and messenger for inter-controller communication.
29
- */
30
- export class DepositService {
31
- /**
32
- * Create a new DepositService instance
33
- *
34
- * @param deps - Platform dependencies for logging, metrics, etc.
35
- * @param messenger - Controller messenger for cross-controller communication.
36
- */
37
- constructor(deps, messenger) {
38
- _DepositService_deps.set(this, void 0);
39
- _DepositService_messenger.set(this, void 0);
40
- __classPrivateFieldSet(this, _DepositService_deps, deps, "f");
41
- __classPrivateFieldSet(this, _DepositService_messenger, messenger, "f");
42
- }
43
- /**
44
- * Prepare deposit transaction for confirmation
45
- * Extracts transaction construction logic from controller
46
- *
47
- * @param options - Configuration object
48
- * @param options.provider - Active provider instance
49
- * @returns Transaction data ready for TransactionController.addTransaction
50
- */
51
- async prepareTransaction(options) {
52
- const { provider } = options;
53
- __classPrivateFieldGet(this, _DepositService_deps, "f").debugLogger.log('DepositService: Preparing deposit transaction');
54
- // Generate deposit request ID for tracking
55
- const currentDepositId = generateDepositId();
56
- // Get deposit routes from provider
57
- const depositRoutes = provider.getDepositRoutes({ isTestnet: false });
58
- const route = depositRoutes[0];
59
- const bridgeContractAddress = route.contractAddress;
60
- // Generate transfer data for ERC-20 token transfer (portable, no mobile imports)
61
- const transferData = generateERC20TransferData(bridgeContractAddress, '0x0');
62
- // Get EVM account from selected account group via messenger
63
- const evmAccount = getSelectedEvmAccount(__classPrivateFieldGet(this, _DepositService_messenger, "f").call('AccountTreeController:getAccountsFromSelectedAccountGroup'));
64
- if (!evmAccount) {
65
- throw new Error('No EVM-compatible account found in selected account group');
66
- }
67
- const accountAddress = evmAccount.address;
68
- // Parse CAIP asset ID to extract chain ID and token address
69
- const parsedAsset = parseCaipAssetId(route.assetId);
70
- const assetChainId = toHex(parsedAsset.chainId.split(':')[1]);
71
- const tokenAddress = parsedAsset.assetReference;
72
- // Build transaction parameters for TransactionController
73
- const transaction = {
74
- from: accountAddress,
75
- to: tokenAddress,
76
- value: '0x0',
77
- data: transferData,
78
- gas: DEPOSIT_GAS_LIMIT,
79
- };
80
- __classPrivateFieldGet(this, _DepositService_deps, "f").debugLogger.log('DepositService: Deposit transaction prepared', {
81
- depositId: currentDepositId,
82
- assetChainId,
83
- from: accountAddress,
84
- to: tokenAddress,
85
- });
86
- return {
87
- transaction,
88
- assetChainId,
89
- currentDepositId,
90
- };
91
- }
92
- }
93
- _DepositService_deps = new WeakMap(), _DepositService_messenger = new WeakMap();
94
- //# sourceMappingURL=DepositService.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DepositService.mjs","sourceRoot":"","sources":["../../src/services/DepositService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB;AASnD,OAAO,EAAE,qBAAqB,EAAE,kCAA8B;AAC9D,OAAO,EAAE,iBAAiB,EAAE,6BAAyB;AACrD,OAAO,EAAE,yBAAyB,EAAE,kCAA8B;AAElE,qEAAqE;AACrE,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAExC;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAc;IAKzB;;;;;OAKG;IACH,YACE,IAA+B,EAC/B,SAAuC;QAZhC,uCAAiC;QAEjC,4CAAyC;QAYhD,uBAAA,IAAI,wBAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,6BAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,kBAAkB,CAAC,OAAoC;QAK3D,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAE7B,uBAAA,IAAI,4BAAM,CAAC,WAAW,CAAC,GAAG,C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E,YAAY;SACjB,CAAC,CAAC;QAEH,OAAO;YACL,WAAW;YACX,YAAY;YACZ,gBAAgB;SACjB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport { parseCaipAssetId } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n PerpsProvider,\n PerpsPlatformDependencies,\n PerpsTransactionParams,\n} from '../types';\nimport type { PerpsControllerMessengerBase } from '../types/messenger';\nimport { getSelectedEvmAccount } from '../utils/accountUtils';\nimport { generateDepositId } from '../utils/idUtils';\nimport { generateERC20TransferData } from '../utils/transferData';\n\n// Temporary to avoid estimation failures due to insufficient balance\nconst DEPOSIT_GAS_LIMIT = toHex(100000);\n\n/**\n * DepositService\n *\n * Handles deposit transaction preparation and validation.\n * Stateless service that prepares transaction data for TransactionController.\n * Controller handles TransactionController integration and promise lifecycle.\n *\n * Instance-based service with constructor injection of platform dependencies\n * and messenger for inter-controller communication.\n */\nexport class DepositService {\n readonly #deps: PerpsPlatformDependencies;\n\n readonly #messenger: PerpsControllerMessengerBase;\n\n /**\n * Create a new DepositService instance\n *\n * @param deps - Platform dependencies for logging, metrics, etc.\n * @param messenger - Controller messenger for cross-controller communication.\n */\n constructor(\n deps: PerpsPlatformDependencies,\n messenger: PerpsControllerMessengerBase,\n ) {\n this.#deps = deps;\n this.#messenger = messenger;\n }\n\n /**\n * Prepare deposit transaction for confirmation\n * Extracts transaction construction logic from controller\n *\n * @param options - Configuration object\n * @param options.provider - Active provider instance\n * @returns Transaction data ready for TransactionController.addTransaction\n */\n async prepareTransaction(options: { provider: PerpsProvider }): Promise<{\n transaction: PerpsTransactionParams;\n assetChainId: Hex;\n currentDepositId: string;\n }> {\n const { provider } = options;\n\n this.#deps.debugLogger.log('DepositService: Preparing deposit transaction');\n\n // Generate deposit request ID for tracking\n const currentDepositId = generateDepositId();\n\n // Get deposit routes from provider\n const depositRoutes = provider.getDepositRoutes({ isTestnet: false });\n const route = depositRoutes[0];\n const bridgeContractAddress = route.contractAddress;\n\n // Generate transfer data for ERC-20 token transfer (portable, no mobile imports)\n const transferData = generateERC20TransferData(\n bridgeContractAddress,\n '0x0',\n );\n\n // Get EVM account from selected account group via messenger\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n if (!evmAccount) {\n throw new Error(\n 'No EVM-compatible account found in selected account group',\n );\n }\n const accountAddress = evmAccount.address as Hex;\n\n // Parse CAIP asset ID to extract chain ID and token address\n const parsedAsset = parseCaipAssetId(route.assetId);\n const assetChainId = toHex(parsedAsset.chainId.split(':')[1]);\n const tokenAddress = parsedAsset.assetReference as Hex;\n\n // Build transaction parameters for TransactionController\n const transaction: PerpsTransactionParams = {\n from: accountAddress,\n to: tokenAddress,\n value: '0x0',\n data: transferData,\n gas: DEPOSIT_GAS_LIMIT,\n };\n\n this.#deps.debugLogger.log('DepositService: Deposit transaction prepared', {\n depositId: currentDepositId,\n assetChainId,\n from: accountAddress,\n to: tokenAddress,\n });\n\n return {\n transaction,\n assetChainId,\n currentDepositId,\n };\n }\n}\n"]}
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _EligibilityService_instances, _EligibilityService_geoCacheTtlMs, _EligibilityService_deps, _EligibilityService_geoLocationCache, _EligibilityService_geoLocationFetchPromise, _EligibilityService_performGeoLocationFetch;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.EligibilityService = void 0;
16
- const controller_utils_1 = require("@metamask/controller-utils");
17
- const perpsConfig_1 = require("../constants/perpsConfig.cjs");
18
- const utils_1 = require("../utils/index.cjs");
19
- const errorUtils_1 = require("../utils/errorUtils.cjs");
20
- // Geo-blocking API URLs
21
- const ON_RAMP_GEO_BLOCKING_URLS = {
22
- DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',
23
- PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',
24
- };
25
- /**
26
- * EligibilityService
27
- *
28
- * Handles geo-location fetching and eligibility checking.
29
- * Manages caching to minimize API calls.
30
- *
31
- * Instance-based service with constructor injection of platform dependencies.
32
- * Cache is instance-scoped to support multiple service instances (e.g., testing).
33
- */
34
- class EligibilityService {
35
- /**
36
- * Create a new EligibilityService instance
37
- *
38
- * @param deps - Platform dependencies for logging, metrics, etc.
39
- */
40
- constructor(deps) {
41
- _EligibilityService_instances.add(this);
42
- _EligibilityService_geoCacheTtlMs.set(this, 5 * 60 * 1000); // 5 minutes
43
- _EligibilityService_deps.set(this, void 0);
44
- _EligibilityService_geoLocationCache.set(this, null);
45
- _EligibilityService_geoLocationFetchPromise.set(this, null);
46
- __classPrivateFieldSet(this, _EligibilityService_deps, deps, "f");
47
- }
48
- /**
49
- * Fetch geo location with caching and deduplication
50
- *
51
- * @returns The user's geo location string.
52
- */
53
- async fetchGeoLocation() {
54
- // Check cache first
55
- if (__classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f")) {
56
- const cacheAge = Date.now() - __classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f").timestamp;
57
- if (cacheAge < __classPrivateFieldGet(this, _EligibilityService_geoCacheTtlMs, "f")) {
58
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Using cached geo location', {
59
- location: __classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f").location,
60
- cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,
61
- });
62
- return __classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f").location;
63
- }
64
- }
65
- // If already fetching, return the existing promise
66
- if (__classPrivateFieldGet(this, _EligibilityService_geoLocationFetchPromise, "f")) {
67
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Geo location fetch already in progress, waiting...');
68
- return __classPrivateFieldGet(this, _EligibilityService_geoLocationFetchPromise, "f");
69
- }
70
- // Start new fetch
71
- __classPrivateFieldSet(this, _EligibilityService_geoLocationFetchPromise, __classPrivateFieldGet(this, _EligibilityService_instances, "m", _EligibilityService_performGeoLocationFetch).call(this), "f");
72
- try {
73
- const location = await __classPrivateFieldGet(this, _EligibilityService_geoLocationFetchPromise, "f");
74
- return location;
75
- }
76
- finally {
77
- // Clear the promise after completion (success or failure)
78
- __classPrivateFieldSet(this, _EligibilityService_geoLocationFetchPromise, null, "f");
79
- }
80
- }
81
- /**
82
- * Check if user is eligible based on geo-blocked regions
83
- *
84
- * @param options - The eligibility check parameters.
85
- * @param options.blockedRegions - List of blocked region codes (e.g., ['US', 'CN']).
86
- * @returns True if eligible (not in blocked region), false otherwise.
87
- */
88
- async checkEligibility(options) {
89
- const { blockedRegions } = options;
90
- try {
91
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Checking eligibility', {
92
- blockedRegionsCount: blockedRegions.length,
93
- });
94
- // Returns UNKNOWN if we can't fetch the geo location
95
- const geoLocation = await this.fetchGeoLocation();
96
- // Only set to eligible if we have valid geolocation and it's not blocked
97
- if (geoLocation !== 'UNKNOWN') {
98
- const isEligible = blockedRegions.every((geoBlockedRegion) => !geoLocation
99
- .toUpperCase()
100
- .startsWith(geoBlockedRegion.toUpperCase()));
101
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Eligibility check completed', {
102
- geoLocation,
103
- isEligible,
104
- blockedRegions,
105
- });
106
- return isEligible;
107
- }
108
- // Default to eligible if location is unknown
109
- return true;
110
- }
111
- catch (error) {
112
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").logger.error((0, errorUtils_1.ensureError)(error, 'EligibilityService.checkEligibility'), {
113
- tags: { feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName },
114
- context: {
115
- name: 'EligibilityService.checkEligibility',
116
- data: {},
117
- },
118
- });
119
- // Default to eligible on error
120
- return true;
121
- }
122
- }
123
- /**
124
- * Clear the geo-location cache
125
- * Useful for testing or forcing a fresh fetch
126
- */
127
- clearCache() {
128
- __classPrivateFieldSet(this, _EligibilityService_geoLocationCache, null, "f");
129
- __classPrivateFieldSet(this, _EligibilityService_geoLocationFetchPromise, null, "f");
130
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Cache cleared');
131
- }
132
- }
133
- exports.EligibilityService = EligibilityService;
134
- _EligibilityService_geoCacheTtlMs = new WeakMap(), _EligibilityService_deps = new WeakMap(), _EligibilityService_geoLocationCache = new WeakMap(), _EligibilityService_geoLocationFetchPromise = new WeakMap(), _EligibilityService_instances = new WeakSet(), _EligibilityService_performGeoLocationFetch =
135
- /**
136
- * Perform the actual geo location fetch
137
- * Separated to allow proper promise management
138
- *
139
- * @returns The fetched geo location string, or 'UNKNOWN' on failure.
140
- */
141
- async function _EligibilityService_performGeoLocationFetch() {
142
- let location = 'UNKNOWN';
143
- try {
144
- const environment = (0, utils_1.getEnvironment)();
145
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Fetching geo location from API', {
146
- environment,
147
- });
148
- const response = await (0, controller_utils_1.successfulFetch)(ON_RAMP_GEO_BLOCKING_URLS[environment]);
149
- const textResult = await response?.text();
150
- location = textResult || 'UNKNOWN';
151
- // Cache the successful result
152
- __classPrivateFieldSet(this, _EligibilityService_geoLocationCache, {
153
- location,
154
- timestamp: Date.now(),
155
- }, "f");
156
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Geo location fetched successfully', {
157
- location,
158
- });
159
- return location;
160
- }
161
- catch (error) {
162
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").logger.error((0, errorUtils_1.ensureError)(error, 'EligibilityService.performGeoLocationFetch'), {
163
- tags: { feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName },
164
- context: {
165
- name: 'EligibilityService.performGeoLocationFetch',
166
- data: {},
167
- },
168
- });
169
- // Don't cache failures
170
- return location;
171
- }
172
- };
173
- //# sourceMappingURL=EligibilityService.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EligibilityService.cjs","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAA6D;AAE7D,8DAA2D;AAK3D,8CAA0C;AAC1C,wDAAkD;AAElD,wBAAwB;AACxB,MAAM,yBAAyB,GAAG;IAChC,GAAG,EAAE,oDAAoD;IACzD,IAAI,EAAE,gDAAgD;CAC9C,CAAC;AAUX;;;;;;;;GAQG;AACH,MAAa,kBAAkB;IAS7B;;;;OAIG;IACH,YAAY,IAA+B;;QAblC,4CAAiB,CAAC,GAAG,EAAE,GAAG,IAAI,EAAC,CAAC,YAAY;QAE5C,2CAAiC;QAE1C,+CAA6C,IAAI,EAAC;QAElD,sDAAmD,IAAI,EAAC;QAQtD,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,gBAAgB;QACpB,oBAAoB;QACpB,IAAI,uBAAA,IAAI,4CAAkB,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,uBAAA,IAAI,4CAAkB,CAAC,SAAS,CAAC;YAC/D,IAAI,QAAQ,GAAG,uBAAA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ACpC,yBAAyB,CAAC,WAAW,CAAC,CACvC,CAAC;QAEF,MAAM,UAAU,GAAG,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC1C,QAAQ,GAAG,UAAU,IAAI,SAAS,CAAC;QAEnC,8BAA8B;QAC9B,uBAAA,IAAI,wCAAqB;YACvB,QAAQ;YACR,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,MAAA,CAAC;QAEF,uBAAA,IAAI,gCAAM,CAAC,WAAW,CAAC,GAAG,CACxB,uDAAuD,EACvD;YACE,QAAQ;SACT,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,uBAAA,IAAI,gCAAM,CAAC,MAAM,CAAC,KAAK,CACrB,IAAA,wBAAW,EAAC,KAAK,EAAE,4CAA4C,CAAC,EAChE;YACE,IAAI,EAAE,EAAE,OAAO,EAAE,6BAAe,CAAC,WAAW,EAAE;YAC9C,OAAO,EAAE;gBACP,IAAI,EAAE,4CAA4C;gBAClD,IAAI,EAAE,EAAE;aACT;SACF,CACF,CAAC;QACF,uBAAuB;QACvB,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC","sourcesContent":["import { successfulFetch } from '@metamask/controller-utils';\n\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport type {\n PerpsPlatformDependencies,\n CheckEligibilityParams,\n} from '../types';\nimport { getEnvironment } from '../utils';\nimport { ensureError } from '../utils/errorUtils';\n\n// Geo-blocking API URLs\nconst ON_RAMP_GEO_BLOCKING_URLS = {\n DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',\n PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',\n} as const;\n\n/**\n * Geo-location cache entry\n */\ntype GeoLocationCache = {\n location: string;\n timestamp: number;\n};\n\n/**\n * EligibilityService\n *\n * Handles geo-location fetching and eligibility checking.\n * Manages caching to minimize API calls.\n *\n * Instance-based service with constructor injection of platform dependencies.\n * Cache is instance-scoped to support multiple service instances (e.g., testing).\n */\nexport class EligibilityService {\n readonly #geoCacheTtlMs = 5 * 60 * 1000; // 5 minutes\n\n readonly #deps: PerpsPlatformDependencies;\n\n #geoLocationCache: GeoLocationCache | null = null;\n\n #geoLocationFetchPromise: Promise<string> | null = null;\n\n /**\n * Create a new EligibilityService instance\n *\n * @param deps - Platform dependencies for logging, metrics, etc.\n */\n constructor(deps: PerpsPlatformDependencies) {\n this.#deps = deps;\n }\n\n /**\n * Fetch geo location with caching and deduplication\n *\n * @returns The user's geo location string.\n */\n async fetchGeoLocation(): Promise<string> {\n // Check cache first\n if (this.#geoLocationCache) {\n const cacheAge = Date.now() - this.#geoLocationCache.timestamp;\n if (cacheAge < this.#geoCacheTtlMs) {\n this.#deps.debugLogger.log(\n 'EligibilityService: Using cached geo location',\n {\n location: this.#geoLocationCache.location,\n cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,\n },\n );\n return this.#geoLocationCache.location;\n }\n }\n\n // If already fetching, return the existing promise\n if (this.#geoLocationFetchPromise) {\n this.#deps.debugLogger.log(\n 'EligibilityService: Geo location fetch already in progress, waiting...',\n );\n return this.#geoLocationFetchPromise;\n }\n\n // Start new fetch\n this.#geoLocationFetchPromise = this.#performGeoLocationFetch();\n\n try {\n const location = await this.#geoLocationFetchPromise;\n return location;\n } finally {\n // Clear the promise after completion (success or failure)\n this.#geoLocationFetchPromise = null;\n }\n }\n\n /**\n * Perform the actual geo location fetch\n * Separated to allow proper promise management\n *\n * @returns The fetched geo location string, or 'UNKNOWN' on failure.\n */\n async #performGeoLocationFetch(): Promise<string> {\n let location = 'UNKNOWN';\n\n try {\n const environment = getEnvironment();\n\n this.#deps.debugLogger.log(\n 'EligibilityService: Fetching geo location from API',\n {\n environment,\n },\n );\n\n const response = await successfulFetch(\n ON_RAMP_GEO_BLOCKING_URLS[environment],\n );\n\n const textResult = await response?.text();\n location = textResult || 'UNKNOWN';\n\n // Cache the successful result\n this.#geoLocationCache = {\n location,\n timestamp: Date.now(),\n };\n\n this.#deps.debugLogger.log(\n 'EligibilityService: Geo location fetched successfully',\n {\n location,\n },\n );\n\n return location;\n } catch (error) {\n this.#deps.logger.error(\n ensureError(error, 'EligibilityService.performGeoLocationFetch'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'EligibilityService.performGeoLocationFetch',\n data: {},\n },\n },\n );\n // Don't cache failures\n return location;\n }\n }\n\n /**\n * Check if user is eligible based on geo-blocked regions\n *\n * @param options - The eligibility check parameters.\n * @param options.blockedRegions - List of blocked region codes (e.g., ['US', 'CN']).\n * @returns True if eligible (not in blocked region), false otherwise.\n */\n async checkEligibility(options: CheckEligibilityParams): Promise<boolean> {\n const { blockedRegions } = options;\n try {\n this.#deps.debugLogger.log('EligibilityService: Checking eligibility', {\n blockedRegionsCount: blockedRegions.length,\n });\n\n // Returns UNKNOWN if we can't fetch the geo location\n const geoLocation = await this.fetchGeoLocation();\n\n // Only set to eligible if we have valid geolocation and it's not blocked\n if (geoLocation !== 'UNKNOWN') {\n const isEligible = blockedRegions.every(\n (geoBlockedRegion) =>\n !geoLocation\n .toUpperCase()\n .startsWith(geoBlockedRegion.toUpperCase()),\n );\n\n this.#deps.debugLogger.log(\n 'EligibilityService: Eligibility check completed',\n {\n geoLocation,\n isEligible,\n blockedRegions,\n },\n );\n\n return isEligible;\n }\n\n // Default to eligible if location is unknown\n return true;\n } catch (error) {\n this.#deps.logger.error(\n ensureError(error, 'EligibilityService.checkEligibility'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'EligibilityService.checkEligibility',\n data: {},\n },\n },\n );\n // Default to eligible on error\n return true;\n }\n }\n\n /**\n * Clear the geo-location cache\n * Useful for testing or forcing a fresh fetch\n */\n clearCache(): void {\n this.#geoLocationCache = null;\n this.#geoLocationFetchPromise = null;\n this.#deps.debugLogger.log('EligibilityService: Cache cleared');\n }\n}\n"]}
@@ -1,39 +0,0 @@
1
- import type { PerpsPlatformDependencies, CheckEligibilityParams } from "../types/index.cjs";
2
- /**
3
- * EligibilityService
4
- *
5
- * Handles geo-location fetching and eligibility checking.
6
- * Manages caching to minimize API calls.
7
- *
8
- * Instance-based service with constructor injection of platform dependencies.
9
- * Cache is instance-scoped to support multiple service instances (e.g., testing).
10
- */
11
- export declare class EligibilityService {
12
- #private;
13
- /**
14
- * Create a new EligibilityService instance
15
- *
16
- * @param deps - Platform dependencies for logging, metrics, etc.
17
- */
18
- constructor(deps: PerpsPlatformDependencies);
19
- /**
20
- * Fetch geo location with caching and deduplication
21
- *
22
- * @returns The user's geo location string.
23
- */
24
- fetchGeoLocation(): Promise<string>;
25
- /**
26
- * Check if user is eligible based on geo-blocked regions
27
- *
28
- * @param options - The eligibility check parameters.
29
- * @param options.blockedRegions - List of blocked region codes (e.g., ['US', 'CN']).
30
- * @returns True if eligible (not in blocked region), false otherwise.
31
- */
32
- checkEligibility(options: CheckEligibilityParams): Promise<boolean>;
33
- /**
34
- * Clear the geo-location cache
35
- * Useful for testing or forcing a fresh fetch
36
- */
37
- clearCache(): void;
38
- }
39
- //# sourceMappingURL=EligibilityService.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EligibilityService.d.cts","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACvB,2BAAiB;AAkBlB;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;;IAS7B;;;;OAIG;gBACS,IAAI,EAAE,yBAAyB;IAI3C;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IA4FzC;;;;;;OAMG;IACG,gBAAgB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;IAiDzE;;;OAGG;IACH,UAAU,IAAI,IAAI;CAKnB"}
@@ -1,39 +0,0 @@
1
- import type { PerpsPlatformDependencies, CheckEligibilityParams } from "../types/index.mjs";
2
- /**
3
- * EligibilityService
4
- *
5
- * Handles geo-location fetching and eligibility checking.
6
- * Manages caching to minimize API calls.
7
- *
8
- * Instance-based service with constructor injection of platform dependencies.
9
- * Cache is instance-scoped to support multiple service instances (e.g., testing).
10
- */
11
- export declare class EligibilityService {
12
- #private;
13
- /**
14
- * Create a new EligibilityService instance
15
- *
16
- * @param deps - Platform dependencies for logging, metrics, etc.
17
- */
18
- constructor(deps: PerpsPlatformDependencies);
19
- /**
20
- * Fetch geo location with caching and deduplication
21
- *
22
- * @returns The user's geo location string.
23
- */
24
- fetchGeoLocation(): Promise<string>;
25
- /**
26
- * Check if user is eligible based on geo-blocked regions
27
- *
28
- * @param options - The eligibility check parameters.
29
- * @param options.blockedRegions - List of blocked region codes (e.g., ['US', 'CN']).
30
- * @returns True if eligible (not in blocked region), false otherwise.
31
- */
32
- checkEligibility(options: CheckEligibilityParams): Promise<boolean>;
33
- /**
34
- * Clear the geo-location cache
35
- * Useful for testing or forcing a fresh fetch
36
- */
37
- clearCache(): void;
38
- }
39
- //# sourceMappingURL=EligibilityService.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EligibilityService.d.mts","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACvB,2BAAiB;AAkBlB;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;;IAS7B;;;;OAIG;gBACS,IAAI,EAAE,yBAAyB;IAI3C;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IA4FzC;;;;;;OAMG;IACG,gBAAgB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;IAiDzE;;;OAGG;IACH,UAAU,IAAI,IAAI;CAKnB"}
@@ -1,169 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _EligibilityService_instances, _EligibilityService_geoCacheTtlMs, _EligibilityService_deps, _EligibilityService_geoLocationCache, _EligibilityService_geoLocationFetchPromise, _EligibilityService_performGeoLocationFetch;
13
- import { successfulFetch } from "@metamask/controller-utils";
14
- import { PERPS_CONSTANTS } from "../constants/perpsConfig.mjs";
15
- import { getEnvironment } from "../utils/index.mjs";
16
- import { ensureError } from "../utils/errorUtils.mjs";
17
- // Geo-blocking API URLs
18
- const ON_RAMP_GEO_BLOCKING_URLS = {
19
- DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',
20
- PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',
21
- };
22
- /**
23
- * EligibilityService
24
- *
25
- * Handles geo-location fetching and eligibility checking.
26
- * Manages caching to minimize API calls.
27
- *
28
- * Instance-based service with constructor injection of platform dependencies.
29
- * Cache is instance-scoped to support multiple service instances (e.g., testing).
30
- */
31
- export class EligibilityService {
32
- /**
33
- * Create a new EligibilityService instance
34
- *
35
- * @param deps - Platform dependencies for logging, metrics, etc.
36
- */
37
- constructor(deps) {
38
- _EligibilityService_instances.add(this);
39
- _EligibilityService_geoCacheTtlMs.set(this, 5 * 60 * 1000); // 5 minutes
40
- _EligibilityService_deps.set(this, void 0);
41
- _EligibilityService_geoLocationCache.set(this, null);
42
- _EligibilityService_geoLocationFetchPromise.set(this, null);
43
- __classPrivateFieldSet(this, _EligibilityService_deps, deps, "f");
44
- }
45
- /**
46
- * Fetch geo location with caching and deduplication
47
- *
48
- * @returns The user's geo location string.
49
- */
50
- async fetchGeoLocation() {
51
- // Check cache first
52
- if (__classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f")) {
53
- const cacheAge = Date.now() - __classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f").timestamp;
54
- if (cacheAge < __classPrivateFieldGet(this, _EligibilityService_geoCacheTtlMs, "f")) {
55
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Using cached geo location', {
56
- location: __classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f").location,
57
- cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,
58
- });
59
- return __classPrivateFieldGet(this, _EligibilityService_geoLocationCache, "f").location;
60
- }
61
- }
62
- // If already fetching, return the existing promise
63
- if (__classPrivateFieldGet(this, _EligibilityService_geoLocationFetchPromise, "f")) {
64
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Geo location fetch already in progress, waiting...');
65
- return __classPrivateFieldGet(this, _EligibilityService_geoLocationFetchPromise, "f");
66
- }
67
- // Start new fetch
68
- __classPrivateFieldSet(this, _EligibilityService_geoLocationFetchPromise, __classPrivateFieldGet(this, _EligibilityService_instances, "m", _EligibilityService_performGeoLocationFetch).call(this), "f");
69
- try {
70
- const location = await __classPrivateFieldGet(this, _EligibilityService_geoLocationFetchPromise, "f");
71
- return location;
72
- }
73
- finally {
74
- // Clear the promise after completion (success or failure)
75
- __classPrivateFieldSet(this, _EligibilityService_geoLocationFetchPromise, null, "f");
76
- }
77
- }
78
- /**
79
- * Check if user is eligible based on geo-blocked regions
80
- *
81
- * @param options - The eligibility check parameters.
82
- * @param options.blockedRegions - List of blocked region codes (e.g., ['US', 'CN']).
83
- * @returns True if eligible (not in blocked region), false otherwise.
84
- */
85
- async checkEligibility(options) {
86
- const { blockedRegions } = options;
87
- try {
88
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Checking eligibility', {
89
- blockedRegionsCount: blockedRegions.length,
90
- });
91
- // Returns UNKNOWN if we can't fetch the geo location
92
- const geoLocation = await this.fetchGeoLocation();
93
- // Only set to eligible if we have valid geolocation and it's not blocked
94
- if (geoLocation !== 'UNKNOWN') {
95
- const isEligible = blockedRegions.every((geoBlockedRegion) => !geoLocation
96
- .toUpperCase()
97
- .startsWith(geoBlockedRegion.toUpperCase()));
98
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Eligibility check completed', {
99
- geoLocation,
100
- isEligible,
101
- blockedRegions,
102
- });
103
- return isEligible;
104
- }
105
- // Default to eligible if location is unknown
106
- return true;
107
- }
108
- catch (error) {
109
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").logger.error(ensureError(error, 'EligibilityService.checkEligibility'), {
110
- tags: { feature: PERPS_CONSTANTS.FeatureName },
111
- context: {
112
- name: 'EligibilityService.checkEligibility',
113
- data: {},
114
- },
115
- });
116
- // Default to eligible on error
117
- return true;
118
- }
119
- }
120
- /**
121
- * Clear the geo-location cache
122
- * Useful for testing or forcing a fresh fetch
123
- */
124
- clearCache() {
125
- __classPrivateFieldSet(this, _EligibilityService_geoLocationCache, null, "f");
126
- __classPrivateFieldSet(this, _EligibilityService_geoLocationFetchPromise, null, "f");
127
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Cache cleared');
128
- }
129
- }
130
- _EligibilityService_geoCacheTtlMs = new WeakMap(), _EligibilityService_deps = new WeakMap(), _EligibilityService_geoLocationCache = new WeakMap(), _EligibilityService_geoLocationFetchPromise = new WeakMap(), _EligibilityService_instances = new WeakSet(), _EligibilityService_performGeoLocationFetch =
131
- /**
132
- * Perform the actual geo location fetch
133
- * Separated to allow proper promise management
134
- *
135
- * @returns The fetched geo location string, or 'UNKNOWN' on failure.
136
- */
137
- async function _EligibilityService_performGeoLocationFetch() {
138
- let location = 'UNKNOWN';
139
- try {
140
- const environment = getEnvironment();
141
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Fetching geo location from API', {
142
- environment,
143
- });
144
- const response = await successfulFetch(ON_RAMP_GEO_BLOCKING_URLS[environment]);
145
- const textResult = await response?.text();
146
- location = textResult || 'UNKNOWN';
147
- // Cache the successful result
148
- __classPrivateFieldSet(this, _EligibilityService_geoLocationCache, {
149
- location,
150
- timestamp: Date.now(),
151
- }, "f");
152
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").debugLogger.log('EligibilityService: Geo location fetched successfully', {
153
- location,
154
- });
155
- return location;
156
- }
157
- catch (error) {
158
- __classPrivateFieldGet(this, _EligibilityService_deps, "f").logger.error(ensureError(error, 'EligibilityService.performGeoLocationFetch'), {
159
- tags: { feature: PERPS_CONSTANTS.FeatureName },
160
- context: {
161
- name: 'EligibilityService.performGeoLocationFetch',
162
- data: {},
163
- },
164
- });
165
- // Don't cache failures
166
- return location;
167
- }
168
- };
169
- //# sourceMappingURL=EligibilityService.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EligibilityService.mjs","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,mCAAmC;AAE7D,OAAO,EAAE,eAAe,EAAE,qCAAiC;AAK3D,OAAO,EAAE,cAAc,EAAE,2BAAiB;AAC1C,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAElD,wBAAwB;AACxB,MAAM,yBAAyB,GAAG;IAChC,GAAG,EAAE,oDAAoD;IACzD,IAAI,EAAE,gDAAgD;CAC9C,CAAC;AAUX;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAkB;IAS7B;;;;OAIG;IACH,YAAY,IAA+B;;QAblC,4CAAiB,CAAC,GAAG,EAAE,GAAG,IAAI,EAAC,CAAC,YAAY;QAE5C,2CAAiC;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C,mCAAmC,CAAC,CAAC;IAClE,CAAC;CACF;;AAzHC;;;;;GAKG;AACH,KAAK;IACH,IAAI,QAAQ,GAAG,SAAS,CAAC;IAEzB,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;QAErC,uBAAA,IAAI,gCAAM,CAAC,WAAW,CAAC,GAAG,CACxB,oDAAoD,EACpD;YACE,WAAW;SACZ,CACF,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,eAAe,CACpC,yBAAyB,CAAC,WAAW,CAAC,CACvC,CAAC;QAEF,MAAM,UAAU,GAAG,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC1C,QAAQ,GAAG,UAAU,IAAI,SAAS,CAAC;QAEnC,8BAA8B;QAC9B,uBAAA,IAAI,wCAAqB;YACvB,QAAQ;YACR,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,MAAA,CAAC;QAEF,uBAAA,IAAI,gCAAM,CAAC,WAAW,CAAC,GAAG,CACxB,uDAAuD,EACvD;YACE,QAAQ;SACT,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,uBAAA,IAAI,gCAAM,CAAC,MAAM,CAAC,KAAK,CACrB,WAAW,CAAC,KAAK,EAAE,4CAA4C,CAAC,EAChE;YACE,IAAI,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,WAAW,EAAE;YAC9C,OAAO,EAAE;gBACP,IAAI,EAAE,4CAA4C;gBAClD,IAAI,EAAE,EAAE;aACT;SACF,CACF,CAAC;QACF,uBAAuB;QACvB,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC","sourcesContent":["import { successfulFetch } from '@metamask/controller-utils';\n\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport type {\n PerpsPlatformDependencies,\n CheckEligibilityParams,\n} from '../types';\nimport { getEnvironment } from '../utils';\nimport { ensureError } from '../utils/errorUtils';\n\n// Geo-blocking API URLs\nconst ON_RAMP_GEO_BLOCKING_URLS = {\n DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',\n PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',\n} as const;\n\n/**\n * Geo-location cache entry\n */\ntype GeoLocationCache = {\n location: string;\n timestamp: number;\n};\n\n/**\n * EligibilityService\n *\n * Handles geo-location fetching and eligibility checking.\n * Manages caching to minimize API calls.\n *\n * Instance-based service with constructor injection of platform dependencies.\n * Cache is instance-scoped to support multiple service instances (e.g., testing).\n */\nexport class EligibilityService {\n readonly #geoCacheTtlMs = 5 * 60 * 1000; // 5 minutes\n\n readonly #deps: PerpsPlatformDependencies;\n\n #geoLocationCache: GeoLocationCache | null = null;\n\n #geoLocationFetchPromise: Promise<string> | null = null;\n\n /**\n * Create a new EligibilityService instance\n *\n * @param deps - Platform dependencies for logging, metrics, etc.\n */\n constructor(deps: PerpsPlatformDependencies) {\n this.#deps = deps;\n }\n\n /**\n * Fetch geo location with caching and deduplication\n *\n * @returns The user's geo location string.\n */\n async fetchGeoLocation(): Promise<string> {\n // Check cache first\n if (this.#geoLocationCache) {\n const cacheAge = Date.now() - this.#geoLocationCache.timestamp;\n if (cacheAge < this.#geoCacheTtlMs) {\n this.#deps.debugLogger.log(\n 'EligibilityService: Using cached geo location',\n {\n location: this.#geoLocationCache.location,\n cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,\n },\n );\n return this.#geoLocationCache.location;\n }\n }\n\n // If already fetching, return the existing promise\n if (this.#geoLocationFetchPromise) {\n this.#deps.debugLogger.log(\n 'EligibilityService: Geo location fetch already in progress, waiting...',\n );\n return this.#geoLocationFetchPromise;\n }\n\n // Start new fetch\n this.#geoLocationFetchPromise = this.#performGeoLocationFetch();\n\n try {\n const location = await this.#geoLocationFetchPromise;\n return location;\n } finally {\n // Clear the promise after completion (success or failure)\n this.#geoLocationFetchPromise = null;\n }\n }\n\n /**\n * Perform the actual geo location fetch\n * Separated to allow proper promise management\n *\n * @returns The fetched geo location string, or 'UNKNOWN' on failure.\n */\n async #performGeoLocationFetch(): Promise<string> {\n let location = 'UNKNOWN';\n\n try {\n const environment = getEnvironment();\n\n this.#deps.debugLogger.log(\n 'EligibilityService: Fetching geo location from API',\n {\n environment,\n },\n );\n\n const response = await successfulFetch(\n ON_RAMP_GEO_BLOCKING_URLS[environment],\n );\n\n const textResult = await response?.text();\n location = textResult || 'UNKNOWN';\n\n // Cache the successful result\n this.#geoLocationCache = {\n location,\n timestamp: Date.now(),\n };\n\n this.#deps.debugLogger.log(\n 'EligibilityService: Geo location fetched successfully',\n {\n location,\n },\n );\n\n return location;\n } catch (error) {\n this.#deps.logger.error(\n ensureError(error, 'EligibilityService.performGeoLocationFetch'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'EligibilityService.performGeoLocationFetch',\n data: {},\n },\n },\n );\n // Don't cache failures\n return location;\n }\n }\n\n /**\n * Check if user is eligible based on geo-blocked regions\n *\n * @param options - The eligibility check parameters.\n * @param options.blockedRegions - List of blocked region codes (e.g., ['US', 'CN']).\n * @returns True if eligible (not in blocked region), false otherwise.\n */\n async checkEligibility(options: CheckEligibilityParams): Promise<boolean> {\n const { blockedRegions } = options;\n try {\n this.#deps.debugLogger.log('EligibilityService: Checking eligibility', {\n blockedRegionsCount: blockedRegions.length,\n });\n\n // Returns UNKNOWN if we can't fetch the geo location\n const geoLocation = await this.fetchGeoLocation();\n\n // Only set to eligible if we have valid geolocation and it's not blocked\n if (geoLocation !== 'UNKNOWN') {\n const isEligible = blockedRegions.every(\n (geoBlockedRegion) =>\n !geoLocation\n .toUpperCase()\n .startsWith(geoBlockedRegion.toUpperCase()),\n );\n\n this.#deps.debugLogger.log(\n 'EligibilityService: Eligibility check completed',\n {\n geoLocation,\n isEligible,\n blockedRegions,\n },\n );\n\n return isEligible;\n }\n\n // Default to eligible if location is unknown\n return true;\n } catch (error) {\n this.#deps.logger.error(\n ensureError(error, 'EligibilityService.checkEligibility'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'EligibilityService.checkEligibility',\n data: {},\n },\n },\n );\n // Default to eligible on error\n return true;\n }\n }\n\n /**\n * Clear the geo-location cache\n * Useful for testing or forcing a fresh fetch\n */\n clearCache(): void {\n this.#geoLocationCache = null;\n this.#geoLocationFetchPromise = null;\n this.#deps.debugLogger.log('EligibilityService: Cache cleared');\n }\n}\n"]}