Votes.sol : _moveDelegateVotes after mint or burn

Hello guys,

I am trying to use governance/utils.votes.sol. I am almost done but I am still figuring out how _moveDelegateVotes can work when called by _transferVotingUnits in a Minting context. Because _delegation is empty delegates(from) and delegates(to) returns the zero address. By doing so _moveDelegateVotes can't write in the _delegateCheckpoints mapping as it doesn't match the required condition. At the end getVotes() will return 0 because of that. Does it mean an account must delegate first after a successful minting ? I thought it was done automatically when minting.

Let me explicit my misunderstanding with my comments in the code:

    // _transferVotingUnits is called in an afterTokenTransfer callback
    function _transferVotingUnits(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        if (from == address(0)) {
            _totalCheckpoints.push(_add, amount);
        }
        if (to == address(0)) {
            _totalCheckpoints.push(_subtract, amount);
        }
       // here both delegates() returns address(0) because _delegation is empty during this vert first mint.
        _moveDelegateVotes(delegates(from), delegates(to), amount);
    }

    function _moveDelegateVotes(
        address from,
        address to,
        uint256 amount
    ) private {
        // from and to equal address(0)
        if (from != to && amount > 0) {
            if (from != address(0)) {
                (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_subtract, amount);
                emit DelegateVotesChanged(from, oldValue, newValue);
            }
            if (to != address(0)) {
                (uint256 oldValue, uint256 newValue) = _delegateCheckpoints[to].push(_add, amount);
                emit DelegateVotesChanged(to, oldValue, newValue);
            }
        }
    }

Please can you give more explanation about implementation of Votes ? Is this the expected expected ?

:computer: Environment

Solidity 0.8.6

You are correct. Please refer to our documentation where we answer that question. You can see it is the desired behavior as expressed here:

voting units must be delegated in order to count as actual votes, and an account has to delegate those votes to itself if it wishes to participate in decisions and does not have a trusted representative.

Sorry, I did not know this section in your doc. Thank you @JulissaDantes.

1 Like