Skip to content

Commit

Permalink
feat: use governance from address book DRY (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Oct 24, 2022
1 parent 2118f43 commit eebcded
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 228 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/aave-address-book
Submodule aave-address-book updated 72 files
+13 −0 .editorconfig
+4 −0 .github/workflows/merge-main.yml
+4 −0 .prettierignore
+15 −0 .prettierrc
+14 −0 CHANGELOG.md
+80 −36 README.md
+1 −1 lib/forge-std
+2 −2 package.json
+568 −0 scripts/abi/stableDebtToken_v3_abi.json
+515 −0 scripts/abi/variableDebtToken_v3_abi.json
+105 −4 scripts/config.ts
+43 −60 scripts/generator.ts
+25 −102 scripts/generator_v2.ts
+85 −109 scripts/generator_v3.ts
+28 −0 scripts/helpers.ts
+1 −6 src/AaveAddressBook.sol
+0 −143 src/AaveAddressBookV2.sol
+0 −97 src/AaveAddressBookV2Testnet.sol
+0 −166 src/AaveAddressBookV3.sol
+0 −166 src/AaveAddressBookV3Testnet.sol
+1 −1 src/AaveGovernanceV2.sol
+86 −0 src/AaveMisc.sol
+15 −0 src/AaveV2.sol
+0 −1 src/AaveV2Avalanche.sol
+0 −1 src/AaveV2Ethereum.sol
+0 −1 src/AaveV2EthereumAMM.sol
+0 −1 src/AaveV2EthereumArc.sol
+0 −1 src/AaveV2Fuji.sol
+0 −1 src/AaveV2Goerli.sol
+0 −1 src/AaveV2Mumbai.sol
+0 −1 src/AaveV2Polygon.sol
+70 −8 src/AaveV3.sol
+15 −4 src/AaveV3Arbitrum.sol
+15 −4 src/AaveV3ArbitrumGoerli.sol
+15 −4 src/AaveV3Avalanche.sol
+15 −4 src/AaveV3Fantom.sol
+15 −4 src/AaveV3FantomTestnet.sol
+15 −4 src/AaveV3Fuji.sol
+15 −4 src/AaveV3Goerli.sol
+15 −4 src/AaveV3Harmony.sol
+0 −34 src/AaveV3HarmonyTestnet.sol
+15 −4 src/AaveV3Mumbai.sol
+15 −4 src/AaveV3Optimism.sol
+15 −4 src/AaveV3OptimismGoerli.sol
+0 −34 src/AaveV3OptimismKovan.sol
+15 −4 src/AaveV3Polygon.sol
+0 −9 src/Common.sol
+2 −3 src/test/AaveV2Misfits.t.sol
+3 −3 src/test/AaveV3Avalanche.t.sol
+3 −0 src/ts/AaveAddressBook.ts
+4 −0 src/ts/AaveGovernanceV2.ts
+2 −0 src/ts/AaveSafetyModule.ts
+5 −0 src/ts/AaveV2Avalanche.ts
+5 −0 src/ts/AaveV2Ethereum.ts
+5 −0 src/ts/AaveV2EthereumAMM.ts
+2 −0 src/ts/AaveV2Fuji.ts
+2 −0 src/ts/AaveV2Goerli.ts
+2 −0 src/ts/AaveV2Mumbai.ts
+5 −0 src/ts/AaveV2Polygon.ts
+13 −0 src/ts/AaveV3Arbitrum.ts
+10 −0 src/ts/AaveV3ArbitrumGoerli.ts
+13 −0 src/ts/AaveV3Avalanche.ts
+13 −0 src/ts/AaveV3Fantom.ts
+10 −0 src/ts/AaveV3FantomTestnet.ts
+10 −0 src/ts/AaveV3Fuji.ts
+10 −0 src/ts/AaveV3Goerli.ts
+9 −0 src/ts/AaveV3Harmony.ts
+10 −0 src/ts/AaveV3Mumbai.ts
+13 −0 src/ts/AaveV3Optimism.ts
+10 −0 src/ts/AaveV3OptimismGoerli.ts
+0 −13 src/ts/AaveV3OptimismKovan.ts
+13 −0 src/ts/AaveV3Polygon.ts
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 1 files
+13 −0 src/Vm.sol
2 changes: 1 addition & 1 deletion lib/solidity-utils
6 changes: 4 additions & 2 deletions src/AaveHelpers.sol
Original file line number Diff line number Diff line change
@@ -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";
import {GovHelpers, AaveGovernanceV2} from './GovHelpers.sol';
import {ProxyHelpers} from './ProxyHelpers.sol';
import {BridgeExecutorHelpers} from './BridgeExecutorHelpers.sol';
import {ProtocolV3TestBase} from './ProtocolV3TestBase.sol';
226 changes: 8 additions & 218 deletions src/GovHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -278,7 +68,7 @@ library GovHelpers {
function getProposalById(uint256 proposalId)
internal
view
returns (IAaveGov.ProposalWithoutVotes memory)
returns (IAaveGovernanceV2.ProposalWithoutVotes memory)
{
return GOV.getProposalById(proposalId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ProxyHelpers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {GovHelpers} from '../GovHelpers.sol';

contract ProxyHelpersTest is Test {
function setUp() public {
vm.createSelectFork('ethereum', 15446410);
vm.createSelectFork('ethereum', 15816947);
}

function testAdmin() public {
address admin = ProxyHelpers.getInitializableAdminUpgradeabilityProxyAdmin(
vm,
0x41A08648C3766F9F9d85598fF102a08f4ef84F84
);
assertEq(admin, GovHelpers.LONG_EXECUTOR);
assertEq(admin, GovHelpers.SHORT_EXECUTOR);
}

function testImplementation() public {
Expand Down

0 comments on commit eebcded

Please sign in to comment.