chore: include partialFillOffset as part of user_data
This commit is contained in:
@@ -100,6 +100,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(12), // partialFillOffset for swapSingle (388 = 4 + 12*32)
|
||||
originalAmountIn,
|
||||
uint8(1) // approvalNeeded: true
|
||||
);
|
||||
@@ -110,6 +111,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
address tokenOut,
|
||||
RestrictTransferFrom.TransferType transferType,
|
||||
bytes memory decodedBebopCalldata,
|
||||
uint8 decodedPartialFillOffset,
|
||||
uint256 decodedOriginalAmountIn,
|
||||
bool decodedApprovalNeeded
|
||||
) = bebopExecutor.decodeParams(params);
|
||||
@@ -126,6 +128,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
keccak256(bebopCalldata),
|
||||
"bebopCalldata mismatch"
|
||||
);
|
||||
assertEq(decodedPartialFillOffset, 12, "partialFillOffset mismatch");
|
||||
assertEq(
|
||||
decodedOriginalAmountIn,
|
||||
originalAmountIn,
|
||||
@@ -212,6 +215,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(12), // partialFillOffset for swapSingle (388 = 4 + 12*32)
|
||||
testData.order.taker_amount, // originalAmountIn (matches what encoder would produce)
|
||||
uint8(1) // approvalNeeded: true
|
||||
);
|
||||
@@ -307,6 +311,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(12), // partialFillOffset for swapSingle (388 = 4 + 12*32)
|
||||
testData.order.taker_amount, // originalAmountIn (full order amount)
|
||||
uint8(1) // approvalNeeded: true
|
||||
);
|
||||
@@ -441,6 +446,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(2), // partialFillOffset for swapAggregate (68 = 4 + 2*32)
|
||||
totalTakerAmount, // originalAmountIn
|
||||
uint8(0) // approvalNeeded: false for native ETH
|
||||
);
|
||||
@@ -580,6 +586,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(2), // partialFillOffset for swapAggregate (68 = 4 + 2*32)
|
||||
totalTakerAmount, // originalAmountIn (full order amount)
|
||||
uint8(0) // approvalNeeded: false for native ETH
|
||||
);
|
||||
@@ -628,6 +635,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(12), // partialFillOffset for swapSingle (388 = 4 + 12*32)
|
||||
originalAmountIn,
|
||||
uint8(1) // approvalNeeded: true
|
||||
);
|
||||
@@ -703,6 +711,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(12), // partialFillOffset for swapSingle (388 = 4 + 12*32)
|
||||
uint256(200000000), // originalAmountIn
|
||||
uint8(1) // approvalNeeded: true
|
||||
);
|
||||
@@ -823,6 +832,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer),
|
||||
uint32(bebopCalldata.length),
|
||||
bebopCalldata,
|
||||
uint8(2), // partialFillOffset for swapAggregate (68 = 4 + 2*32)
|
||||
ethAmount, // originalAmountIn
|
||||
uint8(0) // approvalNeeded: false for native ETH
|
||||
);
|
||||
@@ -1098,7 +1108,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
|
||||
bytes memory modifiedCalldata = bebopExecutor
|
||||
.exposed_modifyFilledTakerAmount(
|
||||
originalCalldata, givenAmount, originalAmountIn
|
||||
originalCalldata, givenAmount, originalAmountIn, 12 // partialFillOffset for swapSingle
|
||||
);
|
||||
|
||||
// Decode the modified calldata to verify the filledTakerAmount was updated
|
||||
@@ -1174,7 +1184,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
|
||||
bytes memory modifiedCalldata = bebopExecutor
|
||||
.exposed_modifyFilledTakerAmount(
|
||||
originalCalldata, givenAmount, originalAmountIn
|
||||
originalCalldata, givenAmount, originalAmountIn, 2 // partialFillOffset for swapAggregate
|
||||
);
|
||||
|
||||
// Decode the modified calldata to verify the filledTakerAmount was updated
|
||||
@@ -1233,7 +1243,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
// So we'll test that it properly sets the value we want
|
||||
bytes memory modifiedCalldata = bebopExecutor
|
||||
.exposed_modifyFilledTakerAmount(
|
||||
originalCalldata, givenAmount, originalAmountIn
|
||||
originalCalldata, givenAmount, originalAmountIn, 12 // partialFillOffset for swapSingle
|
||||
);
|
||||
|
||||
// Extract the new filledTakerAmount
|
||||
@@ -1249,7 +1259,7 @@ contract BebopExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
// Normal test - amounts match so calldata should be unchanged
|
||||
bytes memory modifiedCalldata = bebopExecutor
|
||||
.exposed_modifyFilledTakerAmount(
|
||||
originalCalldata, givenAmount, originalAmountIn
|
||||
originalCalldata, givenAmount, originalAmountIn, 12 // partialFillOffset for swapSingle
|
||||
);
|
||||
|
||||
assertEq(
|
||||
|
||||
@@ -3,9 +3,11 @@ pragma solidity ^0.8.10;
|
||||
|
||||
import "../../src/executors/BebopExecutor.sol";
|
||||
import {Test, console} from "forge-std/Test.sol";
|
||||
import "@openzeppelin/contracts/utils/Address.sol";
|
||||
|
||||
contract BebopExecutorHarness is BebopExecutor, Test {
|
||||
using SafeERC20 for IERC20;
|
||||
using Address for address;
|
||||
|
||||
constructor(address _bebopSettlement, address _permit2)
|
||||
BebopExecutor(_bebopSettlement, _permit2)
|
||||
@@ -56,6 +58,7 @@ contract BebopExecutorHarness is BebopExecutor, Test {
|
||||
address tokenOut,
|
||||
TransferType transferType,
|
||||
bytes memory bebopCalldata,
|
||||
uint8 partialFillOffset,
|
||||
uint256 originalFilledTakerAmount,
|
||||
bool approvalNeeded
|
||||
)
|
||||
@@ -63,22 +66,24 @@ contract BebopExecutorHarness is BebopExecutor, Test {
|
||||
return _decodeData(data);
|
||||
}
|
||||
|
||||
// Expose the internal getActualFilledTakerAmount function for testing
|
||||
// No longer needed since we inlined the logic
|
||||
function exposed_getActualFilledTakerAmount(
|
||||
uint256 givenAmount,
|
||||
uint256 filledTakerAmount
|
||||
) external pure returns (uint256 actualFilledTakerAmount) {
|
||||
return _getActualFilledTakerAmount(givenAmount, filledTakerAmount);
|
||||
// Inline the simple logic here for backward compatibility
|
||||
actualFilledTakerAmount = filledTakerAmount > givenAmount ? givenAmount : filledTakerAmount;
|
||||
}
|
||||
|
||||
// Expose the internal modifyFilledTakerAmount function for testing
|
||||
function exposed_modifyFilledTakerAmount(
|
||||
bytes memory bebopCalldata,
|
||||
uint256 givenAmount,
|
||||
uint256 originalFilledTakerAmount
|
||||
uint256 originalFilledTakerAmount,
|
||||
uint8 partialFillOffset
|
||||
) external pure returns (bytes memory) {
|
||||
return _modifyFilledTakerAmount(
|
||||
bebopCalldata, givenAmount, originalFilledTakerAmount
|
||||
bebopCalldata, givenAmount, originalFilledTakerAmount, partialFillOffset
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,6 +100,7 @@ contract BebopExecutorHarness is BebopExecutor, Test {
|
||||
,
|
||||
TransferType transferType,
|
||||
bytes memory bebopCalldata,
|
||||
, // partialFillOffset not needed in test harness
|
||||
uint256 originalFilledTakerAmount,
|
||||
) = _decodeData(data);
|
||||
|
||||
@@ -133,8 +139,9 @@ contract BebopExecutorHarness is BebopExecutor, Test {
|
||||
expiry = order.expiry;
|
||||
}
|
||||
|
||||
// Inline the simple logic since _getActualFilledTakerAmount was removed
|
||||
uint256 actualFilledTakerAmount =
|
||||
_getActualFilledTakerAmount(givenAmount, originalFilledTakerAmount);
|
||||
originalFilledTakerAmount > givenAmount ? givenAmount : originalFilledTakerAmount;
|
||||
|
||||
// For testing: transfer tokens from executor to taker address
|
||||
// This simulates the taker having the tokens with approval
|
||||
@@ -164,6 +171,7 @@ contract BebopExecutorHarness is BebopExecutor, Test {
|
||||
uint256 currentTimestamp = block.timestamp;
|
||||
vm.warp(expiry - 1); // Set timestamp to just before expiry
|
||||
|
||||
// Call the parent's internal _swap function
|
||||
calculatedAmount = _swap(givenAmount, data);
|
||||
|
||||
// Restore original timestamp
|
||||
|
||||
Reference in New Issue
Block a user