Co-authored-by: Haichen Shen <shenhaichen@gmail.com> Co-authored-by: Thegaram <th307q@gmail.com> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com>
6.0 KiB
L1WETHGateway
L1WETHGateway
The L1WETHGateway contract is used to deposit WETH token in layer 1 and finalize withdraw WETH from layer 2.
The deposited WETH tokens are not held in the gateway. It will first be unwrapped as Ether and then the Ether will be sent to the L1ScrollMessenger contract. On finalizing withdraw, the Ether will be transfered from L1ScrollMessenger, then wrapped as WETH and finally transfer to recipient.
Methods
WETH
function WETH() external view returns (address)
The address of L1 WETH address.
Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |
counterpart
function counterpart() external view returns (address)
The address of corresponding L1/L2 Gateway contract.
Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |
depositERC20
function depositERC20(address _token, uint256 _amount, uint256 _gasLimit) external payable
Deposit some token to a caller's account on L2.
Make this function payable to send relayer fee in Ether.
Parameters
| Name | Type | Description |
|---|---|---|
| _token | address | The address of token in L1. |
| _amount | uint256 | The amount of token to transfer. |
| _gasLimit | uint256 | Gas limit required to complete the deposit on L2. |
depositERC20
function depositERC20(address _token, address _to, uint256 _amount, uint256 _gasLimit) external payable
Deposit some token to a recipient's account on L2.
Make this function payable to send relayer fee in Ether.
Parameters
| Name | Type | Description |
|---|---|---|
| _token | address | The address of token in L1. |
| _to | address | The address of recipient's account on L2. |
| _amount | uint256 | The amount of token to transfer. |
| _gasLimit | uint256 | Gas limit required to complete the deposit on L2. |
depositERC20AndCall
function depositERC20AndCall(address _token, address _to, uint256 _amount, bytes _data, uint256 _gasLimit) external payable
Deposit some token to a recipient's account on L2 and call.
Make this function payable to send relayer fee in Ether.
Parameters
| Name | Type | Description |
|---|---|---|
| _token | address | The address of token in L1. |
| _to | address | The address of recipient's account on L2. |
| _amount | uint256 | The amount of token to transfer. |
| _data | bytes | Optional data to forward to recipient's account. |
| _gasLimit | uint256 | Gas limit required to complete the deposit on L2. |
finalizeWithdrawERC20
function finalizeWithdrawERC20(address _l1Token, address _l2Token, address _from, address _to, uint256 _amount, bytes _data) external payable
Complete ERC20 withdraw from L2 to L1 and send fund to recipient's account in L1.
Make this function payable to handle WETH deposit/withdraw. The function should only be called by L1ScrollMessenger. The function should also only be called by L2ERC20Gateway in L2.
Parameters
| Name | Type | Description |
|---|---|---|
| _l1Token | address | The address of corresponding L1 token. |
| _l2Token | address | The address of corresponding L2 token. |
| _from | address | The address of account who withdraw the token in L2. |
| _to | address | The address of recipient in L1 to receive the token. |
| _amount | uint256 | The amount of the token to withdraw. |
| _data | bytes | Optional data to forward to recipient's account. |
getL2ERC20Address
function getL2ERC20Address(address) external view returns (address)
Return the corresponding l2 token address given l1 token address.
Parameters
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |
initialize
function initialize(address _counterpart, address _router, address _messenger) external nonpayable
Initialize the storage of L1WETHGateway.
Parameters
| Name | Type | Description |
|---|---|---|
| _counterpart | address | The address of L2ETHGateway in L2. |
| _router | address | The address of L1GatewayRouter. |
| _messenger | address | The address of L1ScrollMessenger. |
l2WETH
function l2WETH() external view returns (address)
The address of L2 WETH address.
Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |
messenger
function messenger() external view returns (address)
The address of corresponding L1ScrollMessenger/L2ScrollMessenger contract.
Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |
router
function router() external view returns (address)
The address of L1GatewayRouter/L2GatewayRouter contract.
Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | undefined |
Events
DepositERC20
event DepositERC20(address indexed l1Token, address indexed l2Token, address indexed from, address to, uint256 amount, bytes data)
Emitted when someone deposit ERC20 token from L1 to L2.
Parameters
| Name | Type | Description |
|---|---|---|
l1Token indexed |
address | undefined |
l2Token indexed |
address | undefined |
from indexed |
address | undefined |
| to | address | undefined |
| amount | uint256 | undefined |
| data | bytes | undefined |
FinalizeWithdrawERC20
event FinalizeWithdrawERC20(address indexed l1Token, address indexed l2Token, address indexed from, address to, uint256 amount, bytes data)
Emitted when ERC20 token is withdrawn from L2 to L1 and transfer to recipient.
Parameters
| Name | Type | Description |
|---|---|---|
l1Token indexed |
address | undefined |
l2Token indexed |
address | undefined |
from indexed |
address | undefined |
| to | address | undefined |
| amount | uint256 | undefined |
| data | bytes | undefined |