Skip to content

Commit 2562c11

Browse files
Amxxernestognw
andauthored
Document VotesExtended assumptions (#5306)
Co-authored-by: ernestognw <ernestognw@gmail.com>
1 parent e1d44e0 commit 2562c11

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

contracts/governance/utils/VotesExtended.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ import {SafeCast} from "../../utils/math/SafeCast.sol";
77

88
/**
99
* @dev Extension of {Votes} that adds checkpoints for delegations and balances.
10+
*
11+
* WARNING: While this contract extends {Votes}, valid uses of {Votes} may not be compatible with
12+
* {VotesExtended} without additional considerations. This implementation of {_transferVotingUnits} must
13+
* run AFTER the voting weight movement is registered, such that it is reflected on {_getVotingUnits}.
14+
*
15+
* Said differently, {VotesExtended} MUST be integrated in a way that calls {_transferVotingUnits} AFTER the
16+
* asset transfer is registered and balances are updated:
17+
*
18+
* ```solidity
19+
* contract VotingToken is Token, VotesExtended {
20+
* function transfer(address from, address to, uint256 tokenId) public override {
21+
* super.transfer(from, to, tokenId); // <- Perform the transfer first ...
22+
* _transferVotingUnits(from, to, 1); // <- ... then call _transferVotingUnits.
23+
* }
24+
*
25+
* function _getVotingUnits(address account) internal view override returns (uint256) {
26+
* return balanceOf(account);
27+
* }
28+
* }
29+
* ```
30+
*
31+
* {ERC20Votes} and {ERC721Votes} follow this pattern and are thus safe to use with {VotesExtended}.
1032
*/
1133
abstract contract VotesExtended is Votes {
1234
using SafeCast for uint256;

0 commit comments

Comments
 (0)