Skip to content

Commit 0e086bf

Browse files
committed
revert: remove ScheduledUpgrade struct
1 parent e3b73b8 commit 0e086bf

File tree

7 files changed

+113
-110
lines changed

7 files changed

+113
-110
lines changed

src/XanV1.sol

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ contract XanV1 is
6363
error ImplementationNotDelayed(address expected, address actual);
6464

6565
error UpgradeNotScheduled(address impl);
66-
error UpgradeAlreadyScheduled(ScheduledUpgrade scheduledImpl);
67-
error UpgradeCancellationInvalid(ScheduledUpgrade scheduledImpl);
66+
error UpgradeAlreadyScheduled(address impl, uint48 endTime);
67+
error UpgradeCancellationInvalid(address impl, uint48 endTime);
6868
error UpgradeIsNotAllowedToBeScheduledTwice(address impl);
6969

7070
error MinLockedSupplyNotReached();
7171
error QuorumNowhereReached();
7272
error QuorumNotReached(address impl);
7373
error QuorumReached(address impl);
7474

75-
error DelayPeriodNotStarted(ScheduledUpgrade scheduledImpl);
76-
error DelayPeriodNotEnded(ScheduledUpgrade scheduledImpl);
75+
error DelayPeriodNotStarted(uint48 endTime);
76+
error DelayPeriodNotEnded(uint48 endTime);
7777

7878
error UnauthorizedCaller(address caller);
7979

@@ -184,13 +184,14 @@ contract XanV1 is
184184
}
185185

186186
/// @inheritdoc IXanV1
187+
// TODO! remove input arg
187188
function scheduleVoterBodyUpgrade(address proposedImpl) external override {
188189
Voting.Data storage votingData = _getVotingData();
189190

190191
// Check that no other upgrade has been scheduled yet.
191192
{
192-
if (votingData.scheduledUpgrade.endTime != 0 && votingData.scheduledUpgrade.impl != address(0)) {
193-
revert UpgradeAlreadyScheduled(votingData.scheduledUpgrade);
193+
if (votingData.scheduledEndTime != 0 && votingData.scheduledImpl != address(0)) {
194+
revert UpgradeAlreadyScheduled(votingData.scheduledImpl, votingData.scheduledEndTime);
194195
}
195196
}
196197

@@ -205,37 +206,36 @@ contract XanV1 is
205206
// Check if the council has proposed an upgrade and, if so, cancel.
206207
{
207208
Council.Data storage councilData = _getCouncilData();
208-
if (councilData.scheduledUpgrade.endTime != 0 && councilData.scheduledUpgrade.impl != address(0)) {
209+
if (councilData.scheduledEndTime != 0 && councilData.scheduledImpl != address(0)) {
209210
_cancelCouncilUpgrade();
210211

211212
emit CouncilUpgradeVetoed(); // TODO! Revisit event args
212213
}
213214
}
214215

215216
// Schedule the upgrade and emit the associated event.
216-
votingData.scheduledUpgrade =
217-
ScheduledUpgrade({impl: proposedImpl, endTime: Time.timestamp() + Parameters.DELAY_DURATION});
217+
votingData.scheduledImpl = proposedImpl;
218+
votingData.scheduledEndTime = Time.timestamp() + Parameters.DELAY_DURATION;
218219

219-
emit VoterBodyUpgradeScheduled(votingData.scheduledUpgrade);
220+
emit VoterBodyUpgradeScheduled(votingData.scheduledImpl, votingData.scheduledEndTime);
220221
}
221222

222223
/// @inheritdoc IXanV1
223224
function cancelVoterBodyUpgrade() external override {
224225
Voting.Data storage data = _getVotingData();
225226

226-
ScheduledUpgrade memory scheduledUpgrade = data.scheduledUpgrade;
227-
228-
_checkDelayCriterion(scheduledUpgrade);
227+
_checkDelayCriterion(data.scheduledEndTime);
229228

230229
// Check that the quorum for the new implementation is reached.
231-
if (_isQuorumReached(scheduledUpgrade.impl) && scheduledUpgrade.impl == data.ranking[0]) {
232-
revert UpgradeCancellationInvalid(scheduledUpgrade);
230+
if (_isQuorumReached(data.scheduledImpl) && data.scheduledImpl == data.ranking[0]) {
231+
revert UpgradeCancellationInvalid(data.scheduledImpl, data.scheduledEndTime);
233232
}
234233

235-
emit VoterBodyUpgradeCancelled(data.scheduledUpgrade);
234+
emit VoterBodyUpgradeCancelled(data.scheduledImpl, data.scheduledEndTime);
236235

237236
// Reset the scheduled upgrade
238-
data.scheduledUpgrade = ScheduledUpgrade({impl: address(0), endTime: 0});
237+
data.scheduledImpl = address(0);
238+
data.scheduledEndTime = 0;
239239
}
240240

241241
/// @notice @inheritdoc IXanV1
@@ -252,14 +252,14 @@ contract XanV1 is
252252

253253
Council.Data storage data = _getCouncilData();
254254

255-
if (data.scheduledUpgrade.impl == proposedImpl) {
255+
if (data.scheduledImpl == proposedImpl) {
256256
revert ImplementationAlreadyProposed(proposedImpl);
257257
}
258258

259-
data.scheduledUpgrade =
260-
ScheduledUpgrade({impl: proposedImpl, endTime: Time.timestamp() + Parameters.DELAY_DURATION});
259+
data.scheduledImpl = proposedImpl;
260+
data.scheduledEndTime = Time.timestamp() + Parameters.DELAY_DURATION;
261261

262-
emit CouncilUpgradeScheduled(data.scheduledUpgrade);
262+
emit CouncilUpgradeScheduled(data.scheduledImpl, data.scheduledEndTime);
263263
}
264264

265265
/// @notice @inheritdoc IXanV1
@@ -324,13 +324,17 @@ contract XanV1 is
324324
}
325325

326326
/// @inheritdoc IXanV1
327-
function scheduledVoterBodyUpgrade() public view override returns (ScheduledUpgrade memory scheduledUpgrade) {
328-
scheduledUpgrade = _getVotingData().scheduledUpgrade;
327+
function scheduledVoterBodyUpgrade() public view override returns (address impl, uint48 endTime) {
328+
Voting.Data storage data = _getVotingData();
329+
impl = data.scheduledImpl;
330+
endTime = data.scheduledEndTime;
329331
}
330332

331333
/// @inheritdoc IXanV1
332-
function scheduledCouncilUpgrade() public view override returns (ScheduledUpgrade memory scheduledUpgrade) {
333-
scheduledUpgrade = _getCouncilData().scheduledUpgrade;
334+
function scheduledCouncilUpgrade() public view override returns (address impl, uint48 endTime) {
335+
Council.Data storage data = _getCouncilData();
336+
impl = data.scheduledImpl;
337+
endTime = data.scheduledEndTime;
334338
}
335339

336340
/// @inheritdoc IXanV1
@@ -385,7 +389,10 @@ contract XanV1 is
385389

386390
/// @notice Cancels the scheduled upgrade by the council by resetting it to 0.
387391
function _cancelCouncilUpgrade() internal {
388-
_getCouncilData().scheduledUpgrade = ScheduledUpgrade({impl: address(0), endTime: 0});
392+
Council.Data storage data = _getCouncilData();
393+
394+
data.scheduledImpl = address(0);
395+
data.scheduledEndTime = 0;
389396
}
390397

391398
/// @notice Authorizes an upgrade.
@@ -396,13 +403,12 @@ contract XanV1 is
396403
}
397404

398405
Voting.Data storage votingData = _getVotingData();
399-
address bestRankedVoterBodyImpl = votingData.ranking[0];
406+
Council.Data storage councilData = _getCouncilData();
400407

401-
ScheduledUpgrade memory voterBodyUpgrade = votingData.scheduledUpgrade;
402-
ScheduledUpgrade memory councilUpgrade = scheduledCouncilUpgrade();
408+
address bestRankedVoterBodyImpl = votingData.ranking[0];
403409

404-
bool isScheduledByVoterBody = (newImpl == voterBodyUpgrade.impl);
405-
bool isScheduledByCouncil = (newImpl == councilUpgrade.impl);
410+
bool isScheduledByVoterBody = (newImpl == votingData.scheduledImpl);
411+
bool isScheduledByCouncil = (newImpl == councilData.scheduledImpl);
406412

407413
// NOTE: councilUpgrade.impl and voterBodyUpgrade.impl can still be address(0);
408414

@@ -412,17 +418,17 @@ contract XanV1 is
412418
}
413419

414420
if (isScheduledByVoterBody) {
415-
_checkDelayCriterion(voterBodyUpgrade);
421+
_checkDelayCriterion(votingData.scheduledEndTime);
416422
_checkVoterBodyUpgradeCriteria({
417-
impl: voterBodyUpgrade.impl,
423+
impl: votingData.scheduledImpl,
418424
bestRankedVoterBodyImpl: bestRankedVoterBodyImpl
419425
});
420426

421427
return;
422428
}
423429

424430
if (isScheduledByCouncil) {
425-
_checkDelayCriterion(councilUpgrade);
431+
_checkDelayCriterion(councilData.scheduledEndTime);
426432
_checkCouncilUpgradeCriteria({bestRankedVoterBodyImpl: bestRankedVoterBodyImpl});
427433

428434
return;
@@ -486,14 +492,14 @@ contract XanV1 is
486492
}
487493

488494
/// @notice Checks if the delay period for a scheduled upgrade has ended and reverts with errors if not.
489-
/// @param scheduledUpgrade The end time to check.
490-
function _checkDelayCriterion(ScheduledUpgrade memory scheduledUpgrade) internal view {
491-
if (scheduledUpgrade.endTime == 0) {
492-
revert DelayPeriodNotStarted(scheduledUpgrade);
495+
/// @param endTime The end time of the delay period to check.
496+
function _checkDelayCriterion(uint48 endTime) internal view {
497+
if (endTime == 0) {
498+
revert DelayPeriodNotStarted(endTime);
493499
}
494500

495-
if (Time.timestamp() < scheduledUpgrade.endTime) {
496-
revert DelayPeriodNotEnded(scheduledUpgrade);
501+
if (Time.timestamp() < endTime) {
502+
revert DelayPeriodNotEnded(endTime);
497503
}
498504
}
499505

src/interfaces/IXanV1.sol

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
pragma solidity ^0.8.30;
33

44
interface IXanV1 {
5-
/// @notice A struct representing a scheduled implementation.
6-
/// @param impl The scheduled implementation for which the delay period has been started.
7-
/// @param endTime The end time of the delay period.
8-
struct ScheduledUpgrade {
9-
address impl;
10-
uint48 endTime;
11-
}
12-
135
/// @notice Emitted when tokens are locked.
146
/// @param account The owning account.
157
/// @param value The number of tokens being locked.
@@ -28,16 +20,19 @@ interface IXanV1 {
2820
event VoteRevoked(address indexed voter, address indexed implementation, uint256 value);
2921

3022
/// @notice Emitted when the upgrade to a new implementation proposed by the voter body is scheduled.
31-
/// @param scheduledUpgrade The scheduled upgrade.
32-
event VoterBodyUpgradeScheduled(ScheduledUpgrade scheduledUpgrade);
23+
/// @param impl The implementation that has been scheduled.
24+
/// @param endTime The end time of the delay period.
25+
event VoterBodyUpgradeScheduled(address indexed impl, uint48 endTime);
3326

3427
/// @notice Emitted when the upgrade to a new implementation proposed by the voter body is cancelled.
35-
/// @param cancelledUpgrade The scheduled upgrade that was cancelled.
36-
event VoterBodyUpgradeCancelled(ScheduledUpgrade cancelledUpgrade);
28+
/// @param impl The implementation that has been cancelled.
29+
/// @param endTime The end time of the delay period.
30+
event VoterBodyUpgradeCancelled(address indexed impl, uint48 endTime);
3731

3832
/// @notice Emitted when the upgrade to a new implementation proposed by the governance council is scheduled.
39-
/// @param scheduledUpgrade The scheduled upgrade.
40-
event CouncilUpgradeScheduled(ScheduledUpgrade indexed scheduledUpgrade);
33+
/// @param impl The implementation that has been scheduled.
34+
/// @param endTime The end time of the delay period.
35+
event CouncilUpgradeScheduled(address indexed impl, uint48 endTime);
4136

4237
/// @notice Emitted when the upgrade scheduled by the governance council is cancelled.
4338
// TODO! do we need to emit data
@@ -71,7 +66,6 @@ interface IXanV1 {
7166
/// @param winningImpl The winning implementation to activate the delay period for.
7267
function scheduleVoterBodyUpgrade(address winningImpl) external;
7368

74-
// TODO! Remove input args.
7569
/// @notice Cancels the upgrade for a losing implementation.
7670
function cancelVoterBodyUpgrade() external;
7771

@@ -117,13 +111,15 @@ interface IXanV1 {
117111

118112
/// @notice Returns the upgrade scheduled by the voter body or `ScheduledUpgrade(0)`
119113
/// if no implementation has reached quorum yet.
120-
/// @return scheduledUpgrade The upgrade scheduled by the voter body.
121-
function scheduledVoterBodyUpgrade() external view returns (ScheduledUpgrade memory scheduledUpgrade);
114+
/// @return impl The implementation to upgrade to.
115+
/// @return endTime The end time of the scheduled delay.
116+
function scheduledVoterBodyUpgrade() external view returns (address impl, uint48 endTime);
122117

123118
/// @notice Returns the upgrade scheduled by the council or `ScheduledUpgrade(0)`
124119
/// if no implementation has reached quorum yet.
125-
/// @return scheduledUpgrade The upgrade scheduled by the council.
126-
function scheduledCouncilUpgrade() external view returns (ScheduledUpgrade memory scheduledUpgrade);
120+
/// @return impl The implementation to upgrade to.
121+
/// @return endTime The end time of the scheduled delay.
122+
function scheduledCouncilUpgrade() external view returns (address impl, uint48 endTime);
127123

128124
/// @notice Returns the current implementation
129125
/// @return current The current implementation.

src/libs/Council.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {IXanV1} from "../interfaces/IXanV1.sol";
66
library Council {
77
/// @notice A struct containing data associated with a current implementation and proposed upgrades from it.
88
/// @param council The address of the governance council.
9-
/// @param scheduledUpgrade An upgrade scheduled by the council.
9+
/// @param scheduledImpl The scheduled implementation.
10+
/// @param scheduledEndTime The scheduled end time of the delay period.
1011
struct Data {
1112
address council;
12-
IXanV1.ScheduledUpgrade scheduledUpgrade;
13+
address scheduledImpl;
14+
uint48 scheduledEndTime;
1315
}
1416
}

src/libs/Voting.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ library Voting {
1010
/// @param ballots The ballots of proposed implementations to upgrade to.
1111
/// @param ranking The proposed implementations ranking.
1212
/// @param implCount The count of proposed implementations.
13-
/// @param scheduledUpgrade An upgrade scheduled by the voting body.
13+
/// @param scheduledImpl The scheduled implementation.
14+
/// @param scheduledEndTime The scheduled end time of the delay period.
1415
struct Data {
1516
mapping(address proposedImpl => Ballot) ballots;
1617
mapping(uint48 rank => address proposedImpl) ranking;
1718
uint48 implCount;
18-
IXanV1.ScheduledUpgrade scheduledUpgrade;
19+
address scheduledImpl;
20+
uint48 scheduledEndTime;
1921
}
2022

2123
/// @notice The vote data of a proposed implementation.

test/XanV1.council.t.sol

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ contract XanV1CouncilTest is Test {
9090
function test_scheduleCouncilUpgrade_emits_the_CouncilUpgradeScheduled_event() public {
9191
vm.prank(_COUNCIL);
9292
vm.expectEmit(address(_xanProxy));
93-
emit IXanV1.CouncilUpgradeScheduled(
94-
IXanV1.ScheduledUpgrade({impl: _NEW_IMPL, endTime: Time.timestamp() + Parameters.DELAY_DURATION})
95-
);
93+
emit IXanV1.CouncilUpgradeScheduled({impl: _NEW_IMPL, endTime: Time.timestamp() + Parameters.DELAY_DURATION});
9694
_xanProxy.scheduleCouncilUpgrade(_NEW_IMPL);
9795
}
9896

@@ -119,8 +117,9 @@ contract XanV1CouncilTest is Test {
119117
emit IXanV1.CouncilUpgradeCancelled();
120118
_xanProxy.cancelCouncilUpgrade();
121119

122-
assertEq(_xanProxy.scheduledVoterBodyUpgrade().impl, address(0));
123-
assertEq(_xanProxy.scheduledVoterBodyUpgrade().endTime, 0);
120+
(address impl, uint48 endTime) = _xanProxy.scheduledVoterBodyUpgrade();
121+
assertEq(impl, address(0));
122+
assertEq(endTime, 0);
124123
}
125124

126125
function test_vetoCouncilUpgrade_reverts_if_no_implementation_proposed_by_the_voter_body_has_reached_quorum()
@@ -146,8 +145,9 @@ contract XanV1CouncilTest is Test {
146145

147146
_xanProxy.vetoCouncilUpgrade();
148147

149-
assertEq(_xanProxy.scheduledVoterBodyUpgrade().impl, address(0));
150-
assertEq(_xanProxy.scheduledVoterBodyUpgrade().endTime, 0);
148+
(address impl, uint48 endTime) = _xanProxy.scheduledVoterBodyUpgrade();
149+
assertEq(impl, address(0));
150+
assertEq(endTime, 0);
151151
}
152152

153153
function test_vetoCouncilUpgrade_emits_the_CouncilUpgradeVetoed_event() public {
@@ -172,12 +172,14 @@ contract XanV1CouncilTest is Test {
172172
vm.prank(_COUNCIL);
173173
_xanProxy.scheduleCouncilUpgrade(_NEW_IMPL);
174174

175-
assertEq(_xanProxy.scheduledCouncilUpgrade().impl, _NEW_IMPL);
176-
assertEq(_xanProxy.scheduledCouncilUpgrade().endTime, expectedEndTime);
175+
(address impl, uint48 endTime) = _xanProxy.scheduledCouncilUpgrade();
176+
assertEq(impl, _NEW_IMPL);
177+
assertEq(endTime, expectedEndTime);
177178
}
178179

179180
function test_scheduledCouncilImplementation_returns_0_if_no_upgrade_delay_has_been_started() public view {
180-
assertEq(_xanProxy.scheduledCouncilUpgrade().impl, address(0));
181-
assertEq(_xanProxy.scheduledCouncilUpgrade().endTime, 0);
181+
(address impl, uint48 endTime) = _xanProxy.scheduledCouncilUpgrade();
182+
assertEq(impl, address(0));
183+
assertEq(endTime, 0);
182184
}
183185
}

0 commit comments

Comments
 (0)