Skip to content

Commit e0cd230

Browse files
authored
Merge pull request #575 from everclearorg/ci/prod-to-staging-merge
ci: sync staging to prod
2 parents 0730417 + 5747ac4 commit e0cd230

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/poller/src/rebalance/onDemand.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ function buildRouteEntriesForDestination(
501501
}
502502

503503
// For swap+bridge routes, swapOutputAsset is the intermediate asset on origin chain
504-
// We need to resolve the final output asset from the invoice ticker on destination chain
504+
// (the asset the bridge actually carries). We must resolve what the bridge delivers
505+
// on the destination chain and verify it matches the invoice ticker.
505506
const isSwapBridgeRoute = combinedRoute.swapOutputAsset && route.origin !== route.destination;
506507
logger?.debug('Determining output asset address', {
507508
invoiceId,
@@ -513,18 +514,23 @@ function buildRouteEntriesForDestination(
513514
combinedRouteDestinationAsset: combinedRoute.swapOutputAsset,
514515
});
515516

516-
// For swap+bridge routes, we must get the token address from the destination chain config
517-
// The fallback to route.asset would be wrong (it's on origin chain, not destination)
517+
// For swap+bridge routes, resolve the output from the bridge's actual asset, not
518+
// the invoice ticker. The bridge carries swapOutputAsset (e.g. USDC) — look up its
519+
// ticker on the origin chain, then find that ticker's address on the destination.
518520
let swapOutputAssetAddress: string | undefined;
519521
if (isSwapBridgeRoute) {
520-
swapOutputAssetAddress = getTokenAddressFromConfig(invoiceTickerLower, route.destination.toString(), config);
522+
const bridgeAssetTicker = getTickerForAsset(combinedRoute.swapOutputAsset!, route.origin, config);
523+
if (bridgeAssetTicker) {
524+
swapOutputAssetAddress = getTokenAddressFromConfig(bridgeAssetTicker, route.destination.toString(), config);
525+
}
521526
if (!swapOutputAssetAddress) {
522527
logger?.warn('Failed to resolve destination asset address for swap+bridge route', {
523528
invoiceId,
524529
invoiceTicker: invoiceTickerLower,
525530
destinationChain: route.destination,
526531
originChain: route.origin,
527532
intermediateAsset: combinedRoute.swapOutputAsset,
533+
bridgeAssetTicker: bridgeAssetTicker || 'not found',
528534
});
529535
}
530536
} else {
@@ -547,7 +553,9 @@ function buildRouteEntriesForDestination(
547553
outputTicker = getTickerForAsset(swapOutputAssetAddress, route.destination, config)?.toLowerCase();
548554
}
549555

550-
if (!outputTicker) {
556+
// Fallback: for direct bridge routes only, try resolving from the invoice ticker.
557+
// Do NOT fallback for swap+bridge routes — the bridge output must match on its own.
558+
if (!outputTicker && !isSwapBridgeRoute) {
551559
logger?.debug('Output ticker not found, trying fallback', {
552560
invoiceId,
553561
swapOutputAssetAddress,

0 commit comments

Comments
 (0)