-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathL2GraphToken.sol
94 lines (82 loc) · 3.47 KB
/
L2GraphToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.7.6;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./GraphTokenUpgradeable.sol";
import "../../arbitrum/IArbToken.sol";
/**
* @title L2 Graph Token Contract
* @dev Provides the L2 version of the GRT token, meant to be minted/burned
* through the L2GraphTokenGateway.
*/
contract L2GraphToken is GraphTokenUpgradeable, IArbToken {
using SafeMath for uint256;
// Address of the gateway (on L2) that is allowed to mint tokens
address public gateway;
// Address of the corresponding Graph Token contract on L1
address public override l1Address;
// Emitted when the bridge / gateway has minted new tokens, i.e. tokens were transferred to L2
event BridgeMinted(address indexed account, uint256 amount);
// Emitted when the bridge / gateway has burned tokens, i.e. tokens were transferred back to L1
event BridgeBurned(address indexed account, uint256 amount);
// Emitted when the address of the gateway has been updated
event GatewaySet(address gateway);
// Emitted when the address of the Graph Token contract on L1 has been updated
event L1AddressSet(address l1Address);
/**
* @dev Checks that the sender is the L2 gateway from the L1/L2 token bridge
*/
modifier onlyGateway() {
require(msg.sender == gateway, "NOT_GATEWAY");
_;
}
/**
* @dev L2 Graph Token Contract initializer.
* Note some parameters have to be set separately as they are generally
* not expected to be available at initialization time:
* - gateway using setGateway
* - l1Address using setL1Address
* @param _owner Governance address that owns this contract
*/
function initialize(address _owner) external onlyImpl {
require(_owner != address(0), "Owner must be set");
// Initial supply hard coded to 0 as tokens are only supposed
// to be minted through the bridge.
GraphTokenUpgradeable._initialize(_owner, 0);
}
/**
* @dev Sets the address of the L2 gateway allowed to mint tokens
* @param _gw Address for the L2GraphTokenGateway that will be allowed to mint tokens
*/
function setGateway(address _gw) external onlyGovernor {
require(_gw != address(0), "INVALID_GATEWAY");
gateway = _gw;
emit GatewaySet(gateway);
}
/**
* @dev Sets the address of the counterpart token on L1
* @param _addr Address for the GraphToken contract on L1
*/
function setL1Address(address _addr) external onlyGovernor {
require(_addr != address(0), "INVALID_L1_ADDRESS");
l1Address = _addr;
emit L1AddressSet(_addr);
}
/**
* @dev Increases token supply, only callable by the L1/L2 bridge (when tokens are transferred to L2)
* @param _account Address to credit with the new tokens
* @param _amount Number of tokens to mint
*/
function bridgeMint(address _account, uint256 _amount) external override onlyGateway {
_mint(_account, _amount);
emit BridgeMinted(_account, _amount);
}
/**
* @dev Decreases token supply, only callable by the L1/L2 bridge (when tokens are transferred to L1).
* @param _account Address from which to extract the tokens
* @param _amount Number of tokens to burn
*/
function bridgeBurn(address _account, uint256 _amount) external override onlyGateway {
burnFrom(_account, _amount);
emit BridgeBurned(_account, _amount);
}
}