// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; abstract contract ERC20VotesEscrowed is ERC20Votes { function getAddresses() internal view virtual returns(address[] memory); function escrowBalance(address holder) internal view virtual returns(uint256); // to be called after tokens have been transferred to this escrow contract function setUpVotingPower() internal { address[] memory addresses = getAddresses(); for (uint i = 0; i < addresses.length; i++) { address a = addresses[i]; _jankyMoveVotingPower(address(this), a, escrowBalance(a)); } } function _afterTokenTransfer(address _from, address _to, uint256 _amount) internal override { // if it's the escrow contract, don't transfer any voting power when it leaves escrow, the // power will remain with whoever it's been delegated to already if (address(this) != _from) { super._afterTokenTransfer(_from, _to, _amount); } } function _delegate(address _delegator, address _delegatee) internal override { super._delegate(_delegator, _delegatee); // adds the escrow balance to the new delegatee's voting power address currentDelegate = delegates(_delegator); uint256 escrow = escrowBalance(_delegator); _jankyMoveVotingPower(currentDelegate, _delegatee, escrow); } // Moves voting power with the normally private `_moveVotingPower` function // by calling the `_afterTokenTransfer` function. // // see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfef6a68ee18dbd2e1f5a099061a3b8a0e404485/contracts/token/ERC20/extensions/ERC20Votes.sol#LL217C6-L217C6 // see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfef6a68ee18dbd2e1f5a099061a3b8a0e404485/contracts/token/ERC20/ERC20.sol#L364 function _jankyMoveVotingPower(address _src, address _dst, uint256 _amount) internal { super._afterTokenTransfer(_src, _dst, _amount); } }
0.7.1