@hyperlane-xyz/cli 33.0.0 → 33.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/index.js +798 -614
- package/package.json +15 -15
package/bundle/index.js
CHANGED
|
@@ -693924,7 +693924,7 @@ __webpack_async_result__();
|
|
|
693924
693924
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
693925
693925
|
/* harmony export */ x: () => (/* binding */ VERSION)
|
|
693926
693926
|
/* harmony export */ });
|
|
693927
|
-
const VERSION = '33.0.
|
|
693927
|
+
const VERSION = '33.0.1';
|
|
693928
693928
|
//# sourceMappingURL=version.js.map
|
|
693929
693929
|
|
|
693930
693930
|
/***/ }),
|
|
@@ -735381,23 +735381,24 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
735381
735381
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
735382
735382
|
/* harmony export */ c: () => (/* binding */ InventoryRebalancer)
|
|
735383
735383
|
/* harmony export */ });
|
|
735384
|
-
/* harmony import */ var
|
|
735385
|
-
/* harmony import */ var
|
|
735386
|
-
/* harmony import */ var
|
|
735387
|
-
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(95778);
|
|
735388
|
-
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_9__ = __nccwpck_require__(54194);
|
|
735384
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(4879);
|
|
735385
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(95778);
|
|
735386
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(54194);
|
|
735389
735387
|
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_12__ = __nccwpck_require__(25047);
|
|
735390
735388
|
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_13__ = __nccwpck_require__(71598);
|
|
735391
735389
|
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_14__ = __nccwpck_require__(59942);
|
|
735392
|
-
/* harmony import */ var
|
|
735393
|
-
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(
|
|
735394
|
-
/* harmony import */ var
|
|
735395
|
-
/* harmony import */ var
|
|
735390
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(21387);
|
|
735391
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(39196);
|
|
735392
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_10__ = __nccwpck_require__(16639);
|
|
735393
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_11__ = __nccwpck_require__(93142);
|
|
735394
|
+
/* harmony import */ var _utils_gasEstimation_js__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(47560);
|
|
735396
735395
|
/* harmony import */ var _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(46618);
|
|
735397
735396
|
/* harmony import */ var _utils_solanaKeyParser_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(20162);
|
|
735398
|
-
/* harmony import */ var
|
|
735399
|
-
var
|
|
735400
|
-
([_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__,
|
|
735397
|
+
/* harmony import */ var _utils_transactionUtils_js__WEBPACK_IMPORTED_MODULE_9__ = __nccwpck_require__(32581);
|
|
735398
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(11369);
|
|
735399
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__, _utils_transactionUtils_js__WEBPACK_IMPORTED_MODULE_9__]);
|
|
735400
|
+
([_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__, _utils_transactionUtils_js__WEBPACK_IMPORTED_MODULE_9__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
735401
|
+
|
|
735401
735402
|
|
|
735402
735403
|
|
|
735403
735404
|
|
|
@@ -735421,6 +735422,46 @@ const GAS_COST_MULTIPLIER = 20n;
|
|
|
735421
735422
|
* If gas exceeds this threshold, the bridge is not economically worthwhile.
|
|
735422
735423
|
*/
|
|
735423
735424
|
const MAX_GAS_PERCENT_THRESHOLD = 10n;
|
|
735425
|
+
const RECOVERABLE_MAX_TRANSFER_ERROR_MESSAGES = [
|
|
735426
|
+
'balance may be insufficient',
|
|
735427
|
+
'transfer amount exceeds balance',
|
|
735428
|
+
'insufficient balance',
|
|
735429
|
+
];
|
|
735430
|
+
function hasRecoverableMaxTransferErrorMessage(message) {
|
|
735431
|
+
const normalized = message.toLowerCase();
|
|
735432
|
+
return (normalized.includes('unpredictable_gas_limit') ||
|
|
735433
|
+
RECOVERABLE_MAX_TRANSFER_ERROR_MESSAGES.some((pattern) => normalized.includes(pattern)));
|
|
735434
|
+
}
|
|
735435
|
+
function isRecoverableMaxTransferProbeError(error) {
|
|
735436
|
+
const seen = new Set();
|
|
735437
|
+
const stack = [error];
|
|
735438
|
+
while (stack.length > 0) {
|
|
735439
|
+
const current = stack.pop();
|
|
735440
|
+
if (current == null)
|
|
735441
|
+
continue;
|
|
735442
|
+
if (typeof current === 'string') {
|
|
735443
|
+
if (hasRecoverableMaxTransferErrorMessage(current))
|
|
735444
|
+
return true;
|
|
735445
|
+
continue;
|
|
735446
|
+
}
|
|
735447
|
+
if (typeof current !== 'object')
|
|
735448
|
+
continue;
|
|
735449
|
+
if (seen.has(current))
|
|
735450
|
+
continue;
|
|
735451
|
+
seen.add(current);
|
|
735452
|
+
const candidate = current;
|
|
735453
|
+
if (typeof candidate.code === 'string' &&
|
|
735454
|
+
candidate.code.toUpperCase() === 'UNPREDICTABLE_GAS_LIMIT') {
|
|
735455
|
+
return true;
|
|
735456
|
+
}
|
|
735457
|
+
if (typeof candidate.message === 'string' &&
|
|
735458
|
+
hasRecoverableMaxTransferErrorMessage(candidate.message)) {
|
|
735459
|
+
return true;
|
|
735460
|
+
}
|
|
735461
|
+
stack.push(candidate.cause, candidate.error);
|
|
735462
|
+
}
|
|
735463
|
+
return false;
|
|
735464
|
+
}
|
|
735424
735465
|
/**
|
|
735425
735466
|
* Executes inventory-based rebalances for chains that don't support MovableCollateralRouter.
|
|
735426
735467
|
*
|
|
@@ -735507,10 +735548,10 @@ class InventoryRebalancer {
|
|
|
735507
735548
|
if (!inventoryChainSet.has(token.chainName)) {
|
|
735508
735549
|
continue;
|
|
735509
735550
|
}
|
|
735510
|
-
if (!
|
|
735551
|
+
if (!_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_3__/* .TOKEN_COLLATERALIZED_STANDARDS */ .PP.includes(token.standard)) {
|
|
735511
735552
|
throw new Error(`InventoryRebalancer cannot be used with synthetic token on chain "${token.chainName}". ` +
|
|
735512
735553
|
`Token standard "${token.standard}" is not collateral-backed. ` +
|
|
735513
|
-
`Only collateral-backed standards are supported: ${
|
|
735554
|
+
`Only collateral-backed standards are supported: ${_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_3__/* .TOKEN_COLLATERALIZED_STANDARDS */ .PP.join(', ')}`);
|
|
735514
735555
|
}
|
|
735515
735556
|
}
|
|
735516
735557
|
}
|
|
@@ -735522,14 +735563,14 @@ class InventoryRebalancer {
|
|
|
735522
735563
|
}
|
|
735523
735564
|
getProtocolForChain(chainName) {
|
|
735524
735565
|
const metadata = this.warpCore.multiProvider.getChainMetadata?.(chainName) ?? undefined;
|
|
735525
|
-
(0,
|
|
735526
|
-
(0,
|
|
735566
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(metadata, `No chain metadata found for chain ${chainName}`);
|
|
735567
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(metadata.protocol, `No protocol type in metadata for chain ${chainName}`);
|
|
735527
735568
|
return metadata.protocol;
|
|
735528
735569
|
}
|
|
735529
735570
|
getInventorySignerAddress(chainName) {
|
|
735530
735571
|
const protocol = this.getProtocolForChain(chainName);
|
|
735531
735572
|
const signerConfig = this.config.inventorySigners[protocol];
|
|
735532
|
-
(0,
|
|
735573
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(signerConfig?.address, `Missing inventory signer address for protocol ${protocol} (chain ${chainName})`);
|
|
735533
735574
|
return signerConfig.address;
|
|
735534
735575
|
}
|
|
735535
735576
|
/**
|
|
@@ -735569,6 +735610,9 @@ class InventoryRebalancer {
|
|
|
735569
735610
|
}
|
|
735570
735611
|
return total;
|
|
735571
735612
|
}
|
|
735613
|
+
formatLocalAmount(amount, token) {
|
|
735614
|
+
return (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .fromWei */ .kX)(amount.toString(), token.decimals);
|
|
735615
|
+
}
|
|
735572
735616
|
/**
|
|
735573
735617
|
* Get the effective available inventory for a chain, accounting for
|
|
735574
735618
|
* inventory already consumed during this execution cycle.
|
|
@@ -735751,45 +735795,96 @@ class InventoryRebalancer {
|
|
|
735751
735795
|
this.logger.info({
|
|
735752
735796
|
strategyRoute: `${origin} (surplus) → ${destination} (deficit)`,
|
|
735753
735797
|
executionRoute: `transferRemote FROM ${destination} TO ${origin}`,
|
|
735754
|
-
|
|
735798
|
+
canonicalAmount: amount.toString(),
|
|
735755
735799
|
intentId: intent.id,
|
|
735756
735800
|
}, 'Executing inventory route');
|
|
735801
|
+
const sourceToken = this.getTokenForChain(destination);
|
|
735802
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(sourceToken, `No token found for source chain: ${destination}`);
|
|
735803
|
+
const requestedLocalAmount = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__/* .denormalizeToLocal */ .bK)(amount, sourceToken);
|
|
735804
|
+
const executionSender = this.getInventorySignerAddress(destination);
|
|
735805
|
+
const executionRecipient = this.getInventorySignerAddress(origin);
|
|
735757
735806
|
// Check available inventory on the DESTINATION (deficit) chain
|
|
735758
735807
|
// We need inventory here because transferRemote is called FROM this chain
|
|
735759
735808
|
const availableInventory = this.getEffectiveAvailableInventory(destination);
|
|
735760
735809
|
this.logger.info({
|
|
735761
735810
|
checkingChain: destination,
|
|
735762
735811
|
availableInventory: availableInventory.toString(),
|
|
735763
|
-
|
|
735764
|
-
requiredAmount:
|
|
735765
|
-
|
|
735812
|
+
availableInventoryFormatted: this.formatLocalAmount(availableInventory, sourceToken),
|
|
735813
|
+
requiredAmount: requestedLocalAmount.toString(),
|
|
735814
|
+
requiredAmountFormatted: this.formatLocalAmount(requestedLocalAmount, sourceToken),
|
|
735766
735815
|
}, 'Checking effective inventory on destination (deficit) chain');
|
|
735767
735816
|
// Calculate transfer costs including max transferable and min viable amounts
|
|
735768
735817
|
// transferRemote is called FROM destination TO origin (swapped direction)
|
|
735769
|
-
const costs = await (0,
|
|
735818
|
+
const costs = await (0,_utils_gasEstimation_js__WEBPACK_IMPORTED_MODULE_6__/* .calculateTransferCosts */ ._P)(destination, // FROM chain (where transferRemote is called)
|
|
735770
735819
|
origin, // TO chain (where Hyperlane message goes)
|
|
735771
|
-
availableInventory,
|
|
735772
|
-
const {
|
|
735820
|
+
availableInventory, requestedLocalAmount, this.multiProvider, this.warpCore.multiProvider, this.getTokenForChain.bind(this), executionSender, _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .isNativeTokenStandard */ .OJ, this.logger);
|
|
735821
|
+
const { minViableTransfer } = costs;
|
|
735822
|
+
let maxTransferable = costs.maxTransferable;
|
|
735823
|
+
if (!(0,_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .isNativeTokenStandard */ .OJ)(sourceToken.standard)) {
|
|
735824
|
+
if (availableInventory === 0n) {
|
|
735825
|
+
maxTransferable = 0n;
|
|
735826
|
+
this.logger.debug({
|
|
735827
|
+
fromChain: destination,
|
|
735828
|
+
toChain: origin,
|
|
735829
|
+
requestedAmount: requestedLocalAmount.toString(),
|
|
735830
|
+
}, 'Skipping fee-aware max transferable probe because destination inventory is zero');
|
|
735831
|
+
}
|
|
735832
|
+
else {
|
|
735833
|
+
try {
|
|
735834
|
+
const feeAwareMaxTransfer = await this.warpCore.getMaxTransferAmount({
|
|
735835
|
+
balance: sourceToken.amount(availableInventory),
|
|
735836
|
+
destination: origin,
|
|
735837
|
+
sender: executionSender,
|
|
735838
|
+
recipient: executionRecipient,
|
|
735839
|
+
});
|
|
735840
|
+
maxTransferable =
|
|
735841
|
+
feeAwareMaxTransfer.amount < requestedLocalAmount
|
|
735842
|
+
? feeAwareMaxTransfer.amount
|
|
735843
|
+
: requestedLocalAmount;
|
|
735844
|
+
this.logger.debug({
|
|
735845
|
+
fromChain: destination,
|
|
735846
|
+
toChain: origin,
|
|
735847
|
+
availableInventory: availableInventory.toString(),
|
|
735848
|
+
requestedAmount: requestedLocalAmount.toString(),
|
|
735849
|
+
feeAwareMaxTransferable: maxTransferable.toString(),
|
|
735850
|
+
}, 'Calculated fee-aware max transferable amount for non-native route');
|
|
735851
|
+
}
|
|
735852
|
+
catch (error) {
|
|
735853
|
+
if (!isRecoverableMaxTransferProbeError(error)) {
|
|
735854
|
+
throw error;
|
|
735855
|
+
}
|
|
735856
|
+
maxTransferable = 0n;
|
|
735857
|
+
this.logger.warn({
|
|
735858
|
+
fromChain: destination,
|
|
735859
|
+
toChain: origin,
|
|
735860
|
+
availableInventory: availableInventory.toString(),
|
|
735861
|
+
requestedAmount: requestedLocalAmount.toString(),
|
|
735862
|
+
error: error instanceof Error ? error.message : String(error),
|
|
735863
|
+
intentId: intent.id,
|
|
735864
|
+
}, 'Fee-aware max transferable probe failed due to insufficient balance, falling back to external bridge');
|
|
735865
|
+
}
|
|
735866
|
+
}
|
|
735867
|
+
}
|
|
735773
735868
|
// Calculate total inventory across all chains
|
|
735774
735869
|
// Note: consumedInventory tracking is handled separately within this cycle
|
|
735775
735870
|
const totalInventory = this.getTotalInventory([]);
|
|
735776
735871
|
this.logger.info({
|
|
735777
735872
|
fromChain: destination,
|
|
735778
735873
|
toChain: origin,
|
|
735779
|
-
|
|
735780
|
-
|
|
735781
|
-
|
|
735782
|
-
|
|
735783
|
-
|
|
735784
|
-
canFullyFulfill: maxTransferable >= amount,
|
|
735874
|
+
availableInventoryFormatted: this.formatLocalAmount(availableInventory, sourceToken),
|
|
735875
|
+
requestedAmountFormatted: this.formatLocalAmount(requestedLocalAmount, sourceToken),
|
|
735876
|
+
maxTransferableFormatted: this.formatLocalAmount(maxTransferable, sourceToken),
|
|
735877
|
+
minViableTransferFormatted: this.formatLocalAmount(minViableTransfer, sourceToken),
|
|
735878
|
+
canFullyFulfill: maxTransferable >= requestedLocalAmount,
|
|
735785
735879
|
canPartialFulfill: maxTransferable >= minViableTransfer,
|
|
735880
|
+
totalInventory: totalInventory.toString(),
|
|
735786
735881
|
}, 'Calculated max transferable amount with cost-based threshold');
|
|
735787
735882
|
// Early exit: If remaining amount is below minViableTransfer, complete the intent
|
|
735788
735883
|
// This prevents infinite loops when the remaining amount is too small to economically bridge
|
|
735789
|
-
if (
|
|
735884
|
+
if (requestedLocalAmount < minViableTransfer) {
|
|
735790
735885
|
this.logger.info({
|
|
735791
735886
|
intentId: intent.id,
|
|
735792
|
-
amount:
|
|
735887
|
+
amount: requestedLocalAmount.toString(),
|
|
735793
735888
|
minViableTransfer: minViableTransfer.toString(),
|
|
735794
735889
|
}, 'Remaining amount below minViableTransfer, completing intent with acceptable loss');
|
|
735795
735890
|
await this.actionTracker.completeRebalanceIntent(intent.id);
|
|
@@ -735805,156 +735900,176 @@ class InventoryRebalancer {
|
|
|
735805
735900
|
...route,
|
|
735806
735901
|
origin: destination, // transferRemote called FROM here
|
|
735807
735902
|
destination: origin, // Hyperlane message goes TO here
|
|
735903
|
+
amount: requestedLocalAmount,
|
|
735808
735904
|
};
|
|
735809
|
-
if (maxTransferable >=
|
|
735905
|
+
if (maxTransferable >= requestedLocalAmount) {
|
|
735810
735906
|
// Sufficient inventory on destination - execute transferRemote directly
|
|
735811
|
-
const
|
|
735907
|
+
const fulfilledCanonicalAmount = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__/* .normalizeToCanonical */ .R2)(requestedLocalAmount, sourceToken);
|
|
735908
|
+
const result = await this.executeTransferRemote(swappedRoute, intent, fulfilledCanonicalAmount);
|
|
735812
735909
|
// Return original strategy route in result (not the swapped execution route)
|
|
735813
735910
|
return { ...result, route };
|
|
735814
735911
|
}
|
|
735815
735912
|
else if (maxTransferable > 0n && maxTransferable >= minViableTransfer) {
|
|
735816
735913
|
// Partial transfer: Transfer available inventory when economically viable
|
|
735817
|
-
const
|
|
735818
|
-
|
|
735819
|
-
|
|
735820
|
-
};
|
|
735821
|
-
const result = await this.executeTransferRemote(partialSwappedRoute, intent, costs.gasQuote);
|
|
735822
|
-
this.logger.info({
|
|
735823
|
-
intentId: intent.id,
|
|
735824
|
-
partialAmount: maxTransferable.toString(),
|
|
735825
|
-
requestedAmount: amount.toString(),
|
|
735826
|
-
remainingAmount: (amount - maxTransferable).toString(),
|
|
735827
|
-
}, 'Executed partial inventory deposit, remaining will be handled in future cycles');
|
|
735828
|
-
// Return original strategy route in result (not the swapped execution route)
|
|
735829
|
-
return { ...result, route };
|
|
735830
|
-
}
|
|
735831
|
-
else {
|
|
735832
|
-
// Inventory below cost-based threshold - trigger ExternalBridge movement TO destination chain
|
|
735833
|
-
this.logger.info({
|
|
735834
|
-
targetChain: destination,
|
|
735835
|
-
maxTransferable: maxTransferable.toString(),
|
|
735836
|
-
minViableTransfer: minViableTransfer.toString(),
|
|
735837
|
-
costMultiplier: _utils_gasEstimation_js__WEBPACK_IMPORTED_MODULE_4__/* .MIN_VIABLE_COST_MULTIPLIER */ .hh.toString(),
|
|
735838
|
-
intentId: intent.id,
|
|
735839
|
-
}, 'Inventory below cost-based threshold on destination, triggering LiFi movement');
|
|
735840
|
-
// Get all available source chains with raw inventory
|
|
735841
|
-
const allSources = this.selectAllSourceChains(destination);
|
|
735842
|
-
if (allSources.length === 0) {
|
|
735843
|
-
this.logger.warn({
|
|
735844
|
-
origin,
|
|
735845
|
-
destination,
|
|
735846
|
-
amount: amount.toString(),
|
|
735914
|
+
const alignedExecution = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__/* .alignLocalToCanonical */ .gU)(maxTransferable, sourceToken);
|
|
735915
|
+
if (alignedExecution.messageAmount === 0n) {
|
|
735916
|
+
this.logger.info({
|
|
735847
735917
|
intentId: intent.id,
|
|
735848
|
-
|
|
735849
|
-
|
|
735850
|
-
route,
|
|
735851
|
-
success: false,
|
|
735852
|
-
error: 'No inventory available on any monitored chain',
|
|
735853
|
-
};
|
|
735918
|
+
maxTransferable: maxTransferable.toString(),
|
|
735919
|
+
}, 'Skipping partial transferRemote because available local amount cannot produce canonical progress');
|
|
735854
735920
|
}
|
|
735855
|
-
|
|
735856
|
-
|
|
735857
|
-
|
|
735858
|
-
|
|
735859
|
-
const maxViable = await this.calculateMaxViableBridgeAmount(source.chain, destination, source.availableAmount, route.externalBridge);
|
|
735860
|
-
if (maxViable > 0n) {
|
|
735861
|
-
viableSources.push({ chain: source.chain, maxViable });
|
|
735862
|
-
}
|
|
735863
|
-
}
|
|
735864
|
-
// Sort by max viable descending (bridge from largest sources first)
|
|
735865
|
-
viableSources.sort((a, b) => (a.maxViable > b.maxViable ? -1 : 1));
|
|
735866
|
-
if (viableSources.length === 0) {
|
|
735867
|
-
this.logger.warn({
|
|
735868
|
-
targetChain: destination,
|
|
735869
|
-
sourcesChecked: allSources.length,
|
|
735870
|
-
intentId: intent.id,
|
|
735871
|
-
}, 'No viable bridge sources - all chains have insufficient inventory or high gas costs');
|
|
735872
|
-
return {
|
|
735873
|
-
route,
|
|
735874
|
-
success: false,
|
|
735875
|
-
error: 'No viable bridge sources available',
|
|
735921
|
+
else {
|
|
735922
|
+
const partialSwappedRoute = {
|
|
735923
|
+
...swappedRoute,
|
|
735924
|
+
amount: alignedExecution.localAmount,
|
|
735876
735925
|
};
|
|
735926
|
+
const result = await this.executeTransferRemote(partialSwappedRoute, intent, alignedExecution.messageAmount);
|
|
735927
|
+
this.logger.info({
|
|
735928
|
+
intentId: intent.id,
|
|
735929
|
+
partialAmount: alignedExecution.localAmount.toString(),
|
|
735930
|
+
partialAmountCanonical: alignedExecution.messageAmount.toString(),
|
|
735931
|
+
requestedAmount: requestedLocalAmount.toString(),
|
|
735932
|
+
requestedAmountCanonical: amount.toString(),
|
|
735933
|
+
remainingAmountCanonical: (amount > alignedExecution.messageAmount
|
|
735934
|
+
? amount - alignedExecution.messageAmount
|
|
735935
|
+
: 0n).toString(),
|
|
735936
|
+
}, 'Executed partial inventory deposit, remaining will be handled in future cycles');
|
|
735937
|
+
// Return original strategy route in result (not the swapped execution route)
|
|
735938
|
+
return { ...result, route };
|
|
735939
|
+
}
|
|
735940
|
+
}
|
|
735941
|
+
// Inventory below cost-based threshold - trigger ExternalBridge movement TO destination chain
|
|
735942
|
+
this.logger.info({
|
|
735943
|
+
targetChain: destination,
|
|
735944
|
+
maxTransferable: maxTransferable.toString(),
|
|
735945
|
+
minViableTransfer: minViableTransfer.toString(),
|
|
735946
|
+
costMultiplier: _utils_gasEstimation_js__WEBPACK_IMPORTED_MODULE_6__/* .MIN_VIABLE_COST_MULTIPLIER */ .hh.toString(),
|
|
735947
|
+
intentId: intent.id,
|
|
735948
|
+
}, 'Inventory below cost-based threshold on destination, triggering LiFi movement');
|
|
735949
|
+
// Get all available source chains with raw inventory
|
|
735950
|
+
const allSources = this.selectAllSourceChains(destination);
|
|
735951
|
+
if (allSources.length === 0) {
|
|
735952
|
+
this.logger.warn({
|
|
735953
|
+
origin,
|
|
735954
|
+
destination,
|
|
735955
|
+
amount: requestedLocalAmount.toString(),
|
|
735956
|
+
intentId: intent.id,
|
|
735957
|
+
}, 'No inventory available on any monitored chain');
|
|
735958
|
+
return {
|
|
735959
|
+
route,
|
|
735960
|
+
success: false,
|
|
735961
|
+
error: 'No inventory available on any monitored chain',
|
|
735962
|
+
};
|
|
735963
|
+
}
|
|
735964
|
+
// Calculate source capacities in destination-local units.
|
|
735965
|
+
const viableSources = [];
|
|
735966
|
+
for (const source of allSources) {
|
|
735967
|
+
const capacity = await this.calculateBridgeCapacity(source.chain, destination, source.availableAmount, route.externalBridge);
|
|
735968
|
+
if (capacity.maxTargetOutput > 0n) {
|
|
735969
|
+
viableSources.push({ chain: source.chain, ...capacity });
|
|
735877
735970
|
}
|
|
735878
|
-
|
|
735879
|
-
|
|
735880
|
-
|
|
735881
|
-
|
|
735882
|
-
|
|
735883
|
-
if (totalPlanned >= targetWithBuffer)
|
|
735884
|
-
break;
|
|
735885
|
-
const remaining = targetWithBuffer - totalPlanned;
|
|
735886
|
-
const amountFromSource = source.maxViable >= remaining ? remaining : source.maxViable; // Already gas-adjusted!
|
|
735887
|
-
bridgePlans.push({
|
|
735888
|
-
chain: source.chain,
|
|
735889
|
-
amount: amountFromSource,
|
|
735890
|
-
});
|
|
735891
|
-
totalPlanned += amountFromSource;
|
|
735892
|
-
}
|
|
735893
|
-
this.logger.info({
|
|
735971
|
+
}
|
|
735972
|
+
// Sort by destination output descending.
|
|
735973
|
+
viableSources.sort((a, b) => a.maxTargetOutput > b.maxTargetOutput ? -1 : 1);
|
|
735974
|
+
if (viableSources.length === 0) {
|
|
735975
|
+
this.logger.warn({
|
|
735894
735976
|
targetChain: destination,
|
|
735895
|
-
|
|
735896
|
-
chain: s.chain,
|
|
735897
|
-
maxViable: s.maxViable.toString(),
|
|
735898
|
-
maxViableEth: (Number(s.maxViable) / 1e18).toFixed(6),
|
|
735899
|
-
})),
|
|
735900
|
-
bridgePlans: bridgePlans.map((p) => ({
|
|
735901
|
-
chain: p.chain,
|
|
735902
|
-
amount: p.amount.toString(),
|
|
735903
|
-
amountEth: (Number(p.amount) / 1e18).toFixed(6),
|
|
735904
|
-
})),
|
|
735905
|
-
totalPlanned: totalPlanned.toString(),
|
|
735906
|
-
targetWithBuffer: targetWithBuffer.toString(),
|
|
735977
|
+
sourcesChecked: allSources.length,
|
|
735907
735978
|
intentId: intent.id,
|
|
735908
|
-
}, '
|
|
735909
|
-
|
|
735910
|
-
|
|
735911
|
-
|
|
735912
|
-
|
|
735913
|
-
|
|
735914
|
-
|
|
735915
|
-
|
|
735916
|
-
|
|
735917
|
-
|
|
735918
|
-
|
|
735919
|
-
|
|
735920
|
-
|
|
735921
|
-
|
|
735922
|
-
|
|
735923
|
-
|
|
735924
|
-
|
|
735925
|
-
|
|
735926
|
-
|
|
735927
|
-
|
|
735928
|
-
|
|
735929
|
-
|
|
735930
|
-
|
|
735931
|
-
|
|
735932
|
-
|
|
735933
|
-
|
|
735934
|
-
|
|
735935
|
-
|
|
735936
|
-
|
|
735937
|
-
|
|
735938
|
-
|
|
735939
|
-
|
|
735979
|
+
}, 'No viable bridge sources - all chains have insufficient inventory or high gas costs');
|
|
735980
|
+
return {
|
|
735981
|
+
route,
|
|
735982
|
+
success: false,
|
|
735983
|
+
error: 'No viable bridge sources available',
|
|
735984
|
+
};
|
|
735985
|
+
}
|
|
735986
|
+
// Create bridge plans using destination-local output amounts.
|
|
735987
|
+
const shortfall = requestedLocalAmount > availableInventory
|
|
735988
|
+
? requestedLocalAmount - availableInventory
|
|
735989
|
+
: 0n;
|
|
735990
|
+
const targetWithBuffer = ((shortfall + costs.totalCost) * (100n + BRIDGE_BUFFER_PERCENT)) / 100n;
|
|
735991
|
+
const bridgePlans = [];
|
|
735992
|
+
let totalPlanned = 0n;
|
|
735993
|
+
for (const source of viableSources) {
|
|
735994
|
+
if (totalPlanned >= targetWithBuffer)
|
|
735995
|
+
break;
|
|
735996
|
+
const remaining = targetWithBuffer - totalPlanned;
|
|
735997
|
+
const targetOutput = source.maxTargetOutput >= remaining
|
|
735998
|
+
? remaining
|
|
735999
|
+
: source.maxTargetOutput;
|
|
736000
|
+
bridgePlans.push({
|
|
736001
|
+
chain: source.chain,
|
|
736002
|
+
maxSourceInput: source.maxSourceInput,
|
|
736003
|
+
targetOutput,
|
|
736004
|
+
});
|
|
736005
|
+
totalPlanned += targetOutput;
|
|
736006
|
+
}
|
|
736007
|
+
this.logger.info({
|
|
736008
|
+
targetChain: destination,
|
|
736009
|
+
viableSources: viableSources.map((s) => ({
|
|
736010
|
+
chain: s.chain,
|
|
736011
|
+
maxSourceInput: s.maxSourceInput.toString(),
|
|
736012
|
+
maxTargetOutput: s.maxTargetOutput.toString(),
|
|
736013
|
+
})),
|
|
736014
|
+
bridgePlans: bridgePlans.map((p) => ({
|
|
736015
|
+
chain: p.chain,
|
|
736016
|
+
maxSourceInput: p.maxSourceInput.toString(),
|
|
736017
|
+
targetOutput: p.targetOutput.toString(),
|
|
736018
|
+
})),
|
|
736019
|
+
totalPlanned: totalPlanned.toString(),
|
|
736020
|
+
shortfall: shortfall.toString(),
|
|
736021
|
+
targetWithBuffer: targetWithBuffer.toString(),
|
|
736022
|
+
intentId: intent.id,
|
|
736023
|
+
}, 'Created bridge plans using gas-adjusted viable amounts');
|
|
736024
|
+
// Execute all bridges in parallel
|
|
736025
|
+
const bridgeResults = await Promise.allSettled(bridgePlans.map((plan) => this.executeInventoryMovement(plan.chain, destination, plan.targetOutput, plan.maxSourceInput, intent, route.externalBridge)));
|
|
736026
|
+
// Process results
|
|
736027
|
+
let successCount = 0;
|
|
736028
|
+
let totalBridged = 0n;
|
|
736029
|
+
const failedErrors = [];
|
|
736030
|
+
for (let i = 0; i < bridgeResults.length; i++) {
|
|
736031
|
+
const result = bridgeResults[i];
|
|
736032
|
+
const plan = bridgePlans[i];
|
|
736033
|
+
if (result.status === 'fulfilled' && result.value.success) {
|
|
736034
|
+
successCount++;
|
|
736035
|
+
totalBridged += plan.targetOutput;
|
|
736036
|
+
this.logger.info({
|
|
736037
|
+
sourceChain: plan.chain,
|
|
736038
|
+
amount: plan.targetOutput.toString(),
|
|
736039
|
+
txHash: result.value.txHash,
|
|
736040
|
+
}, 'Inventory movement succeeded');
|
|
735940
736041
|
}
|
|
735941
|
-
|
|
735942
|
-
const
|
|
735943
|
-
|
|
735944
|
-
|
|
735945
|
-
|
|
735946
|
-
|
|
735947
|
-
}
|
|
736042
|
+
else {
|
|
736043
|
+
const error = result.status === 'rejected'
|
|
736044
|
+
? result.reason?.message
|
|
736045
|
+
: result.value.error;
|
|
736046
|
+
if (error) {
|
|
736047
|
+
failedErrors.push(`${plan.chain}: ${error}`);
|
|
736048
|
+
}
|
|
736049
|
+
this.logger.warn({
|
|
736050
|
+
sourceChain: plan.chain,
|
|
736051
|
+
amount: plan.targetOutput.toString(),
|
|
736052
|
+
error,
|
|
736053
|
+
}, 'Inventory movement failed');
|
|
735948
736054
|
}
|
|
735949
|
-
this.logger.info({
|
|
735950
|
-
targetChain: destination,
|
|
735951
|
-
successCount,
|
|
735952
|
-
totalBridged: totalBridged.toString(),
|
|
735953
|
-
targetAmount: amount.toString(),
|
|
735954
|
-
intentId: intent.id,
|
|
735955
|
-
}, 'Parallel inventory movements completed, transferRemote will execute after bridges complete');
|
|
735956
|
-
return { route, success: true };
|
|
735957
736055
|
}
|
|
736056
|
+
if (successCount === 0) {
|
|
736057
|
+
const errorDetails = failedErrors.length > 0 ? ` (${failedErrors.join('; ')})` : '';
|
|
736058
|
+
return {
|
|
736059
|
+
route,
|
|
736060
|
+
success: false,
|
|
736061
|
+
error: `All inventory movements failed${errorDetails}`,
|
|
736062
|
+
};
|
|
736063
|
+
}
|
|
736064
|
+
this.logger.info({
|
|
736065
|
+
targetChain: destination,
|
|
736066
|
+
successCount,
|
|
736067
|
+
totalBridged: totalBridged.toString(),
|
|
736068
|
+
targetAmount: requestedLocalAmount.toString(),
|
|
736069
|
+
targetAmountCanonical: amount.toString(),
|
|
736070
|
+
intentId: intent.id,
|
|
736071
|
+
}, 'Parallel inventory movements completed, transferRemote will execute after bridges complete');
|
|
736072
|
+
return { route, success: true };
|
|
735958
736073
|
}
|
|
735959
736074
|
/**
|
|
735960
736075
|
* Execute a transferRemote to deposit collateral.
|
|
@@ -735969,50 +736084,23 @@ class InventoryRebalancer {
|
|
|
735969
736084
|
*
|
|
735970
736085
|
* @param route - The transfer route (swapped direction)
|
|
735971
736086
|
* @param intent - The rebalance intent being executed
|
|
735972
|
-
* @param gasQuote - Pre-calculated gas quote from calculateTransferCosts
|
|
735973
736087
|
*/
|
|
735974
|
-
async executeTransferRemote(route, intent,
|
|
736088
|
+
async executeTransferRemote(route, intent, fulfilledCanonicalAmount) {
|
|
735975
736089
|
const { origin, destination, amount } = route;
|
|
735976
736090
|
const originToken = this.getTokenForChain(origin);
|
|
735977
736091
|
if (!originToken) {
|
|
735978
736092
|
throw new Error(`No token found for origin chain: ${origin}`);
|
|
735979
736093
|
}
|
|
735980
736094
|
const destinationDomain = this.multiProvider.getDomainId(destination);
|
|
735981
|
-
this.logger.debug({
|
|
735982
|
-
origin,
|
|
735983
|
-
destination,
|
|
735984
|
-
amount: amount.toString(),
|
|
735985
|
-
gasQuote: {
|
|
735986
|
-
igpQuote: gasQuote.igpQuote.amount.toString(),
|
|
735987
|
-
tokenFeeQuote: gasQuote.tokenFeeQuote?.amount?.toString() ?? 'none',
|
|
735988
|
-
},
|
|
735989
|
-
}, 'Using pre-calculated gas quote for transferRemote');
|
|
735990
|
-
// Convert pre-calculated gas quote to TokenAmount for WarpCore
|
|
735991
|
-
const originChainMetadata = this.multiProvider.getChainMetadata(origin);
|
|
735992
|
-
const igpAddressOrDenom = gasQuote.igpQuote.addressOrDenom;
|
|
735993
|
-
const igpToken = !igpAddressOrDenom || (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .isZeroishAddress */ .Hi)(igpAddressOrDenom)
|
|
735994
|
-
? _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_6__/* .Token */ .o.FromChainMetadataNativeToken(originChainMetadata)
|
|
735995
|
-
: this.warpCore.findToken(origin, igpAddressOrDenom);
|
|
735996
|
-
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .v)(igpToken, `IGP fee token ${igpAddressOrDenom} is unknown`);
|
|
735997
|
-
const interchainFee = new _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_7__/* .TokenAmount */ .s(gasQuote.igpQuote.amount, igpToken);
|
|
735998
|
-
let tokenFeeQuote;
|
|
735999
|
-
if (gasQuote.tokenFeeQuote?.amount) {
|
|
736000
|
-
const feeAddress = gasQuote.tokenFeeQuote.addressOrDenom;
|
|
736001
|
-
const feeToken = !feeAddress || (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .isZeroishAddress */ .Hi)(feeAddress)
|
|
736002
|
-
? _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_6__/* .Token */ .o.FromChainMetadataNativeToken(originChainMetadata)
|
|
736003
|
-
: originToken;
|
|
736004
|
-
tokenFeeQuote = new _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_7__/* .TokenAmount */ .s(gasQuote.tokenFeeQuote.amount, feeToken);
|
|
736005
|
-
}
|
|
736095
|
+
this.logger.debug({ origin, destination, amount: amount.toString() }, 'Building transferRemote transactions for exact execution amount');
|
|
736006
736096
|
const originTokenAmount = originToken.amount(amount);
|
|
736007
736097
|
const transferTxs = await this.warpCore.getTransferRemoteTxs({
|
|
736008
736098
|
originTokenAmount,
|
|
736009
736099
|
destination,
|
|
736010
736100
|
sender: this.getInventorySignerAddress(origin),
|
|
736011
736101
|
recipient: this.getInventorySignerAddress(destination),
|
|
736012
|
-
interchainFee,
|
|
736013
|
-
tokenFeeQuote,
|
|
736014
736102
|
});
|
|
736015
|
-
(0,
|
|
736103
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(transferTxs.length > 0, 'Expected at least one transaction from WarpCore');
|
|
736016
736104
|
this.logger.info({
|
|
736017
736105
|
origin,
|
|
736018
736106
|
destination,
|
|
@@ -736023,14 +736111,14 @@ class InventoryRebalancer {
|
|
|
736023
736111
|
let transferTxHash;
|
|
736024
736112
|
for (const tx of transferTxs) {
|
|
736025
736113
|
const { txHash } = await this.sendAndConfirmInventoryTx(origin, tx);
|
|
736026
|
-
if (tx.category ===
|
|
736114
|
+
if (tx.category === _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_7__/* .WarpTxCategory */ .b.Transfer) {
|
|
736027
736115
|
transferTxHash = txHash;
|
|
736028
736116
|
}
|
|
736029
736117
|
}
|
|
736030
736118
|
const messageId = transferTxHash
|
|
736031
736119
|
? await this.extractDispatchedMessageId(origin, transferTxHash)
|
|
736032
736120
|
: undefined;
|
|
736033
|
-
(0,
|
|
736121
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(transferTxHash, 'No transfer transaction hash found');
|
|
736034
736122
|
if (!messageId) {
|
|
736035
736123
|
this.logger.warn({
|
|
736036
736124
|
origin,
|
|
@@ -736051,7 +736139,7 @@ class InventoryRebalancer {
|
|
|
736051
736139
|
intentId: intent.id,
|
|
736052
736140
|
origin: this.multiProvider.getDomainId(origin),
|
|
736053
736141
|
destination: destinationDomain,
|
|
736054
|
-
amount,
|
|
736142
|
+
amount: fulfilledCanonicalAmount,
|
|
736055
736143
|
type: 'inventory_deposit',
|
|
736056
736144
|
txHash: transferTxHash,
|
|
736057
736145
|
messageId,
|
|
@@ -736065,24 +736153,24 @@ class InventoryRebalancer {
|
|
|
736065
736153
|
async sendAndConfirmInventoryTx(chain, typedTx) {
|
|
736066
736154
|
const protocol = this.getProtocolForChain(chain);
|
|
736067
736155
|
const signerConfig = this.config.inventorySigners[protocol];
|
|
736068
|
-
(0,
|
|
736156
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(signerConfig?.key, `Missing signer key for protocol ${protocol} (chain ${chain})`);
|
|
736069
736157
|
const accountConfig = this.buildSignerAccountConfig(protocol, signerConfig.key, chain);
|
|
736070
|
-
const signer = await (0,
|
|
736158
|
+
const signer = await (0,_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_8__/* .getSignerForChain */ .h)(chain, accountConfig, this.warpCore.multiProvider);
|
|
736071
736159
|
const metadata = this.warpCore.multiProvider.getChainMetadata(chain);
|
|
736072
736160
|
const configuredConfirmations = metadata.blocks?.reorgPeriod ?? metadata.blocks?.confirmations;
|
|
736073
736161
|
let waitConfirmations = 1;
|
|
736074
736162
|
if (typeof configuredConfirmations === 'number') {
|
|
736075
736163
|
waitConfirmations = configuredConfirmations;
|
|
736076
736164
|
}
|
|
736077
|
-
const txHash = await signer.sendAndConfirmTransaction((0,
|
|
736165
|
+
const txHash = await signer.sendAndConfirmTransaction((0,_utils_transactionUtils_js__WEBPACK_IMPORTED_MODULE_9__/* .toProtocolTransaction */ .S)(typedTx, protocol), { waitConfirmations });
|
|
736078
736166
|
return { txHash };
|
|
736079
736167
|
}
|
|
736080
736168
|
buildSignerAccountConfig(protocol, key, chain) {
|
|
736081
736169
|
void chain;
|
|
736082
736170
|
switch (protocol) {
|
|
736083
|
-
case
|
|
736084
|
-
return { protocol, privateKey: (0,
|
|
736085
|
-
case
|
|
736171
|
+
case _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_10__/* .ProtocolType */ .Hb.Ethereum:
|
|
736172
|
+
return { protocol, privateKey: (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_11__/* .ensure0x */ .Ho)(key) };
|
|
736173
|
+
case _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_10__/* .ProtocolType */ .Hb.Sealevel:
|
|
736086
736174
|
return { protocol, privateKey: (0,_utils_solanaKeyParser_js__WEBPACK_IMPORTED_MODULE_1__/* .parseSolanaPrivateKey */ .E)(key) };
|
|
736087
736175
|
default:
|
|
736088
736176
|
throw new Error(`Unsupported protocol ${protocol} for inventory signer`);
|
|
@@ -736100,21 +736188,21 @@ class InventoryRebalancer {
|
|
|
736100
736188
|
if (!logs)
|
|
736101
736189
|
return undefined;
|
|
736102
736190
|
const parsed = _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_14__/* .SealevelCoreAdapter */ .M.parseMessageDispatchLogs(logs);
|
|
736103
|
-
return parsed[0]?.messageId ? (0,
|
|
736191
|
+
return parsed[0]?.messageId ? (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_11__/* .ensure0x */ .Ho)(parsed[0].messageId) : undefined;
|
|
736104
736192
|
}
|
|
736105
736193
|
return undefined;
|
|
736106
736194
|
}
|
|
736107
736195
|
async getTransactionReceipt(origin, txHash) {
|
|
736108
736196
|
try {
|
|
736109
736197
|
const protocol = this.getProtocolForChain(origin);
|
|
736110
|
-
if (protocol ===
|
|
736198
|
+
if (protocol === _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_10__/* .ProtocolType */ .Hb.Ethereum) {
|
|
736111
736199
|
const provider = this.warpCore.multiProvider.getEthersV5Provider(origin);
|
|
736112
736200
|
const receipt = await provider.getTransactionReceipt(txHash);
|
|
736113
736201
|
if (!receipt)
|
|
736114
736202
|
return undefined;
|
|
736115
736203
|
return { type: _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_12__/* .ProviderType */ .c.EthersV5, receipt };
|
|
736116
736204
|
}
|
|
736117
|
-
if (protocol ===
|
|
736205
|
+
if (protocol === _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_10__/* .ProtocolType */ .Hb.Sealevel) {
|
|
736118
736206
|
const provider = this.warpCore.multiProvider.getSolanaWeb3Provider(origin);
|
|
736119
736207
|
const receipt = await provider.getTransaction(txHash, {
|
|
736120
736208
|
commitment: 'confirmed',
|
|
@@ -736153,39 +736241,26 @@ class InventoryRebalancer {
|
|
|
736153
736241
|
return sources.sort((a, b) => a.availableAmount > b.availableAmount ? -1 : 1);
|
|
736154
736242
|
}
|
|
736155
736243
|
/**
|
|
736156
|
-
* Calculate the
|
|
736157
|
-
* Uses LiFi
|
|
736158
|
-
*
|
|
736244
|
+
* Calculate the bridge capacity from a source chain in destination-local units.
|
|
736245
|
+
* Uses LiFi quotes to conservatively estimate the destination output available
|
|
736246
|
+
* from the source chain's current local inventory.
|
|
736159
736247
|
*
|
|
736160
|
-
*
|
|
736161
|
-
*
|
|
736162
|
-
* - Applies conservative 20x buffer (LiFi underestimates by ~14x historically)
|
|
736163
|
-
* - Returns 0 if gas > 10% of inventory (not worth bridging)
|
|
736164
|
-
* - Returns inventory - estimatedGas if viable
|
|
736165
|
-
*
|
|
736166
|
-
* @param sourceChain - Chain to bridge from
|
|
736167
|
-
* @param targetChain - Chain to bridge to
|
|
736168
|
-
* @param rawInventory - Raw available inventory on source chain
|
|
736169
|
-
* @param externalBridgeType - External bridge type to use
|
|
736170
|
-
* @returns Maximum viable bridge amount (0 if not viable)
|
|
736248
|
+
* For native-token sources, gas is reserved from the source inventory and the
|
|
736249
|
+
* output capacity is re-quoted from the remaining source input.
|
|
736171
736250
|
*/
|
|
736172
|
-
async
|
|
736251
|
+
async calculateBridgeCapacity(sourceChain, targetChain, rawInventory, externalBridgeType) {
|
|
736173
736252
|
const sourceToken = this.getTokenForChain(sourceChain);
|
|
736174
736253
|
const targetToken = this.getTokenForChain(targetChain);
|
|
736175
|
-
|
|
736176
|
-
|
|
736177
|
-
// Only applies to native tokens (need gas from same balance)
|
|
736178
|
-
if (!(0,_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .isNativeTokenStandard */ .OJ)(sourceToken.standard)) {
|
|
736179
|
-
return rawInventory; // ERC20s don't compete with gas
|
|
736180
|
-
}
|
|
736254
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(sourceToken, `No token found for source chain: ${sourceChain}`);
|
|
736255
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(targetToken, `No token found for target chain: ${targetChain}`);
|
|
736181
736256
|
// Convert HypNative token addresses to the external bridge's native token representation
|
|
736182
|
-
const fromTokenAddress = this.getNativeTokenAddress(
|
|
736257
|
+
const fromTokenAddress = (0,_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .getExternalBridgeTokenAddress */ .iV)(sourceToken, externalBridgeType, this.getNativeTokenAddress.bind(this));
|
|
736183
736258
|
const toTokenAddress = (0,_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .getExternalBridgeTokenAddress */ .iV)(targetToken, externalBridgeType, this.getNativeTokenAddress.bind(this));
|
|
736184
736259
|
const sourceChainId = Number(this.multiProvider.getChainId(sourceChain));
|
|
736185
736260
|
const targetChainId = Number(this.multiProvider.getChainId(targetChain));
|
|
736186
736261
|
try {
|
|
736187
736262
|
const externalBridge = this.getExternalBridge(externalBridgeType);
|
|
736188
|
-
const
|
|
736263
|
+
const initialQuote = await externalBridge.quote({
|
|
736189
736264
|
fromChain: sourceChainId,
|
|
736190
736265
|
toChain: targetChainId,
|
|
736191
736266
|
fromToken: fromTokenAddress,
|
|
@@ -736194,62 +736269,72 @@ class InventoryRebalancer {
|
|
|
736194
736269
|
fromAddress: this.getInventorySignerAddress(sourceChain),
|
|
736195
736270
|
toAddress: this.getInventorySignerAddress(targetChain),
|
|
736196
736271
|
});
|
|
736197
|
-
|
|
736198
|
-
|
|
736199
|
-
|
|
736200
|
-
|
|
736201
|
-
|
|
736202
|
-
|
|
736203
|
-
|
|
736204
|
-
|
|
736205
|
-
|
|
736206
|
-
|
|
736207
|
-
|
|
736208
|
-
|
|
736209
|
-
|
|
736210
|
-
|
|
736211
|
-
|
|
736212
|
-
}
|
|
736213
|
-
|
|
736272
|
+
let maxSourceInput = rawInventory;
|
|
736273
|
+
let outputQuote = initialQuote;
|
|
736274
|
+
if ((0,_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .isNativeTokenStandard */ .OJ)(sourceToken.standard)) {
|
|
736275
|
+
const estimatedGas = initialQuote.gasCosts * GAS_COST_MULTIPLIER;
|
|
736276
|
+
const maxGasThreshold = rawInventory / MAX_GAS_PERCENT_THRESHOLD;
|
|
736277
|
+
if (estimatedGas > maxGasThreshold) {
|
|
736278
|
+
this.logger.info({
|
|
736279
|
+
sourceChain,
|
|
736280
|
+
targetChain,
|
|
736281
|
+
rawInventory: rawInventory.toString(),
|
|
736282
|
+
quotedGas: initialQuote.gasCosts.toString(),
|
|
736283
|
+
estimatedGas: estimatedGas.toString(),
|
|
736284
|
+
maxGasThreshold: maxGasThreshold.toString(),
|
|
736285
|
+
}, 'Bridge not viable - gas cost exceeds 10% of inventory');
|
|
736286
|
+
return { maxSourceInput: 0n, maxTargetOutput: 0n };
|
|
736287
|
+
}
|
|
736288
|
+
maxSourceInput = rawInventory - estimatedGas;
|
|
736289
|
+
if (maxSourceInput <= 0n) {
|
|
736290
|
+
return { maxSourceInput: 0n, maxTargetOutput: 0n };
|
|
736291
|
+
}
|
|
736292
|
+
outputQuote = await externalBridge.quote({
|
|
736293
|
+
fromChain: sourceChainId,
|
|
736294
|
+
toChain: targetChainId,
|
|
736295
|
+
fromToken: fromTokenAddress,
|
|
736296
|
+
toToken: toTokenAddress,
|
|
736297
|
+
fromAmount: maxSourceInput,
|
|
736298
|
+
fromAddress: this.getInventorySignerAddress(sourceChain),
|
|
736299
|
+
toAddress: this.getInventorySignerAddress(targetChain),
|
|
736300
|
+
});
|
|
736214
736301
|
}
|
|
736215
|
-
// Max viable = inventory minus estimated gas
|
|
736216
|
-
const maxViable = rawInventory - estimatedGas;
|
|
736217
736302
|
this.logger.info({
|
|
736218
736303
|
sourceChain,
|
|
736219
736304
|
targetChain,
|
|
736220
736305
|
rawInventory: rawInventory.toString(),
|
|
736221
|
-
|
|
736222
|
-
|
|
736223
|
-
|
|
736224
|
-
|
|
736225
|
-
|
|
736226
|
-
|
|
736227
|
-
}
|
|
736228
|
-
return maxViable;
|
|
736306
|
+
maxSourceInput: maxSourceInput.toString(),
|
|
736307
|
+
maxTargetOutput: outputQuote.toAmountMin.toString(),
|
|
736308
|
+
}, 'Calculated bridge capacity');
|
|
736309
|
+
return {
|
|
736310
|
+
maxSourceInput,
|
|
736311
|
+
maxTargetOutput: outputQuote.toAmountMin,
|
|
736312
|
+
};
|
|
736229
736313
|
}
|
|
736230
736314
|
catch (error) {
|
|
736231
736315
|
this.logger.warn({
|
|
736232
736316
|
sourceChain,
|
|
736233
736317
|
targetChain,
|
|
736234
736318
|
error: error.message,
|
|
736235
|
-
}, 'Failed to calculate
|
|
736236
|
-
return 0n;
|
|
736319
|
+
}, 'Failed to calculate bridge capacity, skipping chain');
|
|
736320
|
+
return { maxSourceInput: 0n, maxTargetOutput: 0n };
|
|
736237
736321
|
}
|
|
736238
736322
|
}
|
|
736239
736323
|
/**
|
|
736240
736324
|
* Execute inventory movement from source chain to target chain via LiFi bridge.
|
|
736241
736325
|
*
|
|
736242
|
-
*
|
|
736243
|
-
*
|
|
736326
|
+
* Uses reverse quotes (`toAmount`) so plans are expressed in target-chain local
|
|
736327
|
+
* units and source-local spend is discovered by the bridge quote.
|
|
736244
736328
|
*
|
|
736245
736329
|
* @param sourceChain - Chain to move inventory from
|
|
736246
736330
|
* @param targetChain - Chain to move inventory to (origin chain for rebalancing)
|
|
736247
|
-
* @param
|
|
736331
|
+
* @param targetOutputAmount - Destination-local amount to receive
|
|
736332
|
+
* @param maxSourceInput - Maximum source-local amount available for this plan
|
|
736248
736333
|
* @param intent - Rebalance intent for tracking
|
|
736249
736334
|
* @param externalBridgeType - External bridge type to use
|
|
736250
736335
|
* @returns Result with success status and optional txHash/error
|
|
736251
736336
|
*/
|
|
736252
|
-
async executeInventoryMovement(sourceChain, targetChain,
|
|
736337
|
+
async executeInventoryMovement(sourceChain, targetChain, targetOutputAmount, maxSourceInput, intent, externalBridgeType) {
|
|
736253
736338
|
const sourceToken = this.getTokenForChain(sourceChain);
|
|
736254
736339
|
if (!sourceToken) {
|
|
736255
736340
|
return {
|
|
@@ -736278,30 +736363,6 @@ class InventoryRebalancer {
|
|
|
736278
736363
|
fromTokenAddress,
|
|
736279
736364
|
toTokenAddress,
|
|
736280
736365
|
}, 'Resolved token addresses for LiFi bridge');
|
|
736281
|
-
// Calculate minViableTransfer for the target chain
|
|
736282
|
-
// If bridging less than this, the received amount won't be enough to execute transferRemote
|
|
736283
|
-
// So we over-bridge to ensure we can complete the intent in the next cycle
|
|
736284
|
-
const costs = await (0,_utils_gasEstimation_js__WEBPACK_IMPORTED_MODULE_4__/* .calculateTransferCosts */ ._P)(targetChain, // FROM chain for transferRemote (the target of this bridge)
|
|
736285
|
-
sourceChain, // TO chain for transferRemote (Hyperlane message destination)
|
|
736286
|
-
amount, // availableInventory (not used for minViableTransfer calculation)
|
|
736287
|
-
amount, // requestedAmount
|
|
736288
|
-
this.multiProvider, this.warpCore.multiProvider, this.getTokenForChain.bind(this), this.getInventorySignerAddress(targetChain), _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .isNativeTokenStandard */ .OJ, this.logger);
|
|
736289
|
-
const { minViableTransfer } = costs;
|
|
736290
|
-
// If the requested amount is below minViableTransfer, adjust it up
|
|
736291
|
-
// This ensures we bridge enough to actually complete the final transferRemote
|
|
736292
|
-
const effectiveAmount = amount < minViableTransfer ? minViableTransfer : amount;
|
|
736293
|
-
if (effectiveAmount !== amount) {
|
|
736294
|
-
this.logger.info({
|
|
736295
|
-
originalAmount: amount.toString(),
|
|
736296
|
-
effectiveAmount: effectiveAmount.toString(),
|
|
736297
|
-
minViableTransfer: minViableTransfer.toString(),
|
|
736298
|
-
originalAmountEth: (Number(amount) / 1e18).toFixed(6),
|
|
736299
|
-
effectiveAmountEth: (Number(effectiveAmount) / 1e18).toFixed(6),
|
|
736300
|
-
minViableTransferEth: (Number(minViableTransfer) / 1e18).toFixed(6),
|
|
736301
|
-
adjustedUp: true,
|
|
736302
|
-
intentId: intent.id,
|
|
736303
|
-
}, 'Over-bridging to minViableTransfer to ensure final transferRemote can complete');
|
|
736304
|
-
}
|
|
736305
736366
|
try {
|
|
736306
736367
|
const externalBridge = this.getExternalBridge(externalBridgeType);
|
|
736307
736368
|
const quote = await externalBridge.quote({
|
|
@@ -736309,28 +736370,33 @@ class InventoryRebalancer {
|
|
|
736309
736370
|
toChain: targetChainId,
|
|
736310
736371
|
fromToken: fromTokenAddress,
|
|
736311
736372
|
toToken: toTokenAddress,
|
|
736312
|
-
|
|
736373
|
+
toAmount: targetOutputAmount,
|
|
736313
736374
|
fromAddress: this.getInventorySignerAddress(sourceChain),
|
|
736314
736375
|
toAddress: this.getInventorySignerAddress(targetChain),
|
|
736315
736376
|
});
|
|
736316
736377
|
const inputRequired = quote.fromAmount;
|
|
736378
|
+
if (inputRequired > maxSourceInput) {
|
|
736379
|
+
return {
|
|
736380
|
+
success: false,
|
|
736381
|
+
error: `Bridge input ${inputRequired} exceeded planned source capacity ${maxSourceInput}`,
|
|
736382
|
+
};
|
|
736383
|
+
}
|
|
736317
736384
|
this.logger.info({
|
|
736318
736385
|
sourceChain,
|
|
736319
736386
|
targetChain,
|
|
736320
736387
|
sourceChainId,
|
|
736321
736388
|
targetChainId,
|
|
736322
|
-
|
|
736323
|
-
|
|
736324
|
-
effectiveAmount: effectiveAmount.toString(),
|
|
736325
|
-
effectiveAmountEth: (Number(effectiveAmount) / 1e18).toFixed(6),
|
|
736389
|
+
requestedTargetOutput: targetOutputAmount.toString(),
|
|
736390
|
+
requestedTargetOutputFormatted: this.formatLocalAmount(targetOutputAmount, targetToken),
|
|
736326
736391
|
inputRequired: inputRequired.toString(),
|
|
736392
|
+
inputRequiredFormatted: this.formatLocalAmount(inputRequired, sourceToken),
|
|
736327
736393
|
expectedOutput: quote.toAmount.toString(),
|
|
736328
|
-
|
|
736394
|
+
expectedOutputMin: quote.toAmountMin.toString(),
|
|
736395
|
+
expectedOutputFormatted: this.formatLocalAmount(quote.toAmount, targetToken),
|
|
736329
736396
|
gasCosts: quote.gasCosts.toString(),
|
|
736330
736397
|
feeCosts: quote.feeCosts.toString(),
|
|
736331
736398
|
intentId: intent.id,
|
|
736332
|
-
|
|
736333
|
-
}, 'Executing inventory movement via LiFi with pre-validated amount');
|
|
736399
|
+
}, 'Executing inventory movement via LiFi reverse quote');
|
|
736334
736400
|
this.logger.debug({
|
|
736335
736401
|
quoteId: quote.id,
|
|
736336
736402
|
tool: quote.tool,
|
|
@@ -736349,7 +736415,7 @@ class InventoryRebalancer {
|
|
|
736349
736415
|
}
|
|
736350
736416
|
}
|
|
736351
736417
|
const sourceProtocol = this.getProtocolForChain(sourceChain);
|
|
736352
|
-
(0,
|
|
736418
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .assert */ .v)(privateKeys[sourceProtocol], `Missing inventory signer key for protocol ${sourceProtocol} (chain ${sourceChain})`);
|
|
736353
736419
|
const result = await externalBridge.execute(quote, privateKeys);
|
|
736354
736420
|
this.logger.info({
|
|
736355
736421
|
sourceChain,
|
|
@@ -736357,6 +736423,8 @@ class InventoryRebalancer {
|
|
|
736357
736423
|
txHash: result.txHash,
|
|
736358
736424
|
intentId: intent.id,
|
|
736359
736425
|
}, 'Inventory movement transaction executed');
|
|
736426
|
+
// Keep bridge consumption in source-local units; intent fulfillment only
|
|
736427
|
+
// advances from canonical inventory_deposit amounts after transferRemote.
|
|
736360
736428
|
await this.actionTracker.createRebalanceAction({
|
|
736361
736429
|
intentId: intent.id,
|
|
736362
736430
|
origin: this.multiProvider.getDomainId(sourceChain),
|
|
@@ -736380,7 +736448,7 @@ class InventoryRebalancer {
|
|
|
736380
736448
|
this.logger.error({
|
|
736381
736449
|
sourceChain,
|
|
736382
736450
|
targetChain,
|
|
736383
|
-
amount:
|
|
736451
|
+
amount: targetOutputAmount.toString(),
|
|
736384
736452
|
intentId: intent.id,
|
|
736385
736453
|
error: error.message,
|
|
736386
736454
|
}, 'Failed to execute inventory movement');
|
|
@@ -736404,11 +736472,15 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
736404
736472
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
736405
736473
|
/* harmony export */ K: () => (/* binding */ Rebalancer)
|
|
736406
736474
|
/* harmony export */ });
|
|
736407
|
-
/* harmony import */ var
|
|
736408
|
-
/* harmony import */ var
|
|
736409
|
-
/* harmony import */ var
|
|
736410
|
-
/* harmony import */ var
|
|
736411
|
-
/* harmony import */ var
|
|
736475
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(21582);
|
|
736476
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(71598);
|
|
736477
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(14918);
|
|
736478
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(73689);
|
|
736479
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(93142);
|
|
736480
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(11369);
|
|
736481
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__]);
|
|
736482
|
+
_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
|
|
736483
|
+
|
|
736412
736484
|
|
|
736413
736485
|
|
|
736414
736486
|
class Rebalancer {
|
|
@@ -736466,7 +736538,8 @@ class Rebalancer {
|
|
|
736466
736538
|
for (const result of successfulResults) {
|
|
736467
736539
|
const token = this.tokensByChainName[result.route.origin];
|
|
736468
736540
|
if (token) {
|
|
736469
|
-
this.metrics.recordRebalanceAmount(result.route, token.amount(result.
|
|
736541
|
+
this.metrics.recordRebalanceAmount(result.route, token.amount(result.localAmount ??
|
|
736542
|
+
(0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .denormalizeToLocal */ .bK)(result.route.amount, token)));
|
|
736470
736543
|
}
|
|
736471
736544
|
}
|
|
736472
736545
|
}
|
|
@@ -736496,7 +736569,7 @@ class Rebalancer {
|
|
|
736496
736569
|
intentId,
|
|
736497
736570
|
origin: this.multiProvider.getDomainId(result.route.origin),
|
|
736498
736571
|
destination: this.multiProvider.getDomainId(result.route.destination),
|
|
736499
|
-
amount: result.route.amount,
|
|
736572
|
+
amount: result.canonicalAmount ?? result.route.amount,
|
|
736500
736573
|
type: 'rebalance_message',
|
|
736501
736574
|
messageId: result.messageId,
|
|
736502
736575
|
txHash: result.txHash,
|
|
@@ -736532,9 +736605,9 @@ class Rebalancer {
|
|
|
736532
736605
|
}
|
|
736533
736606
|
async prepareTransactions(routes) {
|
|
736534
736607
|
this.logger.info({ numRoutes: routes.length }, 'Preparing all rebalance transactions.');
|
|
736535
|
-
const { fulfilled, rejected } = await (0,
|
|
736608
|
+
const { fulfilled, rejected } = await (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_1__/* .mapAllSettled */ .bh)(routes, (route) => this.prepareTransaction(route), (_, i) => i);
|
|
736536
736609
|
// Filter out null results (validation failures logged internally)
|
|
736537
|
-
const preparedTransactions = Array.from(fulfilled.values()).filter((tx) => !(0,
|
|
736610
|
+
const preparedTransactions = Array.from(fulfilled.values()).filter((tx) => !(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__/* .isNullish */ .u)(tx));
|
|
736538
736611
|
// Create failure results for tracking
|
|
736539
736612
|
const preparationFailureResults = [];
|
|
736540
736613
|
for (const [i, error] of rejected) {
|
|
@@ -736548,7 +736621,7 @@ class Rebalancer {
|
|
|
736548
736621
|
}
|
|
736549
736622
|
// Also track null results (validation failures)
|
|
736550
736623
|
Array.from(fulfilled.entries()).forEach(([i, tx]) => {
|
|
736551
|
-
if ((0,
|
|
736624
|
+
if ((0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__/* .isNullish */ .u)(tx)) {
|
|
736552
736625
|
preparationFailureResults.push({
|
|
736553
736626
|
route: routes[i],
|
|
736554
736627
|
intentId: routes[i].intentId,
|
|
@@ -736575,14 +736648,15 @@ class Rebalancer {
|
|
|
736575
736648
|
const originToken = this.tokensByChainName[origin];
|
|
736576
736649
|
const destinationToken = this.tokensByChainName[destination];
|
|
736577
736650
|
const destinationChainMeta = this.chainMetadata[destination];
|
|
736578
|
-
const
|
|
736651
|
+
const localAmount = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .denormalizeToLocal */ .bK)(amount, originToken);
|
|
736652
|
+
const originTokenAmount = originToken.amount(localAmount);
|
|
736579
736653
|
const decimalFormattedAmount = originTokenAmount.getDecimalFormattedAmount();
|
|
736580
736654
|
const originHypAdapter = originToken.getHypAdapter(this.warpCore.multiProvider);
|
|
736581
736655
|
const { bridge } = route;
|
|
736582
736656
|
// 2. Get quotes
|
|
736583
736657
|
let quotes;
|
|
736584
736658
|
try {
|
|
736585
|
-
quotes = await originHypAdapter.getRebalanceQuotes(bridge, destinationChainMeta.domainId, destinationToken.addressOrDenom,
|
|
736659
|
+
quotes = await originHypAdapter.getRebalanceQuotes(bridge, destinationChainMeta.domainId, destinationToken.addressOrDenom, localAmount);
|
|
736586
736660
|
}
|
|
736587
736661
|
catch (error) {
|
|
736588
736662
|
this.logger.error({
|
|
@@ -736597,7 +736671,7 @@ class Rebalancer {
|
|
|
736597
736671
|
// 3. Populate transaction
|
|
736598
736672
|
let populatedTx;
|
|
736599
736673
|
try {
|
|
736600
|
-
populatedTx = await originHypAdapter.populateRebalanceTx(destinationChainMeta.domainId,
|
|
736674
|
+
populatedTx = await originHypAdapter.populateRebalanceTx(destinationChainMeta.domainId, localAmount, bridge, quotes);
|
|
736601
736675
|
}
|
|
736602
736676
|
catch (error) {
|
|
736603
736677
|
this.logger.error({
|
|
@@ -736620,7 +736694,8 @@ class Rebalancer {
|
|
|
736620
736694
|
this.logger.error({ origin, destination, amount }, 'Route validation failed: origin token not found.');
|
|
736621
736695
|
return false;
|
|
736622
736696
|
}
|
|
736623
|
-
const
|
|
736697
|
+
const localAmount = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .denormalizeToLocal */ .bK)(amount, originToken);
|
|
736698
|
+
const originTokenAmount = originToken.amount(localAmount);
|
|
736624
736699
|
const decimalFormattedAmount = originTokenAmount.getDecimalFormattedAmount();
|
|
736625
736700
|
if (!destinationToken) {
|
|
736626
736701
|
this.logger.error({ origin, destination, amount: decimalFormattedAmount }, 'Route validation failed: destination token not found.');
|
|
@@ -736631,7 +736706,7 @@ class Rebalancer {
|
|
|
736631
736706
|
return false;
|
|
736632
736707
|
}
|
|
736633
736708
|
const originHypAdapter = originToken.getHypAdapter(this.warpCore.multiProvider);
|
|
736634
|
-
if (!(originHypAdapter instanceof
|
|
736709
|
+
if (!(originHypAdapter instanceof _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_3__/* .EvmMovableCollateralAdapter */ .vo)) {
|
|
736635
736710
|
this.logger.error({
|
|
736636
736711
|
origin,
|
|
736637
736712
|
destination,
|
|
@@ -736654,7 +736729,7 @@ class Rebalancer {
|
|
|
736654
736729
|
return false;
|
|
736655
736730
|
}
|
|
736656
736731
|
const allowedDestination = await originHypAdapter.getAllowedDestination(destinationDomain.domainId);
|
|
736657
|
-
if (!(0,
|
|
736732
|
+
if (!(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_4__/* .eqAddress */ .fv)(allowedDestination, destinationToken.addressOrDenom)) {
|
|
736658
736733
|
this.logger.error({
|
|
736659
736734
|
origin,
|
|
736660
736735
|
destination,
|
|
@@ -736816,7 +736891,7 @@ class Rebalancer {
|
|
|
736816
736891
|
*/
|
|
736817
736892
|
buildResult(transaction, receipt) {
|
|
736818
736893
|
const { origin, destination } = transaction.route;
|
|
736819
|
-
const dispatchedMessages =
|
|
736894
|
+
const dispatchedMessages = _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_5__/* .HyperlaneCore */ .K.getDispatchedMessages(receipt);
|
|
736820
736895
|
if (dispatchedMessages.length === 0) {
|
|
736821
736896
|
this.logger.error({ origin, destination, txHash: receipt.transactionHash }, 'No Dispatch event found in confirmed rebalance receipt');
|
|
736822
736897
|
return {
|
|
@@ -736834,6 +736909,8 @@ class Rebalancer {
|
|
|
736834
736909
|
success: true,
|
|
736835
736910
|
messageId: dispatchedMessages[0].id,
|
|
736836
736911
|
txHash: receipt.transactionHash,
|
|
736912
|
+
canonicalAmount: (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .normalizeToCanonical */ .R2)(transaction.originTokenAmount.amount, transaction.originTokenAmount.token),
|
|
736913
|
+
localAmount: transaction.originTokenAmount.amount,
|
|
736837
736914
|
};
|
|
736838
736915
|
}
|
|
736839
736916
|
getReorgPeriod(chainName) {
|
|
@@ -736892,7 +736969,7 @@ class RebalancerOrchestrator {
|
|
|
736892
736969
|
await Promise.all(event.tokensInfo.map((tokenInfo) => metrics.processToken(tokenInfo)));
|
|
736893
736970
|
}
|
|
736894
736971
|
await this.syncActionTracker(event.confirmedBlockTags);
|
|
736895
|
-
const rawBalances = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_1__/* .getRawBalances */ .
|
|
736972
|
+
const rawBalances = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_1__/* .getRawBalances */ .qb)((0,_config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .getStrategyChainNames */ .zj)(this.rebalancerConfig.strategyConfig), event, this.logger);
|
|
736896
736973
|
this.logger.info({
|
|
736897
736974
|
balances: Object.entries(rawBalances).map(([chain, balance]) => ({
|
|
736898
736975
|
chain,
|
|
@@ -737025,14 +737102,15 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
737025
737102
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
737026
737103
|
/* harmony export */ $: () => (/* binding */ RebalancerService)
|
|
737027
737104
|
/* harmony export */ });
|
|
737028
|
-
/* harmony import */ var
|
|
737029
|
-
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(39196);
|
|
737105
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(21387);
|
|
737030
737106
|
/* harmony import */ var _config_types_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(75102);
|
|
737031
737107
|
/* harmony import */ var _factories_RebalancerContextFactory_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(84569);
|
|
737032
737108
|
/* harmony import */ var _interfaces_IMonitor_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(36513);
|
|
737033
|
-
/* harmony import */ var
|
|
737034
|
-
var
|
|
737035
|
-
|
|
737109
|
+
/* harmony import */ var _tracking_InflightContextAdapter_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(52209);
|
|
737110
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(11369);
|
|
737111
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_factories_RebalancerContextFactory_js__WEBPACK_IMPORTED_MODULE_1__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_3__]);
|
|
737112
|
+
([_factories_RebalancerContextFactory_js__WEBPACK_IMPORTED_MODULE_1__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_3__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
737113
|
+
|
|
737036
737114
|
|
|
737037
737115
|
|
|
737038
737116
|
|
|
@@ -737130,7 +737208,7 @@ class RebalancerService {
|
|
|
737130
737208
|
if (this.config.actionTracker) {
|
|
737131
737209
|
// Use externally provided ActionTracker (e.g., for simulation/testing)
|
|
737132
737210
|
this.actionTracker = this.config.actionTracker;
|
|
737133
|
-
this.inflightContextAdapter = new
|
|
737211
|
+
this.inflightContextAdapter = new _tracking_InflightContextAdapter_js__WEBPACK_IMPORTED_MODULE_4__/* .InflightContextAdapter */ .m(this.actionTracker, this.multiProvider);
|
|
737134
737212
|
await this.actionTracker.initialize();
|
|
737135
737213
|
this.logger.info('Using externally provided ActionTracker');
|
|
737136
737214
|
}
|
|
@@ -737185,7 +737263,7 @@ class RebalancerService {
|
|
|
737185
737263
|
*/
|
|
737186
737264
|
async executeManual(request) {
|
|
737187
737265
|
await this.initialize();
|
|
737188
|
-
(0,
|
|
737266
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .assert */ .v)(this.rebalancer, 'Rebalancer not available. MonitorOnly mode cannot execute manual rebalances.');
|
|
737189
737267
|
const { origin, destination, amount } = request;
|
|
737190
737268
|
this.logger.info(`Manual rebalance strategy selected. Origin: ${origin}, Destination: ${destination}, Amount: ${amount}`);
|
|
737191
737269
|
const warpCore = this.contextFactory.getWarpCore();
|
|
@@ -737197,17 +737275,17 @@ class RebalancerService {
|
|
|
737197
737275
|
}
|
|
737198
737276
|
// Validate amount
|
|
737199
737277
|
const amountNum = Number(amount);
|
|
737200
|
-
(0,
|
|
737201
|
-
(0,
|
|
737278
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .assert */ .v)(!isNaN(amountNum), 'Amount must be a valid number');
|
|
737279
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .assert */ .v)(amountNum > 0, 'Amount must be greater than 0');
|
|
737202
737280
|
const originConfig = (0,_config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .getStrategyChainConfig */ .nt)(this.rebalancerConfig.strategyConfig, origin);
|
|
737203
|
-
(0,
|
|
737281
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .assert */ .v)(originConfig?.bridge, `No bridge configured for origin chain ${origin}`);
|
|
737204
737282
|
// Use destination-specific bridge override if configured, otherwise use default
|
|
737205
737283
|
const bridge = originConfig.override?.[destination]?.bridge ?? originConfig.bridge;
|
|
737206
737284
|
try {
|
|
737207
737285
|
const manualRoute = {
|
|
737208
737286
|
origin,
|
|
737209
737287
|
destination,
|
|
737210
|
-
amount:
|
|
737288
|
+
amount: (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_3__/* .normalizeConfiguredAmount */ .k9)(amount, originToken),
|
|
737211
737289
|
executionType: 'movableCollateral',
|
|
737212
737290
|
bridge,
|
|
737213
737291
|
intentId: `manual-${Date.now()}`,
|
|
@@ -737228,7 +737306,7 @@ class RebalancerService {
|
|
|
737228
737306
|
throw new Error('start() can only be called in daemon mode');
|
|
737229
737307
|
}
|
|
737230
737308
|
await this.initialize();
|
|
737231
|
-
(0,
|
|
737309
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .assert */ .v)(this.monitor, 'Monitor must be initialized for daemon mode');
|
|
737232
737310
|
// Setup monitor event listeners
|
|
737233
737311
|
this.monitor
|
|
737234
737312
|
.on(_interfaces_IMonitor_js__WEBPACK_IMPORTED_MODULE_2__/* .MonitorEventType */ .nE.TokenInfo, this.onTokenInfo.bind(this))
|
|
@@ -737315,29 +737393,30 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
737315
737393
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
737316
737394
|
/* harmony export */ n: () => (/* binding */ RebalancerContextFactory)
|
|
737317
737395
|
/* harmony export */ });
|
|
737318
|
-
/* harmony import */ var
|
|
737319
|
-
/* harmony import */ var
|
|
737320
|
-
/* harmony import */ var
|
|
737321
|
-
/* harmony import */ var
|
|
737322
|
-
/* harmony import */ var
|
|
737323
|
-
/* harmony import */ var
|
|
737324
|
-
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_20__ = __nccwpck_require__(21387);
|
|
737396
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_14__ = __nccwpck_require__(95176);
|
|
737397
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_15__ = __nccwpck_require__(9035);
|
|
737398
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_19__ = __nccwpck_require__(32772);
|
|
737399
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_12__ = __nccwpck_require__(73938);
|
|
737400
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_13__ = __nccwpck_require__(16639);
|
|
737401
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__ = __nccwpck_require__(21387);
|
|
737325
737402
|
/* harmony import */ var _bridges_LiFiBridge_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(70311);
|
|
737326
737403
|
/* harmony import */ var _config_types_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(75102);
|
|
737327
737404
|
/* harmony import */ var _core_InventoryRebalancer_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(13081);
|
|
737328
|
-
/* harmony import */ var
|
|
737329
|
-
/* harmony import */ var
|
|
737330
|
-
/* harmony import */ var
|
|
737331
|
-
/* harmony import */ var
|
|
737332
|
-
/* harmony import */ var
|
|
737333
|
-
/* harmony import */ var
|
|
737334
|
-
/* harmony import */ var
|
|
737335
|
-
/* harmony import */ var
|
|
737336
|
-
/* harmony import */ var
|
|
737337
|
-
/* harmony import */ var
|
|
737338
|
-
/* harmony import */ var
|
|
737339
|
-
|
|
737340
|
-
([_core_InventoryRebalancer_js__WEBPACK_IMPORTED_MODULE_2__,
|
|
737405
|
+
/* harmony import */ var _core_Rebalancer_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(3903);
|
|
737406
|
+
/* harmony import */ var _core_RebalancerOrchestrator_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(67279);
|
|
737407
|
+
/* harmony import */ var _metrics_Metrics_js__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(42575);
|
|
737408
|
+
/* harmony import */ var _metrics_PriceGetter_js__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(81708);
|
|
737409
|
+
/* harmony import */ var _monitor_Monitor_js__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(14135);
|
|
737410
|
+
/* harmony import */ var _strategy_StrategyFactory_js__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(88757);
|
|
737411
|
+
/* harmony import */ var _tracking_ActionTracker_js__WEBPACK_IMPORTED_MODULE_9__ = __nccwpck_require__(60732);
|
|
737412
|
+
/* harmony import */ var _tracking_InflightContextAdapter_js__WEBPACK_IMPORTED_MODULE_20__ = __nccwpck_require__(52209);
|
|
737413
|
+
/* harmony import */ var _tracking_store_index_js__WEBPACK_IMPORTED_MODULE_17__ = __nccwpck_require__(98867);
|
|
737414
|
+
/* harmony import */ var _utils_ExplorerClient_js__WEBPACK_IMPORTED_MODULE_18__ = __nccwpck_require__(14660);
|
|
737415
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_10__ = __nccwpck_require__(11369);
|
|
737416
|
+
/* harmony import */ var _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_11__ = __nccwpck_require__(46618);
|
|
737417
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_core_InventoryRebalancer_js__WEBPACK_IMPORTED_MODULE_2__, _core_Rebalancer_js__WEBPACK_IMPORTED_MODULE_3__, _core_RebalancerOrchestrator_js__WEBPACK_IMPORTED_MODULE_4__, _metrics_Metrics_js__WEBPACK_IMPORTED_MODULE_5__, _metrics_PriceGetter_js__WEBPACK_IMPORTED_MODULE_6__, _strategy_StrategyFactory_js__WEBPACK_IMPORTED_MODULE_8__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_10__, _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_11__, _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_14__, _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_15__]);
|
|
737418
|
+
([_core_InventoryRebalancer_js__WEBPACK_IMPORTED_MODULE_2__, _core_Rebalancer_js__WEBPACK_IMPORTED_MODULE_3__, _core_RebalancerOrchestrator_js__WEBPACK_IMPORTED_MODULE_4__, _metrics_Metrics_js__WEBPACK_IMPORTED_MODULE_5__, _metrics_PriceGetter_js__WEBPACK_IMPORTED_MODULE_6__, _strategy_StrategyFactory_js__WEBPACK_IMPORTED_MODULE_8__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_10__, _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_11__, _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_14__, _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_15__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
737419
|
+
|
|
737341
737420
|
|
|
737342
737421
|
|
|
737343
737422
|
|
|
@@ -737369,7 +737448,7 @@ class RebalancerContextFactory {
|
|
|
737369
737448
|
* @param warpCore - An instance of `WarpCore` configured for the specified `warpRouteId`.
|
|
737370
737449
|
* @param tokensByChainName - A map of chain->token to ease the lookup of token by chain
|
|
737371
737450
|
* @param multiProvider - MultiProvider instance (for movable collateral operations)
|
|
737372
|
-
* @param multiProtocolProvider -
|
|
737451
|
+
* @param multiProtocolProvider - MultiProtocolProvider instance (with mailbox metadata)
|
|
737373
737452
|
* @param registry - IRegistry instance
|
|
737374
737453
|
* @param logger - Logger instance
|
|
737375
737454
|
*/
|
|
@@ -737386,7 +737465,7 @@ class RebalancerContextFactory {
|
|
|
737386
737465
|
/**
|
|
737387
737466
|
* @param config - The rebalancer config
|
|
737388
737467
|
* @param multiProvider - MultiProvider instance (for movable collateral operations)
|
|
737389
|
-
* @param multiProtocolProvider -
|
|
737468
|
+
* @param multiProtocolProvider - MultiProtocolProvider instance (optional, created from multiProvider if not provided)
|
|
737390
737469
|
* @param registry - IRegistry instance
|
|
737391
737470
|
* @param logger - Logger instance
|
|
737392
737471
|
*/
|
|
@@ -737398,7 +737477,7 @@ class RebalancerContextFactory {
|
|
|
737398
737477
|
const addresses = await registry.getAddresses();
|
|
737399
737478
|
// The Sealevel warp adapters require the Mailbox address, so we
|
|
737400
737479
|
// get mailboxes for all chains and merge them with the chain metadata.
|
|
737401
|
-
const mailboxes = (0,
|
|
737480
|
+
const mailboxes = (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_12__/* .objMap */ .Yp)(addresses, (_, { mailbox }) => ({ mailbox }));
|
|
737402
737481
|
// Fetch warp route config FIRST to get chain list
|
|
737403
737482
|
const warpCoreConfig = warpCoreConfigOverride ??
|
|
737404
737483
|
(await registry.getWarpRoute(config.warpRouteId));
|
|
@@ -737413,17 +737492,17 @@ class RebalancerContextFactory {
|
|
|
737413
737492
|
...new Set(warpCoreConfig.tokens.map((t) => t.chainName)),
|
|
737414
737493
|
];
|
|
737415
737494
|
for (const chain of warpChains) {
|
|
737416
|
-
if (multiProvider.getProtocol(chain) !==
|
|
737495
|
+
if (multiProvider.getProtocol(chain) !== _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_13__/* .ProtocolType */ .Hb.Ethereum) {
|
|
737417
737496
|
logger.debug({ chain }, 'Skipping provider init for non-EVM chain');
|
|
737418
737497
|
continue;
|
|
737419
737498
|
}
|
|
737420
737499
|
multiProvider.getProvider(chain);
|
|
737421
737500
|
}
|
|
737422
|
-
// Create
|
|
737501
|
+
// Create MultiProtocolProvider (convert from MultiProvider if not provided)
|
|
737423
737502
|
const mpp = multiProtocolProvider ??
|
|
737424
|
-
|
|
737503
|
+
_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_14__/* .MultiProtocolProvider */ .f.fromMultiProvider(multiProvider);
|
|
737425
737504
|
const extendedMultiProtocolProvider = mpp.extendChainMetadata(mailboxes);
|
|
737426
|
-
const warpCore =
|
|
737505
|
+
const warpCore = _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_15__/* .WarpCore */ .u.FromConfig(extendedMultiProtocolProvider, warpCoreConfig);
|
|
737427
737506
|
const tokensByChainName = Object.fromEntries(warpCore.tokens.map((t) => [t.chainName, t]));
|
|
737428
737507
|
logger.debug({
|
|
737429
737508
|
warpRouteId: config.warpRouteId,
|
|
@@ -737438,16 +737517,16 @@ class RebalancerContextFactory {
|
|
|
737438
737517
|
}
|
|
737439
737518
|
async createMetrics(coingeckoApiKey) {
|
|
737440
737519
|
this.logger.debug({ warpRouteId: this.config.warpRouteId }, 'Creating Metrics');
|
|
737441
|
-
const tokenPriceGetter =
|
|
737520
|
+
const tokenPriceGetter = _metrics_PriceGetter_js__WEBPACK_IMPORTED_MODULE_6__/* .PriceGetter */ .z.create(this.multiProvider.metadata, this.logger, coingeckoApiKey);
|
|
737442
737521
|
const warpDeployConfig = await this.registry.getWarpDeployConfig(this.config.warpRouteId);
|
|
737443
|
-
return new
|
|
737522
|
+
return new _metrics_Metrics_js__WEBPACK_IMPORTED_MODULE_5__/* .Metrics */ .K(tokenPriceGetter, warpDeployConfig, this.warpCore, this.config.warpRouteId, this.logger);
|
|
737444
737523
|
}
|
|
737445
737524
|
createMonitor(checkFrequency, inventoryConfig) {
|
|
737446
737525
|
this.logger.debug({
|
|
737447
737526
|
warpRouteId: this.config.warpRouteId,
|
|
737448
737527
|
checkFrequency: checkFrequency,
|
|
737449
737528
|
}, 'Creating Monitor');
|
|
737450
|
-
return new
|
|
737529
|
+
return new _monitor_Monitor_js__WEBPACK_IMPORTED_MODULE_7__/* .Monitor */ .V(checkFrequency, this.warpCore, this.logger, inventoryConfig);
|
|
737451
737530
|
}
|
|
737452
737531
|
async createStrategy(metrics) {
|
|
737453
737532
|
const strategyTypes = this.config.strategyConfig.map((s) => s.rebalanceStrategy);
|
|
@@ -737463,27 +737542,27 @@ class RebalancerContextFactory {
|
|
|
737463
737542
|
const chainConfig = (0,_config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .getStrategyChainConfig */ .nt)(this.config.strategyConfig, chainName);
|
|
737464
737543
|
if (chainConfig?.bridgeMinAcceptedAmount) {
|
|
737465
737544
|
const token = this.tokensByChainName[chainName];
|
|
737466
|
-
|
|
737467
|
-
minAmountsByChain[chainName] =
|
|
737545
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__/* .assert */ .v)(token, `No token found for configured strategy chain ${chainName} in warp route ${this.config.warpRouteId}`);
|
|
737546
|
+
minAmountsByChain[chainName] = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_10__/* .normalizeConfiguredAmount */ .k9)(chainConfig.bridgeMinAcceptedAmount, token);
|
|
737468
737547
|
}
|
|
737469
737548
|
}
|
|
737470
737549
|
this.logger.debug({
|
|
737471
737550
|
minAmountsByChain: Object.fromEntries(Object.entries(minAmountsByChain).map(([k, v]) => [k, v.toString()])),
|
|
737472
737551
|
}, 'Built minimum amounts by chain for strategy');
|
|
737473
|
-
return
|
|
737552
|
+
return _strategy_StrategyFactory_js__WEBPACK_IMPORTED_MODULE_8__/* .StrategyFactory */ .M.createStrategy(this.config.strategyConfig, this.tokensByChainName, await this.getInitialTotalCollateral(), this.logger, metrics, minAmountsByChain);
|
|
737474
737553
|
}
|
|
737475
737554
|
createMovableCollateralRebalancer(actionTracker, metrics) {
|
|
737476
737555
|
this.logger.debug({ warpRouteId: this.config.warpRouteId }, 'Creating Rebalancer');
|
|
737477
|
-
const rebalancer = new
|
|
737556
|
+
const rebalancer = new _core_Rebalancer_js__WEBPACK_IMPORTED_MODULE_3__/* .Rebalancer */ .K(this.warpCore, this.multiProvider.metadata, this.tokensByChainName, this.multiProvider, actionTracker, this.logger, metrics);
|
|
737478
737557
|
return rebalancer;
|
|
737479
737558
|
}
|
|
737480
737559
|
async createActionTracker(explorerUrlOrClient = DEFAULT_EXPLORER_URL) {
|
|
737481
737560
|
this.logger.debug({ warpRouteId: this.config.warpRouteId }, 'Creating ActionTracker');
|
|
737482
|
-
const transferStore = new
|
|
737483
|
-
const intentStore = new
|
|
737484
|
-
const actionStore = new
|
|
737561
|
+
const transferStore = new _tracking_store_index_js__WEBPACK_IMPORTED_MODULE_17__/* .InMemoryStore */ .A();
|
|
737562
|
+
const intentStore = new _tracking_store_index_js__WEBPACK_IMPORTED_MODULE_17__/* .InMemoryStore */ .A();
|
|
737563
|
+
const actionStore = new _tracking_store_index_js__WEBPACK_IMPORTED_MODULE_17__/* .InMemoryStore */ .A();
|
|
737485
737564
|
const explorerClient = typeof explorerUrlOrClient === 'string'
|
|
737486
|
-
? new
|
|
737565
|
+
? new _utils_ExplorerClient_js__WEBPACK_IMPORTED_MODULE_18__/* .ExplorerClient */ .x(explorerUrlOrClient, (domain) => this.multiProvider.getProtocol(domain))
|
|
737487
737566
|
: explorerUrlOrClient;
|
|
737488
737567
|
// 3. Get MultiProtocolCore from registry (supports all VM types)
|
|
737489
737568
|
// Only fetch/validate addresses for warp route chains (not all registry chains)
|
|
@@ -737496,7 +737575,7 @@ class RebalancerContextFactory {
|
|
|
737496
737575
|
}
|
|
737497
737576
|
coreAddresses[chain] = addrs;
|
|
737498
737577
|
}
|
|
737499
|
-
const multiProtocolCore =
|
|
737578
|
+
const multiProtocolCore = _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_19__/* .MultiProtocolCore */ .n.fromAddressesMap(coreAddresses, this.multiProtocolProvider);
|
|
737500
737579
|
// 4. Get rebalancer address from signer
|
|
737501
737580
|
// Use the first chain in the strategy to get the signer address
|
|
737502
737581
|
const chainNames = (0,_config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .getStrategyChainNames */ .zj)(this.config.strategyConfig);
|
|
@@ -737518,7 +737597,7 @@ class RebalancerContextFactory {
|
|
|
737518
737597
|
rebalancerAddress,
|
|
737519
737598
|
inventorySignerAddresses: this.config.inventorySigners
|
|
737520
737599
|
? Object.entries(this.config.inventorySigners)
|
|
737521
|
-
.filter(([protocol]) => protocol ===
|
|
737600
|
+
.filter(([protocol]) => protocol === _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_13__/* .ProtocolType */ .Hb.Ethereum)
|
|
737522
737601
|
.map(([, signerConfig]) => signerConfig)
|
|
737523
737602
|
.map((s) => s.address)
|
|
737524
737603
|
.filter(Boolean)
|
|
@@ -737526,9 +737605,9 @@ class RebalancerContextFactory {
|
|
|
737526
737605
|
intentTTL: this.config.intentTTL,
|
|
737527
737606
|
};
|
|
737528
737607
|
// 6. Create ActionTracker
|
|
737529
|
-
const tracker = new
|
|
737608
|
+
const tracker = new _tracking_ActionTracker_js__WEBPACK_IMPORTED_MODULE_9__/* .ActionTracker */ .N(transferStore, intentStore, actionStore, explorerClient, multiProtocolCore, trackerConfig, this.logger);
|
|
737530
737609
|
// 7. Create InflightContextAdapter
|
|
737531
|
-
const adapter = new
|
|
737610
|
+
const adapter = new _tracking_InflightContextAdapter_js__WEBPACK_IMPORTED_MODULE_20__/* .InflightContextAdapter */ .m(tracker, this.multiProvider);
|
|
737532
737611
|
this.logger.debug({
|
|
737533
737612
|
warpRouteId: this.config.warpRouteId,
|
|
737534
737613
|
routerCount: Object.keys(routersByDomain).length,
|
|
@@ -737565,31 +737644,34 @@ class RebalancerContextFactory {
|
|
|
737565
737644
|
this.logger.debug('No inventory chains configured');
|
|
737566
737645
|
return null;
|
|
737567
737646
|
}
|
|
737647
|
+
for (const chain of allRelevantChains) {
|
|
737648
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__/* .assert */ .v)(this.tokensByChainName[chain], `No token found for inventory-relevant chain ${chain} in warp route ${this.config.warpRouteId}`);
|
|
737649
|
+
}
|
|
737568
737650
|
const requiredProtocols = new Set(allRelevantChains.map((chain) => {
|
|
737569
737651
|
const metadata = this.warpCore.multiProvider.getChainMetadata(chain);
|
|
737570
|
-
(0,
|
|
737652
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__/* .assert */ .v)(metadata?.protocol, `No protocol in chain metadata for ${chain}`);
|
|
737571
737653
|
return metadata.protocol;
|
|
737572
737654
|
}));
|
|
737573
737655
|
const SUPPORTED_INVENTORY_PROTOCOLS = new Set([
|
|
737574
|
-
|
|
737575
|
-
|
|
737656
|
+
_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_13__/* .ProtocolType */ .Hb.Ethereum,
|
|
737657
|
+
_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_13__/* .ProtocolType */ .Hb.Sealevel,
|
|
737576
737658
|
]);
|
|
737577
737659
|
for (const protocol of requiredProtocols) {
|
|
737578
737660
|
const chainsForProtocol = allRelevantChains.filter((chain) => this.warpCore.multiProvider.getChainMetadata(chain).protocol ===
|
|
737579
737661
|
protocol);
|
|
737580
|
-
(0,
|
|
737662
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__/* .assert */ .v)(SUPPORTED_INVENTORY_PROTOCOLS.has(protocol), `Inventory rebalancing does not support protocol '${protocol}' (chains: ${chainsForProtocol.join(', ')}). Supported: ethereum, sealevel`);
|
|
737581
737663
|
}
|
|
737582
737664
|
for (const protocol of requiredProtocols) {
|
|
737583
737665
|
const chainsForProtocol = allRelevantChains.filter((chain) => this.warpCore.multiProvider.getChainMetadata(chain).protocol ===
|
|
737584
737666
|
protocol);
|
|
737585
|
-
(0,
|
|
737667
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__/* .assert */ .v)(this.config.inventorySigners?.[protocol]?.key ??
|
|
737586
737668
|
this.inventorySignerKeysByProtocol?.[protocol], `Missing inventory signer key for protocol ${protocol} (required by inventory chains: ${chainsForProtocol.join(', ')})`);
|
|
737587
737669
|
}
|
|
737588
737670
|
// Validate inventory address coverage for all required protocols
|
|
737589
737671
|
for (const protocol of requiredProtocols) {
|
|
737590
737672
|
const chainsForProtocol = allRelevantChains.filter((chain) => this.warpCore.multiProvider.getChainMetadata(chain).protocol ===
|
|
737591
737673
|
protocol);
|
|
737592
|
-
(0,
|
|
737674
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__/* .assert */ .v)(inventorySigners[protocol]?.address, `Missing inventory address for protocol ${protocol} (required by inventory chains: ${chainsForProtocol.join(', ')})`);
|
|
737593
737675
|
}
|
|
737594
737676
|
const externalBridgeRegistry = externalBridgeRegistryOverride ?? this.buildExternalBridgeRegistry();
|
|
737595
737677
|
if (Object.keys(externalBridgeRegistry).length === 0) {
|
|
@@ -737713,7 +737795,7 @@ class RebalancerContextFactory {
|
|
|
737713
737795
|
*/
|
|
737714
737796
|
createOrchestrator(options) {
|
|
737715
737797
|
this.logger.debug({ warpRouteId: this.config.warpRouteId }, 'Creating RebalancerOrchestrator');
|
|
737716
|
-
return new
|
|
737798
|
+
return new _core_RebalancerOrchestrator_js__WEBPACK_IMPORTED_MODULE_4__/* .RebalancerOrchestrator */ .E({
|
|
737717
737799
|
strategy: options.strategy,
|
|
737718
737800
|
actionTracker: options.actionTracker,
|
|
737719
737801
|
inflightContextAdapter: options.inflightContextAdapter,
|
|
@@ -737747,11 +737829,12 @@ class RebalancerContextFactory {
|
|
|
737747
737829
|
let initialTotalCollateral = 0n;
|
|
737748
737830
|
const chainNames = new Set((0,_config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .getStrategyChainNames */ .zj)(this.config.strategyConfig));
|
|
737749
737831
|
await Promise.all(this.warpCore.tokens.map(async (token) => {
|
|
737750
|
-
if ((0,
|
|
737832
|
+
if ((0,_utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_11__/* .isCollateralizedTokenEligibleForRebalancing */ .rC)(token) &&
|
|
737751
737833
|
chainNames.has(token.chainName)) {
|
|
737752
737834
|
const adapter = token.getHypAdapter(this.warpCore.multiProvider);
|
|
737753
737835
|
const bridgedSupply = await adapter.getBridgedSupply();
|
|
737754
|
-
|
|
737836
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_16__/* .assert */ .v)(bridgedSupply !== undefined, `Missing bridged supply for ${token.chainName} while computing initial total collateral for warp route ${this.config.warpRouteId}`);
|
|
737837
|
+
initialTotalCollateral += (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_10__/* .normalizeToCanonical */ .R2)(bridgedSupply, token);
|
|
737755
737838
|
}
|
|
737756
737839
|
}));
|
|
737757
737840
|
return initialTotalCollateral;
|
|
@@ -737769,24 +737852,26 @@ __webpack_async_result__();
|
|
|
737769
737852
|
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
|
|
737770
737853
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
737771
737854
|
/* harmony export */ $X: () => (/* reexport safe */ _core_RebalancerService_js__WEBPACK_IMPORTED_MODULE_0__.$),
|
|
737772
|
-
/* harmony export */ Wo: () => (/* reexport safe */
|
|
737773
|
-
/* harmony export */ zj: () => (/* reexport safe */
|
|
737855
|
+
/* harmony export */ Wo: () => (/* reexport safe */ _config_RebalancerConfig_js__WEBPACK_IMPORTED_MODULE_2__.W),
|
|
737856
|
+
/* harmony export */ zj: () => (/* reexport safe */ _config_types_js__WEBPACK_IMPORTED_MODULE_3__.zj)
|
|
737774
737857
|
/* harmony export */ });
|
|
737775
737858
|
/* harmony import */ var _core_RebalancerService_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(42248);
|
|
737776
|
-
/* harmony import */ var
|
|
737777
|
-
/* harmony import */ var
|
|
737778
|
-
/* harmony import */ var
|
|
737779
|
-
/* harmony import */ var
|
|
737780
|
-
/* harmony import */ var
|
|
737781
|
-
/* harmony import */ var
|
|
737782
|
-
/* harmony import */ var
|
|
737783
|
-
/* harmony import */ var
|
|
737784
|
-
/* harmony import */ var
|
|
737785
|
-
/* harmony import */ var
|
|
737786
|
-
/* harmony import */ var
|
|
737787
|
-
/* harmony import */ var
|
|
737788
|
-
|
|
737789
|
-
|
|
737859
|
+
/* harmony import */ var _core_Rebalancer_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(3903);
|
|
737860
|
+
/* harmony import */ var _config_RebalancerConfig_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(37562);
|
|
737861
|
+
/* harmony import */ var _config_types_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(75102);
|
|
737862
|
+
/* harmony import */ var _strategy_BaseStrategy_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(94598);
|
|
737863
|
+
/* harmony import */ var _strategy_WeightedStrategy_js__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(64438);
|
|
737864
|
+
/* harmony import */ var _strategy_MinAmountStrategy_js__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(82833);
|
|
737865
|
+
/* harmony import */ var _strategy_StrategyFactory_js__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(88757);
|
|
737866
|
+
/* harmony import */ var _monitor_Monitor_js__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(14135);
|
|
737867
|
+
/* harmony import */ var _metrics_Metrics_js__WEBPACK_IMPORTED_MODULE_9__ = __nccwpck_require__(42575);
|
|
737868
|
+
/* harmony import */ var _metrics_PriceGetter_js__WEBPACK_IMPORTED_MODULE_10__ = __nccwpck_require__(81708);
|
|
737869
|
+
/* harmony import */ var _interfaces_IMonitor_js__WEBPACK_IMPORTED_MODULE_11__ = __nccwpck_require__(36513);
|
|
737870
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_12__ = __nccwpck_require__(11369);
|
|
737871
|
+
/* harmony import */ var _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_13__ = __nccwpck_require__(46618);
|
|
737872
|
+
/* harmony import */ var _factories_RebalancerContextFactory_js__WEBPACK_IMPORTED_MODULE_14__ = __nccwpck_require__(84569);
|
|
737873
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_core_RebalancerService_js__WEBPACK_IMPORTED_MODULE_0__, _core_Rebalancer_js__WEBPACK_IMPORTED_MODULE_1__, _strategy_BaseStrategy_js__WEBPACK_IMPORTED_MODULE_4__, _strategy_WeightedStrategy_js__WEBPACK_IMPORTED_MODULE_5__, _strategy_MinAmountStrategy_js__WEBPACK_IMPORTED_MODULE_6__, _strategy_StrategyFactory_js__WEBPACK_IMPORTED_MODULE_7__, _metrics_Metrics_js__WEBPACK_IMPORTED_MODULE_9__, _metrics_PriceGetter_js__WEBPACK_IMPORTED_MODULE_10__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_12__, _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_13__, _factories_RebalancerContextFactory_js__WEBPACK_IMPORTED_MODULE_14__]);
|
|
737874
|
+
([_core_RebalancerService_js__WEBPACK_IMPORTED_MODULE_0__, _core_Rebalancer_js__WEBPACK_IMPORTED_MODULE_1__, _strategy_BaseStrategy_js__WEBPACK_IMPORTED_MODULE_4__, _strategy_WeightedStrategy_js__WEBPACK_IMPORTED_MODULE_5__, _strategy_MinAmountStrategy_js__WEBPACK_IMPORTED_MODULE_6__, _strategy_StrategyFactory_js__WEBPACK_IMPORTED_MODULE_7__, _metrics_Metrics_js__WEBPACK_IMPORTED_MODULE_9__, _metrics_PriceGetter_js__WEBPACK_IMPORTED_MODULE_10__, _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_12__, _utils_tokenUtils_js__WEBPACK_IMPORTED_MODULE_13__, _factories_RebalancerContextFactory_js__WEBPACK_IMPORTED_MODULE_14__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
737790
737875
|
/**
|
|
737791
737876
|
* @hyperlane-xyz/rebalancer
|
|
737792
737877
|
*
|
|
@@ -738218,7 +738303,8 @@ __webpack_async_result__();
|
|
|
738218
738303
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
738219
738304
|
/* harmony export */ V: () => (/* binding */ Monitor)
|
|
738220
738305
|
/* harmony export */ });
|
|
738221
|
-
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(
|
|
738306
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(39196);
|
|
738307
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(14918);
|
|
738222
738308
|
/* harmony import */ var _interfaces_IMonitor_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(36513);
|
|
738223
738309
|
/* harmony import */ var _utils_blockTag_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(82167);
|
|
738224
738310
|
|
|
@@ -738305,13 +738391,21 @@ class Monitor {
|
|
|
738305
738391
|
const inventoryBalances = await this.fetchInventoryBalances();
|
|
738306
738392
|
if (Object.keys(inventoryBalances).length > 0) {
|
|
738307
738393
|
event.inventoryBalances = inventoryBalances;
|
|
738394
|
+
const tokensByChain = new Map(this.warpCore.tokens.map((token) => [token.chainName, token]));
|
|
738395
|
+
// CAST: inventoryBalances keys come from configured monitor chains,
|
|
738396
|
+
// but Object.entries widens them to string.
|
|
738397
|
+
const inventoryBalanceEntries = Object.entries(inventoryBalances);
|
|
738308
738398
|
this.logger.info({
|
|
738309
738399
|
chainsMonitored: Object.keys(inventoryBalances).length,
|
|
738310
|
-
balances:
|
|
738311
|
-
chain
|
|
738312
|
-
|
|
738313
|
-
|
|
738314
|
-
|
|
738400
|
+
balances: inventoryBalanceEntries.map(([chain, balance]) => {
|
|
738401
|
+
const token = tokensByChain.get(chain);
|
|
738402
|
+
return {
|
|
738403
|
+
chain,
|
|
738404
|
+
tokenSymbol: token?.symbol,
|
|
738405
|
+
balance: balance.toString(),
|
|
738406
|
+
balanceFormatted: (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__/* .fromWei */ .kX)(balance.toString(), token?.decimals),
|
|
738407
|
+
};
|
|
738408
|
+
}),
|
|
738315
738409
|
}, 'Inventory balances fetched');
|
|
738316
738410
|
}
|
|
738317
738411
|
if (this.tokenInfoHandler) {
|
|
@@ -738326,7 +738420,7 @@ class Monitor {
|
|
|
738326
738420
|
const elapsed = Date.now() - cycleStart;
|
|
738327
738421
|
const remaining = this.checkFrequency - elapsed;
|
|
738328
738422
|
if (remaining > 0) {
|
|
738329
|
-
await (0,
|
|
738423
|
+
await (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__/* .sleep */ .yy)(remaining);
|
|
738330
738424
|
}
|
|
738331
738425
|
// If elapsed >= checkFrequency, start next cycle immediately
|
|
738332
738426
|
}
|
|
@@ -738436,13 +738530,16 @@ class Monitor {
|
|
|
738436
738530
|
/***/ }),
|
|
738437
738531
|
|
|
738438
738532
|
/***/ 94598:
|
|
738439
|
-
/***/ ((
|
|
738533
|
+
/***/ ((__webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
738440
738534
|
|
|
738535
|
+
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
|
|
738441
738536
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
738442
738537
|
/* harmony export */ Z: () => (/* binding */ BaseStrategy)
|
|
738443
738538
|
/* harmony export */ });
|
|
738444
|
-
/* harmony import */ var
|
|
738445
|
-
/* harmony import */ var
|
|
738539
|
+
/* harmony import */ var _utils_bridgeUtils_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(88688);
|
|
738540
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(11369);
|
|
738541
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__]);
|
|
738542
|
+
_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
|
|
738446
738543
|
|
|
738447
738544
|
|
|
738448
738545
|
/**
|
|
@@ -738466,7 +738563,7 @@ class BaseStrategy {
|
|
|
738466
738563
|
this.tokensByChainName = tokensByChainName;
|
|
738467
738564
|
}
|
|
738468
738565
|
getBridgeConfigForRoute(origin, destination) {
|
|
738469
|
-
return (0,
|
|
738566
|
+
return (0,_utils_bridgeUtils_js__WEBPACK_IMPORTED_MODULE_1__/* .getBridgeConfig */ .Yf)(this.bridgeConfigs, origin, destination);
|
|
738470
738567
|
}
|
|
738471
738568
|
/**
|
|
738472
738569
|
* Main method to get rebalancing routes
|
|
@@ -738548,7 +738645,7 @@ class BaseStrategy {
|
|
|
738548
738645
|
// Get bridge config for this route (with destination-specific overrides)
|
|
738549
738646
|
const bridgeConfig = this.getBridgeConfigForRoute(surplus.chain, deficit.chain);
|
|
738550
738647
|
// Create appropriate route type based on execution type
|
|
738551
|
-
routes.push((0,
|
|
738648
|
+
routes.push((0,_utils_bridgeUtils_js__WEBPACK_IMPORTED_MODULE_1__/* .createStrategyRoute */ .vT)(bridgeConfig, surplus.chain, deficit.chain, transferAmount));
|
|
738552
738649
|
}
|
|
738553
738650
|
// Decreases the amounts for the following iterations
|
|
738554
738651
|
deficit.amount -= transferAmount;
|
|
@@ -738767,16 +738864,18 @@ class BaseStrategy {
|
|
|
738767
738864
|
const token = this.tokensByChainName[route.origin];
|
|
738768
738865
|
if (token) {
|
|
738769
738866
|
const bridgeConfig = this.getBridgeConfigForRoute(route.origin, route.destination);
|
|
738770
|
-
|
|
738771
|
-
|
|
738772
|
-
|
|
738773
|
-
|
|
738774
|
-
|
|
738775
|
-
|
|
738776
|
-
|
|
738777
|
-
|
|
738778
|
-
|
|
738779
|
-
|
|
738867
|
+
if (bridgeConfig.bridgeMinAcceptedAmount != null) {
|
|
738868
|
+
const minAmount = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_0__/* .normalizeConfiguredAmount */ .k9)(bridgeConfig.bridgeMinAcceptedAmount, token);
|
|
738869
|
+
if (route.amount < minAmount) {
|
|
738870
|
+
this.logger.info({
|
|
738871
|
+
context: this.constructor.name,
|
|
738872
|
+
origin: route.origin,
|
|
738873
|
+
destination: route.destination,
|
|
738874
|
+
amount: route.amount.toString(),
|
|
738875
|
+
minAmount: minAmount.toString(),
|
|
738876
|
+
}, 'Dropping route below bridgeMinAcceptedAmount');
|
|
738877
|
+
return false;
|
|
738878
|
+
}
|
|
738780
738879
|
}
|
|
738781
738880
|
}
|
|
738782
738881
|
}
|
|
@@ -738785,152 +738884,24 @@ class BaseStrategy {
|
|
|
738785
738884
|
}
|
|
738786
738885
|
}
|
|
738787
738886
|
//# sourceMappingURL=BaseStrategy.js.map
|
|
738887
|
+
__webpack_async_result__();
|
|
738888
|
+
} catch(e) { __webpack_async_result__(e); } });
|
|
738788
738889
|
|
|
738789
738890
|
/***/ }),
|
|
738790
738891
|
|
|
738791
|
-
/***/
|
|
738792
|
-
/***/ ((
|
|
738892
|
+
/***/ 22532:
|
|
738893
|
+
/***/ ((__webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
738793
738894
|
|
|
738895
|
+
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
|
|
738794
738896
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
738795
|
-
/* harmony export */
|
|
738897
|
+
/* harmony export */ v: () => (/* binding */ CollateralDeficitStrategy)
|
|
738796
738898
|
/* harmony export */ });
|
|
738797
|
-
/* harmony import */ var
|
|
738798
|
-
/* harmony import */ var
|
|
738799
|
-
/* harmony import */ var
|
|
738899
|
+
/* harmony import */ var _config_types_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(75102);
|
|
738900
|
+
/* harmony import */ var _utils_bridgeUtils_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(88688);
|
|
738901
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(11369);
|
|
738800
738902
|
/* harmony import */ var _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(94598);
|
|
738801
|
-
|
|
738802
|
-
|
|
738803
|
-
|
|
738804
|
-
|
|
738805
|
-
/**
|
|
738806
|
-
* Strategy implementation that rebalance based on minimum amounts
|
|
738807
|
-
* It ensures each chain has at least the specified minimum amount
|
|
738808
|
-
*/
|
|
738809
|
-
class MinAmountStrategy extends _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_2__/* .BaseStrategy */ .Z {
|
|
738810
|
-
name = _config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .RebalancerStrategyOptions */ .t$.MinAmount;
|
|
738811
|
-
config = {};
|
|
738812
|
-
logger;
|
|
738813
|
-
constructor(config, tokensByChainName, initialTotalCollateral, logger, bridgeConfigs, metrics) {
|
|
738814
|
-
const chains = Object.keys(config);
|
|
738815
|
-
const log = logger.child({ class: MinAmountStrategy.name });
|
|
738816
|
-
super(chains, log, bridgeConfigs, metrics, tokensByChainName);
|
|
738817
|
-
this.logger = log;
|
|
738818
|
-
const minAmountType = config[chains[0]].minAmount.type;
|
|
738819
|
-
this.validateAmounts(initialTotalCollateral, minAmountType, config);
|
|
738820
|
-
for (const chain of chains) {
|
|
738821
|
-
const { min, target } = config[chain].minAmount;
|
|
738822
|
-
// check range constraints
|
|
738823
|
-
if ((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(target).lt(min)) {
|
|
738824
|
-
throw new Error(`Target (${target}) must be greater than or equal to min (${min}) for chain ${chain}`);
|
|
738825
|
-
}
|
|
738826
|
-
if ((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(min).lt(0)) {
|
|
738827
|
-
throw new Error(`Minimum amount (${min}) cannot be negative for chain ${chain}`);
|
|
738828
|
-
}
|
|
738829
|
-
if ((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(target).lt(0)) {
|
|
738830
|
-
throw new Error(`Target amount (${target}) cannot be negative for chain ${chain}`);
|
|
738831
|
-
}
|
|
738832
|
-
}
|
|
738833
|
-
this.config = config;
|
|
738834
|
-
this.logger.info('MinAmountStrategy created');
|
|
738835
|
-
}
|
|
738836
|
-
/**
|
|
738837
|
-
* Gets balances categorized by surplus and deficit based on minimum amounts and targets
|
|
738838
|
-
* - For absolute values: Uses exact token amounts
|
|
738839
|
-
* - For relative values: Uses percentages of total balance across all chains
|
|
738840
|
-
*
|
|
738841
|
-
* Simulates both types of rebalances before calculating surpluses/deficits:
|
|
738842
|
-
* - pendingRebalances: in-flight intents (origin tx confirmed, add to destination only)
|
|
738843
|
-
* - proposedRebalances: routes from earlier strategies (subtract from origin AND add to destination)
|
|
738844
|
-
*
|
|
738845
|
-
* This prevents over-rebalancing when multiple strategies run in sequence.
|
|
738846
|
-
*/
|
|
738847
|
-
getCategorizedBalances(rawBalances, pendingRebalances, proposedRebalances) {
|
|
738848
|
-
// Step 1: Simulate pending rebalances (in-flight, origin already deducted on-chain)
|
|
738849
|
-
let simulatedBalances = this.simulatePendingRebalances(rawBalances, pendingRebalances ?? []);
|
|
738850
|
-
// Step 2: Simulate proposed rebalances (from earlier strategies, not yet executed)
|
|
738851
|
-
simulatedBalances = this.simulateProposedRebalances(simulatedBalances, proposedRebalances ?? []);
|
|
738852
|
-
const totalCollateral = this.chains.reduce((sum, chain) => sum + simulatedBalances[chain], 0n);
|
|
738853
|
-
return this.chains.reduce((acc, chain) => {
|
|
738854
|
-
const chainConfig = this.config[chain];
|
|
738855
|
-
const balance = simulatedBalances[chain];
|
|
738856
|
-
let minAmount;
|
|
738857
|
-
let targetAmount;
|
|
738858
|
-
if (chainConfig.minAmount.type === _config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .RebalancerMinAmountType */ .gK.Absolute) {
|
|
738859
|
-
const token = this.getTokenByChainName(chain);
|
|
738860
|
-
minAmount = BigInt((0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__/* .toWei */ .fq)(chainConfig.minAmount.min, token.decimals));
|
|
738861
|
-
targetAmount = BigInt((0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__/* .toWei */ .fq)(chainConfig.minAmount.target, token.decimals));
|
|
738862
|
-
}
|
|
738863
|
-
else {
|
|
738864
|
-
minAmount = BigInt((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(totalCollateral.toString())
|
|
738865
|
-
.times(chainConfig.minAmount.min)
|
|
738866
|
-
.toFixed(0, bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g.ROUND_FLOOR));
|
|
738867
|
-
targetAmount = BigInt((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(totalCollateral.toString())
|
|
738868
|
-
.times(chainConfig.minAmount.target)
|
|
738869
|
-
.toFixed(0, bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g.ROUND_FLOOR));
|
|
738870
|
-
}
|
|
738871
|
-
// If balance is less than minAmount, it has a deficit
|
|
738872
|
-
if (balance < minAmount) {
|
|
738873
|
-
acc.deficits.push({ chain, amount: targetAmount - balance });
|
|
738874
|
-
}
|
|
738875
|
-
else {
|
|
738876
|
-
// Any chain with more than minAmount potentially has surplus
|
|
738877
|
-
const surplus = balance - minAmount;
|
|
738878
|
-
if (surplus > 0n) {
|
|
738879
|
-
acc.surpluses.push({ chain, amount: surplus });
|
|
738880
|
-
}
|
|
738881
|
-
}
|
|
738882
|
-
return acc;
|
|
738883
|
-
}, {
|
|
738884
|
-
surpluses: [],
|
|
738885
|
-
deficits: [],
|
|
738886
|
-
});
|
|
738887
|
-
}
|
|
738888
|
-
getTokenByChainName(chainName) {
|
|
738889
|
-
const token = this.tokensByChainName[chainName];
|
|
738890
|
-
if (token === undefined) {
|
|
738891
|
-
throw new Error(`Token not found for chain ${chainName}`);
|
|
738892
|
-
}
|
|
738893
|
-
return token;
|
|
738894
|
-
}
|
|
738895
|
-
validateAmounts(totalCollateral, minAmountType, config) {
|
|
738896
|
-
config ??= this.config;
|
|
738897
|
-
if (minAmountType === _config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .RebalancerMinAmountType */ .gK.Absolute) {
|
|
738898
|
-
let totalTargets = 0n;
|
|
738899
|
-
let decimals = 0;
|
|
738900
|
-
for (const chainName of this.chains) {
|
|
738901
|
-
const token = this.getTokenByChainName(chainName);
|
|
738902
|
-
// all the tokens have the same amount of decimals
|
|
738903
|
-
decimals = token.decimals;
|
|
738904
|
-
totalTargets += BigInt((0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__/* .toWei */ .fq)(config[chainName].minAmount.target, token.decimals));
|
|
738905
|
-
}
|
|
738906
|
-
if (totalTargets > totalCollateral) {
|
|
738907
|
-
throw new Error(`Consider reducing the targets as the sum (${(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__/* .fromWei */ .kX)(totalTargets.toString(), decimals)}) is greater than sum of collaterals (${(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_3__/* .fromWei */ .kX)(totalCollateral.toString(), decimals)})`);
|
|
738908
|
-
}
|
|
738909
|
-
}
|
|
738910
|
-
}
|
|
738911
|
-
}
|
|
738912
|
-
//# sourceMappingURL=MinAmountStrategy.js.map
|
|
738913
|
-
|
|
738914
|
-
/***/ }),
|
|
738915
|
-
|
|
738916
|
-
/***/ 52154:
|
|
738917
|
-
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
738918
|
-
|
|
738919
|
-
|
|
738920
|
-
// EXPORTS
|
|
738921
|
-
__nccwpck_require__.d(__webpack_exports__, {
|
|
738922
|
-
M: () => (/* binding */ StrategyFactory)
|
|
738923
|
-
});
|
|
738924
|
-
|
|
738925
|
-
// EXTERNAL MODULE: ../rebalancer/dist/config/types.js
|
|
738926
|
-
var types = __nccwpck_require__(75102);
|
|
738927
|
-
// EXTERNAL MODULE: ../utils/dist/amount.js
|
|
738928
|
-
var amount = __nccwpck_require__(39196);
|
|
738929
|
-
// EXTERNAL MODULE: ../rebalancer/dist/utils/bridgeUtils.js
|
|
738930
|
-
var bridgeUtils = __nccwpck_require__(88688);
|
|
738931
|
-
// EXTERNAL MODULE: ../rebalancer/dist/strategy/BaseStrategy.js
|
|
738932
|
-
var BaseStrategy = __nccwpck_require__(94598);
|
|
738933
|
-
;// CONCATENATED MODULE: ../rebalancer/dist/strategy/CollateralDeficitStrategy.js
|
|
738903
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_1__, _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_2__]);
|
|
738904
|
+
([_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_1__, _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_2__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
738934
738905
|
|
|
738935
738906
|
|
|
738936
738907
|
|
|
@@ -738945,8 +738916,8 @@ var BaseStrategy = __nccwpck_require__(94598);
|
|
|
738945
738916
|
* 3. Negative simulated balance = deficit (magnitude + buffer)
|
|
738946
738917
|
* 4. Positive simulated balance = potential surplus
|
|
738947
738918
|
*/
|
|
738948
|
-
class CollateralDeficitStrategy extends
|
|
738949
|
-
name =
|
|
738919
|
+
class CollateralDeficitStrategy extends _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_2__/* .BaseStrategy */ .Z {
|
|
738920
|
+
name = _config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .RebalancerStrategyOptions */ .t$.CollateralDeficit;
|
|
738950
738921
|
config;
|
|
738951
738922
|
logger;
|
|
738952
738923
|
constructor(config, tokensByChainName, logger, bridgeConfigs, metrics) {
|
|
@@ -738985,7 +738956,7 @@ class CollateralDeficitStrategy extends BaseStrategy/* BaseStrategy */.Z {
|
|
|
738985
738956
|
for (const chain of this.chains) {
|
|
738986
738957
|
const balance = simulatedBalances[chain];
|
|
738987
738958
|
const token = this.getTokenByChainName(chain);
|
|
738988
|
-
const bufferWei =
|
|
738959
|
+
const bufferWei = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_1__/* .normalizeConfiguredAmount */ .k9)(this.config[chain].buffer, token);
|
|
738989
738960
|
if (balance < 0n) {
|
|
738990
738961
|
// Negative balance indicates deficit
|
|
738991
738962
|
const deficitAmount = -balance + bufferWei;
|
|
@@ -739074,7 +739045,7 @@ class CollateralDeficitStrategy extends BaseStrategy/* BaseStrategy */.Z {
|
|
|
739074
739045
|
const transferAmount = surplus.amount > deficit.amount ? deficit.amount : surplus.amount;
|
|
739075
739046
|
if (transferAmount > 0n) {
|
|
739076
739047
|
const bridgeConfig = this.getBridgeConfigForRoute(surplus.chain, deficit.chain);
|
|
739077
|
-
routes.push((0,
|
|
739048
|
+
routes.push((0,_utils_bridgeUtils_js__WEBPACK_IMPORTED_MODULE_3__/* .createStrategyRoute */ .vT)(bridgeConfig, surplus.chain, deficit.chain, transferAmount));
|
|
739078
739049
|
}
|
|
739079
739050
|
deficit.amount -= transferAmount;
|
|
739080
739051
|
surplus.amount -= transferAmount;
|
|
@@ -739111,12 +739082,12 @@ class CollateralDeficitStrategy extends BaseStrategy/* BaseStrategy */.Z {
|
|
|
739111
739082
|
const bridgeConfig = this.getBridgeConfigForRoute(rebalance.origin, rebalance.destination);
|
|
739112
739083
|
// For movableCollateral routes: match bridge address
|
|
739113
739084
|
if ('bridge' in rebalance && rebalance.bridge) {
|
|
739114
|
-
return ((0,
|
|
739085
|
+
return ((0,_utils_bridgeUtils_js__WEBPACK_IMPORTED_MODULE_3__/* .isMovableCollateralConfig */ .iT)(bridgeConfig) &&
|
|
739115
739086
|
bridgeConfig.bridge === rebalance.bridge);
|
|
739116
739087
|
}
|
|
739117
739088
|
// For inventory routes: match externalBridge type
|
|
739118
739089
|
if ('externalBridge' in rebalance && rebalance.externalBridge) {
|
|
739119
|
-
return ((0,
|
|
739090
|
+
return ((0,_utils_bridgeUtils_js__WEBPACK_IMPORTED_MODULE_3__/* .isInventoryConfig */ .pm)(bridgeConfig) &&
|
|
739120
739091
|
bridgeConfig.externalBridge === rebalance.externalBridge);
|
|
739121
739092
|
}
|
|
739122
739093
|
// Recovered intents without bridge info - include to be safe
|
|
@@ -739184,7 +739155,17 @@ class CollateralDeficitStrategy extends BaseStrategy/* BaseStrategy */.Z {
|
|
|
739184
739155
|
}
|
|
739185
739156
|
}
|
|
739186
739157
|
//# sourceMappingURL=CollateralDeficitStrategy.js.map
|
|
739187
|
-
|
|
739158
|
+
__webpack_async_result__();
|
|
739159
|
+
} catch(e) { __webpack_async_result__(e); } });
|
|
739160
|
+
|
|
739161
|
+
/***/ }),
|
|
739162
|
+
|
|
739163
|
+
/***/ 93282:
|
|
739164
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
739165
|
+
|
|
739166
|
+
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
739167
|
+
/* harmony export */ l: () => (/* binding */ CompositeStrategy)
|
|
739168
|
+
/* harmony export */ });
|
|
739188
739169
|
/**
|
|
739189
739170
|
* Composite strategy that runs multiple sub-strategies sequentially.
|
|
739190
739171
|
*
|
|
@@ -739248,11 +739229,159 @@ class CompositeStrategy {
|
|
|
739248
739229
|
}
|
|
739249
739230
|
}
|
|
739250
739231
|
//# sourceMappingURL=CompositeStrategy.js.map
|
|
739251
|
-
|
|
739252
|
-
|
|
739253
|
-
|
|
739254
|
-
|
|
739255
|
-
|
|
739232
|
+
|
|
739233
|
+
/***/ }),
|
|
739234
|
+
|
|
739235
|
+
/***/ 82833:
|
|
739236
|
+
/***/ ((__webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
739237
|
+
|
|
739238
|
+
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
|
|
739239
|
+
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
739240
|
+
/* harmony export */ I: () => (/* binding */ MinAmountStrategy)
|
|
739241
|
+
/* harmony export */ });
|
|
739242
|
+
/* harmony import */ var bignumber_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(62033);
|
|
739243
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(27043);
|
|
739244
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(39196);
|
|
739245
|
+
/* harmony import */ var _config_types_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(75102);
|
|
739246
|
+
/* harmony import */ var _utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(11369);
|
|
739247
|
+
/* harmony import */ var _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(94598);
|
|
739248
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__, _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_3__]);
|
|
739249
|
+
([_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__, _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_3__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
739250
|
+
|
|
739251
|
+
|
|
739252
|
+
|
|
739253
|
+
|
|
739254
|
+
|
|
739255
|
+
|
|
739256
|
+
/**
|
|
739257
|
+
* Strategy implementation that rebalance based on minimum amounts
|
|
739258
|
+
* It ensures each chain has at least the specified minimum amount
|
|
739259
|
+
*/
|
|
739260
|
+
class MinAmountStrategy extends _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_3__/* .BaseStrategy */ .Z {
|
|
739261
|
+
name = _config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .RebalancerStrategyOptions */ .t$.MinAmount;
|
|
739262
|
+
config = {};
|
|
739263
|
+
logger;
|
|
739264
|
+
constructor(config, tokensByChainName, initialTotalCollateral, logger, bridgeConfigs, metrics) {
|
|
739265
|
+
const chains = Object.keys(config);
|
|
739266
|
+
const log = logger.child({ class: MinAmountStrategy.name });
|
|
739267
|
+
super(chains, log, bridgeConfigs, metrics, tokensByChainName);
|
|
739268
|
+
this.logger = log;
|
|
739269
|
+
const minAmountType = config[chains[0]].minAmount.type;
|
|
739270
|
+
this.validateAmounts(initialTotalCollateral, minAmountType, config);
|
|
739271
|
+
for (const chain of chains) {
|
|
739272
|
+
const { min, target } = config[chain].minAmount;
|
|
739273
|
+
// check range constraints
|
|
739274
|
+
if ((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(target).lt(min)) {
|
|
739275
|
+
throw new Error(`Target (${target}) must be greater than or equal to min (${min}) for chain ${chain}`);
|
|
739276
|
+
}
|
|
739277
|
+
if ((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(min).lt(0)) {
|
|
739278
|
+
throw new Error(`Minimum amount (${min}) cannot be negative for chain ${chain}`);
|
|
739279
|
+
}
|
|
739280
|
+
if ((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(target).lt(0)) {
|
|
739281
|
+
throw new Error(`Target amount (${target}) cannot be negative for chain ${chain}`);
|
|
739282
|
+
}
|
|
739283
|
+
}
|
|
739284
|
+
this.config = config;
|
|
739285
|
+
this.logger.info('MinAmountStrategy created');
|
|
739286
|
+
}
|
|
739287
|
+
/**
|
|
739288
|
+
* Gets balances categorized by surplus and deficit based on minimum amounts and targets
|
|
739289
|
+
* - For absolute values: Uses exact token amounts
|
|
739290
|
+
* - For relative values: Uses percentages of total balance across all chains
|
|
739291
|
+
*
|
|
739292
|
+
* Simulates both types of rebalances before calculating surpluses/deficits:
|
|
739293
|
+
* - pendingRebalances: in-flight intents (origin tx confirmed, add to destination only)
|
|
739294
|
+
* - proposedRebalances: routes from earlier strategies (subtract from origin AND add to destination)
|
|
739295
|
+
*
|
|
739296
|
+
* This prevents over-rebalancing when multiple strategies run in sequence.
|
|
739297
|
+
*/
|
|
739298
|
+
getCategorizedBalances(rawBalances, pendingRebalances, proposedRebalances) {
|
|
739299
|
+
// Step 1: Simulate pending rebalances (in-flight, origin already deducted on-chain)
|
|
739300
|
+
let simulatedBalances = this.simulatePendingRebalances(rawBalances, pendingRebalances ?? []);
|
|
739301
|
+
// Step 2: Simulate proposed rebalances (from earlier strategies, not yet executed)
|
|
739302
|
+
simulatedBalances = this.simulateProposedRebalances(simulatedBalances, proposedRebalances ?? []);
|
|
739303
|
+
const totalCollateral = this.chains.reduce((sum, chain) => sum + simulatedBalances[chain], 0n);
|
|
739304
|
+
return this.chains.reduce((acc, chain) => {
|
|
739305
|
+
const chainConfig = this.config[chain];
|
|
739306
|
+
const balance = simulatedBalances[chain];
|
|
739307
|
+
let minAmount;
|
|
739308
|
+
let targetAmount;
|
|
739309
|
+
if (chainConfig.minAmount.type === _config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .RebalancerMinAmountType */ .gK.Absolute) {
|
|
739310
|
+
const token = this.getTokenByChainName(chain);
|
|
739311
|
+
minAmount = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__/* .normalizeConfiguredAmount */ .k9)(chainConfig.minAmount.min, token);
|
|
739312
|
+
targetAmount = (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__/* .normalizeConfiguredAmount */ .k9)(chainConfig.minAmount.target, token);
|
|
739313
|
+
}
|
|
739314
|
+
else {
|
|
739315
|
+
minAmount = BigInt((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(totalCollateral.toString())
|
|
739316
|
+
.times(chainConfig.minAmount.min)
|
|
739317
|
+
.toFixed(0, bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g.ROUND_FLOOR));
|
|
739318
|
+
targetAmount = BigInt((0,bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g)(totalCollateral.toString())
|
|
739319
|
+
.times(chainConfig.minAmount.target)
|
|
739320
|
+
.toFixed(0, bignumber_js__WEBPACK_IMPORTED_MODULE_0__/* .BigNumber */ .g.ROUND_FLOOR));
|
|
739321
|
+
}
|
|
739322
|
+
// If balance is less than minAmount, it has a deficit
|
|
739323
|
+
if (balance < minAmount) {
|
|
739324
|
+
acc.deficits.push({ chain, amount: targetAmount - balance });
|
|
739325
|
+
}
|
|
739326
|
+
else {
|
|
739327
|
+
// Any chain with more than minAmount potentially has surplus
|
|
739328
|
+
const surplus = balance - minAmount;
|
|
739329
|
+
if (surplus > 0n) {
|
|
739330
|
+
acc.surpluses.push({ chain, amount: surplus });
|
|
739331
|
+
}
|
|
739332
|
+
}
|
|
739333
|
+
return acc;
|
|
739334
|
+
}, {
|
|
739335
|
+
surpluses: [],
|
|
739336
|
+
deficits: [],
|
|
739337
|
+
});
|
|
739338
|
+
}
|
|
739339
|
+
getTokenByChainName(chainName) {
|
|
739340
|
+
const token = this.tokensByChainName[chainName];
|
|
739341
|
+
if (token === undefined) {
|
|
739342
|
+
throw new Error(`Token not found for chain ${chainName}`);
|
|
739343
|
+
}
|
|
739344
|
+
return token;
|
|
739345
|
+
}
|
|
739346
|
+
validateAmounts(totalCollateral, minAmountType, config) {
|
|
739347
|
+
config ??= this.config;
|
|
739348
|
+
if (minAmountType === _config_types_js__WEBPACK_IMPORTED_MODULE_1__/* .RebalancerMinAmountType */ .gK.Absolute) {
|
|
739349
|
+
let totalTargets = 0n;
|
|
739350
|
+
const displayToken = this.getTokenByChainName(this.chains[0]);
|
|
739351
|
+
for (const chainName of this.chains) {
|
|
739352
|
+
const token = this.getTokenByChainName(chainName);
|
|
739353
|
+
totalTargets += (0,_utils_balanceUtils_js__WEBPACK_IMPORTED_MODULE_2__/* .normalizeConfiguredAmount */ .k9)(config[chainName].minAmount.target, token);
|
|
739354
|
+
}
|
|
739355
|
+
if (totalTargets > totalCollateral) {
|
|
739356
|
+
throw new Error(`Consider reducing the targets as the sum (${this.formatCanonicalAmount(totalTargets, displayToken)}) is greater than sum of collaterals (${this.formatCanonicalAmount(totalCollateral, displayToken)})`);
|
|
739357
|
+
}
|
|
739358
|
+
}
|
|
739359
|
+
}
|
|
739360
|
+
formatCanonicalAmount(amount, token) {
|
|
739361
|
+
const localAmount = (0,_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_4__/* .localAmountFromMessage */ .Vd)(amount, token.scale);
|
|
739362
|
+
return (0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_5__/* .fromWei */ .kX)(localAmount.toString(), token.decimals);
|
|
739363
|
+
}
|
|
739364
|
+
}
|
|
739365
|
+
//# sourceMappingURL=MinAmountStrategy.js.map
|
|
739366
|
+
__webpack_async_result__();
|
|
739367
|
+
} catch(e) { __webpack_async_result__(e); } });
|
|
739368
|
+
|
|
739369
|
+
/***/ }),
|
|
739370
|
+
|
|
739371
|
+
/***/ 88757:
|
|
739372
|
+
/***/ ((__webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
739373
|
+
|
|
739374
|
+
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
|
|
739375
|
+
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
739376
|
+
/* harmony export */ M: () => (/* binding */ StrategyFactory)
|
|
739377
|
+
/* harmony export */ });
|
|
739378
|
+
/* harmony import */ var _config_types_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(75102);
|
|
739379
|
+
/* harmony import */ var _CollateralDeficitStrategy_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(22532);
|
|
739380
|
+
/* harmony import */ var _CompositeStrategy_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(93282);
|
|
739381
|
+
/* harmony import */ var _MinAmountStrategy_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(82833);
|
|
739382
|
+
/* harmony import */ var _WeightedStrategy_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(64438);
|
|
739383
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_CollateralDeficitStrategy_js__WEBPACK_IMPORTED_MODULE_1__, _MinAmountStrategy_js__WEBPACK_IMPORTED_MODULE_2__, _WeightedStrategy_js__WEBPACK_IMPORTED_MODULE_3__]);
|
|
739384
|
+
([_CollateralDeficitStrategy_js__WEBPACK_IMPORTED_MODULE_1__, _MinAmountStrategy_js__WEBPACK_IMPORTED_MODULE_2__, _WeightedStrategy_js__WEBPACK_IMPORTED_MODULE_3__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
739256
739385
|
|
|
739257
739386
|
|
|
739258
739387
|
|
|
@@ -739282,7 +739411,7 @@ class StrategyFactory {
|
|
|
739282
739411
|
}
|
|
739283
739412
|
// Multiple strategies - create CompositeStrategy
|
|
739284
739413
|
const subStrategies = strategyConfigs.map((config) => this.createSingleStrategy(config, tokensByChainName, initialTotalCollateral, logger, metrics, minAmountsByChain));
|
|
739285
|
-
return new CompositeStrategy(subStrategies, logger);
|
|
739414
|
+
return new _CompositeStrategy_js__WEBPACK_IMPORTED_MODULE_4__/* .CompositeStrategy */ .l(subStrategies, logger);
|
|
739286
739415
|
}
|
|
739287
739416
|
/**
|
|
739288
739417
|
* Create a single strategy from config.
|
|
@@ -739290,14 +739419,14 @@ class StrategyFactory {
|
|
|
739290
739419
|
static createSingleStrategy(strategyConfig, tokensByChainName, initialTotalCollateral, logger, metrics, _minAmountsByChain) {
|
|
739291
739420
|
const bridgeConfigs = this.extractBridgeConfigs(strategyConfig);
|
|
739292
739421
|
switch (strategyConfig.rebalanceStrategy) {
|
|
739293
|
-
case
|
|
739294
|
-
return new
|
|
739422
|
+
case _config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .RebalancerStrategyOptions */ .t$.Weighted: {
|
|
739423
|
+
return new _WeightedStrategy_js__WEBPACK_IMPORTED_MODULE_3__/* .WeightedStrategy */ .T(strategyConfig.chains, logger, bridgeConfigs, metrics, tokensByChainName);
|
|
739295
739424
|
}
|
|
739296
|
-
case
|
|
739297
|
-
return new
|
|
739425
|
+
case _config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .RebalancerStrategyOptions */ .t$.MinAmount: {
|
|
739426
|
+
return new _MinAmountStrategy_js__WEBPACK_IMPORTED_MODULE_2__/* .MinAmountStrategy */ .I(strategyConfig.chains, tokensByChainName, initialTotalCollateral, logger, bridgeConfigs, metrics);
|
|
739298
739427
|
}
|
|
739299
|
-
case
|
|
739300
|
-
return new CollateralDeficitStrategy(strategyConfig.chains, tokensByChainName, logger, bridgeConfigs, metrics);
|
|
739428
|
+
case _config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .RebalancerStrategyOptions */ .t$.CollateralDeficit: {
|
|
739429
|
+
return new _CollateralDeficitStrategy_js__WEBPACK_IMPORTED_MODULE_1__/* .CollateralDeficitStrategy */ .v(strategyConfig.chains, tokensByChainName, logger, bridgeConfigs, metrics);
|
|
739301
739430
|
}
|
|
739302
739431
|
default: {
|
|
739303
739432
|
throw new Error('Unsupported strategy type');
|
|
@@ -739310,8 +739439,8 @@ class StrategyFactory {
|
|
|
739310
739439
|
const baseConfig = {
|
|
739311
739440
|
bridgeMinAcceptedAmount: config.bridgeMinAcceptedAmount ?? 0,
|
|
739312
739441
|
};
|
|
739313
|
-
const executionType = config.executionType ??
|
|
739314
|
-
if (executionType ===
|
|
739442
|
+
const executionType = config.executionType ?? _config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .ExecutionType */ .Pf.MovableCollateral;
|
|
739443
|
+
if (executionType === _config_types_js__WEBPACK_IMPORTED_MODULE_0__/* .ExecutionType */ .Pf.Inventory) {
|
|
739315
739444
|
bridgeConfigs[chain] = {
|
|
739316
739445
|
...baseConfig,
|
|
739317
739446
|
executionType: 'inventory',
|
|
@@ -739332,17 +739461,22 @@ class StrategyFactory {
|
|
|
739332
739461
|
}
|
|
739333
739462
|
}
|
|
739334
739463
|
//# sourceMappingURL=StrategyFactory.js.map
|
|
739464
|
+
__webpack_async_result__();
|
|
739465
|
+
} catch(e) { __webpack_async_result__(e); } });
|
|
739335
739466
|
|
|
739336
739467
|
/***/ }),
|
|
739337
739468
|
|
|
739338
739469
|
/***/ 64438:
|
|
739339
|
-
/***/ ((
|
|
739470
|
+
/***/ ((__webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
739340
739471
|
|
|
739472
|
+
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
|
|
739341
739473
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
739342
739474
|
/* harmony export */ T: () => (/* binding */ WeightedStrategy)
|
|
739343
739475
|
/* harmony export */ });
|
|
739344
739476
|
/* harmony import */ var _config_types_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(75102);
|
|
739345
739477
|
/* harmony import */ var _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(94598);
|
|
739478
|
+
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_BaseStrategy_js__WEBPACK_IMPORTED_MODULE_1__]);
|
|
739479
|
+
_BaseStrategy_js__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
|
|
739346
739480
|
|
|
739347
739481
|
|
|
739348
739482
|
/**
|
|
@@ -739416,6 +739550,8 @@ class WeightedStrategy extends _BaseStrategy_js__WEBPACK_IMPORTED_MODULE_1__/* .
|
|
|
739416
739550
|
}
|
|
739417
739551
|
}
|
|
739418
739552
|
//# sourceMappingURL=WeightedStrategy.js.map
|
|
739553
|
+
__webpack_async_result__();
|
|
739554
|
+
} catch(e) { __webpack_async_result__(e); } });
|
|
739419
739555
|
|
|
739420
739556
|
/***/ }),
|
|
739421
739557
|
|
|
@@ -739873,7 +740009,8 @@ class ActionTracker {
|
|
|
739873
740009
|
lastBridgeStatus: movement.lastBridgeStatus,
|
|
739874
740010
|
}, 'Failing stale inventory movement to unblock intent');
|
|
739875
740011
|
}
|
|
739876
|
-
//
|
|
740012
|
+
// Only inventory_deposit amounts advance fulfillment. inventory_movement
|
|
740013
|
+
// amounts stay in source-local units and only gate retries/stale cleanup.
|
|
739877
740014
|
const completedAmount = actions
|
|
739878
740015
|
.filter((a) => a.status === 'complete' && a.type === 'inventory_deposit')
|
|
739879
740016
|
.reduce((sum, a) => sum + a.amount, 0n);
|
|
@@ -740587,12 +740724,46 @@ class ExplorerClient {
|
|
|
740587
740724
|
|
|
740588
740725
|
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
|
|
740589
740726
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
740590
|
-
/* harmony export */
|
|
740727
|
+
/* harmony export */ R2: () => (/* binding */ normalizeToCanonical),
|
|
740728
|
+
/* harmony export */ bK: () => (/* binding */ denormalizeToLocal),
|
|
740729
|
+
/* harmony export */ gU: () => (/* binding */ alignLocalToCanonical),
|
|
740730
|
+
/* harmony export */ k9: () => (/* binding */ normalizeConfiguredAmount),
|
|
740731
|
+
/* harmony export */ qb: () => (/* binding */ getRawBalances)
|
|
740591
740732
|
/* harmony export */ });
|
|
740733
|
+
/* unused harmony exports getTokenScale, isIdentityScale */
|
|
740734
|
+
/* harmony import */ var _hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(27043);
|
|
740735
|
+
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(39196);
|
|
740592
740736
|
/* harmony import */ var _tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(46618);
|
|
740593
740737
|
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__]);
|
|
740594
740738
|
_tokenUtils_js__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
|
|
740595
740739
|
|
|
740740
|
+
|
|
740741
|
+
|
|
740742
|
+
function getTokenScale(token) {
|
|
740743
|
+
return (0,_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_1__/* .normalizeScale */ .EM)(token.scale);
|
|
740744
|
+
}
|
|
740745
|
+
function isIdentityScale(token) {
|
|
740746
|
+
return (0,_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_1__/* .scalesEqual */ .gm)(token.scale, undefined);
|
|
740747
|
+
}
|
|
740748
|
+
function normalizeToCanonical(localAmount, tokenOrScale) {
|
|
740749
|
+
return (0,_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_1__/* .messageAmountFromLocal */ .TI)(localAmount, getScaleInput(tokenOrScale));
|
|
740750
|
+
}
|
|
740751
|
+
function denormalizeToLocal(canonicalAmount, tokenOrScale) {
|
|
740752
|
+
// Use ceil semantics so the returned local amount always produces at least
|
|
740753
|
+
// the requested canonical progress once the token router floors on outbound.
|
|
740754
|
+
return (0,_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_1__/* .minLocalAmountForMessage */ .ol)(canonicalAmount, getScaleInput(tokenOrScale));
|
|
740755
|
+
}
|
|
740756
|
+
function alignLocalToCanonical(localAmount, tokenOrScale) {
|
|
740757
|
+
return (0,_hyperlane_xyz_sdk__WEBPACK_IMPORTED_MODULE_1__/* .alignLocalAmountToMessage */ .pD)(localAmount, getScaleInput(tokenOrScale));
|
|
740758
|
+
}
|
|
740759
|
+
function normalizeConfiguredAmount(amount, token) {
|
|
740760
|
+
return normalizeToCanonical(BigInt((0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_2__/* .toWei */ .fq)(amount, token.decimals)), token);
|
|
740761
|
+
}
|
|
740762
|
+
function getScaleInput(tokenOrScale) {
|
|
740763
|
+
return 'numerator' in tokenOrScale && 'denominator' in tokenOrScale
|
|
740764
|
+
? tokenOrScale
|
|
740765
|
+
: tokenOrScale.scale;
|
|
740766
|
+
}
|
|
740596
740767
|
/**
|
|
740597
740768
|
* Returns the raw balances required by the strategies from the monitor event
|
|
740598
740769
|
* @param chains - The chains that should be included in the raw balances (e.g. the chains in the rebalancer config)
|
|
@@ -740627,7 +740798,18 @@ function getRawBalances(chains, event, logger) {
|
|
|
740627
740798
|
if (bridgedSupply === undefined) {
|
|
740628
740799
|
throw new Error(`bridgedSupply should not be undefined for collateralized token ${token.addressOrDenom}`);
|
|
740629
740800
|
}
|
|
740630
|
-
|
|
740801
|
+
const normalizedBalance = normalizeToCanonical(bridgedSupply, token);
|
|
740802
|
+
balances[token.chainName] = normalizedBalance;
|
|
740803
|
+
if (!isIdentityScale(token)) {
|
|
740804
|
+
logger.debug({
|
|
740805
|
+
context: getRawBalances.name,
|
|
740806
|
+
chain: token.chainName,
|
|
740807
|
+
tokenSymbol: token.symbol,
|
|
740808
|
+
bridgedSupply: bridgedSupply.toString(),
|
|
740809
|
+
normalizedBalance: normalizedBalance.toString(),
|
|
740810
|
+
scale: getTokenScale(token),
|
|
740811
|
+
}, 'Normalized bridged supply to canonical units');
|
|
740812
|
+
}
|
|
740631
740813
|
}
|
|
740632
740814
|
return balances;
|
|
740633
740815
|
}
|
|
@@ -740651,7 +740833,7 @@ __webpack_async_result__();
|
|
|
740651
740833
|
* Get the confirmed block tag for a chain, accounting for reorg period.
|
|
740652
740834
|
* Returns a block number that is safe from reorgs, or a named tag like 'finalized'.
|
|
740653
740835
|
*
|
|
740654
|
-
* @param multiProvider -
|
|
740836
|
+
* @param multiProvider - Provider registry with chain metadata and ethers access
|
|
740655
740837
|
* @param chainName - Name of the chain
|
|
740656
740838
|
* @param logger - Optional logger for warnings
|
|
740657
740839
|
* @returns Confirmed block tag (number, named tag, or undefined on error)
|
|
@@ -746629,7 +746811,7 @@ const SEALEVEL_PRIORITY_FEES = {
|
|
|
746629
746811
|
/* harmony export */ g: () => (/* binding */ multiProtocolTestChainMetadata),
|
|
746630
746812
|
/* harmony export */ hR: () => (/* binding */ testChainMetadata)
|
|
746631
746813
|
/* harmony export */ });
|
|
746632
|
-
/* unused harmony exports TestChainName, test1, test2, test3, test4, testXERC20, testVSXERC20, testXERC20Lockbox, testScale1, testScale2, testCollateralFiat, testCosmosChain, testSealevelChain, testStarknetChain,
|
|
746814
|
+
/* unused harmony exports TestChainName, test1, test2, test3, test4, testXERC20, testVSXERC20, testXERC20Lockbox, testScale1, testScale2, testCollateralFiat, testCosmosChain, testSealevelChain, testStarknetChain, KNOWN_ETHEREUM_TIMELOCK_CONTRACT, ethereumTestChain, multiProtocolTestChains */
|
|
746633
746815
|
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(16639);
|
|
746634
746816
|
/* harmony import */ var _metadata_chainMetadataTypes_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(1430);
|
|
746635
746817
|
|
|
@@ -746806,24 +746988,27 @@ const testStarknetChain = {
|
|
|
746806
746988
|
},
|
|
746807
746989
|
],
|
|
746808
746990
|
};
|
|
746809
|
-
// Address of
|
|
746810
|
-
|
|
746811
|
-
//
|
|
746812
|
-
|
|
746991
|
+
// Address of the ENS DAO TimelockController contract on Ethereum mainnet,
|
|
746992
|
+
// used for integration tests that exercise the block explorer path.
|
|
746993
|
+
// Chosen because Base's Blockscout `getcontractcreation` endpoint has been
|
|
746994
|
+
// observed to hang in CI, while eth.blockscout.com is reliable.
|
|
746995
|
+
const KNOWN_ETHEREUM_TIMELOCK_CONTRACT = '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7';
|
|
746996
|
+
// Ethereum mainnet metadata for testing with a live block explorer
|
|
746997
|
+
const ethereumTestChain = {
|
|
746813
746998
|
blockExplorers: [
|
|
746814
746999
|
{
|
|
746815
|
-
apiUrl: 'https://
|
|
747000
|
+
apiUrl: 'https://eth.blockscout.com/api',
|
|
746816
747001
|
family: _metadata_chainMetadataTypes_js__WEBPACK_IMPORTED_MODULE_0__/* .ExplorerFamily */ .id.Blockscout,
|
|
746817
|
-
name: '
|
|
746818
|
-
url: 'https://
|
|
747002
|
+
name: 'Ethereum Explorer',
|
|
747003
|
+
url: 'https://eth.blockscout.com',
|
|
746819
747004
|
},
|
|
746820
747005
|
],
|
|
746821
|
-
blocks: { confirmations: 3, estimateBlockTime:
|
|
746822
|
-
chainId:
|
|
746823
|
-
displayName: '
|
|
746824
|
-
domainId:
|
|
747006
|
+
blocks: { confirmations: 3, estimateBlockTime: 12, reorgPeriod: 14 },
|
|
747007
|
+
chainId: 1,
|
|
747008
|
+
displayName: 'Ethereum',
|
|
747009
|
+
domainId: 1,
|
|
746825
747010
|
gasCurrencyCoinGeckoId: 'ethereum',
|
|
746826
|
-
name: '
|
|
747011
|
+
name: 'ethereum',
|
|
746827
747012
|
nativeToken: {
|
|
746828
747013
|
decimals: 18,
|
|
746829
747014
|
name: 'Ether',
|
|
@@ -746831,15 +747016,12 @@ const baseTestChain = {
|
|
|
746831
747016
|
},
|
|
746832
747017
|
protocol: _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_1__/* .ProtocolType */ .Hb.Ethereum,
|
|
746833
747018
|
rpcUrls: [
|
|
746834
|
-
{ http: 'https://
|
|
746835
|
-
{ http: 'https://
|
|
746836
|
-
{ http: 'https://
|
|
746837
|
-
{ http: 'https://
|
|
746838
|
-
{ http: 'https://
|
|
746839
|
-
{ http: 'https://1rpc.io/base' },
|
|
746840
|
-
{ http: 'https://base-pokt.nodies.app' },
|
|
747019
|
+
{ http: 'https://ethereum-rpc.publicnode.com' },
|
|
747020
|
+
{ http: 'https://eth.llamarpc.com' },
|
|
747021
|
+
{ http: 'https://1rpc.io/eth' },
|
|
747022
|
+
{ http: 'https://ethereum.blockpi.network/v1/rpc/public' },
|
|
747023
|
+
{ http: 'https://eth.drpc.org' },
|
|
746841
747024
|
],
|
|
746842
|
-
technicalStack: _metadata_chainMetadataTypes_js__WEBPACK_IMPORTED_MODULE_0__/* .ChainTechnicalStack */ .DU.OpStack,
|
|
746843
747025
|
};
|
|
746844
747026
|
const multiProtocolTestChainMetadata = {
|
|
746845
747027
|
...testChainMetadata,
|
|
@@ -803133,8 +803315,7 @@ class TokenMetadata {
|
|
|
803133
803315
|
return _TokenStandard_js__WEBPACK_IMPORTED_MODULE_1__/* .TOKEN_MULTI_CHAIN_STANDARDS */ .NR.includes(this.standard);
|
|
803134
803316
|
}
|
|
803135
803317
|
isCrossCollateralToken() {
|
|
803136
|
-
return
|
|
803137
|
-
this.standard === _TokenStandard_js__WEBPACK_IMPORTED_MODULE_1__/* .TokenStandard */ .ph.TronHypCrossCollateralRouter);
|
|
803318
|
+
return _TokenStandard_js__WEBPACK_IMPORTED_MODULE_1__/* .TOKEN_CROSS_COLLATERAL_STANDARDS */ .kK.has(this.standard);
|
|
803138
803319
|
}
|
|
803139
803320
|
getConnections() {
|
|
803140
803321
|
return this.connections || [];
|
|
@@ -815418,10 +815599,13 @@ async function contractHasString(provider, address, searchFor) {
|
|
|
815418
815599
|
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
|
815419
815600
|
/* harmony export */ EM: () => (/* binding */ normalizeScale),
|
|
815420
815601
|
/* harmony export */ TI: () => (/* binding */ messageAmountFromLocal),
|
|
815602
|
+
/* harmony export */ Vd: () => (/* binding */ localAmountFromMessage),
|
|
815421
815603
|
/* harmony export */ gm: () => (/* binding */ scalesEqual),
|
|
815422
|
-
/* harmony export */ k: () => (/* binding */ verifyScale)
|
|
815604
|
+
/* harmony export */ k: () => (/* binding */ verifyScale),
|
|
815605
|
+
/* harmony export */ ol: () => (/* binding */ minLocalAmountForMessage),
|
|
815606
|
+
/* harmony export */ pD: () => (/* binding */ alignLocalAmountToMessage)
|
|
815423
815607
|
/* harmony export */ });
|
|
815424
|
-
/* unused harmony
|
|
815608
|
+
/* unused harmony export DEFAULT_SCALE */
|
|
815425
815609
|
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(21387);
|
|
815426
815610
|
/* harmony import */ var _hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(73938);
|
|
815427
815611
|
|
|
@@ -815447,8 +815631,8 @@ function assertValidScale(scale) {
|
|
|
815447
815631
|
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .v)(scale.numerator > 0n && scale.denominator > 0n, `Scale must be positive, got ${scale.numerator}/${scale.denominator}`);
|
|
815448
815632
|
}
|
|
815449
815633
|
function ceilDiv(numerator, denominator) {
|
|
815450
|
-
assert(denominator > 0n, 'Denominator must be positive');
|
|
815451
|
-
assert(numerator >= 0n, 'Numerator must be non-negative');
|
|
815634
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .v)(denominator > 0n, 'Denominator must be positive');
|
|
815635
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .v)(numerator >= 0n, 'Numerator must be non-negative');
|
|
815452
815636
|
if (numerator === 0n)
|
|
815453
815637
|
return 0n;
|
|
815454
815638
|
return (numerator + denominator - 1n) / denominator;
|
|
@@ -815460,19 +815644,19 @@ function messageAmountFromLocal(localAmount, scale) {
|
|
|
815460
815644
|
return (localAmount * normalized.numerator) / normalized.denominator;
|
|
815461
815645
|
}
|
|
815462
815646
|
function localAmountFromMessage(messageAmount, scale) {
|
|
815463
|
-
assert(messageAmount >= 0n, 'Message amount must be non-negative');
|
|
815647
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .v)(messageAmount >= 0n, 'Message amount must be non-negative');
|
|
815464
815648
|
const normalized = normalizeScale(scale);
|
|
815465
815649
|
assertValidScale(normalized);
|
|
815466
815650
|
return (messageAmount * normalized.denominator) / normalized.numerator;
|
|
815467
815651
|
}
|
|
815468
815652
|
function minLocalAmountForMessage(messageAmount, scale) {
|
|
815469
|
-
assert(messageAmount >= 0n, 'Message amount must be non-negative');
|
|
815653
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .v)(messageAmount >= 0n, 'Message amount must be non-negative');
|
|
815470
815654
|
const normalized = normalizeScale(scale);
|
|
815471
815655
|
assertValidScale(normalized);
|
|
815472
815656
|
return ceilDiv(messageAmount * normalized.denominator, normalized.numerator);
|
|
815473
815657
|
}
|
|
815474
815658
|
function alignLocalAmountToMessage(localAmount, scale) {
|
|
815475
|
-
assert(localAmount >= 0n, 'Local amount must be non-negative');
|
|
815659
|
+
(0,_hyperlane_xyz_utils__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .v)(localAmount >= 0n, 'Local amount must be non-negative');
|
|
815476
815660
|
const messageAmount = messageAmountFromLocal(localAmount, scale);
|
|
815477
815661
|
if (messageAmount === 0n) {
|
|
815478
815662
|
return {
|
|
@@ -905476,7 +905660,7 @@ module.exports = /*#__PURE__*/JSON.parse('[{"type":"function","name":"proveL2Lea
|
|
|
905476
905660
|
/***/ 99468:
|
|
905477
905661
|
/***/ ((module) => {
|
|
905478
905662
|
|
|
905479
|
-
module.exports = {"rE":"33.0.
|
|
905663
|
+
module.exports = {"rE":"33.0.1"};
|
|
905480
905664
|
|
|
905481
905665
|
/***/ })
|
|
905482
905666
|
|