Allow Governor + CompoundTimelock to manage native tokens (eth) in and out of the timelock contract. (#2849)

* Change GovernorTimelockCompound to support ETH in Timelock

* refactor compound timelock module

* Allow governor to receive ETH is executor == address(this)
pull/2870/head
Hadrien Croubois 3 years ago committed by GitHub
parent 296223f876
commit 01f2ff1ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      contracts/governance/Governor.sol
  2. 3
      contracts/governance/extensions/GovernorTimelockCompound.sol
  3. 2
      contracts/mocks/GovernorCompMock.sol
  4. 2
      contracts/mocks/GovernorMock.sol

@ -55,6 +55,13 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor {
_name = name_; _name = name_;
} }
/**
* @dev Function to receive ETH that will be handled by the governor (disabled if executor is a third party contract)
*/
receive() external payable virtual {
require(_executor() == address(this));
}
/** /**
* @dev See {IERC165-supportsInterface}. * @dev See {IERC165-supportsInterface}.
*/ */

@ -177,8 +177,9 @@ abstract contract GovernorTimelockCompound is IGovernorTimelock, Governor {
) internal virtual override { ) internal virtual override {
uint256 eta = proposalEta(proposalId); uint256 eta = proposalEta(proposalId);
require(eta > 0, "GovernorTimelockCompound: proposal not yet queued"); require(eta > 0, "GovernorTimelockCompound: proposal not yet queued");
Address.sendValue(payable(_timelock), msg.value);
for (uint256 i = 0; i < targets.length; ++i) { for (uint256 i = 0; i < targets.length; ++i) {
_timelock.executeTransaction{value: values[i]}(targets[i], values[i], "", calldatas[i], eta); _timelock.executeTransaction(targets[i], values[i], "", calldatas[i], eta);
} }
} }

@ -20,8 +20,6 @@ contract GovernorCompMock is Governor, GovernorVotesComp, GovernorCountingSimple
_votingPeriod = votingPeriod_; _votingPeriod = votingPeriod_;
} }
receive() external payable {}
function votingDelay() public view override returns (uint256) { function votingDelay() public view override returns (uint256) {
return _votingDelay; return _votingDelay;
} }

@ -21,8 +21,6 @@ contract GovernorMock is Governor, GovernorVotesQuorumFraction, GovernorCounting
_votingPeriod = votingPeriod_; _votingPeriod = votingPeriod_;
} }
receive() external payable {}
function votingDelay() public view override returns (uint256) { function votingDelay() public view override returns (uint256) {
return _votingDelay; return _votingDelay;
} }

Loading…
Cancel
Save