diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute-ClassicSwap.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute-ClassicSwap.snap new file mode 100644 index 00000000..210b2a35 --- /dev/null +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute-ClassicSwap.snap @@ -0,0 +1 @@ +114609 \ No newline at end of file diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap index 4d3bbd84..cbd02fe8 100644 --- a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap @@ -1 +1 @@ -257101 \ No newline at end of file +257101 diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput-ClassicSwap.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput-ClassicSwap.snap new file mode 100644 index 00000000..c463ba34 --- /dev/null +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput-ClassicSwap.snap @@ -0,0 +1 @@ +133790 \ No newline at end of file diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput.snap index bd5c8426..654ee983 100644 --- a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput.snap +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput.snap @@ -1 +1 @@ -283469 \ No newline at end of file +283469 diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute-ClassicSwap.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute-ClassicSwap.snap new file mode 100644 index 00000000..b0b2727b --- /dev/null +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute-ClassicSwap.snap @@ -0,0 +1 @@ +111978 \ No newline at end of file diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap index cc2709dd..9bb1cc97 100644 --- a/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap @@ -1 +1 @@ -313198 \ No newline at end of file +313198 diff --git a/test/foundry-tests/integration/RelayOrderReactorIntegration.t.sol b/test/foundry-tests/integration/RelayOrderReactorIntegration.t.sol index 460f83e5..f3c70de2 100644 --- a/test/foundry-tests/integration/RelayOrderReactorIntegration.t.sol +++ b/test/foundry-tests/integration/RelayOrderReactorIntegration.t.sol @@ -95,6 +95,30 @@ contract RelayOrderReactorIntegrationTest is GasSnapshot, Test, Interop, PermitS assertEq(allowance, 0, "reactor must not have approval for tokens"); } + /// @dev Snapshot the gas required for an encoded call + /// - must be before the reactor execution since pool state will have changed + /// - since our generated calldata assumes that the router has custody of the tokens, we must transfer them here + function _snapshotClassicSwapCall( + ERC20 inputToken, + uint256 inputAmount, + MethodParameters memory methodParameters, + string memory testName + ) internal { + uint256 snapshot = vm.snapshot(); + + vm.startPrank(swapper); + inputToken.transfer(UNIVERSAL_ROUTER, inputAmount); + + snapStart(string.concat("RelayOrderReactorIntegrationTest-", testName, "-ClassicSwap")); + (bool success,) = UNIVERSAL_ROUTER.call{value: methodParameters.value}(methodParameters.data); + snapEnd(); + + require(success, "call failed"); + vm.stopPrank(); + + vm.revertTo(snapshot); + } + // swapper creates one order containing a universal router swap for 100 DAI -> USDC // order contains two inputs: DAI for the swap and USDC as gas payment for fillers // at the forked block, 95276229 is the minAmountOut @@ -135,7 +159,9 @@ contract RelayOrderReactorIntegrationTest is GasSnapshot, Test, Interop, PermitS ERC20 tokenIn = DAI; ERC20 tokenOut = USDC; + _checkpointBalances(swapper, filler, tokenIn, tokenOut, USDC); + _snapshotClassicSwapCall(tokenIn, 100 * ONE, methodParameters, "testExecute"); vm.prank(filler); snapStart("RelayOrderReactorIntegrationTest-testExecute"); @@ -297,6 +323,7 @@ contract RelayOrderReactorIntegrationTest is GasSnapshot, Test, Interop, PermitS ERC20 tokenOut = DAI; // in this case, gas payment will go to executor (msg.sender) _checkpointBalances(swapper2, address(permitExecutor), tokenIn, tokenOut, USDC); + _snapshotClassicSwapCall(tokenIn, 100 * USDC_ONE, methodParameters, "testPermitAndExecute"); vm.prank(filler); snapStart("RelayOrderReactorIntegrationTest-testPermitAndExecute"); @@ -367,6 +394,8 @@ contract RelayOrderReactorIntegrationTest is GasSnapshot, Test, Interop, PermitS routerOutputBalanceStart = UNIVERSAL_ROUTER.balance; fillerGasInputBalanceStart = USDC.balanceOf(filler); + _snapshotClassicSwapCall(tokenIn, 100 * ONE, methodParameters, "testExecuteWithNativeAsOutput"); + vm.prank(filler); snapStart("RelayOrderReactorIntegrationTest-testExecuteWithNativeAsOutput"); reactor.execute{value: methodParameters.value}(signedOrder);