From 41ffeb0196c11e33300bfc319ad3fcae98b7a9be Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 6 Sep 2021 19:32:30 +0200 Subject: [PATCH 1/3] Change GovernorTimelockCompound to support ETH in Timelock --- contracts/governance/extensions/GovernorTimelockCompound.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/governance/extensions/GovernorTimelockCompound.sol b/contracts/governance/extensions/GovernorTimelockCompound.sol index 84fc272656e..64a4328591c 100644 --- a/contracts/governance/extensions/GovernorTimelockCompound.sol +++ b/contracts/governance/extensions/GovernorTimelockCompound.sol @@ -178,7 +178,7 @@ abstract contract GovernorTimelockCompound is IGovernorTimelock, Governor { uint256 eta = proposalEta(proposalId); require(eta > 0, "GovernorTimelockCompound: proposal not yet queued"); for (uint256 i = 0; i < targets.length; ++i) { - _timelock.executeTransaction{value: values[i]}(targets[i], values[i], "", calldatas[i], eta); + _timelock.executeTransaction{value: i == 0 ? msg.value : 0}(targets[i], values[i], "", calldatas[i], eta); } } From 3c29f6b7ff34ce9f0c1400a2b86bfe75a576bd3d Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 13 Sep 2021 21:42:38 +0200 Subject: [PATCH 2/3] refactor compound timelock module --- contracts/governance/extensions/GovernorTimelockCompound.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/governance/extensions/GovernorTimelockCompound.sol b/contracts/governance/extensions/GovernorTimelockCompound.sol index 64a4328591c..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: i == 0 ? msg.value : 0}(targets[i], values[i], "", calldatas[i], eta); + _timelock.executeTransaction(targets[i], values[i], "", calldatas[i], eta); } } From ae3311fe2c3a84ed352857f78935d05af3008461 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 13 Sep 2021 21:42:53 +0200 Subject: [PATCH 3/3] Allow governor to receive ETH is executor == address(this) --- contracts/governance/Governor.sol | 7 +++++++ contracts/mocks/GovernorCompMock.sol | 2 -- contracts/mocks/GovernorMock.sol | 2 -- 3 files changed, 7 insertions(+), 4 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/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; }