@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
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { BigNumber } from 'bignumber.js';
|
|
2
|
+
import { type Logger } from 'pino';
|
|
3
|
+
|
|
4
|
+
import { type ChainMap, type Token } from '@humanode-hyperlane/sdk';
|
|
5
|
+
import { fromWei, toWei } from '@humanode-hyperlane/utils';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type MinAmountStrategyConfig,
|
|
9
|
+
RebalancerMinAmountType,
|
|
10
|
+
RebalancerStrategyOptions,
|
|
11
|
+
} from '../config/types.js';
|
|
12
|
+
import type {
|
|
13
|
+
RawBalances,
|
|
14
|
+
Route,
|
|
15
|
+
StrategyRoute,
|
|
16
|
+
} from '../interfaces/IStrategy.js';
|
|
17
|
+
import { type Metrics } from '../metrics/Metrics.js';
|
|
18
|
+
import type { BridgeConfigWithOverride } from '../utils/bridgeUtils.js';
|
|
19
|
+
|
|
20
|
+
import { BaseStrategy, type Delta } from './BaseStrategy.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Strategy implementation that rebalance based on minimum amounts
|
|
24
|
+
* It ensures each chain has at least the specified minimum amount
|
|
25
|
+
*/
|
|
26
|
+
export class MinAmountStrategy extends BaseStrategy {
|
|
27
|
+
readonly name = RebalancerStrategyOptions.MinAmount;
|
|
28
|
+
private readonly config: MinAmountStrategyConfig = {};
|
|
29
|
+
protected readonly logger: Logger;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
config: MinAmountStrategyConfig,
|
|
33
|
+
tokensByChainName: ChainMap<Token>,
|
|
34
|
+
initialTotalCollateral: bigint,
|
|
35
|
+
logger: Logger,
|
|
36
|
+
bridgeConfigs: ChainMap<BridgeConfigWithOverride>,
|
|
37
|
+
metrics?: Metrics,
|
|
38
|
+
) {
|
|
39
|
+
const chains = Object.keys(config);
|
|
40
|
+
const log = logger.child({ class: MinAmountStrategy.name });
|
|
41
|
+
super(chains, log, bridgeConfigs, metrics, tokensByChainName);
|
|
42
|
+
this.logger = log;
|
|
43
|
+
|
|
44
|
+
const minAmountType = config[chains[0]].minAmount.type;
|
|
45
|
+
this.validateAmounts(initialTotalCollateral, minAmountType, config);
|
|
46
|
+
|
|
47
|
+
for (const chain of chains) {
|
|
48
|
+
const { min, target } = config[chain].minAmount;
|
|
49
|
+
|
|
50
|
+
// check range constraints
|
|
51
|
+
if (BigNumber(target).lt(min)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Target (${target}) must be greater than or equal to min (${min}) for chain ${chain}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (BigNumber(min).lt(0)) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Minimum amount (${min}) cannot be negative for chain ${chain}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (BigNumber(target).lt(0)) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Target amount (${target}) cannot be negative for chain ${chain}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.config = config;
|
|
71
|
+
this.logger.info('MinAmountStrategy created');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets balances categorized by surplus and deficit based on minimum amounts and targets
|
|
76
|
+
* - For absolute values: Uses exact token amounts
|
|
77
|
+
* - For relative values: Uses percentages of total balance across all chains
|
|
78
|
+
*
|
|
79
|
+
* Simulates both types of rebalances before calculating surpluses/deficits:
|
|
80
|
+
* - pendingRebalances: in-flight intents (origin tx confirmed, add to destination only)
|
|
81
|
+
* - proposedRebalances: routes from earlier strategies (subtract from origin AND add to destination)
|
|
82
|
+
*
|
|
83
|
+
* This prevents over-rebalancing when multiple strategies run in sequence.
|
|
84
|
+
*/
|
|
85
|
+
protected getCategorizedBalances(
|
|
86
|
+
rawBalances: RawBalances,
|
|
87
|
+
pendingRebalances?: Route[],
|
|
88
|
+
proposedRebalances?: StrategyRoute[],
|
|
89
|
+
): {
|
|
90
|
+
surpluses: Delta[];
|
|
91
|
+
deficits: Delta[];
|
|
92
|
+
} {
|
|
93
|
+
// Step 1: Simulate pending rebalances (in-flight, origin already deducted on-chain)
|
|
94
|
+
let simulatedBalances = this.simulatePendingRebalances(
|
|
95
|
+
rawBalances,
|
|
96
|
+
pendingRebalances ?? [],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Step 2: Simulate proposed rebalances (from earlier strategies, not yet executed)
|
|
100
|
+
simulatedBalances = this.simulateProposedRebalances(
|
|
101
|
+
simulatedBalances,
|
|
102
|
+
proposedRebalances ?? [],
|
|
103
|
+
);
|
|
104
|
+
const totalCollateral = this.chains.reduce(
|
|
105
|
+
(sum, chain) => sum + simulatedBalances[chain],
|
|
106
|
+
0n,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
return this.chains.reduce(
|
|
110
|
+
(acc, chain) => {
|
|
111
|
+
const chainConfig = this.config[chain];
|
|
112
|
+
const balance = simulatedBalances[chain];
|
|
113
|
+
let minAmount: bigint;
|
|
114
|
+
let targetAmount: bigint;
|
|
115
|
+
|
|
116
|
+
if (chainConfig.minAmount.type === RebalancerMinAmountType.Absolute) {
|
|
117
|
+
const token = this.getTokenByChainName(chain);
|
|
118
|
+
|
|
119
|
+
minAmount = BigInt(toWei(chainConfig.minAmount.min, token.decimals));
|
|
120
|
+
targetAmount = BigInt(
|
|
121
|
+
toWei(chainConfig.minAmount.target, token.decimals),
|
|
122
|
+
);
|
|
123
|
+
} else {
|
|
124
|
+
minAmount = BigInt(
|
|
125
|
+
BigNumber(totalCollateral.toString())
|
|
126
|
+
.times(chainConfig.minAmount.min)
|
|
127
|
+
.toFixed(0, BigNumber.ROUND_FLOOR),
|
|
128
|
+
);
|
|
129
|
+
targetAmount = BigInt(
|
|
130
|
+
BigNumber(totalCollateral.toString())
|
|
131
|
+
.times(chainConfig.minAmount.target)
|
|
132
|
+
.toFixed(0, BigNumber.ROUND_FLOOR),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// If balance is less than minAmount, it has a deficit
|
|
137
|
+
if (balance < minAmount) {
|
|
138
|
+
acc.deficits.push({ chain, amount: targetAmount - balance });
|
|
139
|
+
} else {
|
|
140
|
+
// Any chain with more than minAmount potentially has surplus
|
|
141
|
+
const surplus = balance - minAmount;
|
|
142
|
+
if (surplus > 0n) {
|
|
143
|
+
acc.surpluses.push({ chain, amount: surplus });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return acc;
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
surpluses: [] as Delta[],
|
|
151
|
+
deficits: [] as Delta[],
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected getTokenByChainName(chainName: string): Token {
|
|
157
|
+
const token = this.tokensByChainName![chainName];
|
|
158
|
+
|
|
159
|
+
if (token === undefined) {
|
|
160
|
+
throw new Error(`Token not found for chain ${chainName}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return token;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private validateAmounts(
|
|
167
|
+
totalCollateral: bigint,
|
|
168
|
+
minAmountType: RebalancerMinAmountType,
|
|
169
|
+
config?: MinAmountStrategyConfig,
|
|
170
|
+
): void {
|
|
171
|
+
config ??= this.config;
|
|
172
|
+
|
|
173
|
+
if (minAmountType === RebalancerMinAmountType.Absolute) {
|
|
174
|
+
let totalTargets = 0n;
|
|
175
|
+
let decimals: number = 0;
|
|
176
|
+
|
|
177
|
+
for (const chainName of this.chains) {
|
|
178
|
+
const token = this.getTokenByChainName(chainName);
|
|
179
|
+
// all the tokens have the same amount of decimals
|
|
180
|
+
decimals = token.decimals;
|
|
181
|
+
|
|
182
|
+
totalTargets += BigInt(
|
|
183
|
+
toWei(config[chainName].minAmount.target, token.decimals),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (totalTargets > totalCollateral) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Consider reducing the targets as the sum (${fromWei(
|
|
190
|
+
totalTargets.toString(),
|
|
191
|
+
decimals,
|
|
192
|
+
)}) is greater than sum of collaterals (${fromWei(
|
|
193
|
+
totalCollateral.toString(),
|
|
194
|
+
decimals,
|
|
195
|
+
)})`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
import { pino } from 'pino';
|
|
4
|
+
|
|
5
|
+
import { type ChainMap, Token, TokenStandard } from '@humanode-hyperlane/sdk';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type MinAmountStrategyConfig,
|
|
9
|
+
RebalancerMinAmountType,
|
|
10
|
+
RebalancerStrategyOptions,
|
|
11
|
+
type StrategyConfig,
|
|
12
|
+
type WeightedStrategyConfig,
|
|
13
|
+
} from '../config/types.js';
|
|
14
|
+
|
|
15
|
+
import { MinAmountStrategy } from './MinAmountStrategy.js';
|
|
16
|
+
import { StrategyFactory } from './StrategyFactory.js';
|
|
17
|
+
import { WeightedStrategy } from './WeightedStrategy.js';
|
|
18
|
+
|
|
19
|
+
const testLogger = pino({ level: 'silent' });
|
|
20
|
+
|
|
21
|
+
describe('StrategyFactory', () => {
|
|
22
|
+
const chain1 = 'chain1';
|
|
23
|
+
const chain2 = 'chain2';
|
|
24
|
+
const totalCollateral = BigInt(20e18);
|
|
25
|
+
|
|
26
|
+
const tokensByChainName: ChainMap<Token> = {};
|
|
27
|
+
const tokenArgs = {
|
|
28
|
+
name: 'token',
|
|
29
|
+
decimals: 18,
|
|
30
|
+
symbol: 'TOKEN',
|
|
31
|
+
standard: TokenStandard.ERC20,
|
|
32
|
+
addressOrDenom: '',
|
|
33
|
+
};
|
|
34
|
+
tokensByChainName[chain1] = new Token({ ...tokenArgs, chainName: chain1 });
|
|
35
|
+
tokensByChainName[chain2] = new Token({ ...tokenArgs, chainName: chain2 });
|
|
36
|
+
|
|
37
|
+
describe('createStrategy', () => {
|
|
38
|
+
it('creates a WeightedStrategy when given weighted configuration', () => {
|
|
39
|
+
const config: WeightedStrategyConfig = {
|
|
40
|
+
[chain1]: {
|
|
41
|
+
weighted: {
|
|
42
|
+
weight: 100n,
|
|
43
|
+
tolerance: 0n,
|
|
44
|
+
},
|
|
45
|
+
bridge: ethers.constants.AddressZero,
|
|
46
|
+
bridgeLockTime: 1,
|
|
47
|
+
},
|
|
48
|
+
[chain2]: {
|
|
49
|
+
weighted: {
|
|
50
|
+
weight: 100n,
|
|
51
|
+
tolerance: 0n,
|
|
52
|
+
},
|
|
53
|
+
bridge: ethers.constants.AddressZero,
|
|
54
|
+
bridgeLockTime: 1,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const strategyConfig: StrategyConfig = {
|
|
59
|
+
rebalanceStrategy: RebalancerStrategyOptions.Weighted,
|
|
60
|
+
chains: config,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const strategy = StrategyFactory.createStrategy(
|
|
64
|
+
[strategyConfig],
|
|
65
|
+
tokensByChainName,
|
|
66
|
+
totalCollateral,
|
|
67
|
+
testLogger,
|
|
68
|
+
);
|
|
69
|
+
expect(strategy).to.be.instanceOf(WeightedStrategy);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('creates a MinAmountStrategy when given minAmount configuration', () => {
|
|
73
|
+
const config: MinAmountStrategyConfig = {
|
|
74
|
+
[chain1]: {
|
|
75
|
+
minAmount: {
|
|
76
|
+
min: 8,
|
|
77
|
+
target: 10,
|
|
78
|
+
type: RebalancerMinAmountType.Absolute,
|
|
79
|
+
},
|
|
80
|
+
bridge: ethers.constants.AddressZero,
|
|
81
|
+
bridgeLockTime: 1,
|
|
82
|
+
},
|
|
83
|
+
[chain2]: {
|
|
84
|
+
minAmount: {
|
|
85
|
+
min: 8,
|
|
86
|
+
target: 10,
|
|
87
|
+
type: RebalancerMinAmountType.Absolute,
|
|
88
|
+
},
|
|
89
|
+
bridge: ethers.constants.AddressZero,
|
|
90
|
+
bridgeLockTime: 1,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const strategyConfig: StrategyConfig = {
|
|
95
|
+
rebalanceStrategy: RebalancerStrategyOptions.MinAmount,
|
|
96
|
+
chains: config,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const strategy = StrategyFactory.createStrategy(
|
|
100
|
+
[strategyConfig],
|
|
101
|
+
tokensByChainName,
|
|
102
|
+
totalCollateral,
|
|
103
|
+
testLogger,
|
|
104
|
+
);
|
|
105
|
+
expect(strategy).to.be.instanceOf(MinAmountStrategy);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type Logger } from 'pino';
|
|
2
|
+
|
|
3
|
+
import { type ChainMap, type Token } from '@humanode-hyperlane/sdk';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
ExecutionType,
|
|
7
|
+
RebalancerStrategyOptions,
|
|
8
|
+
type StrategyConfig,
|
|
9
|
+
} from '../config/types.js';
|
|
10
|
+
import { type IStrategy } from '../interfaces/IStrategy.js';
|
|
11
|
+
import { type Metrics } from '../metrics/Metrics.js';
|
|
12
|
+
import type {
|
|
13
|
+
BridgeConfigWithOverride,
|
|
14
|
+
InventoryBridgeConfig,
|
|
15
|
+
MovableCollateralBridgeConfig,
|
|
16
|
+
} from '../utils/bridgeUtils.js';
|
|
17
|
+
|
|
18
|
+
import { CollateralDeficitStrategy } from './CollateralDeficitStrategy.js';
|
|
19
|
+
import { CompositeStrategy } from './CompositeStrategy.js';
|
|
20
|
+
import { MinAmountStrategy } from './MinAmountStrategy.js';
|
|
21
|
+
import { WeightedStrategy } from './WeightedStrategy.js';
|
|
22
|
+
|
|
23
|
+
export class StrategyFactory {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a strategy from an array of strategy configs.
|
|
26
|
+
* - Single strategy (array with 1 element): Creates that strategy directly
|
|
27
|
+
* - Multiple strategies (array with 2+ elements): Creates CompositeStrategy
|
|
28
|
+
*
|
|
29
|
+
* @param strategyConfigs Array of strategy configurations (always array format)
|
|
30
|
+
* @param tokensByChainName A map of chain->token to ease the lookup of token by chain
|
|
31
|
+
* @param initialTotalCollateral The initial total collateral of the rebalancer
|
|
32
|
+
* @param logger The logger to use for the strategy
|
|
33
|
+
* @param metrics The metrics to use for the strategy
|
|
34
|
+
* @param minAmountsByChain Optional minimum amounts per chain for filtering routes
|
|
35
|
+
* @returns A concrete strategy implementation
|
|
36
|
+
*/
|
|
37
|
+
static createStrategy(
|
|
38
|
+
strategyConfigs: StrategyConfig[],
|
|
39
|
+
tokensByChainName: ChainMap<Token>,
|
|
40
|
+
initialTotalCollateral: bigint,
|
|
41
|
+
logger: Logger,
|
|
42
|
+
metrics?: Metrics,
|
|
43
|
+
minAmountsByChain?: ChainMap<bigint>,
|
|
44
|
+
): IStrategy {
|
|
45
|
+
if (strategyConfigs.length === 0) {
|
|
46
|
+
throw new Error('At least one strategy must be configured');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Single strategy - create directly without CompositeStrategy wrapper
|
|
50
|
+
if (strategyConfigs.length === 1) {
|
|
51
|
+
return this.createSingleStrategy(
|
|
52
|
+
strategyConfigs[0],
|
|
53
|
+
tokensByChainName,
|
|
54
|
+
initialTotalCollateral,
|
|
55
|
+
logger,
|
|
56
|
+
metrics,
|
|
57
|
+
minAmountsByChain,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Multiple strategies - create CompositeStrategy
|
|
62
|
+
const subStrategies = strategyConfigs.map((config) =>
|
|
63
|
+
this.createSingleStrategy(
|
|
64
|
+
config,
|
|
65
|
+
tokensByChainName,
|
|
66
|
+
initialTotalCollateral,
|
|
67
|
+
logger,
|
|
68
|
+
metrics,
|
|
69
|
+
minAmountsByChain,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
return new CompositeStrategy(subStrategies, logger);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create a single strategy from config.
|
|
77
|
+
*/
|
|
78
|
+
private static createSingleStrategy(
|
|
79
|
+
strategyConfig: StrategyConfig,
|
|
80
|
+
tokensByChainName: ChainMap<Token>,
|
|
81
|
+
initialTotalCollateral: bigint,
|
|
82
|
+
logger: Logger,
|
|
83
|
+
metrics?: Metrics,
|
|
84
|
+
_minAmountsByChain?: ChainMap<bigint>,
|
|
85
|
+
): IStrategy {
|
|
86
|
+
const bridgeConfigs = this.extractBridgeConfigs(strategyConfig);
|
|
87
|
+
|
|
88
|
+
switch (strategyConfig.rebalanceStrategy) {
|
|
89
|
+
case RebalancerStrategyOptions.Weighted: {
|
|
90
|
+
return new WeightedStrategy(
|
|
91
|
+
strategyConfig.chains,
|
|
92
|
+
logger,
|
|
93
|
+
bridgeConfigs,
|
|
94
|
+
metrics,
|
|
95
|
+
tokensByChainName,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
case RebalancerStrategyOptions.MinAmount: {
|
|
99
|
+
return new MinAmountStrategy(
|
|
100
|
+
strategyConfig.chains,
|
|
101
|
+
tokensByChainName,
|
|
102
|
+
initialTotalCollateral,
|
|
103
|
+
logger,
|
|
104
|
+
bridgeConfigs,
|
|
105
|
+
metrics,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
case RebalancerStrategyOptions.CollateralDeficit: {
|
|
109
|
+
return new CollateralDeficitStrategy(
|
|
110
|
+
strategyConfig.chains,
|
|
111
|
+
tokensByChainName,
|
|
112
|
+
logger,
|
|
113
|
+
bridgeConfigs,
|
|
114
|
+
metrics,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
default: {
|
|
118
|
+
throw new Error('Unsupported strategy type');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private static extractBridgeConfigs(
|
|
124
|
+
strategyConfig: StrategyConfig,
|
|
125
|
+
): ChainMap<BridgeConfigWithOverride> {
|
|
126
|
+
const bridgeConfigs: ChainMap<BridgeConfigWithOverride> = {};
|
|
127
|
+
|
|
128
|
+
for (const [chain, config] of Object.entries(strategyConfig.chains)) {
|
|
129
|
+
const baseConfig = {
|
|
130
|
+
bridgeMinAcceptedAmount: config.bridgeMinAcceptedAmount ?? 0,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const executionType =
|
|
134
|
+
config.executionType ?? ExecutionType.MovableCollateral;
|
|
135
|
+
|
|
136
|
+
if (executionType === ExecutionType.Inventory) {
|
|
137
|
+
bridgeConfigs[chain] = {
|
|
138
|
+
...baseConfig,
|
|
139
|
+
executionType: 'inventory',
|
|
140
|
+
externalBridge: config.externalBridge!, // Validated by config schema
|
|
141
|
+
override: config.override as ChainMap<Partial<InventoryBridgeConfig>>,
|
|
142
|
+
};
|
|
143
|
+
} else {
|
|
144
|
+
bridgeConfigs[chain] = {
|
|
145
|
+
...baseConfig,
|
|
146
|
+
executionType: 'movableCollateral',
|
|
147
|
+
bridge: config.bridge!, // Validated by config schema
|
|
148
|
+
override: config.override as ChainMap<
|
|
149
|
+
Partial<MovableCollateralBridgeConfig>
|
|
150
|
+
>,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return bridgeConfigs;
|
|
156
|
+
}
|
|
157
|
+
}
|