From af0f4c454eddbc69d4decc809f173586cc990f4f Mon Sep 17 00:00:00 2001 From: pedrobergamini <41773103+pedrobergamini@users.noreply.github.com> Date: Wed, 4 Jun 2025 19:12:07 -0300 Subject: [PATCH] chore: implement correct native ETH support --- foundry/src/executors/BebopExecutor.sol | 10 +++------- foundry/test/executors/BebopExecutor.t.sol | 20 ++++++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/foundry/src/executors/BebopExecutor.sol b/foundry/src/executors/BebopExecutor.sol index 6987beb..7939d0d 100644 --- a/foundry/src/executors/BebopExecutor.sol +++ b/foundry/src/executors/BebopExecutor.sol @@ -109,16 +109,12 @@ contract BebopExecutor is IExecutor, IExecutorErrors, RestrictTransferFrom { /// @notice The Bebop settlement contract address address public immutable bebopSettlement; - /// @notice The native ETH address representation (same as Curve) - address public immutable nativeToken; constructor( address _bebopSettlement, - address _nativeToken, address _permit2 ) RestrictTransferFrom(_permit2) { bebopSettlement = _bebopSettlement; - nativeToken = _nativeToken; } /// @notice Executes a swap through Bebop's PMM RFQ system @@ -181,12 +177,12 @@ contract BebopExecutor is IExecutor, IExecutorErrors, RestrictTransferFrom { ) = _decodeQuoteData(quoteData, signatureType, signature); // Record balances before swap to calculate amountOut - uint256 balanceBefore = tokenOut == nativeToken + uint256 balanceBefore = tokenOut == address(0) ? order.receiver.balance : IERC20(tokenOut).balanceOf(order.receiver); // Handle ETH vs ERC20 execution - if (tokenIn == nativeToken) { + if (tokenIn == address(0)) { // For ETH input, use msg.value try IBebopSettlement(bebopSettlement).swapSingle{value: amountIn}( order, sig, amountIn @@ -207,7 +203,7 @@ contract BebopExecutor is IExecutor, IExecutorErrors, RestrictTransferFrom { } // Calculate actual amount received - uint256 balanceAfter = tokenOut == nativeToken + uint256 balanceAfter = tokenOut == address(0) ? order.receiver.balance : IERC20(tokenOut).balanceOf(order.receiver); diff --git a/foundry/test/executors/BebopExecutor.t.sol b/foundry/test/executors/BebopExecutor.t.sol index 4b684da..30c0d6b 100644 --- a/foundry/test/executors/BebopExecutor.t.sol +++ b/foundry/test/executors/BebopExecutor.t.sol @@ -32,9 +32,8 @@ contract MockToken is ERC20 { contract BebopExecutorExposed is BebopExecutor { constructor( address _bebopSettlement, - address _nativeToken, address _permit2 - ) BebopExecutor(_bebopSettlement, _nativeToken, _permit2) {} + ) BebopExecutor(_bebopSettlement, _permit2) {} function decodeParams(bytes calldata data) external @@ -66,7 +65,7 @@ contract MockBebopSettlement is Test, Constants { require(filledTakerAmount <= order.taker_amount, "Exceeds order amount"); // Mock implementation handles input tokens - if (order.taker_token == ETH_ADDR_FOR_CURVE) { + if (order.taker_token == address(0)) { // For ETH input, validate msg.value require(msg.value >= filledTakerAmount, "Insufficient ETH sent"); } else { @@ -80,11 +79,9 @@ contract MockBebopSettlement is Test, Constants { filledMakerAmount = (filledTakerAmount * order.maker_amount) / order.taker_amount; - // Send output tokens to receiver, or back to sender if receiver is zero - address recipient = - order.receiver != address(0) ? order.receiver : msg.sender; + address recipient = order.receiver; - if (order.maker_token == ETH_ADDR_FOR_CURVE) { + if (order.maker_token == address(0)) { // For ETH output, send ETH directly vm.deal(recipient, recipient.balance + filledMakerAmount); } else { @@ -129,7 +126,6 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils { // Deploy Bebop executor bebopExecutor = new BebopExecutorExposed( address(mockBebopSettlement), - ETH_ADDR_FOR_CURVE, // Native token address PERMIT2_ADDRESS ); @@ -242,7 +238,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils { taker_address: address(0), // Any taker maker_address: address(mockBebopSettlement), maker_nonce: 1, - taker_token: ETH_ADDR_FOR_CURVE, // ETH input + taker_token: address(0), // ETH input maker_token: USDC_ADDR, taker_amount: amountIn, maker_amount: expectedAmountOut, @@ -256,7 +252,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils { bytes memory signature = hex"aabbccdd"; // Mock signature bytes memory params = abi.encodePacked( - ETH_ADDR_FOR_CURVE, // ETH input + address(0), // ETH input USDC_ADDR, uint8(RestrictTransferFrom.TransferType.None), // ETH comes via msg.value uint8(0), // OrderType.Single @@ -292,7 +288,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils { maker_address: address(mockBebopSettlement), maker_nonce: 1, taker_token: USDC_ADDR, - maker_token: ETH_ADDR_FOR_CURVE, // ETH output + maker_token: address(0), // ETH output taker_amount: amountIn, maker_amount: expectedAmountOut, receiver: address(bebopExecutor), // Output should go to executor @@ -306,7 +302,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils { bytes memory params = abi.encodePacked( USDC_ADDR, - ETH_ADDR_FOR_CURVE, // ETH output + address(0), // ETH output uint8(RestrictTransferFrom.TransferType.Transfer), uint8(0), // OrderType.Single uint32(quoteData.length),