-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathBridgeMinter.sol
143 lines (116 loc) · 4.65 KB
/
BridgeMinter.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// SPDX-License-Identifier: MIT
// solhint-disable-next-line
pragma solidity 0.8.9;
import "../solc-0.8.9/Manager.sol";
interface IBridgeMinterToken {
function transfer(address _to, uint256 _amount) external;
function mint(address _to, uint256 _amount) external;
function transferOwnership(address _owner) external;
function balanceOf(address _addr) external view returns (uint256);
}
contract BridgeMinter is Manager {
address public l1MigratorAddr;
address public l1LPTGatewayAddr;
event L1MigratorUpdate(address l1MigratorAddr);
event L1LPTGatewayUpdate(address l1LPTGatewayAddr);
modifier onlyL1Migrator() {
require(msg.sender == l1MigratorAddr, "NOT_L1_MIGRATOR");
_;
}
modifier onlyL1LPTGateway() {
require(msg.sender == l1LPTGatewayAddr, "NOT_L1_LPT_GATEWAY");
_;
}
constructor(
address _controller,
address _l1MigratorAddr,
address _l1LPTGatewayAddr
) Manager(_controller) {
l1MigratorAddr = _l1MigratorAddr;
l1LPTGatewayAddr = _l1LPTGatewayAddr;
}
/**
* @notice Set L1Migrator address. Only callable by Controller owner
* @param _l1MigratorAddr L1Migrator address
*/
function setL1Migrator(address _l1MigratorAddr) external onlyControllerOwner {
l1MigratorAddr = _l1MigratorAddr;
emit L1MigratorUpdate(_l1MigratorAddr);
}
/**
* @notice Set L1LPTGateway address. Only callable by Controller owner
* @param _l1LPTGatewayAddr L1LPTGateway address
*/
function setL1LPTGateway(address _l1LPTGatewayAddr) external onlyControllerOwner {
l1LPTGatewayAddr = _l1LPTGatewayAddr;
emit L1LPTGatewayUpdate(_l1LPTGatewayAddr);
}
/**
* @notice Migrate to a new Minter. Only callable by Controller owner
* @param _newMinterAddr New Minter address
*/
function migrateToNewMinter(address _newMinterAddr) external onlyControllerOwner {
require(
_newMinterAddr != address(this) && _newMinterAddr != address(0),
"BridgeMinter#migrateToNewMinter: INVALID_MINTER"
);
IBridgeMinterToken token = livepeerToken();
// Transfer ownership of token to new Minter
token.transferOwnership(_newMinterAddr);
// Transfer current Minter's LPT balance to new Minter
token.transfer(_newMinterAddr, token.balanceOf(address(this)));
// Transfer current Minter's ETH balance to new Minter
// call() should be safe from re-entrancy here because the Controller owner and _newMinterAddr are trusted
(bool ok, ) = _newMinterAddr.call{ value: address(this).balance }("");
require(ok, "BridgeMinter#migrateToNewMinter: FAIL_CALL");
}
/**
* @notice Send contract's ETH to L1Migrator. Only callable by L1Migrator
* @return Amount of ETH sent
*/
function withdrawETHToL1Migrator() external onlyL1Migrator returns (uint256) {
uint256 balance = address(this).balance;
// call() should be safe from re-entrancy here because the L1Migrator and l1MigratorAddr are trusted
(bool ok, ) = l1MigratorAddr.call{ value: balance }("");
require(ok, "BridgeMinter#withdrawETHToL1Migrator: FAIL_CALL");
return balance;
}
/**
* @notice Send contract's LPT to L1Migrator. Only callable by L1Migrator
* @return Amount of LPT sent
*/
function withdrawLPTToL1Migrator() external onlyL1Migrator returns (uint256) {
IBridgeMinterToken token = livepeerToken();
uint256 balance = token.balanceOf(address(this));
token.transfer(l1MigratorAddr, balance);
return balance;
}
/**
* @notice Mint LPT to address. Only callable by L1LPTGateway
* @dev Relies on L1LPTGateway for minting rules
* @param _to Address to receive LPT
* @param _amount Amount of LPT to mint
*/
function bridgeMint(address _to, uint256 _amount) external onlyL1LPTGateway {
livepeerToken().mint(_to, _amount);
}
/**
* @notice Deposit ETH. Required for migrateToNewMinter() from older Minter implementation
*/
function depositETH() external payable returns (bool) {
return true;
}
/**
* @notice Returns Controller address. Required for migrateToNewMinter() from older Minter implementation
* @return Controller address
*/
function getController() public view returns (address) {
return address(controller);
}
/**
* @dev Returns IBridgeMinterToken interface
*/
function livepeerToken() private view returns (IBridgeMinterToken) {
return IBridgeMinterToken(controller.getContract(keccak256("LivepeerToken")));
}
}