Skip to content

Commit

Permalink
Merge branch 'main' into output-rebate
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongeric committed Jan 4, 2024
2 parents 31648e8 + f41a39f commit 76e0855
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
114609
Original file line number Diff line number Diff line change
@@ -1 +1 @@
257101
257101
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
133790
Original file line number Diff line number Diff line change
@@ -1 +1 @@
283469
283469
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
111978
Original file line number Diff line number Diff line change
@@ -1 +1 @@
313198
313198
29 changes: 29 additions & 0 deletions test/foundry-tests/integration/RelayOrderReactorIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 76e0855

Please sign in to comment.