@humanode-hyperlane/rebalancer 0.0.0-stage → 27.2.2-humanode.1

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 (439) hide show
  1. package/LICENSE.md +193 -0
  2. package/README.md +297 -2
  3. package/dist/bridges/LiFiBridge.d.ts +93 -0
  4. package/dist/bridges/LiFiBridge.d.ts.map +1 -0
  5. package/dist/bridges/LiFiBridge.js +527 -0
  6. package/dist/bridges/LiFiBridge.js.map +1 -0
  7. package/dist/bridges/LiFiBridge.test.d.ts +2 -0
  8. package/dist/bridges/LiFiBridge.test.d.ts.map +1 -0
  9. package/dist/bridges/LiFiBridge.test.js +504 -0
  10. package/dist/bridges/LiFiBridge.test.js.map +1 -0
  11. package/dist/config/RebalancerConfig.d.ts +20 -0
  12. package/dist/config/RebalancerConfig.d.ts.map +1 -0
  13. package/dist/config/RebalancerConfig.js +35 -0
  14. package/dist/config/RebalancerConfig.js.map +1 -0
  15. package/dist/config/RebalancerConfig.test.d.ts +2 -0
  16. package/dist/config/RebalancerConfig.test.d.ts.map +1 -0
  17. package/dist/config/RebalancerConfig.test.js +798 -0
  18. package/dist/config/RebalancerConfig.test.js.map +1 -0
  19. package/dist/config/types.d.ts +3008 -0
  20. package/dist/config/types.d.ts.map +1 -0
  21. package/dist/config/types.js +451 -0
  22. package/dist/config/types.js.map +1 -0
  23. package/dist/core/InventoryRebalancer.d.ts +201 -0
  24. package/dist/core/InventoryRebalancer.d.ts.map +1 -0
  25. package/dist/core/InventoryRebalancer.js +994 -0
  26. package/dist/core/InventoryRebalancer.js.map +1 -0
  27. package/dist/core/InventoryRebalancer.test.d.ts +2 -0
  28. package/dist/core/InventoryRebalancer.test.d.ts.map +1 -0
  29. package/dist/core/InventoryRebalancer.test.js +1511 -0
  30. package/dist/core/InventoryRebalancer.test.js.map +1 -0
  31. package/dist/core/Rebalancer.d.ts +37 -0
  32. package/dist/core/Rebalancer.d.ts.map +1 -0
  33. package/dist/core/Rebalancer.js +433 -0
  34. package/dist/core/Rebalancer.js.map +1 -0
  35. package/dist/core/Rebalancer.test.d.ts +2 -0
  36. package/dist/core/Rebalancer.test.d.ts.map +1 -0
  37. package/dist/core/Rebalancer.test.js +424 -0
  38. package/dist/core/Rebalancer.test.js.map +1 -0
  39. package/dist/core/RebalancerOrchestrator.d.ts +56 -0
  40. package/dist/core/RebalancerOrchestrator.d.ts.map +1 -0
  41. package/dist/core/RebalancerOrchestrator.js +154 -0
  42. package/dist/core/RebalancerOrchestrator.js.map +1 -0
  43. package/dist/core/RebalancerOrchestrator.test.d.ts +2 -0
  44. package/dist/core/RebalancerOrchestrator.test.d.ts.map +1 -0
  45. package/dist/core/RebalancerOrchestrator.test.js +721 -0
  46. package/dist/core/RebalancerOrchestrator.test.js.map +1 -0
  47. package/dist/core/RebalancerService.d.ts +127 -0
  48. package/dist/core/RebalancerService.d.ts.map +1 -0
  49. package/dist/core/RebalancerService.js +270 -0
  50. package/dist/core/RebalancerService.js.map +1 -0
  51. package/dist/core/RebalancerService.test.d.ts +2 -0
  52. package/dist/core/RebalancerService.test.d.ts.map +1 -0
  53. package/dist/core/RebalancerService.test.js +777 -0
  54. package/dist/core/RebalancerService.test.js.map +1 -0
  55. package/dist/e2e/collateral-deficit.e2e-test.d.ts +2 -0
  56. package/dist/e2e/collateral-deficit.e2e-test.d.ts.map +1 -0
  57. package/dist/e2e/collateral-deficit.e2e-test.js +227 -0
  58. package/dist/e2e/collateral-deficit.e2e-test.js.map +1 -0
  59. package/dist/e2e/composite.e2e-test.d.ts +2 -0
  60. package/dist/e2e/composite.e2e-test.d.ts.map +1 -0
  61. package/dist/e2e/composite.e2e-test.js +666 -0
  62. package/dist/e2e/composite.e2e-test.js.map +1 -0
  63. package/dist/e2e/fixtures/routes.d.ts +89 -0
  64. package/dist/e2e/fixtures/routes.d.ts.map +1 -0
  65. package/dist/e2e/fixtures/routes.js +420 -0
  66. package/dist/e2e/fixtures/routes.js.map +1 -0
  67. package/dist/e2e/harness/BaseLocalDeploymentManager.d.ts +38 -0
  68. package/dist/e2e/harness/BaseLocalDeploymentManager.d.ts.map +1 -0
  69. package/dist/e2e/harness/BaseLocalDeploymentManager.js +144 -0
  70. package/dist/e2e/harness/BaseLocalDeploymentManager.js.map +1 -0
  71. package/dist/e2e/harness/BridgeSetup.d.ts +11 -0
  72. package/dist/e2e/harness/BridgeSetup.d.ts.map +1 -0
  73. package/dist/e2e/harness/BridgeSetup.js +50 -0
  74. package/dist/e2e/harness/BridgeSetup.js.map +1 -0
  75. package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.d.ts +13 -0
  76. package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.d.ts.map +1 -0
  77. package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.js +105 -0
  78. package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.js.map +1 -0
  79. package/dist/e2e/harness/Erc20LocalDeploymentManager.d.ts +11 -0
  80. package/dist/e2e/harness/Erc20LocalDeploymentManager.d.ts.map +1 -0
  81. package/dist/e2e/harness/Erc20LocalDeploymentManager.js +105 -0
  82. package/dist/e2e/harness/Erc20LocalDeploymentManager.js.map +1 -0
  83. package/dist/e2e/harness/ForkIndexer.d.ts +23 -0
  84. package/dist/e2e/harness/ForkIndexer.d.ts.map +1 -0
  85. package/dist/e2e/harness/ForkIndexer.js +127 -0
  86. package/dist/e2e/harness/ForkIndexer.js.map +1 -0
  87. package/dist/e2e/harness/ForkIndexer.test.d.ts +2 -0
  88. package/dist/e2e/harness/ForkIndexer.test.d.ts.map +1 -0
  89. package/dist/e2e/harness/ForkIndexer.test.js +257 -0
  90. package/dist/e2e/harness/ForkIndexer.test.js.map +1 -0
  91. package/dist/e2e/harness/MixedLocalDeploymentManager.d.ts +21 -0
  92. package/dist/e2e/harness/MixedLocalDeploymentManager.d.ts.map +1 -0
  93. package/dist/e2e/harness/MixedLocalDeploymentManager.js +115 -0
  94. package/dist/e2e/harness/MixedLocalDeploymentManager.js.map +1 -0
  95. package/dist/e2e/harness/MockExplorerClient.d.ts +23 -0
  96. package/dist/e2e/harness/MockExplorerClient.d.ts.map +1 -0
  97. package/dist/e2e/harness/MockExplorerClient.js +57 -0
  98. package/dist/e2e/harness/MockExplorerClient.js.map +1 -0
  99. package/dist/e2e/harness/MockExternalBridge.d.ts +32 -0
  100. package/dist/e2e/harness/MockExternalBridge.d.ts.map +1 -0
  101. package/dist/e2e/harness/MockExternalBridge.js +247 -0
  102. package/dist/e2e/harness/MockExternalBridge.js.map +1 -0
  103. package/dist/e2e/harness/NativeLocalDeploymentManager.d.ts +13 -0
  104. package/dist/e2e/harness/NativeLocalDeploymentManager.d.ts.map +1 -0
  105. package/dist/e2e/harness/NativeLocalDeploymentManager.js +91 -0
  106. package/dist/e2e/harness/NativeLocalDeploymentManager.js.map +1 -0
  107. package/dist/e2e/harness/SnapshotHelper.d.ts +13 -0
  108. package/dist/e2e/harness/SnapshotHelper.d.ts.map +1 -0
  109. package/dist/e2e/harness/SnapshotHelper.js +36 -0
  110. package/dist/e2e/harness/SnapshotHelper.js.map +1 -0
  111. package/dist/e2e/harness/TestHelpers.d.ts +25 -0
  112. package/dist/e2e/harness/TestHelpers.d.ts.map +1 -0
  113. package/dist/e2e/harness/TestHelpers.js +103 -0
  114. package/dist/e2e/harness/TestHelpers.js.map +1 -0
  115. package/dist/e2e/harness/TestRebalancer.d.ts +85 -0
  116. package/dist/e2e/harness/TestRebalancer.d.ts.map +1 -0
  117. package/dist/e2e/harness/TestRebalancer.js +427 -0
  118. package/dist/e2e/harness/TestRebalancer.js.map +1 -0
  119. package/dist/e2e/harness/TransferHelper.d.ts +34 -0
  120. package/dist/e2e/harness/TransferHelper.d.ts.map +1 -0
  121. package/dist/e2e/harness/TransferHelper.js +93 -0
  122. package/dist/e2e/harness/TransferHelper.js.map +1 -0
  123. package/dist/e2e/inventory-erc20-minAmount.e2e-test.d.ts +2 -0
  124. package/dist/e2e/inventory-erc20-minAmount.e2e-test.d.ts.map +1 -0
  125. package/dist/e2e/inventory-erc20-minAmount.e2e-test.js +411 -0
  126. package/dist/e2e/inventory-erc20-minAmount.e2e-test.js.map +1 -0
  127. package/dist/e2e/inventory-erc20-weighted.e2e-test.d.ts +2 -0
  128. package/dist/e2e/inventory-erc20-weighted.e2e-test.d.ts.map +1 -0
  129. package/dist/e2e/inventory-erc20-weighted.e2e-test.js +408 -0
  130. package/dist/e2e/inventory-erc20-weighted.e2e-test.js.map +1 -0
  131. package/dist/e2e/inventory-minAmount.e2e-test.d.ts +2 -0
  132. package/dist/e2e/inventory-minAmount.e2e-test.d.ts.map +1 -0
  133. package/dist/e2e/inventory-minAmount.e2e-test.js +411 -0
  134. package/dist/e2e/inventory-minAmount.e2e-test.js.map +1 -0
  135. package/dist/e2e/inventory-weighted.e2e-test.d.ts +2 -0
  136. package/dist/e2e/inventory-weighted.e2e-test.d.ts.map +1 -0
  137. package/dist/e2e/inventory-weighted.e2e-test.js +409 -0
  138. package/dist/e2e/inventory-weighted.e2e-test.js.map +1 -0
  139. package/dist/e2e/minAmount.e2e-test.d.ts +2 -0
  140. package/dist/e2e/minAmount.e2e-test.d.ts.map +1 -0
  141. package/dist/e2e/minAmount.e2e-test.js +203 -0
  142. package/dist/e2e/minAmount.e2e-test.js.map +1 -0
  143. package/dist/e2e/mixed-weighted.e2e-test.d.ts +2 -0
  144. package/dist/e2e/mixed-weighted.e2e-test.d.ts.map +1 -0
  145. package/dist/e2e/mixed-weighted.e2e-test.js +189 -0
  146. package/dist/e2e/mixed-weighted.e2e-test.js.map +1 -0
  147. package/dist/e2e/weighted.e2e-test.d.ts +2 -0
  148. package/dist/e2e/weighted.e2e-test.d.ts.map +1 -0
  149. package/dist/e2e/weighted.e2e-test.js +198 -0
  150. package/dist/e2e/weighted.e2e-test.js.map +1 -0
  151. package/dist/factories/RebalancerContextFactory.d.ts +89 -0
  152. package/dist/factories/RebalancerContextFactory.d.ts.map +1 -0
  153. package/dist/factories/RebalancerContextFactory.js +420 -0
  154. package/dist/factories/RebalancerContextFactory.js.map +1 -0
  155. package/dist/factories/RebalancerContextFactory.test.d.ts +2 -0
  156. package/dist/factories/RebalancerContextFactory.test.d.ts.map +1 -0
  157. package/dist/factories/RebalancerContextFactory.test.js +270 -0
  158. package/dist/factories/RebalancerContextFactory.test.js.map +1 -0
  159. package/dist/index.d.ts +37 -0
  160. package/dist/index.d.ts.map +1 -0
  161. package/dist/index.js +37 -0
  162. package/dist/index.js.map +1 -0
  163. package/dist/interfaces/IExternalBridge.d.ts +103 -0
  164. package/dist/interfaces/IExternalBridge.d.ts.map +1 -0
  165. package/dist/interfaces/IExternalBridge.js +2 -0
  166. package/dist/interfaces/IExternalBridge.js.map +1 -0
  167. package/dist/interfaces/IMetrics.d.ts +5 -0
  168. package/dist/interfaces/IMetrics.d.ts.map +1 -0
  169. package/dist/interfaces/IMetrics.js +2 -0
  170. package/dist/interfaces/IMetrics.js.map +1 -0
  171. package/dist/interfaces/IMonitor.d.ts +50 -0
  172. package/dist/interfaces/IMonitor.d.ts.map +1 -0
  173. package/dist/interfaces/IMonitor.js +14 -0
  174. package/dist/interfaces/IMonitor.js.map +1 -0
  175. package/dist/interfaces/IRebalancer.d.ts +31 -0
  176. package/dist/interfaces/IRebalancer.d.ts.map +1 -0
  177. package/dist/interfaces/IRebalancer.js +2 -0
  178. package/dist/interfaces/IRebalancer.js.map +1 -0
  179. package/dist/interfaces/IStrategy.d.ts +60 -0
  180. package/dist/interfaces/IStrategy.d.ts.map +1 -0
  181. package/dist/interfaces/IStrategy.js +13 -0
  182. package/dist/interfaces/IStrategy.js.map +1 -0
  183. package/dist/metrics/Metrics.d.ts +25 -0
  184. package/dist/metrics/Metrics.d.ts.map +1 -0
  185. package/dist/metrics/Metrics.js +164 -0
  186. package/dist/metrics/Metrics.js.map +1 -0
  187. package/dist/metrics/PriceGetter.d.ts +10 -0
  188. package/dist/metrics/PriceGetter.d.ts.map +1 -0
  189. package/dist/metrics/PriceGetter.js +41 -0
  190. package/dist/metrics/PriceGetter.js.map +1 -0
  191. package/dist/metrics/scripts/metrics.d.ts +28 -0
  192. package/dist/metrics/scripts/metrics.d.ts.map +1 -0
  193. package/dist/metrics/scripts/metrics.js +61 -0
  194. package/dist/metrics/scripts/metrics.js.map +1 -0
  195. package/dist/monitor/Monitor.d.ts +40 -0
  196. package/dist/monitor/Monitor.d.ts.map +1 -0
  197. package/dist/monitor/Monitor.js +211 -0
  198. package/dist/monitor/Monitor.js.map +1 -0
  199. package/dist/service.d.ts +3 -0
  200. package/dist/service.d.ts.map +1 -0
  201. package/dist/service.js +205 -0
  202. package/dist/service.js.map +1 -0
  203. package/dist/strategy/BaseStrategy.d.ts +86 -0
  204. package/dist/strategy/BaseStrategy.d.ts.map +1 -0
  205. package/dist/strategy/BaseStrategy.js +342 -0
  206. package/dist/strategy/BaseStrategy.js.map +1 -0
  207. package/dist/strategy/CollateralDeficitStrategy.d.ts +65 -0
  208. package/dist/strategy/CollateralDeficitStrategy.d.ts.map +1 -0
  209. package/dist/strategy/CollateralDeficitStrategy.js +253 -0
  210. package/dist/strategy/CollateralDeficitStrategy.js.map +1 -0
  211. package/dist/strategy/CollateralDeficitStrategy.test.d.ts +2 -0
  212. package/dist/strategy/CollateralDeficitStrategy.test.d.ts.map +1 -0
  213. package/dist/strategy/CollateralDeficitStrategy.test.js +497 -0
  214. package/dist/strategy/CollateralDeficitStrategy.test.js.map +1 -0
  215. package/dist/strategy/CompositeStrategy.d.ts +18 -0
  216. package/dist/strategy/CompositeStrategy.d.ts.map +1 -0
  217. package/dist/strategy/CompositeStrategy.js +63 -0
  218. package/dist/strategy/CompositeStrategy.js.map +1 -0
  219. package/dist/strategy/CompositeStrategy.test.d.ts +2 -0
  220. package/dist/strategy/CompositeStrategy.test.d.ts.map +1 -0
  221. package/dist/strategy/CompositeStrategy.test.js +278 -0
  222. package/dist/strategy/CompositeStrategy.test.js.map +1 -0
  223. package/dist/strategy/MinAmountStrategy.d.ts +35 -0
  224. package/dist/strategy/MinAmountStrategy.d.ts.map +1 -0
  225. package/dist/strategy/MinAmountStrategy.js +112 -0
  226. package/dist/strategy/MinAmountStrategy.js.map +1 -0
  227. package/dist/strategy/MinAmountStrategy.test.d.ts +2 -0
  228. package/dist/strategy/MinAmountStrategy.test.d.ts.map +1 -0
  229. package/dist/strategy/MinAmountStrategy.test.js +547 -0
  230. package/dist/strategy/MinAmountStrategy.test.js.map +1 -0
  231. package/dist/strategy/StrategyFactory.d.ts +27 -0
  232. package/dist/strategy/StrategyFactory.d.ts.map +1 -0
  233. package/dist/strategy/StrategyFactory.js +79 -0
  234. package/dist/strategy/StrategyFactory.js.map +1 -0
  235. package/dist/strategy/StrategyFactory.test.d.ts +2 -0
  236. package/dist/strategy/StrategyFactory.test.d.ts.map +1 -0
  237. package/dist/strategy/StrategyFactory.test.js +81 -0
  238. package/dist/strategy/StrategyFactory.test.js.map +1 -0
  239. package/dist/strategy/WeightedStrategy.d.ts +32 -0
  240. package/dist/strategy/WeightedStrategy.d.ts.map +1 -0
  241. package/dist/strategy/WeightedStrategy.js +73 -0
  242. package/dist/strategy/WeightedStrategy.js.map +1 -0
  243. package/dist/strategy/WeightedStrategy.test.d.ts +2 -0
  244. package/dist/strategy/WeightedStrategy.test.d.ts.map +1 -0
  245. package/dist/strategy/WeightedStrategy.test.js +403 -0
  246. package/dist/strategy/WeightedStrategy.test.js.map +1 -0
  247. package/dist/strategy/index.d.ts +7 -0
  248. package/dist/strategy/index.d.ts.map +1 -0
  249. package/dist/strategy/index.js +7 -0
  250. package/dist/strategy/index.js.map +1 -0
  251. package/dist/test/helpers.d.ts +99 -0
  252. package/dist/test/helpers.d.ts.map +1 -0
  253. package/dist/test/helpers.js +311 -0
  254. package/dist/test/helpers.js.map +1 -0
  255. package/dist/test/lifiMocks.d.ts +52 -0
  256. package/dist/test/lifiMocks.d.ts.map +1 -0
  257. package/dist/test/lifiMocks.js +160 -0
  258. package/dist/test/lifiMocks.js.map +1 -0
  259. package/dist/tracking/ActionTracker.d.ts +90 -0
  260. package/dist/tracking/ActionTracker.d.ts.map +1 -0
  261. package/dist/tracking/ActionTracker.js +678 -0
  262. package/dist/tracking/ActionTracker.js.map +1 -0
  263. package/dist/tracking/ActionTracker.test.d.ts +2 -0
  264. package/dist/tracking/ActionTracker.test.d.ts.map +1 -0
  265. package/dist/tracking/ActionTracker.test.js +1351 -0
  266. package/dist/tracking/ActionTracker.test.js.map +1 -0
  267. package/dist/tracking/IActionTracker.d.ts +157 -0
  268. package/dist/tracking/IActionTracker.d.ts.map +1 -0
  269. package/dist/tracking/IActionTracker.js +2 -0
  270. package/dist/tracking/IActionTracker.js.map +1 -0
  271. package/dist/tracking/InflightContextAdapter.d.ts +18 -0
  272. package/dist/tracking/InflightContextAdapter.d.ts.map +1 -0
  273. package/dist/tracking/InflightContextAdapter.js +52 -0
  274. package/dist/tracking/InflightContextAdapter.js.map +1 -0
  275. package/dist/tracking/InflightContextAdapter.test.d.ts +2 -0
  276. package/dist/tracking/InflightContextAdapter.test.d.ts.map +1 -0
  277. package/dist/tracking/InflightContextAdapter.test.js +175 -0
  278. package/dist/tracking/InflightContextAdapter.test.js.map +1 -0
  279. package/dist/tracking/store/IStore.d.ts +41 -0
  280. package/dist/tracking/store/IStore.d.ts.map +1 -0
  281. package/dist/tracking/store/IStore.js +2 -0
  282. package/dist/tracking/store/IStore.js.map +1 -0
  283. package/dist/tracking/store/InMemoryStore.d.ts +21 -0
  284. package/dist/tracking/store/InMemoryStore.d.ts.map +1 -0
  285. package/dist/tracking/store/InMemoryStore.js +40 -0
  286. package/dist/tracking/store/InMemoryStore.js.map +1 -0
  287. package/dist/tracking/store/InMemoryStore.test.d.ts +2 -0
  288. package/dist/tracking/store/InMemoryStore.test.d.ts.map +1 -0
  289. package/dist/tracking/store/InMemoryStore.test.js +290 -0
  290. package/dist/tracking/store/InMemoryStore.test.js.map +1 -0
  291. package/dist/tracking/store/index.d.ts +3 -0
  292. package/dist/tracking/store/index.d.ts.map +1 -0
  293. package/dist/tracking/store/index.js +2 -0
  294. package/dist/tracking/store/index.js.map +1 -0
  295. package/dist/tracking/types.d.ts +77 -0
  296. package/dist/tracking/types.d.ts.map +1 -0
  297. package/dist/tracking/types.js +2 -0
  298. package/dist/tracking/types.js.map +1 -0
  299. package/dist/utils/ExplorerClient.d.ts +68 -0
  300. package/dist/utils/ExplorerClient.d.ts.map +1 -0
  301. package/dist/utils/ExplorerClient.js +324 -0
  302. package/dist/utils/ExplorerClient.js.map +1 -0
  303. package/dist/utils/ExplorerClient.test.d.ts +2 -0
  304. package/dist/utils/ExplorerClient.test.d.ts.map +1 -0
  305. package/dist/utils/ExplorerClient.test.js +261 -0
  306. package/dist/utils/ExplorerClient.test.js.map +1 -0
  307. package/dist/utils/balanceUtils.d.ts +12 -0
  308. package/dist/utils/balanceUtils.d.ts.map +1 -0
  309. package/dist/utils/balanceUtils.js +40 -0
  310. package/dist/utils/balanceUtils.js.map +1 -0
  311. package/dist/utils/balanceUtils.test.d.ts +2 -0
  312. package/dist/utils/balanceUtils.test.d.ts.map +1 -0
  313. package/dist/utils/balanceUtils.test.js +55 -0
  314. package/dist/utils/balanceUtils.test.js.map +1 -0
  315. package/dist/utils/blockTag.d.ts +14 -0
  316. package/dist/utils/blockTag.d.ts.map +1 -0
  317. package/dist/utils/blockTag.js +46 -0
  318. package/dist/utils/blockTag.js.map +1 -0
  319. package/dist/utils/bridgeUtils.d.ts +40 -0
  320. package/dist/utils/bridgeUtils.d.ts.map +1 -0
  321. package/dist/utils/bridgeUtils.js +54 -0
  322. package/dist/utils/bridgeUtils.js.map +1 -0
  323. package/dist/utils/bridgeUtils.test.d.ts +2 -0
  324. package/dist/utils/bridgeUtils.test.d.ts.map +1 -0
  325. package/dist/utils/bridgeUtils.test.js +163 -0
  326. package/dist/utils/bridgeUtils.test.js.map +1 -0
  327. package/dist/utils/errors.d.ts +4 -0
  328. package/dist/utils/errors.d.ts.map +1 -0
  329. package/dist/utils/errors.js +6 -0
  330. package/dist/utils/errors.js.map +1 -0
  331. package/dist/utils/gasEstimation.d.ts +65 -0
  332. package/dist/utils/gasEstimation.d.ts.map +1 -0
  333. package/dist/utils/gasEstimation.js +206 -0
  334. package/dist/utils/gasEstimation.js.map +1 -0
  335. package/dist/utils/solanaKeyParser.d.ts +10 -0
  336. package/dist/utils/solanaKeyParser.d.ts.map +1 -0
  337. package/dist/utils/solanaKeyParser.js +87 -0
  338. package/dist/utils/solanaKeyParser.js.map +1 -0
  339. package/dist/utils/solanaKeyParser.test.d.ts +2 -0
  340. package/dist/utils/solanaKeyParser.test.d.ts.map +1 -0
  341. package/dist/utils/solanaKeyParser.test.js +71 -0
  342. package/dist/utils/solanaKeyParser.test.js.map +1 -0
  343. package/dist/utils/tokenUtils.d.ts +38 -0
  344. package/dist/utils/tokenUtils.d.ts.map +1 -0
  345. package/dist/utils/tokenUtils.js +65 -0
  346. package/dist/utils/tokenUtils.js.map +1 -0
  347. package/dist/utils/transactionUtils.d.ts +22 -0
  348. package/dist/utils/transactionUtils.d.ts.map +1 -0
  349. package/dist/utils/transactionUtils.js +26 -0
  350. package/dist/utils/transactionUtils.js.map +1 -0
  351. package/package.json +87 -3
  352. package/src/bridges/LiFiBridge.test.ts +615 -0
  353. package/src/bridges/LiFiBridge.ts +731 -0
  354. package/src/config/RebalancerConfig.test.ts +921 -0
  355. package/src/config/RebalancerConfig.ts +63 -0
  356. package/src/config/types.ts +613 -0
  357. package/src/core/InventoryRebalancer.test.ts +1858 -0
  358. package/src/core/InventoryRebalancer.ts +1455 -0
  359. package/src/core/Rebalancer.test.ts +686 -0
  360. package/src/core/Rebalancer.ts +686 -0
  361. package/src/core/RebalancerOrchestrator.test.ts +871 -0
  362. package/src/core/RebalancerOrchestrator.ts +273 -0
  363. package/src/core/RebalancerService.test.ts +1094 -0
  364. package/src/core/RebalancerService.ts +412 -0
  365. package/src/e2e/E2E_TEST_CONVENTIONS.md +222 -0
  366. package/src/e2e/collateral-deficit.e2e-test.ts +403 -0
  367. package/src/e2e/composite.e2e-test.ts +1008 -0
  368. package/src/e2e/fixtures/routes.ts +532 -0
  369. package/src/e2e/harness/BaseLocalDeploymentManager.ts +246 -0
  370. package/src/e2e/harness/BridgeSetup.ts +95 -0
  371. package/src/e2e/harness/Erc20InventoryLocalDeploymentManager.ts +183 -0
  372. package/src/e2e/harness/Erc20LocalDeploymentManager.ts +190 -0
  373. package/src/e2e/harness/ForkIndexer.test.ts +448 -0
  374. package/src/e2e/harness/ForkIndexer.ts +183 -0
  375. package/src/e2e/harness/MixedLocalDeploymentManager.ts +196 -0
  376. package/src/e2e/harness/MockExplorerClient.ts +94 -0
  377. package/src/e2e/harness/MockExternalBridge.ts +411 -0
  378. package/src/e2e/harness/NativeLocalDeploymentManager.ts +138 -0
  379. package/src/e2e/harness/SnapshotHelper.ts +56 -0
  380. package/src/e2e/harness/TestHelpers.ts +169 -0
  381. package/src/e2e/harness/TestRebalancer.ts +758 -0
  382. package/src/e2e/harness/TransferHelper.ts +188 -0
  383. package/src/e2e/inventory-erc20-minAmount.e2e-test.ts +735 -0
  384. package/src/e2e/inventory-erc20-weighted.e2e-test.ts +733 -0
  385. package/src/e2e/inventory-minAmount.e2e-test.ts +734 -0
  386. package/src/e2e/inventory-weighted.e2e-test.ts +734 -0
  387. package/src/e2e/minAmount.e2e-test.ts +313 -0
  388. package/src/e2e/mixed-weighted.e2e-test.ts +267 -0
  389. package/src/e2e/weighted.e2e-test.ts +304 -0
  390. package/src/factories/RebalancerContextFactory.test.ts +394 -0
  391. package/src/factories/RebalancerContextFactory.ts +771 -0
  392. package/src/index.ts +125 -0
  393. package/src/interfaces/IExternalBridge.ts +117 -0
  394. package/src/interfaces/IMetrics.ts +5 -0
  395. package/src/interfaces/IMonitor.ts +71 -0
  396. package/src/interfaces/IRebalancer.ts +57 -0
  397. package/src/interfaces/IStrategy.ts +81 -0
  398. package/src/metrics/Metrics.ts +335 -0
  399. package/src/metrics/PriceGetter.ts +74 -0
  400. package/src/metrics/scripts/metrics.ts +139 -0
  401. package/src/monitor/Monitor.ts +324 -0
  402. package/src/service.ts +285 -0
  403. package/src/strategy/BaseStrategy.ts +553 -0
  404. package/src/strategy/CollateralDeficitStrategy.test.ts +728 -0
  405. package/src/strategy/CollateralDeficitStrategy.ts +421 -0
  406. package/src/strategy/CompositeStrategy.test.ts +418 -0
  407. package/src/strategy/CompositeStrategy.ts +102 -0
  408. package/src/strategy/MinAmountStrategy.test.ts +732 -0
  409. package/src/strategy/MinAmountStrategy.ts +200 -0
  410. package/src/strategy/StrategyFactory.test.ts +108 -0
  411. package/src/strategy/StrategyFactory.ts +157 -0
  412. package/src/strategy/WeightedStrategy.test.ts +529 -0
  413. package/src/strategy/WeightedStrategy.ts +126 -0
  414. package/src/strategy/index.ts +6 -0
  415. package/src/test/helpers.ts +477 -0
  416. package/src/test/lifiMocks.ts +211 -0
  417. package/src/tracking/ActionTracker.test.ts +1625 -0
  418. package/src/tracking/ActionTracker.ts +1019 -0
  419. package/src/tracking/IActionTracker.ts +213 -0
  420. package/src/tracking/InflightContextAdapter.test.ts +206 -0
  421. package/src/tracking/InflightContextAdapter.ts +75 -0
  422. package/src/tracking/store/IStore.ts +48 -0
  423. package/src/tracking/store/InMemoryStore.test.ts +338 -0
  424. package/src/tracking/store/InMemoryStore.ts +59 -0
  425. package/src/tracking/store/index.ts +2 -0
  426. package/src/tracking/types.ts +118 -0
  427. package/src/utils/ExplorerClient.test.ts +386 -0
  428. package/src/utils/ExplorerClient.ts +439 -0
  429. package/src/utils/balanceUtils.test.ts +79 -0
  430. package/src/utils/balanceUtils.ts +65 -0
  431. package/src/utils/blockTag.ts +68 -0
  432. package/src/utils/bridgeUtils.test.ts +193 -0
  433. package/src/utils/bridgeUtils.ts +101 -0
  434. package/src/utils/errors.ts +5 -0
  435. package/src/utils/gasEstimation.ts +306 -0
  436. package/src/utils/solanaKeyParser.test.ts +103 -0
  437. package/src/utils/solanaKeyParser.ts +117 -0
  438. package/src/utils/tokenUtils.ts +89 -0
  439. package/src/utils/transactionUtils.ts +41 -0
@@ -0,0 +1,206 @@
1
+ import { BigNumber } from 'ethers';
2
+ import { addBufferToGasLimit, isZeroishAddress, ProtocolType, } from '@humanode-hyperlane/utils';
3
+ /**
4
+ * Fallback gas limit for transferRemote when eth_estimateGas fails.
5
+ * Conservative estimate for cross-chain token transfers.
6
+ */
7
+ export const FALLBACK_TRANSFER_REMOTE_GAS_LIMIT = 300000n;
8
+ /**
9
+ * Cost multiplier for minimum viable transfer.
10
+ * A transfer must be worth at least this multiple of its cost to be worthwhile.
11
+ */
12
+ export const MIN_VIABLE_COST_MULTIPLIER = 2n;
13
+ /**
14
+ * Estimate gas for a transferRemote transaction using eth_estimateGas.
15
+ * Falls back to conservative estimate if estimation fails.
16
+ *
17
+ * @param originChain - Chain where transferRemote will be called
18
+ * @param destinationChain - Chain where the Hyperlane message goes
19
+ * @param amount - Amount to transfer
20
+ * @param multiProvider - MultiProvider for chain access
21
+ * @param warpCoreMultiProvider - MultiProvider from WarpCore for adapter access
22
+ * @param getTokenForChain - Function to get token for a chain
23
+ * @param inventorySigner - Address of the inventory signer
24
+ * @param logger - Logger instance
25
+ * @returns Estimated gas limit for the transaction
26
+ */
27
+ export async function estimateTransferRemoteGas(originChain, destinationChain, amount, multiProvider, warpCoreMultiProvider, getTokenForChain, inventorySigner, logger) {
28
+ const originToken = getTokenForChain(originChain);
29
+ if (!originToken) {
30
+ logger.warn({ originChain }, 'No token found for origin chain, using fallback gas limit');
31
+ return FALLBACK_TRANSFER_REMOTE_GAS_LIMIT;
32
+ }
33
+ try {
34
+ const destinationDomain = multiProvider.getDomainId(destinationChain);
35
+ const adapter = originToken.getHypAdapter(warpCoreMultiProvider);
36
+ // Quote the IGP gas first (needed for the full transaction)
37
+ const gasQuote = await adapter.quoteTransferRemoteGas({
38
+ destination: destinationDomain,
39
+ sender: inventorySigner,
40
+ recipient: inventorySigner,
41
+ amount,
42
+ });
43
+ // Populate with minimal amount for gas estimation
44
+ // Gas cost is independent of transfer size (just a require check in _transferFromSender),
45
+ // and using minimal amount prevents eth_estimateGas from failing when account balance < requested amount
46
+ // Note: getHypAdapter returns IHypTokenAdapter<unknown> for protocol-agnostic support.
47
+ // For EVM chains (which inventory rebalancing uses), the actual type is AnnotatedEV5Transaction.
48
+ const populatedTx = (await adapter.populateTransferRemoteTx({
49
+ destination: destinationDomain,
50
+ recipient: inventorySigner,
51
+ weiAmountOrId: 1n,
52
+ interchainGas: gasQuote,
53
+ }));
54
+ // Estimate gas using the provider
55
+ const provider = multiProvider.getProvider(originChain);
56
+ const gasEstimate = await provider.estimateGas({
57
+ to: populatedTx.to,
58
+ data: populatedTx.data,
59
+ value: populatedTx.value,
60
+ from: inventorySigner,
61
+ });
62
+ const estimatedGas = BigInt(gasEstimate.toString());
63
+ logger.debug({
64
+ originChain,
65
+ destinationChain,
66
+ amount: amount.toString(),
67
+ estimatedGas: estimatedGas.toString(),
68
+ }, 'Estimated transferRemote gas via eth_estimateGas');
69
+ return estimatedGas;
70
+ }
71
+ catch (error) {
72
+ logger.warn({
73
+ originChain,
74
+ destinationChain,
75
+ error: error.message,
76
+ fallbackGas: FALLBACK_TRANSFER_REMOTE_GAS_LIMIT.toString(),
77
+ }, 'Gas estimation failed, using fallback gas limit');
78
+ return FALLBACK_TRANSFER_REMOTE_GAS_LIMIT;
79
+ }
80
+ }
81
+ /**
82
+ * Calculate all transfer costs for a transferRemote operation.
83
+ * Consolidates IGP costs, gas costs, and derived values (max transferable, min viable).
84
+ *
85
+ * @param originChain - Chain to transfer from (where transferRemote is called)
86
+ * @param destinationChain - Chain to transfer to (Hyperlane message destination)
87
+ * @param availableInventory - Available token balance on origin chain
88
+ * @param requestedAmount - Requested transfer amount
89
+ * @param multiProvider - MultiProvider for chain access
90
+ * @param warpCoreMultiProvider - MultiProvider from WarpCore for adapter access
91
+ * @param getTokenForChain - Function to get token for a chain
92
+ * @param inventorySigner - Address of the inventory signer
93
+ * @param isNativeTokenStandard - Function to check if token standard is native
94
+ * @param logger - Logger instance
95
+ * @returns Cost estimate with all components and derived values
96
+ */
97
+ export async function calculateTransferCosts(originChain, destinationChain, availableInventory, requestedAmount, multiProvider, warpCoreMultiProvider, getTokenForChain, inventorySigner, isNativeTokenStandard, logger) {
98
+ const originToken = getTokenForChain(originChain);
99
+ if (!originToken) {
100
+ throw new Error(`No token found for origin chain: ${originChain}`);
101
+ }
102
+ const destinationDomain = multiProvider.getDomainId(destinationChain);
103
+ const adapter = originToken.getHypAdapter(warpCoreMultiProvider);
104
+ // Always quote IGP for the gas quote (needed for populateTransferRemoteTx)
105
+ const gasQuote = await adapter.quoteTransferRemoteGas({
106
+ destination: destinationDomain,
107
+ sender: inventorySigner,
108
+ recipient: inventorySigner,
109
+ amount: requestedAmount,
110
+ });
111
+ // For non-native tokens, no cost reservation needed from token balance
112
+ if (!isNativeTokenStandard(originToken.standard)) {
113
+ return {
114
+ igpCost: 0n,
115
+ gasCost: 0n,
116
+ tokenFeeCost: 0n,
117
+ totalCost: 0n,
118
+ maxTransferable: availableInventory < requestedAmount
119
+ ? availableInventory
120
+ : requestedAmount,
121
+ minViableTransfer: 0n,
122
+ gasQuote,
123
+ };
124
+ }
125
+ // For native tokens, calculate costs
126
+ const igpCost = gasQuote.igpQuote.amount;
127
+ // Extract token fee cost (native denom only)
128
+ const tokenFeeCost = !gasQuote.tokenFeeQuote?.addressOrDenom ||
129
+ isZeroishAddress(gasQuote.tokenFeeQuote.addressOrDenom)
130
+ ? (gasQuote.tokenFeeQuote?.amount ?? 0n)
131
+ : 0n;
132
+ // Skip gas estimation for non-EVM chains (e.g., Solana).
133
+ // Non-EVM chains have negligible base fees (~5000 lamports ~$0.0001 on Solana)
134
+ // compared to EVM gas costs ($0.50-$50/tx). The IGP (Interchain Gas Paymaster)
135
+ // reservation dominates the cost, not chain-specific gas. Thus gasCost=0 is a
136
+ // safe approximation for non-EVM origin chains.
137
+ const originProtocol = multiProvider.getProtocol(originChain);
138
+ if (originProtocol !== ProtocolType.Ethereum) {
139
+ const totalCost = igpCost + tokenFeeCost;
140
+ let maxTransferable;
141
+ if (availableInventory <= totalCost) {
142
+ maxTransferable = 0n;
143
+ }
144
+ else {
145
+ const maxAfterReservation = availableInventory - totalCost;
146
+ maxTransferable =
147
+ maxAfterReservation < requestedAmount
148
+ ? maxAfterReservation
149
+ : requestedAmount;
150
+ }
151
+ const minViableTransfer = totalCost * MIN_VIABLE_COST_MULTIPLIER;
152
+ return {
153
+ igpCost,
154
+ gasCost: 0n,
155
+ tokenFeeCost,
156
+ totalCost,
157
+ maxTransferable,
158
+ minViableTransfer,
159
+ gasQuote,
160
+ };
161
+ }
162
+ // Estimate gas with buffer
163
+ const estimatedGasLimit = await estimateTransferRemoteGas(originChain, destinationChain, requestedAmount, multiProvider, warpCoreMultiProvider, getTokenForChain, inventorySigner, logger);
164
+ const bufferedGasLimit = addBufferToGasLimit(BigNumber.from(estimatedGasLimit.toString()));
165
+ // Get gas price and calculate cost
166
+ const provider = multiProvider.getProvider(originChain);
167
+ const feeData = await provider.getFeeData();
168
+ const gasPrice = feeData.maxFeePerGas ?? feeData.gasPrice ?? 0n;
169
+ const gasCost = bufferedGasLimit.toBigInt() * BigInt(gasPrice.toString());
170
+ const totalCost = igpCost + gasCost + tokenFeeCost;
171
+ // Calculate derived values
172
+ let maxTransferable;
173
+ if (availableInventory <= totalCost) {
174
+ maxTransferable = 0n;
175
+ }
176
+ else {
177
+ const maxAfterReservation = availableInventory - totalCost;
178
+ maxTransferable =
179
+ maxAfterReservation < requestedAmount
180
+ ? maxAfterReservation
181
+ : requestedAmount;
182
+ }
183
+ const minViableTransfer = totalCost * MIN_VIABLE_COST_MULTIPLIER;
184
+ logger.debug({
185
+ originChain,
186
+ destinationChain,
187
+ availableInventory: availableInventory.toString(),
188
+ requestedAmount: requestedAmount.toString(),
189
+ igpCost: igpCost.toString(),
190
+ gasCost: gasCost.toString(),
191
+ tokenFeeCost: tokenFeeCost.toString(),
192
+ totalCost: totalCost.toString(),
193
+ maxTransferable: maxTransferable.toString(),
194
+ minViableTransfer: minViableTransfer.toString(),
195
+ }, 'Calculated transfer costs for native token');
196
+ return {
197
+ igpCost,
198
+ gasCost,
199
+ tokenFeeCost,
200
+ totalCost,
201
+ maxTransferable,
202
+ minViableTransfer,
203
+ gasQuote,
204
+ };
205
+ }
206
+ //# sourceMappingURL=gasEstimation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gasEstimation.js","sourceRoot":"","sources":["../../src/utils/gasEstimation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAWnC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,GACb,MAAM,2BAA2B,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,OAAQ,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAuB7C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,WAAsB,EACtB,gBAA2B,EAC3B,MAAc,EACd,aAA4B,EAC5B,qBAA0B,EAC1B,gBAAyD,EACzD,eAAuB,EACvB,MAAc;IAEd,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAClD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CACT,EAAE,WAAW,EAAE,EACf,2DAA2D,CAC5D,CAAC;QACF,OAAO,kCAAkC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,WAAW,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;QAEjE,4DAA4D;QAC5D,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,sBAAsB,CAAC;YACpD,WAAW,EAAE,iBAAiB;YAC9B,MAAM,EAAE,eAAe;YACvB,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Q,IAAI,EAAE,CAAC;IAChE,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE1E,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,YAAY,CAAC;IAEnD,2BAA2B;IAC3B,IAAI,eAAuB,CAAC;IAC5B,IAAI,kBAAkB,IAAI,SAAS,EAAE,CAAC;QACpC,eAAe,GAAG,EAAE,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,MAAM,mBAAmB,GAAG,kBAAkB,GAAG,SAAS,CAAC;QAC3D,eAAe;YACb,mBAAmB,GAAG,eAAe;gBACnC,CAAC,CAAC,mBAAmB;gBACrB,CAAC,CAAC,eAAe,CAAC;IACxB,CAAC;IAED,MAAM,iBAAiB,GAAG,SAAS,GAAG,0BAA0B,CAAC;IAEjE,MAAM,CAAC,KAAK,CACV;QACE,WAAW;QACX,gBAAgB;QAChB,kBAAkB,EAAE,kBAAkB,CAAC,QAAQ,EAAE;QACjD,eAAe,EAAE,eAAe,CAAC,QAAQ,EAAE;QAC3C,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC3B,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC3B,YAAY,EAAE,YAAY,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,SAAS,CAAC,QAAQ,EAAE;QAC/B,eAAe,EAAE,eAAe,CAAC,QAAQ,EAAE;QAC3C,iBAAiB,EAAE,iBAAiB,CAAC,QAAQ,EAAE;KAChD,EACD,4CAA4C,CAC7C,CAAC;IAEF,OAAO;QACL,OAAO;QACP,OAAO;QACP,YAAY;QACZ,SAAS;QACT,eAAe;QACf,iBAAiB;QACjB,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parses a Solana private key from various formats.
3
+ * Supports JSON array format, comma-separated byte values, and base58 values.
4
+ *
5
+ * @param rawKey - Raw private key string in JSON array, comma-separated, or base58 format
6
+ * @returns Uint8Array representation of the private key
7
+ * @throws Error if the key format is invalid
8
+ */
9
+ export declare function parseSolanaPrivateKey(rawKey: string): Uint8Array;
10
+ //# sourceMappingURL=solanaKeyParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solanaKeyParser.d.ts","sourceRoot":"","sources":["../../src/utils/solanaKeyParser.ts"],"names":[],"mappings":"AA0BA;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAkFhE"}
@@ -0,0 +1,87 @@
1
+ import { Keypair } from '@solana/web3.js';
2
+ import bs58 from 'bs58';
3
+ const SOLANA_KEY_ERROR_MESSAGE = 'Invalid Solana private key format. Expected JSON byte array, comma-separated bytes, or base58 key (32 or 64 bytes). Set HYP_INVENTORY_KEY_SEALEVEL env var.';
4
+ function throwInvalidSolanaKey(reason) {
5
+ throw new Error(`${SOLANA_KEY_ERROR_MESSAGE} ${reason}`);
6
+ }
7
+ function validateKeyLength(bytes) {
8
+ if (bytes.length !== 32 && bytes.length !== 64) {
9
+ throwInvalidSolanaKey(`Received ${bytes.length} bytes; expected exactly 32 or 64.`);
10
+ }
11
+ }
12
+ function toSecretKey(bytes) {
13
+ validateKeyLength(bytes);
14
+ if (bytes.length === 32) {
15
+ return Keypair.fromSeed(Uint8Array.from(bytes)).secretKey;
16
+ }
17
+ return Uint8Array.from(bytes);
18
+ }
19
+ /**
20
+ * Parses a Solana private key from various formats.
21
+ * Supports JSON array format, comma-separated byte values, and base58 values.
22
+ *
23
+ * @param rawKey - Raw private key string in JSON array, comma-separated, or base58 format
24
+ * @returns Uint8Array representation of the private key
25
+ * @throws Error if the key format is invalid
26
+ */
27
+ export function parseSolanaPrivateKey(rawKey) {
28
+ const trimmed = rawKey.trim();
29
+ if (trimmed === '') {
30
+ throwInvalidSolanaKey('Input is empty.');
31
+ }
32
+ try {
33
+ if (trimmed.startsWith('[')) {
34
+ const parsed = JSON.parse(trimmed);
35
+ if (!Array.isArray(parsed)) {
36
+ throwInvalidSolanaKey('JSON input must be an array of bytes.');
37
+ }
38
+ const bytes = parsed.map((value, index) => {
39
+ if (!Number.isInteger(value)) {
40
+ throwInvalidSolanaKey(`JSON byte at index ${index} must be an integer.`);
41
+ }
42
+ if (value < 0 || value > 255) {
43
+ throwInvalidSolanaKey(`JSON byte at index ${index} must be in range 0..255.`);
44
+ }
45
+ return value;
46
+ });
47
+ return toSecretKey(bytes);
48
+ }
49
+ if (trimmed.includes(',')) {
50
+ const bytes = trimmed.split(',').map((segment, index) => {
51
+ const segmentTrimmed = segment.trim();
52
+ if (segmentTrimmed === '') {
53
+ throwInvalidSolanaKey(`Comma-separated byte at index ${index} is empty.`);
54
+ }
55
+ const value = Number(segmentTrimmed);
56
+ if (!Number.isFinite(value)) {
57
+ throwInvalidSolanaKey(`Comma-separated byte at index ${index} is not numeric.`);
58
+ }
59
+ if (!Number.isInteger(value)) {
60
+ throwInvalidSolanaKey(`Comma-separated byte at index ${index} must be an integer.`);
61
+ }
62
+ if (value < 0 || value > 255) {
63
+ throwInvalidSolanaKey(`Comma-separated byte at index ${index} must be in range 0..255.`);
64
+ }
65
+ return value;
66
+ });
67
+ return toSecretKey(bytes);
68
+ }
69
+ try {
70
+ const decoded = bs58.decode(trimmed);
71
+ const bytes = Array.from(decoded);
72
+ return toSecretKey(bytes);
73
+ }
74
+ catch {
75
+ // bs58 decode failed, fall through to outer catch
76
+ }
77
+ }
78
+ catch (error) {
79
+ if (error instanceof Error &&
80
+ error.message.includes(SOLANA_KEY_ERROR_MESSAGE)) {
81
+ throw error;
82
+ }
83
+ throwInvalidSolanaKey('Failed to parse key input.');
84
+ }
85
+ throwInvalidSolanaKey('Failed to match supported format (JSON array, comma-separated bytes, or base58 key).');
86
+ }
87
+ //# sourceMappingURL=solanaKeyParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solanaKeyParser.js","sourceRoot":"","sources":["../../src/utils/solanaKeyParser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qBAAqB,CACnB,iCAAiC,KAAK,2BAA2B,CAClE,CAAC;gBACJ,CAAC;gBAED,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;YAEH,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACrC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACP,kDAAkD;QACpD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,KAAK;YACtB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAChD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,qBAAqB,CAAC,4BAA4B,CAAC,CAAC;IACtD,CAAC;IAED,qBAAqB,CACnB,sFAAsF,CACvF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=solanaKeyParser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solanaKeyParser.test.d.ts","sourceRoot":"","sources":["../../src/utils/solanaKeyParser.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import { expect } from 'chai';
2
+ import { Keypair } from '@solana/web3.js';
3
+ import bs58 from 'bs58';
4
+ import { parseSolanaPrivateKey } from './solanaKeyParser.js';
5
+ describe('parseSolanaPrivateKey', () => {
6
+ it('parses valid 64-byte JSON array', () => {
7
+ const bytes = Array.from({ length: 64 }, (_, i) => i);
8
+ const parsed = parseSolanaPrivateKey(JSON.stringify(bytes));
9
+ expect(parsed).to.be.instanceOf(Uint8Array);
10
+ expect(Array.from(parsed)).to.deep.equal(bytes);
11
+ expect(parsed).to.have.length(64);
12
+ });
13
+ it('parses valid 64-byte comma-separated', () => {
14
+ const bytes = Array.from({ length: 64 }, (_, i) => i);
15
+ const parsed = parseSolanaPrivateKey(bytes.join(','));
16
+ expect(Array.from(parsed)).to.deep.equal(bytes);
17
+ expect(parsed).to.have.length(64);
18
+ });
19
+ it('parses valid 32-byte seed JSON array and expands to 64 bytes', () => {
20
+ const seed = Array.from({ length: 32 }, (_, i) => i);
21
+ const parsed = parseSolanaPrivateKey(JSON.stringify(seed));
22
+ const expected = Keypair.fromSeed(Uint8Array.from(seed)).secretKey;
23
+ expect(parsed).to.have.length(64);
24
+ expect(Array.from(parsed)).to.deep.equal(Array.from(expected));
25
+ });
26
+ it('parses valid 32-byte seed comma-separated and expands to 64 bytes', () => {
27
+ const seed = Array.from({ length: 32 }, (_, i) => i + 1);
28
+ const parsed = parseSolanaPrivateKey(seed.join(','));
29
+ const expected = Keypair.fromSeed(Uint8Array.from(seed)).secretKey;
30
+ expect(parsed).to.have.length(64);
31
+ expect(Array.from(parsed)).to.deep.equal(Array.from(expected));
32
+ });
33
+ it('throws on "1,2,abc,4" (non-numeric)', () => {
34
+ expect(() => parseSolanaPrivateKey('1,2,abc,4')).to.throw('Comma-separated byte at index 2 is not numeric.');
35
+ });
36
+ it('throws on empty string', () => {
37
+ expect(() => parseSolanaPrivateKey(' ')).to.throw('Input is empty.');
38
+ });
39
+ it('throws on "256,1,2" (out of range)', () => {
40
+ expect(() => parseSolanaPrivateKey('256,1,2')).to.throw('Comma-separated byte at index 0 must be in range 0..255.');
41
+ });
42
+ it('throws on "-1,1,2" (negative)', () => {
43
+ expect(() => parseSolanaPrivateKey('-1,1,2')).to.throw('Comma-separated byte at index 0 must be in range 0..255.');
44
+ });
45
+ it('throws on "1.5,2,3" (non-integer)', () => {
46
+ expect(() => parseSolanaPrivateKey('1.5,2,3')).to.throw('Comma-separated byte at index 0 must be an integer.');
47
+ });
48
+ it('throws on 10-byte array (wrong length)', () => {
49
+ const tenBytes = JSON.stringify(Array.from({ length: 10 }, (_, i) => i));
50
+ expect(() => parseSolanaPrivateKey(tenBytes)).to.throw('Received 10 bytes; expected exactly 32 or 64.');
51
+ });
52
+ it('error message contains HYP_INVENTORY_KEY_SEALEVEL', () => {
53
+ expect(() => parseSolanaPrivateKey('not-a-key')).to.throw('HYP_INVENTORY_KEY_SEALEVEL');
54
+ });
55
+ it('parses valid base58-encoded 64-byte key', () => {
56
+ const bytes = Array.from({ length: 64 }, (_, i) => i);
57
+ const base58Key = bs58.encode(Uint8Array.from(bytes));
58
+ const parsed = parseSolanaPrivateKey(base58Key);
59
+ expect(Array.from(parsed)).to.deep.equal(bytes);
60
+ expect(parsed).to.have.length(64);
61
+ });
62
+ it('parses valid base58-encoded 32-byte seed and expands to 64 bytes', () => {
63
+ const seed = Array.from({ length: 32 }, (_, i) => i + 1);
64
+ const base58Seed = bs58.encode(Uint8Array.from(seed));
65
+ const parsed = parseSolanaPrivateKey(base58Seed);
66
+ const expected = Keypair.fromSeed(Uint8Array.from(seed)).secretKey;
67
+ expect(parsed).to.have.length(64);
68
+ expect(Array.from(parsed)).to.deep.equal(Array.from(expected));
69
+ });
70
+ });
71
+ //# sourceMappingURL=solanaKeyParser.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solanaKeyParser.test.js","sourceRoot":"","sources":["../../src/utils/solanaKeyParser.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CA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MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { ExternalBridgeType } from '../config/types.js';
2
+ import { type Token, TokenStandard } from '@humanode-hyperlane/sdk';
3
+ /**
4
+ * Check if a token's balance is the same as native gas balance.
5
+ * For these tokens, we must reserve funds for IGP when calculating max transferable.
6
+ *
7
+ * @param standard - The token standard to check.
8
+ * @returns `true` if the token is a native token standard, `false` otherwise.
9
+ */
10
+ export declare function isNativeTokenStandard(standard: TokenStandard): boolean;
11
+ /**
12
+ * @dev This function exists because the rebalancer currently only supports a subset of collateralized token standards
13
+ * (see `REBALANCEABLE_TOKEN_COLLATERALIZED_STANDARDS` vs. all possible `TOKEN_COLLATERALIZED_STANDARDS`).
14
+ *
15
+ * @deprecated This function is conditionally deprecated. It is intended for removal once the rebalancer
16
+ * achieves full support for all collateralized token standards.
17
+ * After this condition is met and this function is removed, please use `token.isCollateralized()` as the alternative.
18
+ *
19
+ * @param token - The token to be checked for rebalancing eligibility.
20
+ * @returns `true` if the token is of a collateralized standard currently supported by the rebalancer, `false` otherwise.
21
+ */
22
+ export declare function isCollateralizedTokenEligibleForRebalancing(token: Token): boolean;
23
+ /**
24
+ * Resolves the correct token address for external bridges (e.g. LiFi).
25
+ *
26
+ * For warp route tokens, `addressOrDenom` is the warp router contract address,
27
+ * NOT the underlying token. External bridges need the actual token address:
28
+ * - Native tokens (EvmHypNative, SealevelHypNative): Use the bridge's native token representation
29
+ * - Collateral tokens (EvmHypCollateral, SealevelHypCollateral): Use `collateralAddressOrDenom` (the underlying token)
30
+ * - Synthetic tokens: `collateralAddressOrDenom` is undefined, `addressOrDenom` IS the token
31
+ *
32
+ * @param token - The warp route token to resolve
33
+ * @param externalBridgeType - The type of external bridge (e.g. 'lifi')
34
+ * @param getNativeTokenAddress - Function to get the bridge's native token representation
35
+ * @returns The correct token address for the external bridge
36
+ */
37
+ export declare function getExternalBridgeTokenAddress(token: Token, externalBridgeType: ExternalBridgeType, getNativeTokenAddress: (type: ExternalBridgeType) => string): string;
38
+ //# sourceMappingURL=tokenUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tokenUtils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EAEL,KAAK,KAAK,EACV,aAAa,EACd,MAAM,yBAAyB,CAAC;AAkBjC;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAEtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2CAA2C,CACzD,KAAK,EAAE,KAAK,GACX,OAAO,CAKT;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,KAAK,EACZ,kBAAkB,EAAE,kBAAkB,EACtC,qBAAqB,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,MAAM,GAC1D,MAAM,CAaR"}
@@ -0,0 +1,65 @@
1
+ import { ProtocolType, assert } from '@humanode-hyperlane/utils';
2
+ import { PROTOCOL_TO_HYP_NATIVE_STANDARD, TokenStandard, } from '@humanode-hyperlane/sdk';
3
+ const REBALANCEABLE_TOKEN_COLLATERALIZED_STANDARDS = new Set([
4
+ TokenStandard.EvmHypCollateral,
5
+ TokenStandard.EvmHypNative,
6
+ TokenStandard.SealevelHypCollateral,
7
+ TokenStandard.SealevelHypNative,
8
+ ]);
9
+ // SDK-backed native token standard check scoped to EVM and Sealevel only (2-protocol scope).
10
+ // NOTE: We intentionally do NOT use the full PROTOCOL_TO_HYP_NATIVE_STANDARD map (all 7 protocols)
11
+ // because the rebalancer only supports EVM and Sealevel native token bridging.
12
+ // Expanding this would change gas reservation behavior for other protocols.
13
+ const REBALANCER_NATIVE_STANDARDS = new Set([
14
+ PROTOCOL_TO_HYP_NATIVE_STANDARD[ProtocolType.Ethereum],
15
+ PROTOCOL_TO_HYP_NATIVE_STANDARD[ProtocolType.Sealevel],
16
+ ]);
17
+ /**
18
+ * Check if a token's balance is the same as native gas balance.
19
+ * For these tokens, we must reserve funds for IGP when calculating max transferable.
20
+ *
21
+ * @param standard - The token standard to check.
22
+ * @returns `true` if the token is a native token standard, `false` otherwise.
23
+ */
24
+ export function isNativeTokenStandard(standard) {
25
+ return REBALANCER_NATIVE_STANDARDS.has(standard);
26
+ }
27
+ /**
28
+ * @dev This function exists because the rebalancer currently only supports a subset of collateralized token standards
29
+ * (see `REBALANCEABLE_TOKEN_COLLATERALIZED_STANDARDS` vs. all possible `TOKEN_COLLATERALIZED_STANDARDS`).
30
+ *
31
+ * @deprecated This function is conditionally deprecated. It is intended for removal once the rebalancer
32
+ * achieves full support for all collateralized token standards.
33
+ * After this condition is met and this function is removed, please use `token.isCollateralized()` as the alternative.
34
+ *
35
+ * @param token - The token to be checked for rebalancing eligibility.
36
+ * @returns `true` if the token is of a collateralized standard currently supported by the rebalancer, `false` otherwise.
37
+ */
38
+ export function isCollateralizedTokenEligibleForRebalancing(token) {
39
+ return (token.isCollateralized() &&
40
+ REBALANCEABLE_TOKEN_COLLATERALIZED_STANDARDS.has(token.standard));
41
+ }
42
+ /**
43
+ * Resolves the correct token address for external bridges (e.g. LiFi).
44
+ *
45
+ * For warp route tokens, `addressOrDenom` is the warp router contract address,
46
+ * NOT the underlying token. External bridges need the actual token address:
47
+ * - Native tokens (EvmHypNative, SealevelHypNative): Use the bridge's native token representation
48
+ * - Collateral tokens (EvmHypCollateral, SealevelHypCollateral): Use `collateralAddressOrDenom` (the underlying token)
49
+ * - Synthetic tokens: `collateralAddressOrDenom` is undefined, `addressOrDenom` IS the token
50
+ *
51
+ * @param token - The warp route token to resolve
52
+ * @param externalBridgeType - The type of external bridge (e.g. 'lifi')
53
+ * @param getNativeTokenAddress - Function to get the bridge's native token representation
54
+ * @returns The correct token address for the external bridge
55
+ */
56
+ export function getExternalBridgeTokenAddress(token, externalBridgeType, getNativeTokenAddress) {
57
+ if (isNativeTokenStandard(token.standard)) {
58
+ return getNativeTokenAddress(externalBridgeType);
59
+ }
60
+ if (token.collateralAddressOrDenom)
61
+ return token.collateralAddressOrDenom;
62
+ assert(!REBALANCEABLE_TOKEN_COLLATERALIZED_STANDARDS.has(token.standard), `Missing collateralAddressOrDenom for collateralized token on ${token.chainName} (${token.standard})`);
63
+ return token.addressOrDenom;
64
+ }
65
+ //# sourceMappingURL=tokenUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenUtils.js","sourceRoot":"","sources":["../../src/utils/tokenUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAIjE,OAAO,EACL,+BAA+B,EAE/B,aAAa,GACd,MAAM,yBAAyB,CAAC;AAEjC,MAAM,4CAA4C,GAAG,IAAI,GAAG,CAAgB;IAC1E,aAAa,CAAC,gBAAgB;IAC9B,aAAa,CAAC,YAAY;IAC1B,aAAa,CAAC,qBAAqB;IACnC,aAAa,CAAC,iBAAiB;CAChC,CAAC,CAAC;AAEH,6FAA6F;AAC7F,mGAAmG;AACnG,+EAA+E;AAC/E,4EAA4E;AAC5E,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAC;IAC1C,+BAA+B,CAAC,YAAY,CAAC,QAAQ,CAAC;IACtD,+BAA+B,CAAC,YAAY,CAAC,QAAQ,CAAC;CACvD,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAuB;IAC3D,OAAO,2BAA2B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,2CAA2C,CACzD,KAAY;IAEZ,OAAO,CACL,KAAK,CAAC,gBAAgB,EAAE;QACxB,4CAA4C,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CACjE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,6BAA6B,CAC3C,KAAY,EACZ,kBAAsC,EACtC,qBAA2D;IAE3D,IAAI,qBAAqB,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,OAAO,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,KAAK,CAAC,wBAAwB;QAAE,OAAO,KAAK,CAAC,wBAAwB,CAAC;IAE1E,MAAM,CACJ,CAAC,4CAA4C,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EACjE,gEAAgE,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,QAAQ,GAAG,CACtG,CAAC;IAEF,OAAO,KAAK,CAAC,cAAc,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type ProtocolType } from '@humanode-hyperlane/utils';
2
+ import { type ProtocolTypedTransaction, type WarpTypedTransaction } from '@humanode-hyperlane/sdk';
3
+ /**
4
+ * Runtime-validated cast from WarpTypedTransaction to ProtocolTypedTransaction.
5
+ * WarpTypedTransaction extends TypedTransaction but ProtocolTypedTransaction
6
+ * only covers known protocol types.
7
+ * Safe at runtime because WarpCore only produces default-provider transactions.
8
+ *
9
+ * The double-cast (as unknown as) is unavoidable due to TypeScript's type narrowing
10
+ * limitations: WarpTypedTransaction is a union of all protocol transaction types,
11
+ * and ProtocolTypedTransaction<P> is a conditional/mapped type. Even after the
12
+ * runtime assert() proves type safety, TypeScript cannot narrow the union across
13
+ * this structural boundary. The cast is safe because the assert validates the
14
+ * transaction type matches the expected protocol at runtime.
15
+ *
16
+ * @param tx - The transaction to cast
17
+ * @param expectedProtocol - The expected protocol type
18
+ * @returns The transaction cast to ProtocolTypedTransaction
19
+ * @throws Error if the transaction type doesn't match the expected protocol
20
+ */
21
+ export declare function toProtocolTransaction(tx: WarpTypedTransaction, expectedProtocol: ProtocolType): ProtocolTypedTransaction<ProtocolType>;
22
+ //# sourceMappingURL=transactionUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,oBAAoB,EACxB,gBAAgB,EAAE,YAAY,GAC7B,wBAAwB,CAAC,YAAY,CAAC,CAQxC"}
@@ -0,0 +1,26 @@
1
+ import { assert, } from '@humanode-hyperlane/utils';
2
+ import { PROTOCOL_TO_DEFAULT_PROVIDER_TYPE, } from '@humanode-hyperlane/sdk';
3
+ /**
4
+ * Runtime-validated cast from WarpTypedTransaction to ProtocolTypedTransaction.
5
+ * WarpTypedTransaction extends TypedTransaction but ProtocolTypedTransaction
6
+ * only covers known protocol types.
7
+ * Safe at runtime because WarpCore only produces default-provider transactions.
8
+ *
9
+ * The double-cast (as unknown as) is unavoidable due to TypeScript's type narrowing
10
+ * limitations: WarpTypedTransaction is a union of all protocol transaction types,
11
+ * and ProtocolTypedTransaction<P> is a conditional/mapped type. Even after the
12
+ * runtime assert() proves type safety, TypeScript cannot narrow the union across
13
+ * this structural boundary. The cast is safe because the assert validates the
14
+ * transaction type matches the expected protocol at runtime.
15
+ *
16
+ * @param tx - The transaction to cast
17
+ * @param expectedProtocol - The expected protocol type
18
+ * @returns The transaction cast to ProtocolTypedTransaction
19
+ * @throws Error if the transaction type doesn't match the expected protocol
20
+ */
21
+ export function toProtocolTransaction(tx, expectedProtocol) {
22
+ const expectedType = PROTOCOL_TO_DEFAULT_PROVIDER_TYPE[expectedProtocol];
23
+ assert(expectedType && tx.type === expectedType, `Transaction type ${tx.type} doesn't match expected protocol ${expectedProtocol} (expected ${expectedType})`);
24
+ return tx;
25
+ }
26
+ //# sourceMappingURL=transactionUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactionUtils.js","sourceRoot":"","sources":["../../src/utils/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,GAGP,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iCAAiC,GAGlC,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,qBAAqB,CACnC,EAAwB,EACxB,gBAA8B;IAE9B,MAAM,YAAY,GAChB,iCAAiC,CAAC,gBAAqC,CAAC,CAAC;IAC3E,MAAM,CACJ,YAAY,IAAI,EAAE,CAAC,IAAI,KAAK,YAAY,EACxC,oBAAoB,EAAE,CAAC,IAAI,oCAAoC,gBAAgB,cAAc,YAAY,GAAG,CAC7G,CAAC;IACF,OAAO,EAAuD,CAAC;AACjE,CAAC"}