@hyperlane-xyz/rebalancer 27.2.11 → 27.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/core/InventoryRebalancer.d.ts +11 -19
  2. package/dist/core/InventoryRebalancer.d.ts.map +1 -1
  3. package/dist/core/InventoryRebalancer.js +336 -268
  4. package/dist/core/InventoryRebalancer.js.map +1 -1
  5. package/dist/core/InventoryRebalancer.test.js +397 -23
  6. package/dist/core/InventoryRebalancer.test.js.map +1 -1
  7. package/dist/core/Rebalancer.d.ts.map +1 -1
  8. package/dist/core/Rebalancer.js +12 -6
  9. package/dist/core/Rebalancer.js.map +1 -1
  10. package/dist/core/Rebalancer.test.js +51 -0
  11. package/dist/core/Rebalancer.test.js.map +1 -1
  12. package/dist/core/RebalancerOrchestrator.test.js +0 -1
  13. package/dist/core/RebalancerOrchestrator.test.js.map +1 -1
  14. package/dist/core/RebalancerService.d.ts +2 -3
  15. package/dist/core/RebalancerService.d.ts.map +1 -1
  16. package/dist/core/RebalancerService.js +3 -2
  17. package/dist/core/RebalancerService.js.map +1 -1
  18. package/dist/core/RebalancerService.test.js +24 -0
  19. package/dist/core/RebalancerService.test.js.map +1 -1
  20. package/dist/e2e/harness/TestHelpers.js +1 -2
  21. package/dist/e2e/harness/TestHelpers.js.map +1 -1
  22. package/dist/factories/RebalancerContextFactory.d.ts +4 -5
  23. package/dist/factories/RebalancerContextFactory.d.ts.map +1 -1
  24. package/dist/factories/RebalancerContextFactory.js +12 -7
  25. package/dist/factories/RebalancerContextFactory.js.map +1 -1
  26. package/dist/factories/RebalancerContextFactory.test.js +99 -2
  27. package/dist/factories/RebalancerContextFactory.test.js.map +1 -1
  28. package/dist/interfaces/IRebalancer.d.ts +4 -2
  29. package/dist/interfaces/IRebalancer.d.ts.map +1 -1
  30. package/dist/metrics/scripts/metrics.d.ts +1 -1
  31. package/dist/monitor/Monitor.d.ts.map +1 -1
  32. package/dist/monitor/Monitor.js +14 -6
  33. package/dist/monitor/Monitor.js.map +1 -1
  34. package/dist/strategy/BaseStrategy.d.ts.map +1 -1
  35. package/dist/strategy/BaseStrategy.js +13 -11
  36. package/dist/strategy/BaseStrategy.js.map +1 -1
  37. package/dist/strategy/CollateralDeficitStrategy.d.ts.map +1 -1
  38. package/dist/strategy/CollateralDeficitStrategy.js +2 -2
  39. package/dist/strategy/CollateralDeficitStrategy.js.map +1 -1
  40. package/dist/strategy/MinAmountStrategy.d.ts +1 -0
  41. package/dist/strategy/MinAmountStrategy.d.ts.map +1 -1
  42. package/dist/strategy/MinAmountStrategy.js +12 -8
  43. package/dist/strategy/MinAmountStrategy.js.map +1 -1
  44. package/dist/strategy/MinAmountStrategy.test.js +189 -2
  45. package/dist/strategy/MinAmountStrategy.test.js.map +1 -1
  46. package/dist/test/helpers.d.ts +11 -3
  47. package/dist/test/helpers.d.ts.map +1 -1
  48. package/dist/test/helpers.js +9 -11
  49. package/dist/test/helpers.js.map +1 -1
  50. package/dist/test/lifiMocks.d.ts.map +1 -1
  51. package/dist/test/lifiMocks.js +5 -2
  52. package/dist/test/lifiMocks.js.map +1 -1
  53. package/dist/tracking/ActionTracker.d.ts.map +1 -1
  54. package/dist/tracking/ActionTracker.js +2 -1
  55. package/dist/tracking/ActionTracker.js.map +1 -1
  56. package/dist/tracking/ActionTracker.test.js +39 -0
  57. package/dist/tracking/ActionTracker.test.js.map +1 -1
  58. package/dist/utils/balanceUtils.d.ts +7 -1
  59. package/dist/utils/balanceUtils.d.ts.map +1 -1
  60. package/dist/utils/balanceUtils.js +39 -1
  61. package/dist/utils/balanceUtils.js.map +1 -1
  62. package/dist/utils/balanceUtils.test.js +55 -1
  63. package/dist/utils/balanceUtils.test.js.map +1 -1
  64. package/dist/utils/blockTag.d.ts +3 -3
  65. package/dist/utils/blockTag.d.ts.map +1 -1
  66. package/dist/utils/blockTag.js +1 -1
  67. package/dist/utils/blockTag.js.map +1 -1
  68. package/package.json +7 -7
  69. package/src/core/InventoryRebalancer.test.ts +503 -38
  70. package/src/core/InventoryRebalancer.ts +483 -350
  71. package/src/core/Rebalancer.test.ts +84 -0
  72. package/src/core/Rebalancer.ts +22 -6
  73. package/src/core/RebalancerOrchestrator.test.ts +0 -1
  74. package/src/core/RebalancerService.test.ts +35 -0
  75. package/src/core/RebalancerService.ts +9 -5
  76. package/src/e2e/harness/TestHelpers.ts +3 -3
  77. package/src/factories/RebalancerContextFactory.test.ts +143 -6
  78. package/src/factories/RebalancerContextFactory.ts +29 -17
  79. package/src/interfaces/IRebalancer.ts +4 -1
  80. package/src/monitor/Monitor.ts +19 -6
  81. package/src/strategy/BaseStrategy.ts +18 -15
  82. package/src/strategy/CollateralDeficitStrategy.ts +4 -3
  83. package/src/strategy/MinAmountStrategy.test.ts +238 -2
  84. package/src/strategy/MinAmountStrategy.ts +29 -17
  85. package/src/test/helpers.ts +13 -12
  86. package/src/test/lifiMocks.ts +5 -2
  87. package/src/tracking/ActionTracker.test.ts +47 -0
  88. package/src/tracking/ActionTracker.ts +2 -1
  89. package/src/utils/balanceUtils.test.ts +87 -1
  90. package/src/utils/balanceUtils.ts +73 -2
  91. package/src/utils/blockTag.ts +9 -4
@@ -94,6 +94,7 @@ export declare class InventoryRebalancer implements IInventoryRebalancer {
94
94
  * Calculate total inventory across all chains, excluding specified chains.
95
95
  */
96
96
  private getTotalInventory;
97
+ private formatLocalAmount;
97
98
  /**
98
99
  * Get the effective available inventory for a chain, accounting for
99
100
  * inventory already consumed during this execution cycle.
@@ -153,7 +154,6 @@ export declare class InventoryRebalancer implements IInventoryRebalancer {
153
154
  *
154
155
  * @param route - The transfer route (swapped direction)
155
156
  * @param intent - The rebalance intent being executed
156
- * @param gasQuote - Pre-calculated gas quote from calculateTransferCosts
157
157
  */
158
158
  private executeTransferRemote;
159
159
  private sendAndConfirmInventoryTx;
@@ -166,32 +166,24 @@ export declare class InventoryRebalancer implements IInventoryRebalancer {
166
166
  */
167
167
  private selectAllSourceChains;
168
168
  /**
169
- * Calculate the maximum amount that can be bridged from a source chain.
170
- * Uses LiFi quote to determine gas costs, applies 20x multiplier buffer.
171
- * Returns 0 if gas exceeds 10% of inventory (not economically viable).
169
+ * Calculate the bridge capacity from a source chain in destination-local units.
170
+ * Uses LiFi quotes to conservatively estimate the destination output available
171
+ * from the source chain's current local inventory.
172
172
  *
173
- * This is the key method for the gas-aware planning approach:
174
- * - Gets a quote for the full raw inventory to determine actual gas costs
175
- * - Applies conservative 20x buffer (LiFi underestimates by ~14x historically)
176
- * - Returns 0 if gas > 10% of inventory (not worth bridging)
177
- * - Returns inventory - estimatedGas if viable
178
- *
179
- * @param sourceChain - Chain to bridge from
180
- * @param targetChain - Chain to bridge to
181
- * @param rawInventory - Raw available inventory on source chain
182
- * @param externalBridgeType - External bridge type to use
183
- * @returns Maximum viable bridge amount (0 if not viable)
173
+ * For native-token sources, gas is reserved from the source inventory and the
174
+ * output capacity is re-quoted from the remaining source input.
184
175
  */
185
- private calculateMaxViableBridgeAmount;
176
+ private calculateBridgeCapacity;
186
177
  /**
187
178
  * Execute inventory movement from source chain to target chain via LiFi bridge.
188
179
  *
189
- * IMPORTANT: The amount parameter is now the MAX VIABLE amount (gas already subtracted
190
- * by calculateMaxViableBridgeAmount). This method trusts that the amount is pre-validated.
180
+ * Uses reverse quotes (`toAmount`) so plans are expressed in target-chain local
181
+ * units and source-local spend is discovered by the bridge quote.
191
182
  *
192
183
  * @param sourceChain - Chain to move inventory from
193
184
  * @param targetChain - Chain to move inventory to (origin chain for rebalancing)
194
- * @param amount - Pre-validated amount to bridge (gas already accounted for)
185
+ * @param targetOutputAmount - Destination-local amount to receive
186
+ * @param maxSourceInput - Maximum source-local amount available for this plan
195
187
  * @param intent - Rebalance intent for tracking
196
188
  * @param externalBridgeType - External bridge type to use
197
189
  * @returns Result with success status and optional txHash/error
@@ -1 +1 @@
1
- {"version":3,"file":"InventoryRebalancer.d.ts","sourceRoot":"","sources":["../../src/core/InventoryRebalancer.ts"],"names":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