@@ -70,19 +70,15 @@ contract Passage {
7070 emit Enter (rollupChainId, token, rollupRecipient, amount);
7171 }
7272
73- /// @notice Allows the admin to withdraw ETH from the contract.
74- /// @dev Only the admin can call this function.
75- function withdrawEth (address recipient , uint256 amount ) external {
76- if (msg .sender != withdrawalAdmin) revert OnlyWithdrawalAdmin ();
77- payable (recipient).transfer (amount);
78- emit Withdrawal (address (0 ), recipient, amount);
79- }
80-
81- /// @notice Allows the admin to withdraw ERC20 tokens from the contract.
73+ /// @notice Allows the admin to withdraw ETH or ERC20 tokens from the contract.
8274 /// @dev Only the admin can call this function.
8375 function withdraw (address token , address recipient , uint256 amount ) external {
8476 if (msg .sender != withdrawalAdmin) revert OnlyWithdrawalAdmin ();
85- IERC20 (token).transfer (recipient, amount);
77+ if (token == address (0 )) {
78+ payable (recipient).transfer (amount);
79+ } else {
80+ IERC20 (token).transfer (recipient, amount);
81+ }
8682 emit Withdrawal (token, recipient, amount);
8783 }
8884
@@ -97,20 +93,15 @@ contract Passage {
9793 /// Corresponds to recipient_H in the RollupPassage contract.
9894 /// @param amount - The amount of the token to be transferred to the recipient.
9995 /// Corresponds to one or more amountOutMinimum_H in the RollupPassage contract.
100- function fulfillExit (uint256 rollupChainId , address token , address recipient , uint256 amount ) external {
101- IERC20 (token).transferFrom (msg .sender , recipient, amount);
96+ function fulfillExit (uint256 rollupChainId , address token , address recipient , uint256 amount ) external payable {
97+ if (token == address (0 )) {
98+ require (amount == msg .value );
99+ payable (recipient).transfer (msg .value );
100+ } else {
101+ IERC20 (token).transferFrom (msg .sender , recipient, amount);
102+ }
102103 emit ExitFulfilled (rollupChainId, token, recipient, amount);
103104 }
104-
105- /// @notice Fulfill a rollup Exit order
106- /// The user calls `exit` on Rollup; the Builder calls `fulfillExit` on Host.
107- /// @custom:emits ExitFilled
108- /// @param recipient - The recipient of the token on host.
109- /// Corresponds to recipient_H in the RollupPassage contract.
110- function fulfillExitEth (uint256 rollupChainId , address recipient ) external payable {
111- payable (recipient).transfer (msg .value );
112- emit ExitFulfilled (rollupChainId, address (0 ), recipient, msg .value );
113- }
114105}
115106
116107/// @notice A contract deployed to the Rollup that allows users to atomically exchange tokens on the Rollup for tokens on the Host.
@@ -161,57 +152,35 @@ contract RollupPassage {
161152 uint256 deadline ,
162153 uint256 amountIn_RU ,
163154 uint256 amountOutMinimum_H
164- ) external {
155+ ) external payable {
165156 // check that the deadline hasn't passed
166157 if (block .timestamp >= deadline) revert OrderExpired ();
167158
168- IERC20 (tokenIn_RU).transferFrom (msg .sender , address (this ), amountIn_RU);
159+ if (tokenIn_RU == address (0 )) {
160+ require (amountIn_RU == msg .value );
161+ } else {
162+ IERC20 (tokenIn_RU).transferFrom (msg .sender , address (this ), amountIn_RU);
163+ }
169164
170165 // emit the exit event
171166 emit Exit (tokenIn_RU, tokenOut_H, recipient_H, deadline, amountIn_RU, amountOutMinimum_H);
172167 }
173168
174- /// @notice Request exit the rollup with native Ether.
175- /// @dev See `exit` docs above for dev details on exits.
176- /// @dev tokenIn_RU is set to address(0), native rollup Ether.
177- /// amountIn_RU is set to msg.value.
178- /// @param tokenOut_H - The address of the token the user expects to receive on host.
179- /// @param recipient_H - The address of the recipient of tokenOut_H on host.
180- /// @param deadline - The deadline by which the exit order must be fulfilled.
181- /// @param amountOutMinimum_H - The minimum amount of tokenOut_H the user expects to receive on host.
182- /// @custom:reverts Expired if the deadline has passed.
183- /// @custom:emits Exit if the exit transaction succeeds.
184- function exitEth (address tokenOut_H , address recipient_H , uint256 deadline , uint256 amountOutMinimum_H )
185- external
186- payable
187- {
188- // check that the deadline hasn't passed
189- if (block .timestamp >= deadline) revert OrderExpired ();
190-
191- // emit the exit event
192- emit Exit (address (0 ), tokenOut_H, recipient_H, deadline, msg .value , amountOutMinimum_H);
193- }
194-
195169 /// @notice Transfer the entire balance of ERC20 tokens to the recipient.
196- /// @dev Called by the Builder within the same block as users' `exit ` transactions
170+ /// @dev Called by the Builder within the same block as users' `swap ` transactions
197171 /// to claim the amounts of `tokenIn`.
198172 /// @dev Builder MUST ensure that no other account calls `sweep` before them.
199173 /// @param token - The token to transfer.
200174 /// @param recipient - The address to receive the tokens.
201175 function sweep (address token , address recipient ) public {
202- uint256 balance = IERC20 (token).balanceOf (address (this ));
203- IERC20 (token).transfer (recipient, balance);
176+ uint256 balance;
177+ if (token == address (0 )) {
178+ balance = address (this ).balance;
179+ payable (recipient).transfer (balance);
180+ } else {
181+ balance = IERC20 (token).balanceOf (address (this ));
182+ IERC20 (token).transfer (recipient, balance);
183+ }
204184 emit Sweep (token, recipient, balance);
205185 }
206-
207- /// @notice Transfer the entire balance of native Ether to the recipient.
208- /// @dev Called by the Builder within the same block as users' `exit` transactions
209- /// to claim the amounts of native Ether.
210- /// @dev Builder MUST ensure that no other account calls `sweepETH` before them.
211- /// @param recipient - The address to receive the native Ether.
212- function sweepEth (address payable recipient ) public {
213- uint256 balance = address (this ).balance;
214- recipient.transfer (balance);
215- emit Sweep (address (0 ), recipient, balance);
216- }
217186}
0 commit comments