diff --git a/src/Router.sol b/src/Router.sol index d2786f1..7db5119 100644 --- a/src/Router.sol +++ b/src/Router.sol @@ -389,11 +389,13 @@ contract Router is zrc20ToTokenName[intentInfo.zrc20] ); - // Validate that swap result is not greater than expected amount - require(wantedAmountWithTip >= settlementInfo.amountWithTipOut, "Swap returned invalid amount"); - // Calculate slippage difference and adjust tip accordingly - uint256 slippageAndFeeCost = wantedAmountWithTip - settlementInfo.amountWithTipOut; + // If swap returns more than expected (surplus), slippageAndFeeCost will be 0 + // Note: Surplus amounts are currently ignored as they are too small to handle + // This will be addressed in future updates + uint256 slippageAndFeeCost = wantedAmountWithTip > settlementInfo.amountWithTipOut + ? wantedAmountWithTip - settlementInfo.amountWithTipOut + : 0; // Check if tip covers the slippage and fee costs if (wantedTip > slippageAndFeeCost) { diff --git a/test/Router.t.sol b/test/Router.t.sol index cff0399..f80e586 100644 --- a/test/Router.t.sol +++ b/test/Router.t.sol @@ -1392,7 +1392,7 @@ contract RouterTest is Test { // even better with an explicit check of the settlement payload } - function test_OnCall_InvalidSwapAmountOut() public { + function test_OnCall_SwapSurplusHandling() public { // Setup intent contract uint256 sourceChainId = 1; uint256 targetChainId = 2; @@ -1421,7 +1421,7 @@ contract RouterTest is Test { // Set modest slippage (5%) swapModule.setSlippage(500); - // Set a custom amount out for testing that is more than the wanted amount + // Set a custom amount out for testing that is more than the wanted amount (surplus) swapModule.setCustomAmountOut(amount + tip + 1 ether); // Mock setup for IZRC20 withdrawGasFeeWithGasLimit @@ -1446,10 +1446,11 @@ contract RouterTest is Test { senderEVM: sourceIntentContract }); - // Call onCall + // Call onCall - should succeed even with surplus vm.prank(address(gateway)); - vm.expectRevert("Swap returned invalid amount"); router.onCall(context, address(inputToken), amount + tip, intentPayloadBytes); + + // Test passes if no revert occurs - surplus is handled gracefully } function test_OnCall_UsesCustomGasLimitFromPayload() public {