Skip to content

Commit f39af18

Browse files
committed
forge fmt
1 parent 27ae2b2 commit f39af18

File tree

4 files changed

+186
-100
lines changed

4 files changed

+186
-100
lines changed

src/FlexVotingClient.sol

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,10 @@ abstract contract FlexVotingClient {
128128
_expressVote(voter, proposalId, support, weight);
129129
}
130130

131-
function _expressVote(
132-
address voter,
133-
uint256 proposalId,
134-
uint8 support,
135-
uint256 weight
136-
) internal virtual {
131+
function _expressVote(address voter, uint256 proposalId, uint8 support, uint256 weight)
132+
internal
133+
virtual
134+
{
137135
if (weight == 0) revert FlexVotingClient__NoVotingWeight();
138136

139137
if (proposalVotersHasVoted[proposalId][voter]) revert FlexVotingClient__AlreadyVoted();

src/FlexVotingDelegatable.sol

Lines changed: 74 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,80 @@ import {IVotingToken} from "src/interfaces/IVotingToken.sol";
99
import {FlexVotingClient} from "src/FlexVotingClient.sol";
1010

1111
abstract contract FlexVotingDelegatable is Context, FlexVotingClient {
12-
using Checkpoints for Checkpoints.Trace208;
13-
14-
// @dev Emitted when an account changes its delegate.
15-
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
16-
17-
// @dev Emitted when a delegate change results in changes to a delegate's
18-
// number of voting weight.
19-
event DelegateWeightChanged(address indexed delegate, uint256 previousVotes, uint256 newVotes);
20-
21-
mapping(address account => address) private _delegatee;
22-
23-
function expressVote(uint256 proposalId, uint8 support) external override virtual {
24-
address voter = _msgSender();
25-
uint256 weight = FlexVotingClient.getPastRawBalance(voter, GOVERNOR.proposalSnapshot(proposalId));
26-
_expressVote(voter, proposalId, support, weight);
27-
}
28-
29-
// @dev Delegates votes from the sender to `delegatee`.
30-
function delegate(address delegatee) public virtual {
31-
address account = _msgSender();
32-
_delegate(account, delegatee);
33-
}
34-
35-
// @dev Returns the delegate that `account` has chosen. Assumes
36-
// self-delegation if no delegate has been chosen.
37-
function delegates(address _account) public view virtual returns (address) {
38-
address _proxy = _delegatee[_account];
39-
if (_proxy == address(0)) return _account;
40-
return _proxy;
41-
}
42-
43-
// @dev Delegate all of `account`'s voting units to `delegatee`.
44-
//
45-
// Emits events {DelegateChanged} and {DelegateWeightChanged}.
46-
function _delegate(address account, address delegatee) internal virtual {
47-
address oldDelegate = delegates(account);
48-
_delegatee[account] = delegatee;
49-
50-
emit DelegateChanged(account, oldDelegate, delegatee);
51-
_updateDelegateBalance(oldDelegate, delegatee, _rawBalanceOf(account));
12+
using Checkpoints for Checkpoints.Trace208;
13+
14+
// @dev Emitted when an account changes its delegate.
15+
event DelegateChanged(
16+
address indexed delegator, address indexed fromDelegate, address indexed toDelegate
17+
);
18+
19+
// @dev Emitted when a delegate change results in changes to a delegate's
20+
// number of voting weight.
21+
event DelegateWeightChanged(address indexed delegate, uint256 previousVotes, uint256 newVotes);
22+
23+
mapping(address account => address) private _delegatee;
24+
25+
function expressVote(uint256 proposalId, uint8 support) external virtual override {
26+
address voter = _msgSender();
27+
uint256 weight =
28+
FlexVotingClient.getPastRawBalance(voter, GOVERNOR.proposalSnapshot(proposalId));
29+
_expressVote(voter, proposalId, support, weight);
30+
}
31+
32+
// @dev Delegates votes from the sender to `delegatee`.
33+
function delegate(address delegatee) public virtual {
34+
address account = _msgSender();
35+
_delegate(account, delegatee);
36+
}
37+
38+
// @dev Returns the delegate that `account` has chosen. Assumes
39+
// self-delegation if no delegate has been chosen.
40+
function delegates(address _account) public view virtual returns (address) {
41+
address _proxy = _delegatee[_account];
42+
if (_proxy == address(0)) return _account;
43+
return _proxy;
44+
}
45+
46+
// @dev Delegate all of `account`'s voting units to `delegatee`.
47+
//
48+
// Emits events {DelegateChanged} and {DelegateWeightChanged}.
49+
function _delegate(address account, address delegatee) internal virtual {
50+
address oldDelegate = delegates(account);
51+
_delegatee[account] = delegatee;
52+
53+
emit DelegateChanged(account, oldDelegate, delegatee);
54+
_updateDelegateBalance(oldDelegate, delegatee, _rawBalanceOf(account));
55+
}
56+
57+
// @dev Moves delegated votes from one delegate to another.
58+
function _updateDelegateBalance(address from, address to, uint208 amount) internal virtual {
59+
if (from == to || amount == 0) return;
60+
61+
if (from != address(0)) {
62+
(uint256 oldValue, uint256 newValue) =
63+
_push(FlexVotingClient.balanceCheckpoints[from], _subtract, amount);
64+
emit DelegateWeightChanged(from, oldValue, newValue);
5265
}
53-
54-
// @dev Moves delegated votes from one delegate to another.
55-
function _updateDelegateBalance(address from, address to, uint208 amount) internal virtual {
56-
if (from == to || amount == 0) return;
57-
58-
if (from != address(0)) {
59-
(uint256 oldValue, uint256 newValue) = _push(
60-
FlexVotingClient.balanceCheckpoints[from],
61-
_subtract,
62-
amount
63-
);
64-
emit DelegateWeightChanged(from, oldValue, newValue);
65-
}
66-
if (to != address(0)) {
67-
(uint256 oldValue, uint256 newValue) = _push(
68-
FlexVotingClient.balanceCheckpoints[to],
69-
_add,
70-
amount
71-
);
72-
emit DelegateWeightChanged(to, oldValue, newValue);
73-
}
74-
}
75-
76-
function _push(
77-
Checkpoints.Trace208 storage store,
78-
function(uint208, uint208) view returns (uint208) fn,
79-
uint208 delta
80-
) private returns (uint208 oldValue, uint208 newValue) {
81-
return store.push(
82-
IVotingToken(GOVERNOR.token()).clock(),
83-
fn(store.latest(), delta)
84-
);
85-
}
86-
87-
function _add(uint208 a, uint208 b) private pure returns (uint208) {
88-
return a + b;
89-
}
90-
91-
function _subtract(uint208 a, uint208 b) private pure returns (uint208) {
92-
return a - b;
66+
if (to != address(0)) {
67+
(uint256 oldValue, uint256 newValue) =
68+
_push(FlexVotingClient.balanceCheckpoints[to], _add, amount);
69+
emit DelegateWeightChanged(to, oldValue, newValue);
9370
}
71+
}
72+
73+
function _push(
74+
Checkpoints.Trace208 storage store,
75+
function(uint208, uint208) view returns (uint208) fn,
76+
uint208 delta
77+
) private returns (uint208 oldValue, uint208 newValue) {
78+
return store.push(IVotingToken(GOVERNOR.token()).clock(), fn(store.latest(), delta));
79+
}
80+
81+
function _add(uint208 a, uint208 b) private pure returns (uint208) {
82+
return a + b;
83+
}
84+
85+
function _subtract(uint208 a, uint208 b) private pure returns (uint208) {
86+
return a - b;
87+
}
9488
}

0 commit comments

Comments
 (0)