Skip to content

Commit

Permalink
function visibility & ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-carroll committed Jul 19, 2024
1 parent 46e9545 commit 965266d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
56 changes: 28 additions & 28 deletions src/Orders.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand All @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/Passage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,14 @@ 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);
// check and emit
_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();
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Transact.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 965266d

Please sign in to comment.