Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make msgSender public #365

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions contracts/base/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
payerIsUser := calldataload(add(inputs.offset, 0x80))
}
bytes calldata path = inputs.toBytes(3);
address payer = payerIsUser ? _msgSender() : address(this);
address payer = payerIsUser ? msgSender() : address(this);
v3SwapExactInput(map(recipient), amountIn, amountOutMin, path, payer);
} else if (command == Commands.V3_SWAP_EXACT_OUT) {
// equivalent: abi.decode(inputs, (address, uint256, uint256, bytes, bool))
Expand All @@ -72,7 +72,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
payerIsUser := calldataload(add(inputs.offset, 0x80))
}
bytes calldata path = inputs.toBytes(3);
address payer = payerIsUser ? _msgSender() : address(this);
address payer = payerIsUser ? msgSender() : address(this);
v3SwapExactOutput(map(recipient), amountOut, amountInMax, path, payer);
} else if (command == Commands.PERMIT2_TRANSFER_FROM) {
// equivalent: abi.decode(inputs, (address, address, uint160))
Expand All @@ -84,12 +84,12 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
recipient := calldataload(add(inputs.offset, 0x20))
amount := calldataload(add(inputs.offset, 0x40))
}
permit2TransferFrom(token, _msgSender(), map(recipient), amount);
permit2TransferFrom(token, msgSender(), map(recipient), amount);
} else if (command == Commands.PERMIT2_PERMIT_BATCH) {
(IAllowanceTransfer.PermitBatch memory permitBatch,) =
abi.decode(inputs, (IAllowanceTransfer.PermitBatch, bytes));
bytes calldata data = inputs.toBytes(1);
PERMIT2.permit(_msgSender(), permitBatch, data);
PERMIT2.permit(msgSender(), permitBatch, data);
} else if (command == Commands.SWEEP) {
// equivalent: abi.decode(inputs, (address, address, uint256))
address token;
Expand Down Expand Up @@ -143,7 +143,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
payerIsUser := calldataload(add(inputs.offset, 0x80))
}
address[] calldata path = inputs.toAddressArray(3);
address payer = payerIsUser ? _msgSender() : address(this);
address payer = payerIsUser ? msgSender() : address(this);
v2SwapExactInput(map(recipient), amountIn, amountOutMin, path, payer);
} else if (command == Commands.V2_SWAP_EXACT_OUT) {
// equivalent: abi.decode(inputs, (address, uint256, uint256, bytes, bool))
Expand All @@ -159,7 +159,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
payerIsUser := calldataload(add(inputs.offset, 0x80))
}
address[] calldata path = inputs.toAddressArray(3);
address payer = payerIsUser ? _msgSender() : address(this);
address payer = payerIsUser ? msgSender() : address(this);
v2SwapExactOutput(map(recipient), amountOut, amountInMax, path, payer);
} else if (command == Commands.PERMIT2_PERMIT) {
// equivalent: abi.decode(inputs, (IAllowanceTransfer.PermitSingle, bytes))
Expand All @@ -168,7 +168,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
permitSingle := inputs.offset
}
bytes calldata data = inputs.toBytes(6); // PermitSingle takes first 6 slots (0..5)
PERMIT2.permit(_msgSender(), permitSingle, data);
PERMIT2.permit(msgSender(), permitSingle, data);
} else if (command == Commands.WRAP_ETH) {
// equivalent: abi.decode(inputs, (address, uint256))
address recipient;
Expand All @@ -190,7 +190,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
} else if (command == Commands.PERMIT2_TRANSFER_FROM_BATCH) {
(IAllowanceTransfer.AllowanceTransferDetails[] memory batchDetails) =
abi.decode(inputs, (IAllowanceTransfer.AllowanceTransferDetails[]));
permit2TransferFrom(batchDetails, _msgSender());
permit2TransferFrom(batchDetails, msgSender());
} else if (command == Commands.BALANCE_CHECK_ERC20) {
// equivalent: abi.decode(inputs, (address, address, uint256))
address owner;
Expand Down Expand Up @@ -237,7 +237,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
// This can be done in 2 ways:
// 1. This contract is permitted for the specific token and the caller is approved for ALL of the owner's tokens
// 2. This contract is permitted for ALL of the owner's tokens and the caller is permitted for the specific token
if (!isAuthorizedForToken(_msgSender(), tokenId)) {
if (!isAuthorizedForToken(msgSender(), tokenId)) {
revert NotAuthorizedForToken(tokenId);
}

Expand Down Expand Up @@ -265,7 +265,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V3ToV4Migr
/// @return output The resultant recipient for the command
function map(address recipient) internal view returns (address) {
if (recipient == Constants.MSG_SENDER) {
return _msgSender();
return msgSender();
} else if (recipient == Constants.ADDRESS_THIS) {
return address(this);
} else {
Expand Down
4 changes: 2 additions & 2 deletions contracts/base/LockAndMsgSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ contract LockAndMsgSender {
}

/// @notice Function to be used instead of msg.sender, as the contract performs self-reentrancy and at
/// times msg.sender == address(this). Instead _msgSender() returns the initiator of the lock
function _msgSender() internal view returns (address) {
/// times msg.sender == address(this). Instead msgSender() returns the initiator of the lock
function msgSender() public view returns (address) {
return Locker.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, both fail but the transaction succeeds 1`] = `
Object {
"calldataByteLength": 1764,
"gasUsed": 269421,
"gasUsed": 269465,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, neither fails 1`] = `
Object {
"calldataByteLength": 1764,
"gasUsed": 245148,
"gasUsed": 245192,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, second sub plan fails 1`] = `
Object {
"calldataByteLength": 1764,
"gasUsed": 245148,
"gasUsed": 245192,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Batch reverts gas: 2 sub-plans, the first fails 1`] = `
Object {
"calldataByteLength": 1764,
"gasUsed": 269421,
"gasUsed": 269465,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Interleaving routes gas: V2, then V3 1`] = `
Object {
"calldataByteLength": 836,
"gasUsed": 189470,
"gasUsed": 189492,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Interleaving routes gas: V3, then V2 1`] = `
Object {
"calldataByteLength": 836,
"gasUsed": 177054,
"gasUsed": 177076,
}
`;

Expand Down Expand Up @@ -73,35 +73,35 @@ Object {
exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ERC20 split V2 and V3, one hop 1`] = `
Object {
"calldataByteLength": 996,
"gasUsed": 176845,
"gasUsed": 176867,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ERC20 split V2 and V3, one hop, ADDRESS_THIS flag 1`] = `
Object {
"calldataByteLength": 996,
"gasUsed": 176620,
"gasUsed": 176642,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ETH split V2 and V3, exactOut, one hop 1`] = `
Object {
"calldataByteLength": 964,
"gasUsed": 194645,
"gasUsed": 194667,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ERC20 --> ETH split V2 and V3, one hop 1`] = `
Object {
"calldataByteLength": 964,
"gasUsed": 184716,
"gasUsed": 184738,
}
`;

exports[`Uniswap Gas Tests Mixing V2 and V3 with Universal Router. Split routes gas: ETH --> ERC20 split V2 and V3, one hop 1`] = `
Object {
"calldataByteLength": 1124,
"gasUsed": 191723,
"gasUsed": 191745,
}
`;

Expand Down Expand Up @@ -283,69 +283,69 @@ Object {
exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactIn, one trade, one hop 1`] = `
Object {
"calldataByteLength": 516,
"gasUsed": 105541,
"gasUsed": 105563,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactIn, one trade, three hops 1`] = `
Object {
"calldataByteLength": 548,
"gasUsed": 254014,
"gasUsed": 254080,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactIn, one trade, two hops 1`] = `
Object {
"calldataByteLength": 548,
"gasUsed": 177164,
"gasUsed": 177208,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactOut, one trade, one hop 1`] = `
Object {
"calldataByteLength": 516,
"gasUsed": 115071,
"gasUsed": 115093,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactOut, one trade, three hops 1`] = `
Object {
"calldataByteLength": 548,
"gasUsed": 251172,
"gasUsed": 251238,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ERC20 gas: exactOut, one trade, two hops 1`] = `
Object {
"calldataByteLength": 548,
"gasUsed": 174826,
"gasUsed": 174870,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ETH gas: exactIn swap 1`] = `
Object {
"calldataByteLength": 644,
"gasUsed": 121815,
"gasUsed": 121837,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ERC20 --> ETH gas: exactOut swap 1`] = `
Object {
"calldataByteLength": 644,
"gasUsed": 131417,
"gasUsed": 131439,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ETH --> ERC20 gas: exactIn swap 1`] = `
Object {
"calldataByteLength": 644,
"gasUsed": 215384,
"gasUsed": 215406,
}
`;

exports[`Uniswap Gas Tests Trade on UniswapV3 with Universal Router. ETH --> ERC20 gas: exactOut swap 1`] = `
Object {
"calldataByteLength": 772,
"gasUsed": 126560,
"gasUsed": 126582,
}
`;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`UniversalRouter Gas Tests gas: bytecode size 1`] = `14355`;
exports[`UniversalRouter Gas Tests gas: bytecode size 1`] = `14478`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ Object {
}
`;

exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Max Approval Swap 1`] = `1104509`;
exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Max Approval Swap 1`] = `1104729`;

exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Sign Per Swap 1`] = `1138923`;
exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps Permit2 Sign Per Swap 1`] = `1139143`;

exports[`Uniswap UX Tests gas: Comparisons Casual Swapper - 3 swaps SwapRouter02 1`] = `1124979`;

exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Max Approval Swap 1`] = `3082245`;
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Max Approval Swap 1`] = `3082905`;

exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Sign Per Swap 1`] = `3235804`;
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps Permit2 Sign Per Swap 1`] = `3236464`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried to fix this with a separate internal and external function but it still icnreased 🤷‍♀️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weirddd


exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper - 10 swaps SwapRouter02 1`] = `3195011`;

exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Max Approval Swap 1`] = `4104504`;
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Max Approval Swap 1`] = `4105384`;

exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Sign Per Swap 1`] = `4308542`;
exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions Permit2 Sign Per Swap 1`] = `4309422`;

exports[`Uniswap UX Tests gas: Comparisons Frequent Swapper across 3 swap router versions - 15 swaps across 3 versions SwapRouter02 1`] = `4282374`;

exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Max Approval Swap 1`] = `508881`;
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Max Approval Swap 1`] = `508969`;

exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Sign Per Swap 1`] = `509199`;
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap Permit2 Sign Per Swap 1`] = `509287`;

exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Complex Swap SwapRouter02 1`] = `500008`;

exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Max Approval Swap 1`] = `299727`;
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Max Approval Swap 1`] = `299771`;

exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Sign Per Swap 1`] = `299663`;
exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap Permit2 Sign Per Swap 1`] = `299707`;

exports[`Uniswap UX Tests gas: Comparisons One Time Swapper - Simple Swap SwapRouter02 1`] = `270033`;
Loading