@@ -4,79 +4,79 @@ pragma solidity ^0.8.24;
4
4
// import IERC20 from OpenZeppelin
5
5
import {IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol " ;
6
6
7
- // @notice A contract deployed to Host chain that allows tokens to enter the rollup,
8
- // and enables Builders to fulfill requests to exchange tokens on the Rollup for tokens on the Host.
7
+ /// @notice A contract deployed to Host chain that allows tokens to enter the rollup,
8
+ /// and enables Builders to fulfill requests to exchange tokens on the Rollup for tokens on the Host.
9
9
contract HostPassage {
10
- // @notice Thrown when attempting to fulfill an exit order with a deadline that has passed.
11
- error Expired ();
10
+ /// @notice Thrown when attempting to fulfill an exit order with a deadline that has passed.
11
+ error OrderExpired ();
12
12
13
- // @notice Emitted when tokens enter the rollup.
14
- // @param token - The address of the token entering the rollup.
15
- // @param rollupRecipient - The recipient of the token on the rollup.
16
- // @param amount - The amount of the token entering the rollup.
13
+ /// @notice Emitted when tokens enter the rollup.
14
+ /// @param token - The address of the token entering the rollup.
15
+ /// @param rollupRecipient - The recipient of the token on the rollup.
16
+ /// @param amount - The amount of the token entering the rollup.
17
17
event Enter (address indexed token , address indexed rollupRecipient , uint256 amount );
18
18
19
- // @notice Emitted when an exit order is fulfilled by the Builder.
20
- // @param token - The address of the token transferred to the recipient.
21
- // @param hostRecipient - The recipient of the token on host.
22
- // @param amount - The amount of the token transferred to the recipient.
19
+ /// @notice Emitted when an exit order is fulfilled by the Builder.
20
+ /// @param token - The address of the token transferred to the recipient.
21
+ /// @param hostRecipient - The recipient of the token on host.
22
+ /// @param amount - The amount of the token transferred to the recipient.
23
23
event ExitFilled (address indexed token , address indexed hostRecipient , uint256 amount );
24
24
25
- // @notice Details of an exit order to be fulfilled by the Builder.
26
- // @param token - The address of the token to be transferred to the recipient.
27
- // If token is the zero address, the amount is native Ether.
28
- // Corresponds to tokenOut_H in the RollupPassage contract.
29
- // @param recipient - The recipient of the token on host.
30
- // Corresponds to recipient_H in the RollupPassage contract.
31
- // @param amount - The amount of the token to be transferred to the recipient.
32
- // Corresponds to one or more amountOutMinimum_H in the RollupPassage contract.
33
- // @param deadline - The deadline by which the exit order must be fulfilled.
34
- // Corresponds to deadline in the RollupPassage contract.
35
- // If the ExitOrder is a combination of multiple orders, the deadline SHOULD be the latest of all orders.
25
+ /// @notice Details of an exit order to be fulfilled by the Builder.
26
+ /// @param token - The address of the token to be transferred to the recipient.
27
+ /// If token is the zero address, the amount is native Ether.
28
+ /// Corresponds to tokenOut_H in the RollupPassage contract.
29
+ /// @param recipient - The recipient of the token on host.
30
+ /// Corresponds to recipient_H in the RollupPassage contract.
31
+ /// @param amount - The amount of the token to be transferred to the recipient.
32
+ /// Corresponds to one or more amountOutMinimum_H in the RollupPassage contract.
33
+ /// @param deadline - The deadline by which the exit order must be fulfilled.
34
+ /// Corresponds to deadline in the RollupPassage contract.
35
+ /// If the ExitOrder is a combination of multiple orders, the deadline SHOULD be the latest of all orders.
36
36
struct ExitOrder {
37
37
address token;
38
38
address recipient;
39
39
uint256 amount;
40
40
uint256 deadline;
41
41
}
42
42
43
- // @notice Allows native Ether to enter the rollup by being sent directly to the contract.
43
+ /// @notice Allows native Ether to enter the rollup by being sent directly to the contract.
44
44
fallback () external payable {
45
45
enter (msg .sender );
46
46
}
47
47
48
- // @notice Allows native Ether to enter the rollup by being sent directly to the contract.
48
+ /// @notice Allows native Ether to enter the rollup by being sent directly to the contract.
49
49
receive () external payable {
50
50
enter (msg .sender );
51
51
}
52
52
53
- // @notice Allows native Ether to enter the rollup.
54
- // @dev Permanently burns the entire msg.value by locking it in this contract.
55
- // @param rollupRecipient - The recipient of the Ether on the rollup.
56
- // @custom:emits Enter indicatig the amount of Ether to mint on the rollup & its recipient.
53
+ /// @notice Allows native Ether to enter the rollup.
54
+ /// @dev Permanently burns the entire msg.value by locking it in this contract.
55
+ /// @param rollupRecipient - The recipient of the Ether on the rollup.
56
+ /// @custom:emits Enter indicatig the amount of Ether to mint on the rollup & its recipient.
57
57
function enter (address rollupRecipient ) public payable {
58
58
emit Enter (address (0 ), rollupRecipient, msg .value );
59
59
}
60
60
61
- // @notice Fulfills exit orders by transferring tokenOut to the recipient
62
- // @param orders The exit orders to fulfill
63
- // @custom:emits ExitFilled for each exit order fulfilled.
64
- // @dev Called by the Builder atomically with a transaction calling `submitBlock`.
65
- // The user-submitted transactions initiating the ExitOrders on the rollup
66
- // must be included by the Builder in the rollup block submitted via `submitBlock`.
67
- // @dev The user transfers tokenIn on the rollup, and receives tokenOut on host.
68
- // @dev The Builder receives tokenIn on the rollup, and transfers tokenOut to the user on host.
69
- // @dev The rollup STF MUST NOT apply `submitExit` transactions to the rollup state
70
- // UNLESS a corresponding ExitFilled event is emitted on host in the same block.
71
- // @dev If the user submits multiple exit transactions for the same token in the same rollup block,
72
- // the Builder may transfer the cumulative tokenOut to the user in a single ExitFilled event.
73
- // The rollup STF will apply the user's exit transactions on the rollup up to the point that sum(tokenOut) is lte the ExitFilled amount.
74
- // TODO: add option to fulfill ExitOrders with native ETH? or is it sufficient to only allow users to exit via WETH?
61
+ /// @notice Fulfills exit orders by transferring tokenOut to the recipient
62
+ /// @param orders The exit orders to fulfill
63
+ /// @custom:emits ExitFilled for each exit order fulfilled.
64
+ /// @dev Called by the Builder atomically with a transaction calling `submitBlock`.
65
+ /// The user-submitted transactions initiating the ExitOrders on the rollup
66
+ /// must be included by the Builder in the rollup block submitted via `submitBlock`.
67
+ /// @dev The user transfers tokenIn on the rollup, and receives tokenOut on host.
68
+ /// @dev The Builder receives tokenIn on the rollup, and transfers tokenOut to the user on host.
69
+ /// @dev The rollup STF MUST NOT apply `submitExit` transactions to the rollup state
70
+ /// UNLESS a corresponding ExitFilled event is emitted on host in the same block.
71
+ /// @dev If the user submits multiple exit transactions for the same token in the same rollup block,
72
+ /// the Builder may transfer the cumulative tokenOut to the user in a single ExitFilled event.
73
+ /// The rollup STF will apply the user's exit transactions on the rollup up to the point that sum(tokenOut) is lte the ExitFilled amount.
74
+ /// TODO: add option to fulfill ExitOrders with native ETH? or is it sufficient to only allow users to exit via WETH?
75
75
function fulfillExits (ExitOrder[] calldata orders ) external {
76
76
for (uint256 i = 0 ; i < orders.length ; i++ ) {
77
77
ExitOrder memory order = orders[i];
78
78
// check that the deadline hasn't passed
79
- if (block .timestamp >= order.deadline) revert Expired ();
79
+ if (block .timestamp > order.deadline) revert OrderExpired ();
80
80
// transfer tokens to the recipient
81
81
IERC20 (order.token).transferFrom (msg .sender , order.recipient, order.amount);
82
82
// emit
@@ -85,13 +85,13 @@ contract HostPassage {
85
85
}
86
86
}
87
87
88
- // A contract deployed to the Rollup that allows users to atomically exchange tokens on the Rollup for tokens on the Host.
88
+ /// @notice A contract deployed to the Rollup that allows users to atomically exchange tokens on the Rollup for tokens on the Host.
89
89
contract RollupPassage {
90
- // @notice Thrown when an exit tranaction is submitted with a deadline that has passed.
91
- error Expired ();
90
+ /// @notice Thrown when an exit transaction is submitted with a deadline that has passed.
91
+ error OrderExpired ();
92
92
93
- // @notice Emitted when an exit order is submitted & successfully processed, indicating it was also fulfilled on host.
94
- // @dev See `submitExit` for parameter docs.
93
+ /// @notice Emitted when an exit order is submitted & successfully processed, indicating it was also fulfilled on host.
94
+ /// @dev See `submitExit` for parameter docs.
95
95
event Exit (
96
96
address indexed tokenIn_RU ,
97
97
address indexed tokenOut_H ,
@@ -101,31 +101,31 @@ contract RollupPassage {
101
101
uint256 amountOutMinimum_H
102
102
);
103
103
104
- // @notice Emitted when tokens or native Ether is swept from the contract.
105
- // @dev Intended to improve visibility for Builders to ensure Sweep isn't called unexpectedly.
106
- // Intentionally does not bother to emit which token(s) were swept, nor their amounts.
104
+ /// @notice Emitted when tokens or native Ether is swept from the contract.
105
+ /// @dev Intended to improve visibility for Builders to ensure Sweep isn't called unexpectedly.
106
+ /// Intentionally does not bother to emit which token(s) were swept, nor their amounts.
107
107
event Sweep (address indexed recipient );
108
108
109
- // @notice Expresses an intent to exit the rollup with ERC20s.
110
- // @dev Exits are modeled as a swap between two tokens.
111
- // tokenIn_RU is provided on the rollup; in exchange,
112
- // tokenOut_H is expected to be received on host.
113
- // Exits may "swap" native rollup Ether for host WETH -
114
- // two assets that represent the same underlying token and should have roughly the same value -
115
- // or they may be a more "true" swap of rollup USDC for host WETH.
116
- // Fees paid to the Builders for fulfilling the exit orders
117
- // can be included within the "exchange rate" between tokenIn and tokenOut.
118
- // @dev The Builder claims the tokenIn_RU from the contract by submitting a transaction to `sweep` the tokens within the same block.
119
- // @dev The Rollup STF MUST NOT apply `submitExit` transactions to the rollup state
120
- // UNLESS a sufficient ExitFilled event is emitted on host within the same block.
121
- // @param tokenIn_RU - The address of the token the user supplies as the input on the rollup for the trade.
122
- // @param tokenOut_H - The address of the token the user expects to receive on host.
123
- // @param recipient_H - The address of the recipient of tokenOut_H on host.
124
- // @param deadline - The deadline by which the exit order must be fulfilled.
125
- // @param amountIn_RU - The amount of tokenIn_RU the user supplies as the input on the rollup for the trade.
126
- // @param amountOutMinimum_H - The minimum amount of tokenOut_H the user expects to receive on host.
127
- // @custom:reverts Expired if the deadline has passed.
128
- // @custom:emits Exit if the exit transaction succeeds.
109
+ /// @notice Expresses an intent to exit the rollup with ERC20s.
110
+ /// @dev Exits are modeled as a swap between two tokens.
111
+ /// tokenIn_RU is provided on the rollup; in exchange,
112
+ /// tokenOut_H is expected to be received on host.
113
+ /// Exits may "swap" native rollup Ether for host WETH -
114
+ /// two assets that represent the same underlying token and should have roughly the same value -
115
+ /// or they may be a more "true" swap of rollup USDC for host WETH.
116
+ /// Fees paid to the Builders for fulfilling the exit orders
117
+ /// can be included within the "exchange rate" between tokenIn and tokenOut.
118
+ /// @dev The Builder claims the tokenIn_RU from the contract by submitting a transaction to `sweep` the tokens within the same block.
119
+ /// @dev The Rollup STF MUST NOT apply `submitExit` transactions to the rollup state
120
+ /// UNLESS a sufficient ExitFilled event is emitted on host within the same block.
121
+ /// @param tokenIn_RU - The address of the token the user supplies as the input on the rollup for the trade.
122
+ /// @param tokenOut_H - The address of the token the user expects to receive on host.
123
+ /// @param recipient_H - The address of the recipient of tokenOut_H on host.
124
+ /// @param deadline - The deadline by which the exit order must be fulfilled.
125
+ /// @param amountIn_RU - The amount of tokenIn_RU the user supplies as the input on the rollup for the trade.
126
+ /// @param amountOutMinimum_H - The minimum amount of tokenOut_H the user expects to receive on host.
127
+ /// @custom:reverts Expired if the deadline has passed.
128
+ /// @custom:emits Exit if the exit transaction succeeds.
129
129
function submitExit (
130
130
address tokenIn_RU ,
131
131
address tokenOut_H ,
@@ -135,7 +135,7 @@ contract RollupPassage {
135
135
uint256 amountOutMinimum_H
136
136
) external {
137
137
// check that the deadline hasn't passed
138
- if (block .timestamp >= deadline) revert Expired ();
138
+ if (block .timestamp >= deadline) revert OrderExpired ();
139
139
140
140
// transfer the tokens from the user to the contract
141
141
IERC20 (tokenIn_RU).transferFrom (msg .sender , address (this ), amountIn_RU);
@@ -144,33 +144,33 @@ contract RollupPassage {
144
144
emit Exit (tokenIn_RU, tokenOut_H, recipient_H, deadline, amountIn_RU, amountOutMinimum_H);
145
145
}
146
146
147
- // @notice Expresses an intent to exit the rollup with native Ether.
148
- // @dev See `submitExit` above for dev details on how exits work.
149
- // @dev tokenIn_RU is set to address(0), native rollup Ether.
150
- // amountIn_RU is set to msg.value.
151
- // @param tokenOut_H - The address of the token the user expects to receive on host.
152
- // @param recipient_H - The address of the recipient of tokenOut_H on host.
153
- // @param deadline - The deadline by which the exit order must be fulfilled.
154
- // @param amountOutMinimum_H - The minimum amount of tokenOut_H the user expects to receive on host.
155
- // @custom:reverts Expired if the deadline has passed.
156
- // @custom:emits Exit if the exit transaction succeeds.
147
+ /// @notice Expresses an intent to exit the rollup with native Ether.
148
+ /// @dev See `submitExit` above for dev details on how exits work.
149
+ /// @dev tokenIn_RU is set to address(0), native rollup Ether.
150
+ /// amountIn_RU is set to msg.value.
151
+ /// @param tokenOut_H - The address of the token the user expects to receive on host.
152
+ /// @param recipient_H - The address of the recipient of tokenOut_H on host.
153
+ /// @param deadline - The deadline by which the exit order must be fulfilled.
154
+ /// @param amountOutMinimum_H - The minimum amount of tokenOut_H the user expects to receive on host.
155
+ /// @custom:reverts Expired if the deadline has passed.
156
+ /// @custom:emits Exit if the exit transaction succeeds.
157
157
function submitExit (address tokenOut_H , address recipient_H , uint256 deadline , uint256 amountOutMinimum_H )
158
158
external
159
159
payable
160
160
{
161
161
// check that the deadline hasn't passed
162
- if (block .timestamp >= deadline) revert Expired ();
162
+ if (block .timestamp >= deadline) revert OrderExpired ();
163
163
164
164
// emit the exit event
165
165
emit Exit (address (0 ), tokenOut_H, recipient_H, deadline, msg .value , amountOutMinimum_H);
166
166
}
167
167
168
- // @notice Transfer the entire balance of tokens to the recipient.
169
- // @dev Called by the Builder within the same block as `submitExit` transactions to claim the amounts of `tokenIn`.
170
- // @dev Builder MUST ensure that no other account calls `sweep` before them.
171
- // @param recipient - The address to receive the tokens.
172
- // @param tokens - The addresses of the tokens to transfer.
173
- // TODO: should there be more granular control for the builder to specify a different recipient for each token?
168
+ /// @notice Transfer the entire balance of tokens to the recipient.
169
+ /// @dev Called by the Builder within the same block as `submitExit` transactions to claim the amounts of `tokenIn`.
170
+ /// @dev Builder MUST ensure that no other account calls `sweep` before them.
171
+ /// @param recipient - The address to receive the tokens.
172
+ /// @param tokens - The addresses of the tokens to transfer.
173
+ /// TODO: should there be more granular control for the builder to specify a different recipient for each token?
174
174
function sweep (address recipient , address [] calldata tokens ) public {
175
175
for (uint256 i = 0 ; i < tokens.length ; i++ ) {
176
176
IERC20 token = IERC20 (tokens[i]);
@@ -179,10 +179,10 @@ contract RollupPassage {
179
179
emit Sweep (recipient);
180
180
}
181
181
182
- // @notice Transfer the entire balance of native Ether to the recipient.
183
- // @dev Called by the Builder within the same block as `submitExit` transactions to claim the amounts of native Ether.
184
- // @dev Builder MUST ensure that no other account calls `sweepETH` before them.
185
- // @param recipient - The address to receive the native Ether.
182
+ /// @notice Transfer the entire balance of native Ether to the recipient.
183
+ /// @dev Called by the Builder within the same block as `submitExit` transactions to claim the amounts of native Ether.
184
+ /// @dev Builder MUST ensure that no other account calls `sweepETH` before them.
185
+ /// @param recipient - The address to receive the native Ether.
186
186
function sweepETH (address payable recipient ) public {
187
187
recipient.transfer (address (this ).balance);
188
188
emit Sweep (recipient);
0 commit comments