Skip to content

Commit 78d07da

Browse files
committed
fix L1 gateways
1 parent e48e76a commit 78d07da

13 files changed

+483
-170
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import { IL1ERC20Gateway } from "./IL1ERC20Gateway.sol";
6+
7+
import { IScrollGateway } from "../../libraries/gateway/IScrollGateway.sol";
8+
9+
interface IL1ETHGateway {
10+
/**********
11+
* Events *
12+
**********/
13+
14+
/// @notice Emitted when ETH is withdrawn from L2 to L1 and transfer to recipient.
15+
/// @param from The address of sender in L2.
16+
/// @param to The address of recipient in L1.
17+
/// @param amount The amount of ETH withdrawn from L2 to L1.
18+
/// @param data The optional calldata passed to recipient in L1.
19+
event FinalizeWithdrawETH(address indexed from, address indexed to, uint256 amount, bytes data);
20+
21+
/// @notice Emitted when someone deposit ETH from L1 to L2.
22+
/// @param from The address of sender in L1.
23+
/// @param to The address of recipient in L2.
24+
/// @param amount The amount of ETH will be deposited from L1 to L2.
25+
/// @param data The optional calldata passed to recipient in L2.
26+
event DepositETH(address indexed from, address indexed to, uint256 amount, bytes data);
27+
28+
/****************************
29+
* Public Mutated Functions *
30+
****************************/
31+
32+
/// @notice Deposit ETH to caller's account in L2.
33+
/// @param amount The amount of ETH to be deposited.
34+
/// @param gasLimit Gas limit required to complete the deposit on L2.
35+
function depositETH(uint256 amount, uint256 gasLimit) external payable;
36+
37+
/// @notice Deposit ETH to some recipient's account in L2.
38+
/// @param to The address of recipient's account on L2.
39+
/// @param amount The amount of ETH to be deposited.
40+
/// @param gasLimit Gas limit required to complete the deposit on L2.
41+
function depositETH(
42+
address to,
43+
uint256 amount,
44+
uint256 gasLimit
45+
) external payable;
46+
47+
/// @notice Deposit ETH to some recipient's account in L2 and call the target contract.
48+
/// @param to The address of recipient's account on L2.
49+
/// @param amount The amount of ETH to be deposited.
50+
/// @param data Optional data to forward to recipient's account.
51+
/// @param gasLimit Gas limit required to complete the deposit on L2.
52+
function depositETHAndCall(
53+
address to,
54+
uint256 amount,
55+
bytes calldata data,
56+
uint256 gasLimit
57+
) external payable;
58+
59+
/// @notice Complete ETH withdraw from L2 to L1 and send fund to recipient's account in L1.
60+
/// @dev This function should only be called by L1ScrollMessenger.
61+
/// This function should also only be called by L1ETHGateway in L2.
62+
/// @param from The address of account who withdraw ETH in L2.
63+
/// @param to The address of recipient in L1 to receive ETH.
64+
/// @param amount The amount of ETH to withdraw.
65+
/// @param data Optional data to forward to recipient's account.
66+
function finalizeWithdrawETH(
67+
address from,
68+
address to,
69+
uint256 amount,
70+
bytes calldata data
71+
) external payable;
72+
}

contracts/src/L1/gateways/IL1GatewayRouter.sol

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,8 @@
22

33
pragma solidity ^0.8.0;
44

5-
import { IL1ERC20Gateway } from "./IL1ERC20Gateway.sol";
6-
75
import { IScrollGateway } from "../../libraries/gateway/IScrollGateway.sol";
6+
import { IL1ETHGateway } from "./IL1ETHGateway.sol";
7+
import { IL1ERC20Gateway } from "./IL1ERC20Gateway.sol";
88

9-
interface IL1GatewayRouter is IL1ERC20Gateway, IScrollGateway {
10-
/**************************************** Events ****************************************/
11-
12-
event FinalizeWithdrawETH(address indexed _from, address indexed _to, uint256 _amount, bytes _data);
13-
event DepositETH(address indexed _from, address indexed _to, uint256 _amount, bytes _data);
14-
15-
/**************************************** Mutated Functions ****************************************/
16-
17-
/// @notice Deposit ETH to call's account in L2.
18-
/// @param _gasLimit Gas limit required to complete the deposit on L2.
19-
function depositETH(uint256 _gasLimit) external payable;
20-
21-
/// @notice Deposit ETH to recipient's account in L2.
22-
/// @param _to The address of recipient's account on L2.
23-
/// @param _gasLimit Gas limit required to complete the deposit on L2.
24-
function depositETH(address _to, uint256 _gasLimit) external payable;
25-
26-
// @todo add depositETHAndCall;
27-
28-
/// @notice Complete ETH withdraw from L2 to L1 and send fund to recipient's account in L1.
29-
/// @dev This function should only be called by L1ScrollMessenger.
30-
/// This function should also only be called by L2GatewayRouter in L2.
31-
/// @param _from The address of account who withdraw ETH in L2.
32-
/// @param _to The address of recipient in L1 to receive ETH.
33-
/// @param _amount The amount of ETH to withdraw.
34-
/// @param _data Optional data to forward to recipient's account.
35-
function finalizeWithdrawETH(
36-
address _from,
37-
address _to,
38-
uint256 _amount,
39-
bytes calldata _data
40-
) external payable;
41-
}
9+
interface IL1GatewayRouter is IL1ETHGateway, IL1ERC20Gateway, IScrollGateway {}

contracts/src/L1/gateways/L1CustomERC20Gateway.sol

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/O
66
import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
77
import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
88

9-
import { IL1ERC20Gateway, L1ERC20Gateway } from "./L1ERC20Gateway.sol";
10-
import { IL1ScrollMessenger } from "../IL1ScrollMessenger.sol";
119
import { IL2ERC20Gateway } from "../../L2/gateways/IL2ERC20Gateway.sol";
12-
import { ScrollGatewayBase, IScrollGateway } from "../../libraries/gateway/ScrollGatewayBase.sol";
10+
import { IL1ScrollMessenger } from "../IL1ScrollMessenger.sol";
11+
import { IL1ERC20Gateway } from "./IL1ERC20Gateway.sol";
12+
13+
import { ScrollGatewayBase } from "../../libraries/gateway/ScrollGatewayBase.sol";
14+
import { L1ERC20Gateway } from "./L1ERC20Gateway.sol";
1315

1416
/// @title L1CustomERC20Gateway
1517
/// @notice The `L1CustomERC20Gateway` is used to deposit custom ERC20 compatible tokens in layer 1 and
@@ -19,21 +21,30 @@ import { ScrollGatewayBase, IScrollGateway } from "../../libraries/gateway/Scrol
1921
contract L1CustomERC20Gateway is OwnableUpgradeable, ScrollGatewayBase, L1ERC20Gateway {
2022
using SafeERC20Upgradeable for IERC20Upgradeable;
2123

22-
/**************************************** Events ****************************************/
24+
/**********
25+
* Events *
26+
**********/
2327

2428
/// @notice Emitted when token mapping for ERC20 token is updated.
2529
/// @param _l1Token The address of ERC20 token in layer 1.
2630
/// @param _l2Token The address of corresponding ERC20 token in layer 2.
2731
event UpdateTokenMapping(address _l1Token, address _l2Token);
2832

29-
/**************************************** Variables ****************************************/
33+
/*************
34+
* Variables *
35+
*************/
3036

3137
/// @notice Mapping from l1 token address to l2 token address for ERC20 token.
32-
// solhint-disable-next-line var-name-mixedcase
3338
mapping(address => address) public tokenMapping;
3439

35-
/**************************************** Constructor ****************************************/
40+
/***************
41+
* Constructor *
42+
***************/
3643

44+
/// @notice Initialize the storage of L1CustomERC20Gateway.
45+
/// @param _counterpart The address of L2CustomERC20Gateway in L2.
46+
/// @param _router The address of L1GatewayRouter.
47+
/// @param _messenger The address of L1ScrollMessenger.
3748
function initialize(
3849
address _counterpart,
3950
address _router,
@@ -45,14 +56,18 @@ contract L1CustomERC20Gateway is OwnableUpgradeable, ScrollGatewayBase, L1ERC20G
4556
ScrollGatewayBase._initialize(_counterpart, _router, _messenger);
4657
}
4758

48-
/**************************************** View Functions ****************************************/
59+
/*************************
60+
* Public View Functions *
61+
*************************/
4962

5063
/// @inheritdoc IL1ERC20Gateway
5164
function getL2ERC20Address(address _l1Token) public view override returns (address) {
5265
return tokenMapping[_l1Token];
5366
}
5467

55-
/**************************************** Mutate Functions ****************************************/
68+
/****************************
69+
* Public Mutated Functions *
70+
****************************/
5671

5772
/// @inheritdoc IL1ERC20Gateway
5873
function finalizeWithdrawERC20(
@@ -74,12 +89,9 @@ contract L1CustomERC20Gateway is OwnableUpgradeable, ScrollGatewayBase, L1ERC20G
7489
emit FinalizeWithdrawERC20(_l1Token, _l2Token, _from, _to, _amount, _data);
7590
}
7691

77-
/// @inheritdoc IScrollGateway
78-
function finalizeDropMessage() external payable {
79-
// @todo finish the logic later
80-
}
81-
82-
/**************************************** Restricted Functions ****************************************/
92+
/************************
93+
* Restricted Functions *
94+
************************/
8395

8496
/// @notice Update layer 1 to layer 2 token mapping.
8597
/// @param _l1Token The address of ERC20 token in layer 1.
@@ -92,7 +104,9 @@ contract L1CustomERC20Gateway is OwnableUpgradeable, ScrollGatewayBase, L1ERC20G
92104
emit UpdateTokenMapping(_l1Token, _l2Token);
93105
}
94106

95-
/**************************************** Internal Functions ****************************************/
107+
/**********************
108+
* Internal Functions *
109+
**********************/
96110

97111
/// @inheritdoc L1ERC20Gateway
98112
function _deposit(
@@ -135,7 +149,7 @@ contract L1CustomERC20Gateway is OwnableUpgradeable, ScrollGatewayBase, L1ERC20G
135149
);
136150

137151
// 4. Send message to L1ScrollMessenger.
138-
IL1ScrollMessenger(messenger).sendMessage{ value: msg.value }(counterpart, msg.value, _message, _gasLimit);
152+
IL1ScrollMessenger(messenger).sendMessage{ value: msg.value }(counterpart, 0, _message, _gasLimit);
139153

140154
emit DepositERC20(_token, _l2Token, _from, _to, _amount, _data);
141155
}

contracts/src/L1/gateways/L1ERC1155Gateway.sol

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/O
66
import { IERC1155Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol";
77
import { ERC1155HolderUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol";
88

9-
import { IL1ERC1155Gateway } from "./IL1ERC1155Gateway.sol";
10-
import { IL1ScrollMessenger } from "../IL1ScrollMessenger.sol";
119
import { IL2ERC1155Gateway } from "../../L2/gateways/IL2ERC1155Gateway.sol";
12-
import { ScrollGatewayBase, IScrollGateway } from "../../libraries/gateway/ScrollGatewayBase.sol";
10+
import { IL1ScrollMessenger } from "../IL1ScrollMessenger.sol";
11+
import { IL1ERC1155Gateway } from "./IL1ERC1155Gateway.sol";
12+
13+
import { ScrollGatewayBase } from "../../libraries/gateway/ScrollGatewayBase.sol";
1314

1415
/// @title L1ERC1155Gateway
1516
/// @notice The `L1ERC1155Gateway` is used to deposit ERC1155 compatible NFT in layer 1 and
@@ -20,27 +21,37 @@ import { ScrollGatewayBase, IScrollGateway } from "../../libraries/gateway/Scrol
2021
/// This will be changed if we have more specific scenarios.
2122
// @todo Current implementation doesn't support calling from `L1GatewayRouter`.
2223
contract L1ERC1155Gateway is OwnableUpgradeable, ERC1155HolderUpgradeable, ScrollGatewayBase, IL1ERC1155Gateway {
23-
/**************************************** Events ****************************************/
24+
/**********
25+
* Events *
26+
**********/
2427

2528
/// @notice Emitted when token mapping for ERC1155 token is updated.
2629
/// @param _l1Token The address of ERC1155 token in layer 1.
2730
/// @param _l1Token The address of corresponding ERC1155 token in layer 2.
2831
event UpdateTokenMapping(address _l1Token, address _l2Token);
2932

30-
/**************************************** Variables ****************************************/
33+
/*************
34+
* Variables *
35+
*************/
3136

3237
/// @notice Mapping from l1 token address to l2 token address for ERC1155 NFT.
33-
// solhint-disable-next-line var-name-mixedcase
3438
mapping(address => address) public tokenMapping;
3539

36-
/**************************************** Constructor ****************************************/
40+
/***************
41+
* Constructor *
42+
***************/
3743

44+
/// @notice Initialize the storage of L1ERC1155Gateway.
45+
/// @param _counterpart The address of L2ERC1155Gateway in L2.
46+
/// @param _messenger The address of L1ScrollMessenger.
3847
function initialize(address _counterpart, address _messenger) external initializer {
3948
OwnableUpgradeable.__Ownable_init();
4049
ScrollGatewayBase._initialize(_counterpart, address(0), _messenger);
4150
}
4251

43-
/**************************************** Mutate Funtions ****************************************/
52+
/****************************
53+
* Public Mutated Functions *
54+
****************************/
4455

4556
/// @inheritdoc IL1ERC1155Gateway
4657
function depositERC1155(
@@ -112,12 +123,9 @@ contract L1ERC1155Gateway is OwnableUpgradeable, ERC1155HolderUpgradeable, Scrol
112123
emit FinalizeBatchWithdrawERC1155(_l1Token, _l2Token, _from, _to, _tokenIds, _amounts);
113124
}
114125

115-
/// @inheritdoc IScrollGateway
116-
function finalizeDropMessage() external payable {
117-
// @todo finish the logic later
118-
}
119-
120-
/**************************************** Restricted Funtions ****************************************/
126+
/************************
127+
* Restricted Functions *
128+
************************/
121129

122130
/// @notice Update layer 2 to layer 2 token mapping.
123131
/// @param _l1Token The address of ERC1155 token in layer 1.
@@ -130,7 +138,9 @@ contract L1ERC1155Gateway is OwnableUpgradeable, ERC1155HolderUpgradeable, Scrol
130138
emit UpdateTokenMapping(_l1Token, _l2Token);
131139
}
132140

133-
/**************************************** Internal Funtions ****************************************/
141+
/**********************
142+
* Internal Functions *
143+
**********************/
134144

135145
/// @dev Internal function to deposit ERC1155 NFT to layer 2.
136146
/// @param _token The address of ERC1155 NFT in layer 1.
@@ -165,7 +175,7 @@ contract L1ERC1155Gateway is OwnableUpgradeable, ERC1155HolderUpgradeable, Scrol
165175
);
166176

167177
// 3. Send message to L1ScrollMessenger.
168-
IL1ScrollMessenger(messenger).sendMessage(counterpart, msg.value, _message, _gasLimit);
178+
IL1ScrollMessenger(messenger).sendMessage{ value: msg.value }(counterpart, 0, _message, _gasLimit);
169179

170180
emit DepositERC1155(_token, _l2Token, msg.sender, _to, _tokenId, _amount);
171181
}
@@ -208,7 +218,7 @@ contract L1ERC1155Gateway is OwnableUpgradeable, ERC1155HolderUpgradeable, Scrol
208218
);
209219

210220
// 3. Send message to L1ScrollMessenger.
211-
IL1ScrollMessenger(messenger).sendMessage{ value: msg.value }(counterpart, msg.value, _message, _gasLimit);
221+
IL1ScrollMessenger(messenger).sendMessage{ value: msg.value }(counterpart, 0, _message, _gasLimit);
212222

213223
emit BatchDepositERC1155(_token, _l2Token, msg.sender, _to, _tokenIds, _amounts);
214224
}

contracts/src/L1/gateways/L1ERC20Gateway.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { IL1ERC20Gateway } from "./IL1ERC20Gateway.sol";
77
// solhint-disable no-empty-blocks
88

99
abstract contract L1ERC20Gateway is IL1ERC20Gateway {
10+
/****************************
11+
* Public Mutated Functions *
12+
****************************/
13+
1014
/// @inheritdoc IL1ERC20Gateway
1115
function depositERC20(
1216
address _token,
@@ -37,6 +41,10 @@ abstract contract L1ERC20Gateway is IL1ERC20Gateway {
3741
_deposit(_token, _to, _amount, _data, _gasLimit);
3842
}
3943

44+
/**********************
45+
* Internal Functions *
46+
**********************/
47+
4048
/// @dev Internal function to do all the deposit operations.
4149
///
4250
/// @param _token The token to deposit.

0 commit comments

Comments
 (0)