-
Notifications
You must be signed in to change notification settings - Fork 4
/
NOAddresses.sol
204 lines (183 loc) · 7.82 KB
/
NOAddresses.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// SPDX-FileCopyrightText: 2024 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { NodeOperator, ICSModule } from "../interfaces/ICSModule.sol";
/// Library for changing and reset node operator's manager and reward addresses
/// @dev the only use of this to be a library is to save CSModule contract size via delegatecalls
interface INOAddresses {
event NodeOperatorManagerAddressChangeProposed(
uint256 indexed nodeOperatorId,
address indexed oldProposedAddress,
address indexed newProposedAddress
);
event NodeOperatorRewardAddressChangeProposed(
uint256 indexed nodeOperatorId,
address indexed oldProposedAddress,
address indexed newProposedAddress
);
// args order as in https://github.com/OpenZeppelin/openzeppelin-contracts/blob/11dc5e3809ebe07d5405fe524385cbe4f890a08b/contracts/access/Ownable.sol#L33
event NodeOperatorManagerAddressChanged(
uint256 indexed nodeOperatorId,
address indexed oldAddress,
address indexed newAddress
);
event NodeOperatorRewardAddressChanged(
uint256 indexed nodeOperatorId,
address indexed oldAddress,
address indexed newAddress
);
error AlreadyProposed();
error SameAddress();
error SenderIsNotManagerAddress();
error SenderIsNotRewardAddress();
error SenderIsNotProposedAddress();
error MethodCallIsNotAllowed();
}
library NOAddresses {
/// @notice Propose a new manager address for the Node Operator
/// @param nodeOperatorId ID of the Node Operator
/// @param proposedAddress Proposed manager address
function proposeNodeOperatorManagerAddressChange(
mapping(uint256 => NodeOperator) storage nodeOperators,
uint256 nodeOperatorId,
address proposedAddress
) external {
NodeOperator storage no = nodeOperators[nodeOperatorId];
if (no.managerAddress == address(0))
revert ICSModule.NodeOperatorDoesNotExist();
if (no.managerAddress != msg.sender)
revert INOAddresses.SenderIsNotManagerAddress();
if (no.managerAddress == proposedAddress)
revert INOAddresses.SameAddress();
if (no.proposedManagerAddress == proposedAddress)
revert INOAddresses.AlreadyProposed();
address oldProposedAddress = no.proposedManagerAddress;
no.proposedManagerAddress = proposedAddress;
emit INOAddresses.NodeOperatorManagerAddressChangeProposed(
nodeOperatorId,
oldProposedAddress,
proposedAddress
);
}
/// @notice Confirm a new manager address for the Node Operator.
/// Should be called from the currently proposed address
/// @param nodeOperatorId ID of the Node Operator
function confirmNodeOperatorManagerAddressChange(
mapping(uint256 => NodeOperator) storage nodeOperators,
uint256 nodeOperatorId
) external {
NodeOperator storage no = nodeOperators[nodeOperatorId];
if (no.managerAddress == address(0))
revert ICSModule.NodeOperatorDoesNotExist();
if (no.proposedManagerAddress != msg.sender)
revert INOAddresses.SenderIsNotProposedAddress();
address oldAddress = no.managerAddress;
no.managerAddress = msg.sender;
delete no.proposedManagerAddress;
emit INOAddresses.NodeOperatorManagerAddressChanged(
nodeOperatorId,
oldAddress,
msg.sender
);
}
/// @notice Propose a new reward address for the Node Operator
/// @param nodeOperatorId ID of the Node Operator
/// @param proposedAddress Proposed reward address
function proposeNodeOperatorRewardAddressChange(
mapping(uint256 => NodeOperator) storage nodeOperators,
uint256 nodeOperatorId,
address proposedAddress
) external {
NodeOperator storage no = nodeOperators[nodeOperatorId];
if (no.rewardAddress == address(0))
revert ICSModule.NodeOperatorDoesNotExist();
if (no.rewardAddress != msg.sender)
revert INOAddresses.SenderIsNotRewardAddress();
if (no.rewardAddress == proposedAddress)
revert INOAddresses.SameAddress();
if (no.proposedRewardAddress == proposedAddress)
revert INOAddresses.AlreadyProposed();
address oldProposedAddress = no.proposedRewardAddress;
no.proposedRewardAddress = proposedAddress;
emit INOAddresses.NodeOperatorRewardAddressChangeProposed(
nodeOperatorId,
oldProposedAddress,
proposedAddress
);
}
/// @notice Confirm a new reward address for the Node Operator.
/// Should be called from the currently proposed address
/// @param nodeOperatorId ID of the Node Operator
function confirmNodeOperatorRewardAddressChange(
mapping(uint256 => NodeOperator) storage nodeOperators,
uint256 nodeOperatorId
) external {
NodeOperator storage no = nodeOperators[nodeOperatorId];
if (no.rewardAddress == address(0))
revert ICSModule.NodeOperatorDoesNotExist();
if (no.proposedRewardAddress != msg.sender)
revert INOAddresses.SenderIsNotProposedAddress();
address oldAddress = no.rewardAddress;
no.rewardAddress = msg.sender;
delete no.proposedRewardAddress;
emit INOAddresses.NodeOperatorRewardAddressChanged(
nodeOperatorId,
oldAddress,
msg.sender
);
}
/// @notice Reset the manager address to the reward address.
/// Should be called from the reward address
/// @param nodeOperatorId ID of the Node Operator
function resetNodeOperatorManagerAddress(
mapping(uint256 => NodeOperator) storage nodeOperators,
uint256 nodeOperatorId
) external {
NodeOperator storage no = nodeOperators[nodeOperatorId];
if (no.rewardAddress == address(0))
revert ICSModule.NodeOperatorDoesNotExist();
if (no.extendedManagerPermissions)
revert INOAddresses.MethodCallIsNotAllowed();
if (no.rewardAddress != msg.sender)
revert INOAddresses.SenderIsNotRewardAddress();
if (no.managerAddress == no.rewardAddress)
revert INOAddresses.SameAddress();
address previousManagerAddress = no.managerAddress;
no.managerAddress = no.rewardAddress;
// @dev Gas golfing
if (no.proposedManagerAddress != address(0))
delete no.proposedManagerAddress;
emit INOAddresses.NodeOperatorManagerAddressChanged(
nodeOperatorId,
previousManagerAddress,
no.rewardAddress
);
}
/// @notice Change rewardAddress if extendedManagerPermissions is enabled for the Node Operator.
/// Should be called from the current manager address
/// @param nodeOperatorId ID of the Node Operator
/// @param newAddress New reward address
function changeNodeOperatorRewardAddress(
mapping(uint256 => NodeOperator) storage nodeOperators,
uint256 nodeOperatorId,
address newAddress
) external {
NodeOperator storage no = nodeOperators[nodeOperatorId];
if (no.managerAddress == address(0))
revert ICSModule.NodeOperatorDoesNotExist();
if (!no.extendedManagerPermissions)
revert INOAddresses.MethodCallIsNotAllowed();
if (no.managerAddress != msg.sender)
revert INOAddresses.SenderIsNotManagerAddress();
address oldAddress = no.rewardAddress;
no.rewardAddress = newAddress;
// @dev Gas golfing
if (no.proposedRewardAddress != address(0))
delete no.proposedRewardAddress;
emit INOAddresses.NodeOperatorRewardAddressChanged(
nodeOperatorId,
oldAddress,
newAddress
);
}
}