Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于openzeppelin的ERC20Votes的投票权重分配逻辑和Governor投票门槛和法定人数概念 #1

Open
tangminjie opened this issue Jun 6, 2022 · 3 comments

Comments

@tangminjie
Copy link
Member

tangminjie commented Jun 6, 2022

ERC20继承 ERC20votes后实现mint后调用_writeCheckpoint来记录代币总的权重。

    function _mint(address account, uint256 amount) internal virtual override {
        super._mint(account, amount);
        require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");

        _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
    }

对应的地址权重使用数组mapping(address => Checkpoint[]) private _checkpoints;记录,对于Checkpointp[]是一个区块索引数组,记录了不同区块下的votes代币数量来标识权重。对于权重所有者,在mint后会调用钩子函数_afterTokenTransfer来对投票权进行转移,并且记录。

@tangminjie
Copy link
Member Author

提案门槛_proposalThreshold 由GovernorSettings构造时设置,用来判断address的投票权重是否符合投票门槛

@tangminjie
Copy link
Member Author

tangminjie commented Jun 6, 2022

法定人数由ERC20区块对应的代币总数的百分比来确定。

    function quorum(uint256 blockNumber) public view virtual override returns (uint256) {
        return (token.getPastTotalSupply(blockNumber) * quorumNumerator()) / quorumDenominator();
    }

其中只有赞成和弃权票计入法定人数。当投票超过法定人数,提案成立。

@tangminjie
Copy link
Member Author

提案门槛_proposalThresholdGovernorSettings构造时设置,用来判断address的投票权重是否符合投票门槛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant