From eebcded1684bb0feed13fb01f4d9bd9fd42c0618 Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 24 Oct 2022 11:41:27 +0200 Subject: [PATCH] feat: use governance from address book DRY (#16) --- .gitmodules | 6 +- lib/aave-address-book | 2 +- lib/forge-std | 2 +- lib/solidity-utils | 2 +- src/AaveHelpers.sol | 6 +- src/GovHelpers.sol | 226 ++---------------------------------- src/test/ProxyHelpers.t.sol | 4 +- 7 files changed, 20 insertions(+), 228 deletions(-) diff --git a/.gitmodules b/.gitmodules index 8b8e8b382..837cb4ae2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "lib/forge-std"] path = lib/forge-std url = https://github.com/foundry-rs/forge-std -[submodule "lib/aave-address-book"] - path = lib/aave-address-book - url = https://github.com/bgd-labs/aave-address-book [submodule "lib/solidity-utils"] path = lib/solidity-utils url = https://github.com/bgd-labs/solidity-utils +[submodule "lib/aave-address-book"] + path = lib/aave-address-book + url = https://github.com/bgd-labs/aave-address-book diff --git a/lib/aave-address-book b/lib/aave-address-book index 9e5f7938a..9f85d42ab 160000 --- a/lib/aave-address-book +++ b/lib/aave-address-book @@ -1 +1 @@ -Subproject commit 9e5f7938acbf9808e097e9c14aefd92b0a631272 +Subproject commit 9f85d42abb2870db406e5c11effc2b0cd4effe41 diff --git a/lib/forge-std b/lib/forge-std index 5b1975772..2a2ce3692 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 5b1975772ef5331c3720b63cb5206ff9cddcdf34 +Subproject commit 2a2ce3692b8c1523b29de3ec9d961ee9fbbc43a6 diff --git a/lib/solidity-utils b/lib/solidity-utils index 723cf9a0d..0c5a8b894 160000 --- a/lib/solidity-utils +++ b/lib/solidity-utils @@ -1 +1 @@ -Subproject commit 723cf9a0dbc11486910594327178b9501e646c20 +Subproject commit 0c5a8b894b6bd9e434c9e8b5b355469c6c306228 diff --git a/src/AaveHelpers.sol b/src/AaveHelpers.sol index f6cd55177..1c374b431 100644 --- a/src/AaveHelpers.sol +++ b/src/AaveHelpers.sol @@ -1,5 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity >=0.7.5 <0.9.0; -import {GovHelpers, IAaveGov} from "./GovHelpers.sol"; -import {ProxyHelpers} from "./ProxyHelpers.sol"; \ No newline at end of file +import {GovHelpers, AaveGovernanceV2} from './GovHelpers.sol'; +import {ProxyHelpers} from './ProxyHelpers.sol'; +import {BridgeExecutorHelpers} from './BridgeExecutorHelpers.sol'; +import {ProtocolV3TestBase} from './ProtocolV3TestBase.sol'; diff --git a/src/GovHelpers.sol b/src/GovHelpers.sol index 683c79ee7..d770a5e8c 100644 --- a/src/GovHelpers.sol +++ b/src/GovHelpers.sol @@ -3,65 +3,9 @@ pragma solidity >=0.7.5 <0.9.0; pragma abicoder v2; import 'forge-std/Vm.sol'; +import {AaveGovernanceV2, IAaveGovernanceV2, IExecutorWithTimelock} from 'aave-address-book/AaveGovernanceV2.sol'; -interface IAaveGov { - enum ProposalState { - Pending, - Canceled, - Active, - Failed, - Succeeded, - Queued, - Expired, - Executed - } - - struct Vote { - bool support; - uint248 votingPower; - } - - struct Proposal { - uint256 id; - address creator; - address executor; - address[] targets; - uint256[] values; - string[] signatures; - bytes[] calldatas; - bool[] withDelegatecalls; - uint256 startBlock; - uint256 endBlock; - uint256 executionTime; - uint256 forVotes; - uint256 againstVotes; - bool executed; - bool canceled; - address strategy; - bytes32 ipfsHash; - mapping(address => Vote) votes; - } - - struct ProposalWithoutVotes { - uint256 id; - address creator; - address executor; - address[] targets; - uint256[] values; - string[] signatures; - bytes[] calldatas; - bool[] withDelegatecalls; - uint256 startBlock; - uint256 endBlock; - uint256 executionTime; - uint256 forVotes; - uint256 againstVotes; - bool executed; - bool canceled; - address strategy; - bytes32 ipfsHash; - } - +library GovHelpers { struct SPropCreateParams { address executor; address[] targets; @@ -72,162 +16,11 @@ interface IAaveGov { bytes32 ipfsHash; } - /** - * @dev Creates a Proposal (needs Proposition Power of creator > Threshold) - * @param executor The ExecutorWithTimelock contract that will execute the proposal - * @param targets list of contracts called by proposal's associated transactions - * @param values list of value in wei for each propoposal's associated transaction - * @param signatures list of function signatures (can be empty) to be used when created the callData - * @param calldatas list of calldatas: if associated signature empty, calldata ready, else calldata is arguments - * @param withDelegatecalls if true, transaction delegatecalls the taget, else calls the target - * @param ipfsHash IPFS hash of the proposal - **/ - function create( - address executor, - address[] memory targets, - uint256[] memory values, - string[] memory signatures, - bytes[] memory calldatas, - bool[] memory withDelegatecalls, - bytes32 ipfsHash - ) external returns (uint256); - - /** - * @dev Cancels a Proposal, - * either at anytime by guardian - * or when proposal is Pending/Active and threshold no longer reached - * @param proposalId id of the proposal - **/ - function cancel(uint256 proposalId) external; - - /** - * @dev Queue the proposal (If Proposal Succeeded) - * @param proposalId id of the proposal to queue - **/ - function queue(uint256 proposalId) external; - - /** - * @dev Execute the proposal (If Proposal Queued) - * @param proposalId id of the proposal to execute - **/ - function execute(uint256 proposalId) external payable; + IAaveGovernanceV2 internal constant GOV = AaveGovernanceV2.GOV; - /** - * @dev Function allowing msg.sender to vote for/against a proposal - * @param proposalId id of the proposal - * @param support boolean, true = vote for, false = vote against - **/ - function submitVote(uint256 proposalId, bool support) external; + address public constant SHORT_EXECUTOR = AaveGovernanceV2.SHORT_EXECUTOR; - /** - * @dev Function to register the vote of user that has voted offchain via signature - * @param proposalId id of the proposal - * @param support boolean, true = vote for, false = vote against - * @param v v part of the voter signature - * @param r r part of the voter signature - * @param s s part of the voter signature - **/ - function submitVoteBySignature( - uint256 proposalId, - bool support, - uint8 v, - bytes32 r, - bytes32 s - ) external; - - /** - * @dev Set new GovernanceStrategy - * Note: owner should be a timelocked executor, so needs to make a proposal - * @param governanceStrategy new Address of the GovernanceStrategy contract - **/ - function setGovernanceStrategy(address governanceStrategy) external; - - /** - * @dev Set new Voting Delay (delay before a newly created proposal can be voted on) - * Note: owner should be a timelocked executor, so needs to make a proposal - * @param votingDelay new voting delay in seconds - **/ - function setVotingDelay(uint256 votingDelay) external; - - /** - * @dev Add new addresses to the list of authorized executors - * @param executors list of new addresses to be authorized executors - **/ - function authorizeExecutors(address[] memory executors) external; - - /** - * @dev Remove addresses to the list of authorized executors - * @param executors list of addresses to be removed as authorized executors - **/ - function unauthorizeExecutors(address[] memory executors) external; - - /** - * @dev Let the guardian abdicate from its priviledged rights - **/ - function __abdicate() external; - - /** - * @dev Getter of the current GovernanceStrategy address - * @return The address of the current GovernanceStrategy contracts - **/ - function getGovernanceStrategy() external view returns (address); - - /** - * @dev Getter of the current Voting Delay (delay before a created proposal can be voted on) - * Different from the voting duration - * @return The voting delay in seconds - **/ - function getVotingDelay() external view returns (uint256); - - /** - * @dev Returns whether an address is an authorized executor - * @param executor address to evaluate as authorized executor - * @return true if authorized - **/ - function isExecutorAuthorized(address executor) external view returns (bool); - - /** - * @dev Getter the address of the guardian, that can mainly cancel proposals - * @return The address of the guardian - **/ - function getGuardian() external view returns (address); - - /** - * @dev Getter of the proposal count (the current number of proposals ever created) - * @return the proposal count - **/ - function getProposalsCount() external view returns (uint256); - - /** - * @dev Getter of a proposal by id - * @param proposalId id of the proposal to get - * @return the proposal as ProposalWithoutVotes memory object - **/ - function getProposalById(uint256 proposalId) external view returns (ProposalWithoutVotes memory); - - /** - * @dev Getter of the Vote of a voter about a proposal - * Note: Vote is a struct: ({bool support, uint248 votingPower}) - * @param proposalId id of the proposal - * @param voter address of the voter - * @return The associated Vote memory object - **/ - function getVoteOnProposal(uint256 proposalId, address voter) external view returns (Vote memory); - - /** - * @dev Get the current state of a proposal - * @param proposalId id of the proposal - * @return The current state if the proposal - **/ - function getProposalState(uint256 proposalId) external view returns (ProposalState); -} - -library GovHelpers { - IAaveGov internal constant GOV = IAaveGov(0xEC568fffba86c094cf06b22134B23074DFE2252c); - - address public constant SHORT_EXECUTOR = 0xEE56e2B3D491590B5b31738cC34d5232F378a8D5; - - address public constant LONG_EXECUTOR = 0x61910EcD7e8e942136CE7Fe7943f956cea1CC2f7; + address public constant LONG_EXECUTOR = AaveGovernanceV2.LONG_EXECUTOR; address public constant AAVE = 0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9; @@ -236,14 +29,11 @@ library GovHelpers { /** * Impersonate the ecosystem reserve and created the proposal. */ - function createProposal(Vm vm, IAaveGov.SPropCreateParams memory params) - internal - returns (uint256) - { + function createProposal(Vm vm, SPropCreateParams memory params) internal returns (uint256) { vm.deal(AAVE_WHALE, 1 ether); vm.startPrank(AAVE_WHALE); uint256 proposalId = GOV.create( - params.executor, + IExecutorWithTimelock(params.executor), params.targets, params.values, params.signatures, @@ -278,7 +68,7 @@ library GovHelpers { function getProposalById(uint256 proposalId) internal view - returns (IAaveGov.ProposalWithoutVotes memory) + returns (IAaveGovernanceV2.ProposalWithoutVotes memory) { return GOV.getProposalById(proposalId); } diff --git a/src/test/ProxyHelpers.t.sol b/src/test/ProxyHelpers.t.sol index 5a2465c26..fc03ec624 100644 --- a/src/test/ProxyHelpers.t.sol +++ b/src/test/ProxyHelpers.t.sol @@ -7,7 +7,7 @@ import {GovHelpers} from '../GovHelpers.sol'; contract ProxyHelpersTest is Test { function setUp() public { - vm.createSelectFork('ethereum', 15446410); + vm.createSelectFork('ethereum', 15816947); } function testAdmin() public { @@ -15,7 +15,7 @@ contract ProxyHelpersTest is Test { vm, 0x41A08648C3766F9F9d85598fF102a08f4ef84F84 ); - assertEq(admin, GovHelpers.LONG_EXECUTOR); + assertEq(admin, GovHelpers.SHORT_EXECUTOR); } function testImplementation() public {