diff --git a/src/Orders.sol b/src/Orders.sol index afea902..31862c7 100644 --- a/src/Orders.sol +++ b/src/Orders.sol @@ -24,20 +24,6 @@ abstract contract OrderDestination is IOrders, OrdersPermit2 { emit Filled(outputs); } - /// @notice Transfer the Order Outputs to their recipients. - function _transferOutputs(Output[] memory outputs) internal { - uint256 value = msg.value; - for (uint256 i; i < outputs.length; i++) { - if (outputs[i].token == address(0)) { - // this line should underflow if there's an attempt to spend more ETH than is attached to the transaction - value -= outputs[i].amount; - payable(outputs[i].recipient).transfer(outputs[i].amount); - } else { - IERC20(outputs[i].token).transferFrom(msg.sender, outputs[i].recipient, outputs[i].amount); - } - } - } - /// @notice Fill any number of Order(s), by transferring their Output(s) via permit2 signed batch transfer. /// @dev Can only provide ERC20 tokens as Outputs. /// @dev Filler may aggregate multiple Outputs with the same (`chainId`, `recipient`, `token`) into a single Output with the summed `amount`. @@ -57,6 +43,20 @@ abstract contract OrderDestination is IOrders, OrdersPermit2 { // emit emit Filled(outputs); } + + /// @notice Transfer the Order Outputs to their recipients. + function _transferOutputs(Output[] memory outputs) internal { + uint256 value = msg.value; + for (uint256 i; i < outputs.length; i++) { + if (outputs[i].token == address(0)) { + // this line should underflow if there's an attempt to spend more ETH than is attached to the transaction + value -= outputs[i].amount; + payable(outputs[i].recipient).transfer(outputs[i].amount); + } else { + IERC20(outputs[i].token).transferFrom(msg.sender, outputs[i].recipient, outputs[i].amount); + } + } + } } /// @notice Contract capable of registering initiation of intent-based Orders. @@ -98,19 +98,6 @@ abstract contract OrderOrigin is IOrders, OrdersPermit2 { emit Order(deadline, inputs, outputs); } - /// @notice Transfer the Order inputs to this contract, where they can be collected by the Order filler via `sweep`. - function _transferInputs(Input[] memory inputs) internal { - uint256 value = msg.value; - for (uint256 i; i < inputs.length; i++) { - if (inputs[i].token == address(0)) { - // this line should underflow if there's an attempt to spend more ETH than is attached to the transaction - value -= inputs[i].amount; - } else { - IERC20(inputs[i].token).transferFrom(msg.sender, address(this), inputs[i].amount); - } - } - } - /// @notice Initiate an Order, transferring Input tokens to the Filler via permit2 signed batch transfer. /// @dev Can only provide ERC20 tokens as Inputs. /// @dev the permit2 signer is the swapper providing the Input tokens in exchange for the Outputs. @@ -141,7 +128,7 @@ abstract contract OrderOrigin is IOrders, OrdersPermit2 { /// @param token - The token to transfer. /// @custom:emits Sweep /// @custom:reverts OnlyBuilder if called by non-block builder - function sweep(address recipient, address token) public { + function sweep(address recipient, address token) external { // send ETH or tokens uint256 balance; if (token == address(0)) { @@ -153,6 +140,19 @@ abstract contract OrderOrigin is IOrders, OrdersPermit2 { } emit Sweep(recipient, token, balance); } + + /// @notice Transfer the Order inputs to this contract, where they can be collected by the Order filler via `sweep`. + function _transferInputs(Input[] memory inputs) internal { + uint256 value = msg.value; + for (uint256 i; i < inputs.length; i++) { + if (inputs[i].token == address(0)) { + // this line should underflow if there's an attempt to spend more ETH than is attached to the transaction + value -= inputs[i].amount; + } else { + IERC20(inputs[i].token).transferFrom(msg.sender, address(this), inputs[i].amount); + } + } + } } contract HostOrders is OrderDestination { diff --git a/src/Passage.sol b/src/Passage.sol index fc1d1a3..a1faded 100644 --- a/src/Passage.sol +++ b/src/Passage.sol @@ -106,7 +106,7 @@ contract Passage is PassagePermit2 { /// @param rollupRecipient - The recipient of tokens on the rollup. /// @param permit2 - The Permit2 information, including token & amount. function enterTokenPermit2(uint256 rollupChainId, address rollupRecipient, PassagePermit2.Permit2 calldata permit2) - public + external { // transfer tokens to this contract via permit2 _permitWitnessTransferFrom(enterWitness(rollupChainId, rollupRecipient), permit2); @@ -114,13 +114,6 @@ contract Passage is PassagePermit2 { _enterToken(rollupChainId, rollupRecipient, permit2.permit.permitted.token, permit2.permit.permitted.amount); } - /// @notice Shared functionality for tokens entering rollup. - function _enterToken(uint256 rollupChainId, address rollupRecipient, address token, uint256 amount) internal { - if (amount == 0) return; - if (!canEnter[token]) revert DisallowedEnter(token); - emit EnterToken(rollupChainId, rollupRecipient, token, amount); - } - /// @notice Alow/Disallow a given ERC20 token to enter the rollup. function configureEnter(address token, bool _canEnter) external { if (msg.sender != tokenAdmin) revert OnlyTokenAdmin(); @@ -139,6 +132,13 @@ contract Passage is PassagePermit2 { emit Withdrawal(token, recipient, amount); } + /// @notice Shared functionality for tokens entering rollup. + function _enterToken(uint256 rollupChainId, address rollupRecipient, address token, uint256 amount) internal { + if (amount == 0) return; + if (!canEnter[token]) revert DisallowedEnter(token); + emit EnterToken(rollupChainId, rollupRecipient, token, amount); + } + /// @notice Helper to configure ERC20 enters on deploy & via admin function function _configureEnter(address token, bool _canEnter) internal { canEnter[token] = _canEnter; @@ -184,7 +184,7 @@ contract RollupPassage is PassagePermit2 { /// @param token - The rollup address of the token exiting the rollup. /// @param amount - The amount of tokens exiting the rollup. /// @custom:emits ExitToken - function exitToken(address hostRecipient, address token, uint256 amount) public { + function exitToken(address hostRecipient, address token, uint256 amount) external { // transfer tokens to this contract IERC20(token).transferFrom(msg.sender, address(this), amount); // burn and emit @@ -195,7 +195,7 @@ contract RollupPassage is PassagePermit2 { /// @param hostRecipient - The *requested* recipient of tokens on the host chain. /// @param permit2 - The Permit2 information, including token & amount. /// @custom:emits ExitToken - function exitTokenPermit2(address hostRecipient, PassagePermit2.Permit2 calldata permit2) public { + function exitTokenPermit2(address hostRecipient, PassagePermit2.Permit2 calldata permit2) external { // transfer tokens to this contract _permitWitnessTransferFrom(exitWitness(hostRecipient), permit2); // burn and emit diff --git a/src/Transact.sol b/src/Transact.sol index 3c738a3..0faedd3 100644 --- a/src/Transact.sol +++ b/src/Transact.sol @@ -78,7 +78,7 @@ contract Transactor { uint256 value, uint256 gas, uint256 maxFeePerGas - ) public payable { + ) external payable { enterTransact(rollupChainId, msg.sender, to, data, value, gas, maxFeePerGas); }