File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -389,11 +389,13 @@ contract Router is
389
389
zrc20ToTokenName[intentInfo.zrc20]
390
390
);
391
391
392
- // Validate that swap result is not greater than expected amount
393
- require (wantedAmountWithTip >= settlementInfo.amountWithTipOut, "Swap returned invalid amount " );
394
-
395
392
// Calculate slippage difference and adjust tip accordingly
396
- uint256 slippageAndFeeCost = wantedAmountWithTip - settlementInfo.amountWithTipOut;
393
+ // If swap returns more than expected (surplus), slippageAndFeeCost will be 0
394
+ // Note: Surplus amounts are currently ignored as they are too small to handle
395
+ // This will be addressed in future updates
396
+ uint256 slippageAndFeeCost = wantedAmountWithTip > settlementInfo.amountWithTipOut
397
+ ? wantedAmountWithTip - settlementInfo.amountWithTipOut
398
+ : 0 ;
397
399
398
400
// Check if tip covers the slippage and fee costs
399
401
if (wantedTip > slippageAndFeeCost) {
Original file line number Diff line number Diff line change @@ -1392,7 +1392,7 @@ contract RouterTest is Test {
1392
1392
// even better with an explicit check of the settlement payload
1393
1393
}
1394
1394
1395
- function test_OnCall_InvalidSwapAmountOut () public {
1395
+ function test_OnCall_SwapSurplusHandling () public {
1396
1396
// Setup intent contract
1397
1397
uint256 sourceChainId = 1 ;
1398
1398
uint256 targetChainId = 2 ;
@@ -1421,7 +1421,7 @@ contract RouterTest is Test {
1421
1421
// Set modest slippage (5%)
1422
1422
swapModule.setSlippage (500 );
1423
1423
1424
- // Set a custom amount out for testing that is more than the wanted amount
1424
+ // Set a custom amount out for testing that is more than the wanted amount (surplus)
1425
1425
swapModule.setCustomAmountOut (amount + tip + 1 ether);
1426
1426
1427
1427
// Mock setup for IZRC20 withdrawGasFeeWithGasLimit
@@ -1446,10 +1446,11 @@ contract RouterTest is Test {
1446
1446
senderEVM: sourceIntentContract
1447
1447
});
1448
1448
1449
- // Call onCall
1449
+ // Call onCall - should succeed even with surplus
1450
1450
vm.prank (address (gateway));
1451
- vm.expectRevert ("Swap returned invalid amount " );
1452
1451
router.onCall (context, address (inputToken), amount + tip, intentPayloadBytes);
1452
+
1453
+ // Test passes if no revert occurs - surplus is handled gracefully
1453
1454
}
1454
1455
1455
1456
function test_OnCall_UsesCustomGasLimitFromPayload () public {
You can’t perform that action at this time.
0 commit comments