-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathLidoMevTxFeeVault.sol
125 lines (105 loc) · 4 KB
/
LidoMevTxFeeVault.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
// SPDX-FileCopyrightText: 2021 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
/* See contracts/COMPILERS.md */
pragma solidity 0.8.9;
import "@openzeppelin/contracts-v4.4/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-v4.4/token/ERC721/IERC721.sol";
interface ILido {
/**
* @notice A payable function supposed to be funded only by LidoMevTxFeeVault contract
* @dev We need a separate function because funds received by default payable function
* will go through entire deposit algorithm
*/
function receiveMevTxFee() external payable;
}
/**
* @title A vault for temporary storage of MEV and transaction fees
*
* This contract has no payable functions because it's balance is supposed to be
* increased directly by ethereum protocol when transaction priority fees and extracted MEV
* rewards are earned by a validator.
* These vault replenishments happen continuously throught a day, while withdrawals
* happen much less often, only on LidoOracle beacon balance reports
*/
contract LidoMevTxFeeVault {
address public immutable LIDO;
address public immutable TREASURY;
/**
* Total amount of rewards received via transactions
* Rewards received on this contract set as coinbase (fee receipient)
* are not counted
*/
uint256 public totalRewardsReceivedViaTransactions;
/**
* Emitted when the ERC20 `token` recovered (e.g. transferred)
* to the Lido treasure address by `requestedBy` sender.
*/
event ERC20Recovered(
address indexed requestedBy,
address indexed token,
uint256 amount
);
/**
* Emitted when the ERC721-compatible `token` (NFT) recovered (e.g. transferred)
* to the Lido treasure address by `requestedBy` sender.
*/
event ERC721Recovered(
address indexed requestedBy,
address indexed token,
uint256 tokenId
);
/**
* Ctor
*
* @param _lido the Lido token (stETH) address
* @param _treasury the Lido treasury address (see ERC20/ERC721-recovery interfaces)
*/
constructor(address _lido, address _treasury) {
require(_lido != address(0), "LIDO_ZERO_ADDRESS");
LIDO = _lido;
TREASURY = _treasury;
}
/**
* @notice Allows the contract to receive ETH
* @dev MEV rewards may be sent as plain ETH transfers
*/
receive() external payable {
totalRewardsReceivedViaTransactions = totalRewardsReceivedViaTransactions + msg.value;
}
/**
* @notice Withdraw all accumulated rewards to Lido contract
* @dev Can be called only by the Lido contract
* @return amount uint256 of funds received as MEV and transaction fees in wei
*/
function withdrawRewards() external returns (uint256 amount) {
require(msg.sender == LIDO, "ONLY_LIDO_CAN_WITHDRAW");
amount = address(this).balance;
if (amount > 0) {
ILido(LIDO).receiveMevTxFee{value: amount}();
}
return amount;
}
/**
* Transfers a given `_amount` of an ERC20-token (defined by the `_token` contract address)
* currently belonging to the burner contract address to the Lido treasury address.
*
* @param _token an ERC20-compatible token
* @param _amount token amount
*/
function recoverERC20(address _token, uint256 _amount) external {
require(_amount > 0, "ZERO_RECOVERY_AMOUNT");
emit ERC20Recovered(msg.sender, _token, _amount);
require(IERC20(_token).transfer(TREASURY, _amount));
}
/**
* Transfers a given token_id of an ERC721-compatible NFT (defined by the token contract address)
* currently belonging to the burner contract address to the Lido treasury address.
*
* @param _token an ERC721-compatible token
* @param _tokenId minted token id
*/
function recoverERC721(address _token, uint256 _tokenId) external {
emit ERC721Recovered(msg.sender, _token, _tokenId);
IERC721(_token).transferFrom(address(this), TREASURY, _tokenId);
}
}