@@ -3,38 +3,9 @@ pragma solidity ^0.8.24;
3
3
4
4
import {IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol " ;
5
5
6
- contract BasePassage {
7
- /// @notice Emitted when an swap order is fulfilled by the Builder.
8
- /// @param originChainId - The chainId on which the swap order was submitted.
9
- /// @param token - The address of the token transferred to the recipient. address(0) corresponds to native Ether.
10
- /// @param recipient - The recipient of the token.
11
- /// @param amount - The amount of the token transferred to the recipient.
12
- event SwapFulfilled (
13
- uint256 indexed originChainId , address indexed token , address indexed recipient , uint256 amount
14
- );
15
-
16
- /// @notice Fulfill a rollup Swap order.
17
- /// The user calls `swap` on a rollup; the Builder calls `fulfillSwap` on the target chain.
18
- /// @custom:emits SwapFulfilled
19
- /// @param originChainId - The chainId of the rollup on which `swap` was called.
20
- /// @param token - The address of the token to be transferred to the recipient.
21
- /// address(0) corresponds to native Ether.
22
- /// @param recipient - The recipient of the token.
23
- /// @param amount - The amount of the token to be transferred to the recipient.
24
- function fulfillSwap (uint256 originChainId , address token , address recipient , uint256 amount ) external payable {
25
- if (token == address (0 )) {
26
- require (amount == msg .value );
27
- payable (recipient).transfer (msg .value );
28
- } else {
29
- IERC20 (token).transferFrom (msg .sender , recipient, amount);
30
- }
31
- emit SwapFulfilled (originChainId, token, recipient, amount);
32
- }
33
- }
34
-
35
6
/// @notice A contract deployed to Host chain that allows tokens to enter the rollup,
36
7
/// and enables Builders to fulfill requests to exchange tokens on the Rollup for tokens on the Host.
37
- contract Passage is BasePassage {
8
+ contract Passage {
38
9
/// @notice The chainId of rollup that Ether will be sent to by default when entering the rollup via fallback() or receive().
39
10
uint256 public immutable defaultRollupChainId;
40
11
@@ -71,7 +42,6 @@ contract Passage is BasePassage {
71
42
}
72
43
73
44
/// @notice Allows native Ether to enter the rollup.
74
- /// @dev Permanently burns the entire msg.value by locking it in this contract.
75
45
/// @param rollupChainId - The rollup chain to enter.
76
46
/// @param rollupRecipient - The recipient of the Ether on the rollup.
77
47
/// @custom:emits Enter indicating the amount of Ether to mint on the rollup & its recipient.
@@ -80,7 +50,6 @@ contract Passage is BasePassage {
80
50
}
81
51
82
52
/// @notice Allows ERC20s to enter the rollup.
83
- /// @dev Permanently burns the token amount by locking it in this contract.
84
53
/// @param rollupChainId - The rollup chain to enter.
85
54
/// @param rollupRecipient - The recipient of the Ether on the rollup.
86
55
/// @param token - The address of the ERC20 token on the Host.
@@ -104,83 +73,56 @@ contract Passage is BasePassage {
104
73
}
105
74
}
106
75
107
- /// @notice A contract deployed to the Rollup that allows users to atomically exchange tokens on the Rollup for tokens on the Host.
108
- contract RollupPassage is BasePassage {
109
- /// @notice Thrown when an swap transaction is submitted with a deadline that has passed.
110
- error OrderExpired ();
111
-
112
- /// @notice Emitted when an swap order is successfully processed, indicating it was also fulfilled on the target chain.
113
- /// @dev See `swap` for parameter docs.
114
- event Swap (
115
- uint256 indexed targetChainId ,
116
- address indexed tokenIn ,
117
- address indexed tokenOut ,
118
- address recipient ,
119
- uint256 deadline ,
120
- uint256 amountIn ,
121
- uint256 amountOut
122
- );
123
-
124
- /// @notice Emitted when tokens or native Ether is swept from the contract.
125
- /// @dev Intended to improve visibility for Builders to ensure Sweep isn't called unexpectedly.
126
- /// Intentionally does not bother to emit which token(s) were swept, nor their amounts.
127
- event Sweep (address indexed token , address indexed recipient , uint256 amount );
128
-
129
- /// @notice Request to swap ERC20s.
130
- /// @dev tokenIn is provided on the rollup; in exchange,
131
- /// tokenOut is expected to be received on targetChainId.
132
- /// @dev targetChainId may be the current chainId, the Host chainId, or..
133
- /// @dev Fees paid to the Builders for fulfilling the swap orders
134
- /// can be included within the "exchange rate" between tokenIn and tokenOut.
135
- /// @dev The Builder claims the tokenIn from the contract by submitting a transaction to `sweep` the tokens within the same block.
136
- /// @dev The Rollup STF MUST NOT apply `swap` transactions to the rollup state
137
- /// UNLESS a sufficient SwapFulfilled event is emitted on the target chain within the same block.
138
- /// @param targetChainId - The chain on which tokens should be output.
139
- /// @param tokenIn - The address of the token the user supplies as the input on the rollup for the trade.
140
- /// @param tokenOut - The address of the token the user expects to receive on the target chain.
141
- /// @param recipient - The address of the recipient of tokenOut on the target chain.
142
- /// @param deadline - The deadline by which the swap order must be fulfilled.
143
- /// @param amountIn - The amount of tokenIn the user supplies as the input on the rollup for the trade.
144
- /// @param amountOut - The minimum amount of tokenOut the user expects to receive on the target chain.
145
- /// @custom:reverts Expired if the deadline has passed.
146
- /// @custom:emits Swap if the swap transaction succeeds.
147
- function swap (
148
- uint256 targetChainId ,
149
- address tokenIn ,
150
- address tokenOut ,
151
- address recipient ,
152
- uint256 deadline ,
153
- uint256 amountIn ,
154
- uint256 amountOut
155
- ) external payable {
156
- // check that the deadline hasn't passed
157
- if (block .timestamp >= deadline) revert OrderExpired ();
158
-
159
- if (tokenIn == address (0 )) {
160
- require (amountIn == msg .value );
161
- } else {
162
- IERC20 (tokenIn).transferFrom (msg .sender , address (this ), amountIn);
163
- }
76
+ /// @notice A contract deployed to the Rollup that allows users to remove tokens from the Rollup TVL back to the Host.
77
+ contract RollupPassage {
78
+ address public immutable hostPassage;
79
+
80
+ /// @notice Thrown when attempting to mint ERC20s if not the host passage contract.
81
+ error OnlyHostPassage ();
82
+
83
+ /// @notice Emitted when tokens exit the rollup.
84
+ /// @param token - The address of the token exiting the rollup.
85
+ /// @param recipient - The desired recipient of the token on the host chain.
86
+ /// @param amount - The amount of the token entering the rollup.
87
+ event Exit (address indexed token , address indexed recipient , uint256 amount );
88
+
89
+ /// @notice Emitted when ERC20 tokens are minted on the rollup.
90
+ /// @param token - The address of the ERC20 token entering the rollup.
91
+ /// @param rollupRecipient - The recipient of the ERC20 token on the rollup.
92
+ /// @param amount - The amount of the ERC20 token entering the rollup.
93
+ event Enter (address indexed token , address indexed rollupRecipient , uint256 amount );
164
94
165
- // emit the swap event
166
- emit Swap (targetChainId, tokenIn, tokenOut, recipient, deadline, amountIn, amountOut) ;
95
+ constructor ( address _hostPassage ) {
96
+ hostPassage = _hostPassage ;
167
97
}
168
98
169
- /// @notice Transfer the entire balance of ERC20 tokens to the recipient.
170
- /// @dev Called by the Builder within the same block as users' `swap` transactions
171
- /// to claim the amounts of `tokenIn`.
172
- /// @dev Builder MUST ensure that no other account calls `sweep` before them.
173
- /// @param token - The token to transfer.
174
- /// @param recipient - The address to receive the tokens.
175
- function sweep (address token , address recipient ) public {
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
- }
184
- emit Sweep (token, recipient, balance);
99
+ /// @notice Allows native Ether to exit the rollup.
100
+ /// @dev Rollup node will burn the msg.value.
101
+ /// @param recipient - The desired recipient of the Ether on the host chain.
102
+ /// @custom:emits Exit indicating the amount of Ether to burn on the rollup & the recipient on the host chain.
103
+ function exit (address recipient ) public payable {
104
+ emit Exit (address (0 ), recipient, msg .value );
105
+ }
106
+
107
+ /// @notice Allows ERC20s to exit the rollup.
108
+ /// @param recipient - The desired recipient of the ERC20s on the host chain.
109
+ /// @param token - The address of the ERC20 token on the Rollup.
110
+ /// @param amount - The amount of the ERC20 token to burn on the Rollup.
111
+ /// @custom:emits Exit indicating the the desired recipient on the host chain.
112
+ function exit (address token , address recipient , uint256 amount ) external payable {
113
+ IERC20 (token).transferFrom (msg .sender , address (this ), amount);
114
+ // TODO: IERC20(token).burn(msg.sender, amount);
115
+ emit Exit (token, recipient, amount);
116
+ }
117
+
118
+ /// @notice Allows ERC20s to enter the rollup from L1.
119
+ /// @param token - The address of the L1 ERC20 token to mint a representation for.
120
+ /// @param rollupRecipient - The recipient of the ERC20 tokens on the rollup, specified by the sender on L1.
121
+ /// @param amount - The amount of the ERC20 token to mint on the Rollup, corresponding to the amount locked on L1.
122
+ /// @custom:emits Exit indicating the the desired recipient on the host chain.
123
+ function enter (address token , address rollupRecipient , uint256 amount ) external {
124
+ if (msg .sender != hostPassage) revert OnlyHostPassage ();
125
+ // TODO: IERC20(token).mint(recipient, amount);
126
+ emit Enter (token, rollupRecipient, amount);
185
127
}
186
128
}
0 commit comments