@humanode-hyperlane/rebalancer 0.0.0-stage → 27.2.2
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.
- package/LICENSE.md +193 -0
- package/README.md +297 -2
- package/dist/bridges/LiFiBridge.d.ts +93 -0
- package/dist/bridges/LiFiBridge.d.ts.map +1 -0
- package/dist/bridges/LiFiBridge.js +527 -0
- package/dist/bridges/LiFiBridge.js.map +1 -0
- package/dist/bridges/LiFiBridge.test.d.ts +2 -0
- package/dist/bridges/LiFiBridge.test.d.ts.map +1 -0
- package/dist/bridges/LiFiBridge.test.js +504 -0
- package/dist/bridges/LiFiBridge.test.js.map +1 -0
- package/dist/config/RebalancerConfig.d.ts +20 -0
- package/dist/config/RebalancerConfig.d.ts.map +1 -0
- package/dist/config/RebalancerConfig.js +35 -0
- package/dist/config/RebalancerConfig.js.map +1 -0
- package/dist/config/RebalancerConfig.test.d.ts +2 -0
- package/dist/config/RebalancerConfig.test.d.ts.map +1 -0
- package/dist/config/RebalancerConfig.test.js +798 -0
- package/dist/config/RebalancerConfig.test.js.map +1 -0
- package/dist/config/types.d.ts +3008 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +451 -0
- package/dist/config/types.js.map +1 -0
- package/dist/core/InventoryRebalancer.d.ts +201 -0
- package/dist/core/InventoryRebalancer.d.ts.map +1 -0
- package/dist/core/InventoryRebalancer.js +994 -0
- package/dist/core/InventoryRebalancer.js.map +1 -0
- package/dist/core/InventoryRebalancer.test.d.ts +2 -0
- package/dist/core/InventoryRebalancer.test.d.ts.map +1 -0
- package/dist/core/InventoryRebalancer.test.js +1511 -0
- package/dist/core/InventoryRebalancer.test.js.map +1 -0
- package/dist/core/Rebalancer.d.ts +37 -0
- package/dist/core/Rebalancer.d.ts.map +1 -0
- package/dist/core/Rebalancer.js +433 -0
- package/dist/core/Rebalancer.js.map +1 -0
- package/dist/core/Rebalancer.test.d.ts +2 -0
- package/dist/core/Rebalancer.test.d.ts.map +1 -0
- package/dist/core/Rebalancer.test.js +424 -0
- package/dist/core/Rebalancer.test.js.map +1 -0
- package/dist/core/RebalancerOrchestrator.d.ts +56 -0
- package/dist/core/RebalancerOrchestrator.d.ts.map +1 -0
- package/dist/core/RebalancerOrchestrator.js +154 -0
- package/dist/core/RebalancerOrchestrator.js.map +1 -0
- package/dist/core/RebalancerOrchestrator.test.d.ts +2 -0
- package/dist/core/RebalancerOrchestrator.test.d.ts.map +1 -0
- package/dist/core/RebalancerOrchestrator.test.js +721 -0
- package/dist/core/RebalancerOrchestrator.test.js.map +1 -0
- package/dist/core/RebalancerService.d.ts +127 -0
- package/dist/core/RebalancerService.d.ts.map +1 -0
- package/dist/core/RebalancerService.js +270 -0
- package/dist/core/RebalancerService.js.map +1 -0
- package/dist/core/RebalancerService.test.d.ts +2 -0
- package/dist/core/RebalancerService.test.d.ts.map +1 -0
- package/dist/core/RebalancerService.test.js +777 -0
- package/dist/core/RebalancerService.test.js.map +1 -0
- package/dist/e2e/collateral-deficit.e2e-test.d.ts +2 -0
- package/dist/e2e/collateral-deficit.e2e-test.d.ts.map +1 -0
- package/dist/e2e/collateral-deficit.e2e-test.js +227 -0
- package/dist/e2e/collateral-deficit.e2e-test.js.map +1 -0
- package/dist/e2e/composite.e2e-test.d.ts +2 -0
- package/dist/e2e/composite.e2e-test.d.ts.map +1 -0
- package/dist/e2e/composite.e2e-test.js +666 -0
- package/dist/e2e/composite.e2e-test.js.map +1 -0
- package/dist/e2e/fixtures/routes.d.ts +89 -0
- package/dist/e2e/fixtures/routes.d.ts.map +1 -0
- package/dist/e2e/fixtures/routes.js +420 -0
- package/dist/e2e/fixtures/routes.js.map +1 -0
- package/dist/e2e/harness/BaseLocalDeploymentManager.d.ts +38 -0
- package/dist/e2e/harness/BaseLocalDeploymentManager.d.ts.map +1 -0
- package/dist/e2e/harness/BaseLocalDeploymentManager.js +144 -0
- package/dist/e2e/harness/BaseLocalDeploymentManager.js.map +1 -0
- package/dist/e2e/harness/BridgeSetup.d.ts +11 -0
- package/dist/e2e/harness/BridgeSetup.d.ts.map +1 -0
- package/dist/e2e/harness/BridgeSetup.js +50 -0
- package/dist/e2e/harness/BridgeSetup.js.map +1 -0
- package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.d.ts +13 -0
- package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.d.ts.map +1 -0
- package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.js +105 -0
- package/dist/e2e/harness/Erc20InventoryLocalDeploymentManager.js.map +1 -0
- package/dist/e2e/harness/Erc20LocalDeploymentManager.d.ts +11 -0
- package/dist/e2e/harness/Erc20LocalDeploymentManager.d.ts.map +1 -0
- package/dist/e2e/harness/Erc20LocalDeploymentManager.js +105 -0
- package/dist/e2e/harness/Erc20LocalDeploymentManager.js.map +1 -0
- package/dist/e2e/harness/ForkIndexer.d.ts +23 -0
- package/dist/e2e/harness/ForkIndexer.d.ts.map +1 -0
- package/dist/e2e/harness/ForkIndexer.js +127 -0
- package/dist/e2e/harness/ForkIndexer.js.map +1 -0
- package/dist/e2e/harness/ForkIndexer.test.d.ts +2 -0
- package/dist/e2e/harness/ForkIndexer.test.d.ts.map +1 -0
- package/dist/e2e/harness/ForkIndexer.test.js +257 -0
- package/dist/e2e/harness/ForkIndexer.test.js.map +1 -0
- package/dist/e2e/harness/MixedLocalDeploymentManager.d.ts +21 -0
- package/dist/e2e/harness/MixedLocalDeploymentManager.d.ts.map +1 -0
- package/dist/e2e/harness/MixedLocalDeploymentManager.js +115 -0
- package/dist/e2e/harness/MixedLocalDeploymentManager.js.map +1 -0
- package/dist/e2e/harness/MockExplorerClient.d.ts +23 -0
- package/dist/e2e/harness/MockExplorerClient.d.ts.map +1 -0
- package/dist/e2e/harness/MockExplorerClient.js +57 -0
- package/dist/e2e/harness/MockExplorerClient.js.map +1 -0
- package/dist/e2e/harness/MockExternalBridge.d.ts +32 -0
- package/dist/e2e/harness/MockExternalBridge.d.ts.map +1 -0
- package/dist/e2e/harness/MockExternalBridge.js +247 -0
- package/dist/e2e/harness/MockExternalBridge.js.map +1 -0
- package/dist/e2e/harness/NativeLocalDeploymentManager.d.ts +13 -0
- package/dist/e2e/harness/NativeLocalDeploymentManager.d.ts.map +1 -0
- package/dist/e2e/harness/NativeLocalDeploymentManager.js +91 -0
- package/dist/e2e/harness/NativeLocalDeploymentManager.js.map +1 -0
- package/dist/e2e/harness/SnapshotHelper.d.ts +13 -0
- package/dist/e2e/harness/SnapshotHelper.d.ts.map +1 -0
- package/dist/e2e/harness/SnapshotHelper.js +36 -0
- package/dist/e2e/harness/SnapshotHelper.js.map +1 -0
- package/dist/e2e/harness/TestHelpers.d.ts +25 -0
- package/dist/e2e/harness/TestHelpers.d.ts.map +1 -0
- package/dist/e2e/harness/TestHelpers.js +103 -0
- package/dist/e2e/harness/TestHelpers.js.map +1 -0
- package/dist/e2e/harness/TestRebalancer.d.ts +85 -0
- package/dist/e2e/harness/TestRebalancer.d.ts.map +1 -0
- package/dist/e2e/harness/TestRebalancer.js +427 -0
- package/dist/e2e/harness/TestRebalancer.js.map +1 -0
- package/dist/e2e/harness/TransferHelper.d.ts +34 -0
- package/dist/e2e/harness/TransferHelper.d.ts.map +1 -0
- package/dist/e2e/harness/TransferHelper.js +93 -0
- package/dist/e2e/harness/TransferHelper.js.map +1 -0
- package/dist/e2e/inventory-erc20-minAmount.e2e-test.d.ts +2 -0
- package/dist/e2e/inventory-erc20-minAmount.e2e-test.d.ts.map +1 -0
- package/dist/e2e/inventory-erc20-minAmount.e2e-test.js +411 -0
- package/dist/e2e/inventory-erc20-minAmount.e2e-test.js.map +1 -0
- package/dist/e2e/inventory-erc20-weighted.e2e-test.d.ts +2 -0
- package/dist/e2e/inventory-erc20-weighted.e2e-test.d.ts.map +1 -0
- package/dist/e2e/inventory-erc20-weighted.e2e-test.js +408 -0
- package/dist/e2e/inventory-erc20-weighted.e2e-test.js.map +1 -0
- package/dist/e2e/inventory-minAmount.e2e-test.d.ts +2 -0
- package/dist/e2e/inventory-minAmount.e2e-test.d.ts.map +1 -0
- package/dist/e2e/inventory-minAmount.e2e-test.js +411 -0
- package/dist/e2e/inventory-minAmount.e2e-test.js.map +1 -0
- package/dist/e2e/inventory-weighted.e2e-test.d.ts +2 -0
- package/dist/e2e/inventory-weighted.e2e-test.d.ts.map +1 -0
- package/dist/e2e/inventory-weighted.e2e-test.js +409 -0
- package/dist/e2e/inventory-weighted.e2e-test.js.map +1 -0
- package/dist/e2e/minAmount.e2e-test.d.ts +2 -0
- package/dist/e2e/minAmount.e2e-test.d.ts.map +1 -0
- package/dist/e2e/minAmount.e2e-test.js +203 -0
- package/dist/e2e/minAmount.e2e-test.js.map +1 -0
- package/dist/e2e/mixed-weighted.e2e-test.d.ts +2 -0
- package/dist/e2e/mixed-weighted.e2e-test.d.ts.map +1 -0
- package/dist/e2e/mixed-weighted.e2e-test.js +189 -0
- package/dist/e2e/mixed-weighted.e2e-test.js.map +1 -0
- package/dist/e2e/weighted.e2e-test.d.ts +2 -0
- package/dist/e2e/weighted.e2e-test.d.ts.map +1 -0
- package/dist/e2e/weighted.e2e-test.js +198 -0
- package/dist/e2e/weighted.e2e-test.js.map +1 -0
- package/dist/factories/RebalancerContextFactory.d.ts +89 -0
- package/dist/factories/RebalancerContextFactory.d.ts.map +1 -0
- package/dist/factories/RebalancerContextFactory.js +420 -0
- package/dist/factories/RebalancerContextFactory.js.map +1 -0
- package/dist/factories/RebalancerContextFactory.test.d.ts +2 -0
- package/dist/factories/RebalancerContextFactory.test.d.ts.map +1 -0
- package/dist/factories/RebalancerContextFactory.test.js +270 -0
- package/dist/factories/RebalancerContextFactory.test.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/IExternalBridge.d.ts +103 -0
- package/dist/interfaces/IExternalBridge.d.ts.map +1 -0
- package/dist/interfaces/IExternalBridge.js +2 -0
- package/dist/interfaces/IExternalBridge.js.map +1 -0
- package/dist/interfaces/IMetrics.d.ts +5 -0
- package/dist/interfaces/IMetrics.d.ts.map +1 -0
- package/dist/interfaces/IMetrics.js +2 -0
- package/dist/interfaces/IMetrics.js.map +1 -0
- package/dist/interfaces/IMonitor.d.ts +50 -0
- package/dist/interfaces/IMonitor.d.ts.map +1 -0
- package/dist/interfaces/IMonitor.js +14 -0
- package/dist/interfaces/IMonitor.js.map +1 -0
- package/dist/interfaces/IRebalancer.d.ts +31 -0
- package/dist/interfaces/IRebalancer.d.ts.map +1 -0
- package/dist/interfaces/IRebalancer.js +2 -0
- package/dist/interfaces/IRebalancer.js.map +1 -0
- package/dist/interfaces/IStrategy.d.ts +60 -0
- package/dist/interfaces/IStrategy.d.ts.map +1 -0
- package/dist/interfaces/IStrategy.js +13 -0
- package/dist/interfaces/IStrategy.js.map +1 -0
- package/dist/metrics/Metrics.d.ts +25 -0
- package/dist/metrics/Metrics.d.ts.map +1 -0
- package/dist/metrics/Metrics.js +164 -0
- package/dist/metrics/Metrics.js.map +1 -0
- package/dist/metrics/PriceGetter.d.ts +10 -0
- package/dist/metrics/PriceGetter.d.ts.map +1 -0
- package/dist/metrics/PriceGetter.js +41 -0
- package/dist/metrics/PriceGetter.js.map +1 -0
- package/dist/metrics/scripts/metrics.d.ts +28 -0
- package/dist/metrics/scripts/metrics.d.ts.map +1 -0
- package/dist/metrics/scripts/metrics.js +61 -0
- package/dist/metrics/scripts/metrics.js.map +1 -0
- package/dist/monitor/Monitor.d.ts +40 -0
- package/dist/monitor/Monitor.d.ts.map +1 -0
- package/dist/monitor/Monitor.js +211 -0
- package/dist/monitor/Monitor.js.map +1 -0
- package/dist/service.d.ts +3 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +205 -0
- package/dist/service.js.map +1 -0
- package/dist/strategy/BaseStrategy.d.ts +86 -0
- package/dist/strategy/BaseStrategy.d.ts.map +1 -0
- package/dist/strategy/BaseStrategy.js +342 -0
- package/dist/strategy/BaseStrategy.js.map +1 -0
- package/dist/strategy/CollateralDeficitStrategy.d.ts +65 -0
- package/dist/strategy/CollateralDeficitStrategy.d.ts.map +1 -0
- package/dist/strategy/CollateralDeficitStrategy.js +253 -0
- package/dist/strategy/CollateralDeficitStrategy.js.map +1 -0
- package/dist/strategy/CollateralDeficitStrategy.test.d.ts +2 -0
- package/dist/strategy/CollateralDeficitStrategy.test.d.ts.map +1 -0
- package/dist/strategy/CollateralDeficitStrategy.test.js +497 -0
- package/dist/strategy/CollateralDeficitStrategy.test.js.map +1 -0
- package/dist/strategy/CompositeStrategy.d.ts +18 -0
- package/dist/strategy/CompositeStrategy.d.ts.map +1 -0
- package/dist/strategy/CompositeStrategy.js +63 -0
- package/dist/strategy/CompositeStrategy.js.map +1 -0
- package/dist/strategy/CompositeStrategy.test.d.ts +2 -0
- package/dist/strategy/CompositeStrategy.test.d.ts.map +1 -0
- package/dist/strategy/CompositeStrategy.test.js +278 -0
- package/dist/strategy/CompositeStrategy.test.js.map +1 -0
- package/dist/strategy/MinAmountStrategy.d.ts +35 -0
- package/dist/strategy/MinAmountStrategy.d.ts.map +1 -0
- package/dist/strategy/MinAmountStrategy.js +112 -0
- package/dist/strategy/MinAmountStrategy.js.map +1 -0
- package/dist/strategy/MinAmountStrategy.test.d.ts +2 -0
- package/dist/strategy/MinAmountStrategy.test.d.ts.map +1 -0
- package/dist/strategy/MinAmountStrategy.test.js +547 -0
- package/dist/strategy/MinAmountStrategy.test.js.map +1 -0
- package/dist/strategy/StrategyFactory.d.ts +27 -0
- package/dist/strategy/StrategyFactory.d.ts.map +1 -0
- package/dist/strategy/StrategyFactory.js +79 -0
- package/dist/strategy/StrategyFactory.js.map +1 -0
- package/dist/strategy/StrategyFactory.test.d.ts +2 -0
- package/dist/strategy/StrategyFactory.test.d.ts.map +1 -0
- package/dist/strategy/StrategyFactory.test.js +81 -0
- package/dist/strategy/StrategyFactory.test.js.map +1 -0
- package/dist/strategy/WeightedStrategy.d.ts +32 -0
- package/dist/strategy/WeightedStrategy.d.ts.map +1 -0
- package/dist/strategy/WeightedStrategy.js +73 -0
- package/dist/strategy/WeightedStrategy.js.map +1 -0
- package/dist/strategy/WeightedStrategy.test.d.ts +2 -0
- package/dist/strategy/WeightedStrategy.test.d.ts.map +1 -0
- package/dist/strategy/WeightedStrategy.test.js +403 -0
- package/dist/strategy/WeightedStrategy.test.js.map +1 -0
- package/dist/strategy/index.d.ts +7 -0
- package/dist/strategy/index.d.ts.map +1 -0
- package/dist/strategy/index.js +7 -0
- package/dist/strategy/index.js.map +1 -0
- package/dist/test/helpers.d.ts +99 -0
- package/dist/test/helpers.d.ts.map +1 -0
- package/dist/test/helpers.js +311 -0
- package/dist/test/helpers.js.map +1 -0
- package/dist/test/lifiMocks.d.ts +52 -0
- package/dist/test/lifiMocks.d.ts.map +1 -0
- package/dist/test/lifiMocks.js +160 -0
- package/dist/test/lifiMocks.js.map +1 -0
- package/dist/tracking/ActionTracker.d.ts +90 -0
- package/dist/tracking/ActionTracker.d.ts.map +1 -0
- package/dist/tracking/ActionTracker.js +678 -0
- package/dist/tracking/ActionTracker.js.map +1 -0
- package/dist/tracking/ActionTracker.test.d.ts +2 -0
- package/dist/tracking/ActionTracker.test.d.ts.map +1 -0
- package/dist/tracking/ActionTracker.test.js +1351 -0
- package/dist/tracking/ActionTracker.test.js.map +1 -0
- package/dist/tracking/IActionTracker.d.ts +157 -0
- package/dist/tracking/IActionTracker.d.ts.map +1 -0
- package/dist/tracking/IActionTracker.js +2 -0
- package/dist/tracking/IActionTracker.js.map +1 -0
- package/dist/tracking/InflightContextAdapter.d.ts +18 -0
- package/dist/tracking/InflightContextAdapter.d.ts.map +1 -0
- package/dist/tracking/InflightContextAdapter.js +52 -0
- package/dist/tracking/InflightContextAdapter.js.map +1 -0
- package/dist/tracking/InflightContextAdapter.test.d.ts +2 -0
- package/dist/tracking/InflightContextAdapter.test.d.ts.map +1 -0
- package/dist/tracking/InflightContextAdapter.test.js +175 -0
- package/dist/tracking/InflightContextAdapter.test.js.map +1 -0
- package/dist/tracking/store/IStore.d.ts +41 -0
- package/dist/tracking/store/IStore.d.ts.map +1 -0
- package/dist/tracking/store/IStore.js +2 -0
- package/dist/tracking/store/IStore.js.map +1 -0
- package/dist/tracking/store/InMemoryStore.d.ts +21 -0
- package/dist/tracking/store/InMemoryStore.d.ts.map +1 -0
- package/dist/tracking/store/InMemoryStore.js +40 -0
- package/dist/tracking/store/InMemoryStore.js.map +1 -0
- package/dist/tracking/store/InMemoryStore.test.d.ts +2 -0
- package/dist/tracking/store/InMemoryStore.test.d.ts.map +1 -0
- package/dist/tracking/store/InMemoryStore.test.js +290 -0
- package/dist/tracking/store/InMemoryStore.test.js.map +1 -0
- package/dist/tracking/store/index.d.ts +3 -0
- package/dist/tracking/store/index.d.ts.map +1 -0
- package/dist/tracking/store/index.js +2 -0
- package/dist/tracking/store/index.js.map +1 -0
- package/dist/tracking/types.d.ts +77 -0
- package/dist/tracking/types.d.ts.map +1 -0
- package/dist/tracking/types.js +2 -0
- package/dist/tracking/types.js.map +1 -0
- package/dist/utils/ExplorerClient.d.ts +68 -0
- package/dist/utils/ExplorerClient.d.ts.map +1 -0
- package/dist/utils/ExplorerClient.js +324 -0
- package/dist/utils/ExplorerClient.js.map +1 -0
- package/dist/utils/ExplorerClient.test.d.ts +2 -0
- package/dist/utils/ExplorerClient.test.d.ts.map +1 -0
- package/dist/utils/ExplorerClient.test.js +261 -0
- package/dist/utils/ExplorerClient.test.js.map +1 -0
- package/dist/utils/balanceUtils.d.ts +12 -0
- package/dist/utils/balanceUtils.d.ts.map +1 -0
- package/dist/utils/balanceUtils.js +40 -0
- package/dist/utils/balanceUtils.js.map +1 -0
- package/dist/utils/balanceUtils.test.d.ts +2 -0
- package/dist/utils/balanceUtils.test.d.ts.map +1 -0
- package/dist/utils/balanceUtils.test.js +55 -0
- package/dist/utils/balanceUtils.test.js.map +1 -0
- package/dist/utils/blockTag.d.ts +14 -0
- package/dist/utils/blockTag.d.ts.map +1 -0
- package/dist/utils/blockTag.js +46 -0
- package/dist/utils/blockTag.js.map +1 -0
- package/dist/utils/bridgeUtils.d.ts +40 -0
- package/dist/utils/bridgeUtils.d.ts.map +1 -0
- package/dist/utils/bridgeUtils.js +54 -0
- package/dist/utils/bridgeUtils.js.map +1 -0
- package/dist/utils/bridgeUtils.test.d.ts +2 -0
- package/dist/utils/bridgeUtils.test.d.ts.map +1 -0
- package/dist/utils/bridgeUtils.test.js +163 -0
- package/dist/utils/bridgeUtils.test.js.map +1 -0
- package/dist/utils/errors.d.ts +4 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +6 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/gasEstimation.d.ts +65 -0
- package/dist/utils/gasEstimation.d.ts.map +1 -0
- package/dist/utils/gasEstimation.js +206 -0
- package/dist/utils/gasEstimation.js.map +1 -0
- package/dist/utils/solanaKeyParser.d.ts +10 -0
- package/dist/utils/solanaKeyParser.d.ts.map +1 -0
- package/dist/utils/solanaKeyParser.js +87 -0
- package/dist/utils/solanaKeyParser.js.map +1 -0
- package/dist/utils/solanaKeyParser.test.d.ts +2 -0
- package/dist/utils/solanaKeyParser.test.d.ts.map +1 -0
- package/dist/utils/solanaKeyParser.test.js +71 -0
- package/dist/utils/solanaKeyParser.test.js.map +1 -0
- package/dist/utils/tokenUtils.d.ts +38 -0
- package/dist/utils/tokenUtils.d.ts.map +1 -0
- package/dist/utils/tokenUtils.js +65 -0
- package/dist/utils/tokenUtils.js.map +1 -0
- package/dist/utils/transactionUtils.d.ts +22 -0
- package/dist/utils/transactionUtils.d.ts.map +1 -0
- package/dist/utils/transactionUtils.js +26 -0
- package/dist/utils/transactionUtils.js.map +1 -0
- package/package.json +87 -3
- package/src/bridges/LiFiBridge.test.ts +615 -0
- package/src/bridges/LiFiBridge.ts +731 -0
- package/src/config/RebalancerConfig.test.ts +921 -0
- package/src/config/RebalancerConfig.ts +63 -0
- package/src/config/types.ts +613 -0
- package/src/core/InventoryRebalancer.test.ts +1858 -0
- package/src/core/InventoryRebalancer.ts +1455 -0
- package/src/core/Rebalancer.test.ts +686 -0
- package/src/core/Rebalancer.ts +686 -0
- package/src/core/RebalancerOrchestrator.test.ts +871 -0
- package/src/core/RebalancerOrchestrator.ts +273 -0
- package/src/core/RebalancerService.test.ts +1094 -0
- package/src/core/RebalancerService.ts +412 -0
- package/src/e2e/E2E_TEST_CONVENTIONS.md +222 -0
- package/src/e2e/collateral-deficit.e2e-test.ts +403 -0
- package/src/e2e/composite.e2e-test.ts +1008 -0
- package/src/e2e/fixtures/routes.ts +532 -0
- package/src/e2e/harness/BaseLocalDeploymentManager.ts +246 -0
- package/src/e2e/harness/BridgeSetup.ts +95 -0
- package/src/e2e/harness/Erc20InventoryLocalDeploymentManager.ts +183 -0
- package/src/e2e/harness/Erc20LocalDeploymentManager.ts +190 -0
- package/src/e2e/harness/ForkIndexer.test.ts +448 -0
- package/src/e2e/harness/ForkIndexer.ts +183 -0
- package/src/e2e/harness/MixedLocalDeploymentManager.ts +196 -0
- package/src/e2e/harness/MockExplorerClient.ts +94 -0
- package/src/e2e/harness/MockExternalBridge.ts +411 -0
- package/src/e2e/harness/NativeLocalDeploymentManager.ts +138 -0
- package/src/e2e/harness/SnapshotHelper.ts +56 -0
- package/src/e2e/harness/TestHelpers.ts +169 -0
- package/src/e2e/harness/TestRebalancer.ts +758 -0
- package/src/e2e/harness/TransferHelper.ts +188 -0
- package/src/e2e/inventory-erc20-minAmount.e2e-test.ts +735 -0
- package/src/e2e/inventory-erc20-weighted.e2e-test.ts +733 -0
- package/src/e2e/inventory-minAmount.e2e-test.ts +734 -0
- package/src/e2e/inventory-weighted.e2e-test.ts +734 -0
- package/src/e2e/minAmount.e2e-test.ts +313 -0
- package/src/e2e/mixed-weighted.e2e-test.ts +267 -0
- package/src/e2e/weighted.e2e-test.ts +304 -0
- package/src/factories/RebalancerContextFactory.test.ts +394 -0
- package/src/factories/RebalancerContextFactory.ts +771 -0
- package/src/index.ts +125 -0
- package/src/interfaces/IExternalBridge.ts +117 -0
- package/src/interfaces/IMetrics.ts +5 -0
- package/src/interfaces/IMonitor.ts +71 -0
- package/src/interfaces/IRebalancer.ts +57 -0
- package/src/interfaces/IStrategy.ts +81 -0
- package/src/metrics/Metrics.ts +335 -0
- package/src/metrics/PriceGetter.ts +74 -0
- package/src/metrics/scripts/metrics.ts +139 -0
- package/src/monitor/Monitor.ts +324 -0
- package/src/service.ts +285 -0
- package/src/strategy/BaseStrategy.ts +553 -0
- package/src/strategy/CollateralDeficitStrategy.test.ts +728 -0
- package/src/strategy/CollateralDeficitStrategy.ts +421 -0
- package/src/strategy/CompositeStrategy.test.ts +418 -0
- package/src/strategy/CompositeStrategy.ts +102 -0
- package/src/strategy/MinAmountStrategy.test.ts +732 -0
- package/src/strategy/MinAmountStrategy.ts +200 -0
- package/src/strategy/StrategyFactory.test.ts +108 -0
- package/src/strategy/StrategyFactory.ts +157 -0
- package/src/strategy/WeightedStrategy.test.ts +529 -0
- package/src/strategy/WeightedStrategy.ts +126 -0
- package/src/strategy/index.ts +6 -0
- package/src/test/helpers.ts +477 -0
- package/src/test/lifiMocks.ts +211 -0
- package/src/tracking/ActionTracker.test.ts +1625 -0
- package/src/tracking/ActionTracker.ts +1019 -0
- package/src/tracking/IActionTracker.ts +213 -0
- package/src/tracking/InflightContextAdapter.test.ts +206 -0
- package/src/tracking/InflightContextAdapter.ts +75 -0
- package/src/tracking/store/IStore.ts +48 -0
- package/src/tracking/store/InMemoryStore.test.ts +338 -0
- package/src/tracking/store/InMemoryStore.ts +59 -0
- package/src/tracking/store/index.ts +2 -0
- package/src/tracking/types.ts +118 -0
- package/src/utils/ExplorerClient.test.ts +386 -0
- package/src/utils/ExplorerClient.ts +439 -0
- package/src/utils/balanceUtils.test.ts +79 -0
- package/src/utils/balanceUtils.ts +65 -0
- package/src/utils/blockTag.ts +68 -0
- package/src/utils/bridgeUtils.test.ts +193 -0
- package/src/utils/bridgeUtils.ts +101 -0
- package/src/utils/errors.ts +5 -0
- package/src/utils/gasEstimation.ts +306 -0
- package/src/utils/solanaKeyParser.test.ts +103 -0
- package/src/utils/solanaKeyParser.ts +117 -0
- package/src/utils/tokenUtils.ts +89 -0
- package/src/utils/transactionUtils.ts +41 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Apache License
|
|
2
|
+
|
|
3
|
+
_Version 2.0, January 2004_
|
|
4
|
+
_<<http://www.apache.org/licenses/>>_
|
|
5
|
+
|
|
6
|
+
### Terms and Conditions for use, reproduction, and distribution
|
|
7
|
+
|
|
8
|
+
#### 1. Definitions
|
|
9
|
+
|
|
10
|
+
“License” shall mean the terms and conditions for use, reproduction, and
|
|
11
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
“Licensor” shall mean the copyright owner or entity authorized by the copyright
|
|
14
|
+
owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
“Legal Entity” shall mean the union of the acting entity and all other entities
|
|
17
|
+
that control, are controlled by, or are under common control with that entity.
|
|
18
|
+
For the purposes of this definition, “control” means **(i)** the power, direct or
|
|
19
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
20
|
+
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or **(iii)** beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
“You” (or “Your”) shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
“Source” form shall mean the preferred form for making modifications, including
|
|
27
|
+
but not limited to software source code, documentation source, and configuration
|
|
28
|
+
files.
|
|
29
|
+
|
|
30
|
+
“Object” form shall mean any form resulting from mechanical transformation or
|
|
31
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
32
|
+
generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
“Work” shall mean the work of authorship, whether in Source or Object form, made
|
|
35
|
+
available under the License, as indicated by a copyright notice that is included
|
|
36
|
+
in or attached to the work (an example is provided in the Appendix below).
|
|
37
|
+
|
|
38
|
+
“Derivative Works” shall mean any work, whether in Source or Object form, that
|
|
39
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
40
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
41
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
42
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
43
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
44
|
+
|
|
45
|
+
“Contribution” shall mean any work of authorship, including the original version
|
|
46
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
47
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
|
48
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
|
49
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
|
50
|
+
“submitted” means any form of electronic, verbal, or written communication sent
|
|
51
|
+
to the Licensor or its representatives, including but not limited to
|
|
52
|
+
communication on electronic mailing lists, source code control systems, and
|
|
53
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
|
54
|
+
the purpose of discussing and improving the Work, but excluding communication
|
|
55
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
56
|
+
owner as “Not a Contribution.”
|
|
57
|
+
|
|
58
|
+
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
|
|
59
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
60
|
+
incorporated within the Work.
|
|
61
|
+
|
|
62
|
+
#### 2. Grant of Copyright License
|
|
63
|
+
|
|
64
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
65
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
66
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
|
68
|
+
Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
#### 3. Grant of Patent License
|
|
71
|
+
|
|
72
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
73
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
74
|
+
irrevocable (except as stated in this section) patent license to make, have
|
|
75
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
|
76
|
+
such license applies only to those patent claims licensable by such Contributor
|
|
77
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
|
78
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
|
79
|
+
submitted. If You institute patent litigation against any entity (including a
|
|
80
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
81
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under this License
|
|
83
|
+
for that Work shall terminate as of the date such litigation is filed.
|
|
84
|
+
|
|
85
|
+
#### 4. Redistribution
|
|
86
|
+
|
|
87
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
|
88
|
+
in any medium, with or without modifications, and in Source or Object form,
|
|
89
|
+
provided that You meet the following conditions:
|
|
90
|
+
|
|
91
|
+
- **(a)** You must give any other recipients of the Work or Derivative Works a copy of
|
|
92
|
+
this License; and
|
|
93
|
+
- **(b)** You must cause any modified files to carry prominent notices stating that You
|
|
94
|
+
changed the files; and
|
|
95
|
+
- **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
|
|
96
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
|
97
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
|
98
|
+
Derivative Works; and
|
|
99
|
+
- **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
|
|
100
|
+
Derivative Works that You distribute must include a readable copy of the
|
|
101
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
102
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
103
|
+
following places: within a NOTICE text file distributed as part of the
|
|
104
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
105
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
106
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
|
107
|
+
the NOTICE file are for informational purposes only and do not modify the
|
|
108
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
109
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
110
|
+
provided that such additional attribution notices cannot be construed as
|
|
111
|
+
modifying the License.
|
|
112
|
+
|
|
113
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
114
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
115
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
116
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
117
|
+
with the conditions stated in this License.
|
|
118
|
+
|
|
119
|
+
#### 5. Submission of Contributions
|
|
120
|
+
|
|
121
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
|
122
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
|
123
|
+
conditions of this License, without any additional terms or conditions.
|
|
124
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
|
125
|
+
any separate license agreement you may have executed with Licensor regarding
|
|
126
|
+
such Contributions.
|
|
127
|
+
|
|
128
|
+
#### 6. Trademarks
|
|
129
|
+
|
|
130
|
+
This License does not grant permission to use the trade names, trademarks,
|
|
131
|
+
service marks, or product names of the Licensor, except as required for
|
|
132
|
+
reasonable and customary use in describing the origin of the Work and
|
|
133
|
+
reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
#### 7. Disclaimer of Warranty
|
|
136
|
+
|
|
137
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
|
138
|
+
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
|
|
139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
|
140
|
+
including, without limitation, any warranties or conditions of TITLE,
|
|
141
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
|
142
|
+
solely responsible for determining the appropriateness of using or
|
|
143
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
|
144
|
+
permissions under this License.
|
|
145
|
+
|
|
146
|
+
#### 8. Limitation of Liability
|
|
147
|
+
|
|
148
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
|
149
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
150
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
|
151
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
|
152
|
+
or consequential damages of any character arising as a result of this License or
|
|
153
|
+
out of the use or inability to use the Work (including but not limited to
|
|
154
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
|
155
|
+
any and all other commercial damages or losses), even if such Contributor has
|
|
156
|
+
been advised of the possibility of such damages.
|
|
157
|
+
|
|
158
|
+
#### 9. Accepting Warranty or Additional Liability
|
|
159
|
+
|
|
160
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
|
161
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
|
162
|
+
other liability obligations and/or rights consistent with this License. However,
|
|
163
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
|
164
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
|
165
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
|
166
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
167
|
+
accepting any such warranty or additional liability.
|
|
168
|
+
|
|
169
|
+
_END OF TERMS AND CONDITIONS_
|
|
170
|
+
|
|
171
|
+
### APPENDIX: How to apply the Apache License to your work
|
|
172
|
+
|
|
173
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
174
|
+
notice, with the fields enclosed by brackets `[]` replaced with your own
|
|
175
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
176
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
177
|
+
recommend that a file or class name and description of purpose be included on
|
|
178
|
+
the same “printed page” as the copyright notice for easier identification within
|
|
179
|
+
third-party archives.
|
|
180
|
+
|
|
181
|
+
Copyright [yyyy] [name of copyright owner]
|
|
182
|
+
|
|
183
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
184
|
+
you may not use this file except in compliance with the License.
|
|
185
|
+
You may obtain a copy of the License at
|
|
186
|
+
|
|
187
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
188
|
+
|
|
189
|
+
Unless required by applicable law or agreed to in writing, software
|
|
190
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
191
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
192
|
+
See the License for the specific language governing permissions and
|
|
193
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,298 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @humanode-hyperlane/rebalancer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Hyperlane Warp Route Collateral Rebalancer Service - maintains optimal collateral distribution across chains for Hyperlane warp routes.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The rebalancer monitors collateral balances across warp route deployments and automatically transfers tokens between chains to maintain configured target balances. It supports both manual one-off rebalances and continuous daemon mode for production deployments.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Multi-Protocol Support**: Protocol-agnostic design supporting EVM chains (Cosmos, Sealevel, etc. when movable collateral contracts available)
|
|
12
|
+
- **Flexible Strategies**: Weighted, minimum-amount, and collateral-deficit rebalancing strategies
|
|
13
|
+
- **Composite Strategies**: Combine multiple strategies with different bridges for layered rebalancing
|
|
14
|
+
- **Inflight Tracking**: Monitors pending rebalances to prevent duplicate transfers
|
|
15
|
+
- **Safety Features**: Inflight message tracking and comprehensive validation
|
|
16
|
+
- **Observability**: Built-in Prometheus metrics and structured logging
|
|
17
|
+
- **Dual Mode**: Manual CLI execution or continuous daemon service
|
|
18
|
+
- **Bridge Support**: Integration with Hyperlane warp routes and external bridges
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# From monorepo root
|
|
24
|
+
pnpm install
|
|
25
|
+
|
|
26
|
+
# Build the package
|
|
27
|
+
pnpm --filter @humanode-hyperlane/rebalancer build
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Manual Rebalancing (CLI)
|
|
33
|
+
|
|
34
|
+
Execute a one-off rebalance using the CLI:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Via CLI package
|
|
38
|
+
pnpm --filter @humanode-hyperlane/cli hyperlane warp rebalancer \
|
|
39
|
+
--config /path/to/rebalancer-config.yaml \
|
|
40
|
+
--manual \
|
|
41
|
+
--origin ethereum \
|
|
42
|
+
--destination arbitrum \
|
|
43
|
+
--amount 1000
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Daemon Mode (Service)
|
|
47
|
+
|
|
48
|
+
Run as a continuous service (typically in K8s):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Set environment variables
|
|
52
|
+
export REBALANCER_CONFIG_FILE=/path/to/rebalancer-config.yaml
|
|
53
|
+
export HYP_KEY=your_private_key
|
|
54
|
+
export COINGECKO_API_KEY=your_api_key
|
|
55
|
+
|
|
56
|
+
# Start the service
|
|
57
|
+
pnpm --filter @humanode-hyperlane/rebalancer start
|
|
58
|
+
|
|
59
|
+
# Or with direct node
|
|
60
|
+
node dist/service.js
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Programmatic Usage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { RebalancerService } from '@humanode-hyperlane/rebalancer';
|
|
67
|
+
|
|
68
|
+
const service = new RebalancerService(
|
|
69
|
+
multiProvider,
|
|
70
|
+
multiProtocolProvider,
|
|
71
|
+
registry,
|
|
72
|
+
rebalancerConfig,
|
|
73
|
+
{
|
|
74
|
+
mode: 'daemon',
|
|
75
|
+
checkFrequency: 60_000,
|
|
76
|
+
withMetrics: true,
|
|
77
|
+
coingeckoApiKey: process.env.COINGECKO_API_KEY,
|
|
78
|
+
logger: console,
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Start daemon
|
|
83
|
+
await service.start();
|
|
84
|
+
|
|
85
|
+
// Or execute manual rebalance
|
|
86
|
+
await service.executeManual({
|
|
87
|
+
origin: 'ethereum',
|
|
88
|
+
destination: 'arbitrum',
|
|
89
|
+
amount: '1000',
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
The rebalancer uses a YAML configuration file with a `warpRouteId` and `strategy` field.
|
|
96
|
+
|
|
97
|
+
### Basic Example (Single Strategy)
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
warpRouteId: ETH/ethereum-arbitrum-optimism
|
|
101
|
+
strategy:
|
|
102
|
+
rebalanceStrategy: weighted
|
|
103
|
+
chains:
|
|
104
|
+
ethereum:
|
|
105
|
+
weight: 60
|
|
106
|
+
tolerance: 5
|
|
107
|
+
bridge: '0x1234...abcd'
|
|
108
|
+
arbitrum:
|
|
109
|
+
weight: 20
|
|
110
|
+
tolerance: 5
|
|
111
|
+
bridge: '0x5678...efgh'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Composite Strategy (v1.0.0+)
|
|
115
|
+
|
|
116
|
+
The `strategy` field accepts an array of strategies for composite rebalancing. Strategies are evaluated in order - the first strategy that produces routes is used.
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
warpRouteId: USDC/base-ethereum-arbitrum
|
|
120
|
+
strategy:
|
|
121
|
+
# First: CollateralDeficitStrategy with fast bridges for reactive rebalancing
|
|
122
|
+
- rebalanceStrategy: collateralDeficit
|
|
123
|
+
chains:
|
|
124
|
+
base:
|
|
125
|
+
buffer: 0
|
|
126
|
+
bridge: '0x584244d02b0fBf9054A5D5C9e9cE9A2E8adA0e28'
|
|
127
|
+
ethereum:
|
|
128
|
+
buffer: 0
|
|
129
|
+
bridge: '0xEE4a09db2C25592C04b8b342CB89f9a7f5E20BD2'
|
|
130
|
+
|
|
131
|
+
# Second: MinAmountStrategy with standard bridges for baseline floors
|
|
132
|
+
- rebalanceStrategy: minAmount
|
|
133
|
+
chains:
|
|
134
|
+
base:
|
|
135
|
+
minAmount:
|
|
136
|
+
min: 0.1
|
|
137
|
+
target: 0.11
|
|
138
|
+
type: 'absolute'
|
|
139
|
+
bridgeLockTime: 1800
|
|
140
|
+
bridge: '0x33e94B6D2ae697c16a750dB7c3d9443622C4405a'
|
|
141
|
+
ethereum:
|
|
142
|
+
minAmount:
|
|
143
|
+
min: 0.1
|
|
144
|
+
target: 0.11
|
|
145
|
+
type: 'absolute'
|
|
146
|
+
bridgeLockTime: 1800
|
|
147
|
+
bridge: '0x8c8D831E1e879604b4B304a2c951B8AEe3aB3a23'
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
> **Note**: When using `collateralDeficit` in a composite strategy, it must be the first strategy in the array.
|
|
151
|
+
|
|
152
|
+
### Strategy Types
|
|
153
|
+
|
|
154
|
+
| Strategy | Use Case | Chain Config Fields |
|
|
155
|
+
| ------------------- | ------------------------------------------------------ | -------------------------------- |
|
|
156
|
+
| `weighted` | Maintain percentage distribution across chains | `weight`, `tolerance` |
|
|
157
|
+
| `minAmount` | Trigger rebalance when balance falls below floor | `minAmount: {min, target, type}` |
|
|
158
|
+
| `collateralDeficit` | React to bridged supply gaps (synthetic vs collateral) | `buffer` |
|
|
159
|
+
|
|
160
|
+
#### Weighted Strategy
|
|
161
|
+
|
|
162
|
+
Maintains target weight percentages across chains. Rebalances when deviation exceeds tolerance.
|
|
163
|
+
|
|
164
|
+
```yaml
|
|
165
|
+
strategy:
|
|
166
|
+
rebalanceStrategy: weighted
|
|
167
|
+
chains:
|
|
168
|
+
ethereum:
|
|
169
|
+
weight: 60 # Target 60% of total supply
|
|
170
|
+
tolerance: 5 # Rebalance if >5% deviation
|
|
171
|
+
bridge: '0x...'
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### MinAmount Strategy
|
|
175
|
+
|
|
176
|
+
Triggers rebalance when a chain's balance falls below the minimum threshold.
|
|
177
|
+
|
|
178
|
+
```yaml
|
|
179
|
+
strategy:
|
|
180
|
+
rebalanceStrategy: minAmount
|
|
181
|
+
chains:
|
|
182
|
+
ethereum:
|
|
183
|
+
minAmount:
|
|
184
|
+
min: 100 # Trigger rebalance below this
|
|
185
|
+
target: 110 # Rebalance up to this amount
|
|
186
|
+
type: 'absolute' # or 'relative' (percentage of total)
|
|
187
|
+
bridge: '0x...'
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### CollateralDeficit Strategy
|
|
191
|
+
|
|
192
|
+
Monitors bridged (synthetic) supply vs collateral and rebalances to cover deficits.
|
|
193
|
+
|
|
194
|
+
```yaml
|
|
195
|
+
strategy:
|
|
196
|
+
rebalanceStrategy: collateralDeficit
|
|
197
|
+
chains:
|
|
198
|
+
ethereum:
|
|
199
|
+
buffer: 1000 # Extra collateral buffer above deficit
|
|
200
|
+
bridge: '0x...'
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Chain Config Reference
|
|
204
|
+
|
|
205
|
+
| Field | Type | Required | Description |
|
|
206
|
+
| ------------------------- | ---------------- | -------- | -------------------------------------------------------------- |
|
|
207
|
+
| `bridge` | `0x...` address | Yes | Bridge contract address for this chain |
|
|
208
|
+
| `bridgeLockTime` | number (seconds) | No | Expected bridge transfer duration (used for inflight tracking) |
|
|
209
|
+
| `bridgeMinAcceptedAmount` | number | No | Skip routes with amounts below this threshold |
|
|
210
|
+
| `override` | object | No | Per-destination bridge overrides (see below) |
|
|
211
|
+
|
|
212
|
+
#### Per-Destination Overrides
|
|
213
|
+
|
|
214
|
+
Use `override` to specify different bridge configs for specific destination chains:
|
|
215
|
+
|
|
216
|
+
```yaml
|
|
217
|
+
strategy:
|
|
218
|
+
rebalanceStrategy: minAmount
|
|
219
|
+
chains:
|
|
220
|
+
ethereum:
|
|
221
|
+
minAmount: { min: 100, target: 110, type: 'absolute' }
|
|
222
|
+
bridge: '0xDefaultBridge...'
|
|
223
|
+
override:
|
|
224
|
+
arbitrum:
|
|
225
|
+
bridge: '0xFastArbitrumBridge...'
|
|
226
|
+
bridgeLockTime: 600
|
|
227
|
+
optimism:
|
|
228
|
+
bridge: '0xOptimismBridge...'
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Architecture
|
|
232
|
+
|
|
233
|
+
### Package Structure
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
typescript/rebalancer/
|
|
237
|
+
├── src/
|
|
238
|
+
│ ├── core/
|
|
239
|
+
│ │ ├── RebalancerService.ts # Main orchestrator
|
|
240
|
+
│ │ └── Rebalancer.ts # Core rebalancing logic
|
|
241
|
+
│ ├── strategy/
|
|
242
|
+
│ │ ├── WeightedStrategy.ts # Weighted distribution
|
|
243
|
+
│ │ ├── MinAmountStrategy.ts # Minimum threshold strategy
|
|
244
|
+
│ │ ├── CollateralDeficitStrategy.ts # Bridged supply deficit strategy
|
|
245
|
+
│ │ └── CompositeStrategy.ts # Combines multiple strategies
|
|
246
|
+
│ ├── monitor/
|
|
247
|
+
│ │ └── Monitor.ts # Balance monitoring
|
|
248
|
+
│ ├── metrics/
|
|
249
|
+
│ │ └── Metrics.ts # Prometheus metrics collection
|
|
250
|
+
│ ├── config/
|
|
251
|
+
│ │ └── RebalancerConfig.ts # Config loading/validation
|
|
252
|
+
│ ├── utils/
|
|
253
|
+
│ ├── interfaces/
|
|
254
|
+
│ ├── service.ts # Service entry point
|
|
255
|
+
│ └── index.ts # Public API
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Dependencies
|
|
259
|
+
|
|
260
|
+
- `@humanode-hyperlane/sdk`: Core SDK with MultiProvider and WarpCore
|
|
261
|
+
- `@humanode-hyperlane/provider-sdk`: Protocol-agnostic provider abstractions
|
|
262
|
+
- `@humanode-hyperlane/utils`: Shared utilities and types
|
|
263
|
+
- `prom-client`: Prometheus metrics
|
|
264
|
+
- `pino`: Structured logging
|
|
265
|
+
|
|
266
|
+
## Development
|
|
267
|
+
|
|
268
|
+
### Running Tests
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
pnpm --filter @humanode-hyperlane/rebalancer test
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Local Development
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Watch mode
|
|
278
|
+
pnpm --filter @humanode-hyperlane/rebalancer dev
|
|
279
|
+
|
|
280
|
+
# Start with test config
|
|
281
|
+
HYP_KEY=your_test_key \
|
|
282
|
+
REBALANCER_CONFIG_FILE=./test-config.yaml \
|
|
283
|
+
pnpm --filter @humanode-hyperlane/rebalancer start:dev
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Migration from CLI
|
|
287
|
+
|
|
288
|
+
This package replaces the rebalancer functionality previously embedded in `@humanode-hyperlane/cli`. Key changes:
|
|
289
|
+
|
|
290
|
+
1. **Dedicated Package**: Now a standalone service package
|
|
291
|
+
2. **Direct Entry Point**: K8s deployments use `service.ts` directly (no CLI wrapper)
|
|
292
|
+
3. **Metrics Included**: Prometheus metrics stay with the service
|
|
293
|
+
4. **Protocol-Agnostic**: Aligned with multi-VM architecture
|
|
294
|
+
5. **Dual Mode Support**: Single codebase for both manual and daemon modes
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
Apache-2.0
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type LiFiStep } from '@lifi/sdk';
|
|
2
|
+
import { ProtocolType } from '@humanode-hyperlane/utils';
|
|
3
|
+
import type { Logger } from 'pino';
|
|
4
|
+
import type { BridgeQuote, BridgeQuoteParams, BridgeTransferResult, BridgeTransferStatus, ExternalBridgeConfig, IExternalBridge } from '../interfaces/IExternalBridge.js';
|
|
5
|
+
/**
|
|
6
|
+
* LiFi implementation of IExternalBridge using the official @lifi/sdk.
|
|
7
|
+
*
|
|
8
|
+
* The SDK provides:
|
|
9
|
+
* - Automatic token approvals via executeRoute()
|
|
10
|
+
* - Multi-step route handling (swap → bridge → swap)
|
|
11
|
+
* - Built-in status tracking via getStatus()
|
|
12
|
+
* - Native support for EVM, Solana, and other chains
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.li.fi/integrate-li.fi-sdk
|
|
15
|
+
*/
|
|
16
|
+
export declare class LiFiBridge implements IExternalBridge {
|
|
17
|
+
private static readonly NATIVE_TOKEN_ADDRESS;
|
|
18
|
+
readonly externalBridgeId = "lifi";
|
|
19
|
+
/**
|
|
20
|
+
* Convert a Hyperlane domain ID to a LiFi-compatible chain ID.
|
|
21
|
+
* For EVM chains, these are identical (e.g., Arbitrum = 42161 in both).
|
|
22
|
+
* For non-EVM chains like Solana, LiFi uses different chain identifiers.
|
|
23
|
+
*/
|
|
24
|
+
static toLiFiChainId(chainId: number): number;
|
|
25
|
+
readonly logger: Logger;
|
|
26
|
+
private initialized;
|
|
27
|
+
private _executeLock;
|
|
28
|
+
private readonly config;
|
|
29
|
+
private readonly chainMetadataByChainId;
|
|
30
|
+
constructor(config: ExternalBridgeConfig, logger: Logger);
|
|
31
|
+
getNativeTokenAddress(): string;
|
|
32
|
+
private initialize;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve RPC URL for a given EVM chainId from chain metadata.
|
|
35
|
+
* Iterates metadata to find matching chainId and returns first HTTP RPC URL.
|
|
36
|
+
*/
|
|
37
|
+
private getRpcUrlForChainId;
|
|
38
|
+
private getProtocolTypeForChainId;
|
|
39
|
+
private addressesEqual;
|
|
40
|
+
/**
|
|
41
|
+
* Configure LiFi SDK providers from the given private keys.
|
|
42
|
+
* Sets up wallet/signer for each protocol type present in the keys map.
|
|
43
|
+
*/
|
|
44
|
+
private configureLiFiProviders;
|
|
45
|
+
/**
|
|
46
|
+
* Get a quote for bridging tokens.
|
|
47
|
+
* Supports two modes:
|
|
48
|
+
* - fromAmount: "I'm sending X, what do I get?" (uses SDK)
|
|
49
|
+
* - toAmount: "I want X, how much do I send?" (uses REST API)
|
|
50
|
+
*
|
|
51
|
+
* Returns route data ready for execution.
|
|
52
|
+
*/
|
|
53
|
+
quote(params: BridgeQuoteParams): Promise<BridgeQuote<LiFiStep>>;
|
|
54
|
+
/**
|
|
55
|
+
* Get a quote by specifying the amount to send (standard quote).
|
|
56
|
+
* Uses the LiFi SDK.
|
|
57
|
+
*/
|
|
58
|
+
private quoteBySpendingAmount;
|
|
59
|
+
/**
|
|
60
|
+
* Get a quote by specifying the amount to receive (reverse quote).
|
|
61
|
+
* Uses the LiFi REST API directly since the SDK doesn't support toAmount.
|
|
62
|
+
*/
|
|
63
|
+
private quoteByReceivingAmount;
|
|
64
|
+
/**
|
|
65
|
+
* Extract gas and fee costs from a LiFi quote response.
|
|
66
|
+
* - gasCosts: Sum of all gas costs (transaction fees)
|
|
67
|
+
* - feeCosts: Sum of non-included fee costs (protocol fees not deducted from amount)
|
|
68
|
+
*/
|
|
69
|
+
private extractCosts;
|
|
70
|
+
/**
|
|
71
|
+
* Execute a bridge transfer using the SDK.
|
|
72
|
+
* Handles approvals, transaction signing, and execution automatically.
|
|
73
|
+
*
|
|
74
|
+
* @param quote - Quote obtained from quote()
|
|
75
|
+
* @param privateKeys - Private keys keyed by protocol type for signing transactions
|
|
76
|
+
*/
|
|
77
|
+
execute(quote: BridgeQuote<LiFiStep>, privateKeys: Partial<Record<ProtocolType, string>>): Promise<BridgeTransferResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Validate that the route returned by LiFi matches the original request parameters.
|
|
80
|
+
* Prevents execution against wrong chains, tokens, or recipients if the bridge API
|
|
81
|
+
* returns a route that diverges from what was originally requested.
|
|
82
|
+
*
|
|
83
|
+
* TODO: Layer 2 validation — validate transaction calldata in route.steps[].transactionRequest
|
|
84
|
+
* and route.steps[0].estimate.approvalAddress against a known whitelist.
|
|
85
|
+
*/
|
|
86
|
+
private validateRouteAgainstRequest;
|
|
87
|
+
/**
|
|
88
|
+
* Get the status of a bridge transfer.
|
|
89
|
+
* Uses SDK's built-in status tracking.
|
|
90
|
+
*/
|
|
91
|
+
getStatus(txHash: string, fromChain: number, toChain: number): Promise<BridgeTransferStatus>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=LiFiBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiFiBridge.d.ts","sourceRoot":"","sources":["../../src/bridges/LiFiBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EASd,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,YAAY,EAAoB,MAAM,2BAA2B,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAKnC,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAwE1C;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,YAAW,eAAe;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CACG;IAE/C,QAAQ,CAAC,gBAAgB,UAAU;IAEnC;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAG7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAoC;IACxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAA6B;gBAExD,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM;IAyBxD,qBAAqB,IAAI,MAAM;IAI/B,OAAO,CAAC,UAAU;IAelB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,yBAAyB;IAIjC,OAAO,CAAC,cAAc;IAStB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA8D9B;;;;;;;OAOG;IACG,KAAK,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IA8BtE;;;OAGG;YACW,qBAAqB;IAuDnC;;;OAGG;YACW,sBAAsB;IA4EpC;;;;OAIG;IACH,OAAO,CAAC,YAAY;IA2BpB;;;;;;OAMG;IACG,OAAO,CACX,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,EAC5B,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,GACjD,OAAO,CAAC,oBAAoB,CAAC;IAwHhC;;;;;;;OAOG;IACH,OAAO,CAAC,2BAA2B;IA+DnC;;;OAGG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC;CAiDjC"}
|