From 01f2ff1ba1220d7d3a0642014d30543bfcbb41ee Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Fri, 17 Sep 2021 16:57:00 +0200 Subject: [PATCH] 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) --- contracts/governance/Governor.sol | 7 +++++++ .../governance/extensions/GovernorTimelockCompound.sol | 3 ++- contracts/mocks/GovernorCompMock.sol | 2 -- contracts/mocks/GovernorMock.sol | 2 -- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/contracts/governance/Governor.sol b/contracts/governance/Governor.sol index 1dfd0dae8a1..741e02f7d98 100644 --- a/contracts/governance/Governor.sol +++ b/contracts/governance/Governor.sol @@ -55,6 +55,13 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor { _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}. */ diff --git a/contracts/governance/extensions/GovernorTimelockCompound.sol b/contracts/governance/extensions/GovernorTimelockCompound.sol index 84fc272656e..415a52b998c 100644 --- a/contracts/governance/extensions/GovernorTimelockCompound.sol +++ b/contracts/governance/extensions/GovernorTimelockCompound.sol @@ -177,8 +177,9 @@ abstract contract GovernorTimelockCompound is IGovernorTimelock, Governor { ) internal virtual override { uint256 eta = proposalEta(proposalId); require(eta > 0, "GovernorTimelockCompound: proposal not yet queued"); + Address.sendValue(payable(_timelock), msg.value); 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); } } diff --git a/contracts/mocks/GovernorCompMock.sol b/contracts/mocks/GovernorCompMock.sol index a0381f2daa7..299a90ac7cb 100644 --- a/contracts/mocks/GovernorCompMock.sol +++ b/contracts/mocks/GovernorCompMock.sol @@ -20,8 +20,6 @@ contract GovernorCompMock is Governor, GovernorVotesComp, GovernorCountingSimple _votingPeriod = votingPeriod_; } - receive() external payable {} - function votingDelay() public view override returns (uint256) { return _votingDelay; } diff --git a/contracts/mocks/GovernorMock.sol b/contracts/mocks/GovernorMock.sol index f31269055e6..362ce7bc495 100644 --- a/contracts/mocks/GovernorMock.sol +++ b/contracts/mocks/GovernorMock.sol @@ -21,8 +21,6 @@ contract GovernorMock is Governor, GovernorVotesQuorumFraction, GovernorCounting _votingPeriod = votingPeriod_; } - receive() external payable {} - function votingDelay() public view override returns (uint256) { return _votingDelay; }