Skip to content

Commit ab8ac0d

Browse files
ncitroncgewecke
authored andcommitted
Add AaveGovernanceV2Adapter (#14)
* add basic structure for SnapshotDelegationModule * add delegate function * add SnapshotGovernanceAdapter * code review changes * add aave v2 governance contracts to aave fixture * add AaveGovernanceV2Adapter * add tests for getting proper calldata * add integration test for aave governance v2 adapter * style fixes * code review changes
1 parent 098cd0c commit ab8ac0d

File tree

16 files changed

+2708
-2
lines changed

16 files changed

+2708
-2
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
18+
19+
pragma solidity 0.6.10;
20+
pragma experimental "ABIEncoderV2";
21+
22+
23+
/**
24+
* @title AaveGovernanceV2Adapter
25+
* @author Noah Citron
26+
*
27+
* Governance adapter for Aave governance that returns data for voting, delegating, and creating proposals
28+
*/
29+
contract AaveGovernanceV2Adapter {
30+
31+
/* ============ Constants ============ */
32+
33+
// Signature of delegate function
34+
string public constant DELEGATE_SIGNATURE = "delegate(address)";
35+
36+
// Signature of vote function
37+
string public constant VOTE_SIGNATURE = "submitVote(uint256,bool)";
38+
39+
// Signature of propose function
40+
string public constant PROPOSE_SIGNATURE = "create(address,address[],uint256[],string[],bytes[],bool[],bytes32)";
41+
42+
/* ============ State Variables ============ */
43+
44+
// Address of Aave proto governance contract
45+
address public immutable aaveGovernanceV2;
46+
47+
// Address of the Aave token
48+
address public immutable aaveToken;
49+
50+
/* ============ Constructor ============ */
51+
52+
/**
53+
* Set state variables
54+
*
55+
* @param _aaveGovernanceV2 Address of AAVE Governance V2 contract
56+
*/
57+
constructor(address _aaveGovernanceV2, address _aaveToken) public {
58+
aaveGovernanceV2 = _aaveGovernanceV2;
59+
aaveToken = _aaveToken;
60+
}
61+
62+
/* ============ External Getter Functions ============ */
63+
64+
/**
65+
* Generates the calldata to vote on a proposal.
66+
*
67+
* @param _proposalId ID of the proposal to vote on
68+
* @param _support Boolean indicating whether to support proposal
69+
*
70+
* @return address Target contract address
71+
* @return uint256 Total quantity of ETH (Set to 0)
72+
* @return bytes Propose calldata
73+
*/
74+
function getVoteCalldata(uint256 _proposalId, bool _support, bytes memory /* _data */) external view returns (address, uint256, bytes memory) {
75+
bytes memory callData = abi.encodeWithSignature(VOTE_SIGNATURE, _proposalId, _support);
76+
return (aaveGovernanceV2, 0, callData);
77+
}
78+
79+
/**
80+
* Generates the calldata to delegate votes to another ETH address. Self and zero address allowed, which is equivalent to registering and revoking in Aave.
81+
*
82+
* @param _delegatee Address of the delegatee
83+
*
84+
* @return address Target contract address
85+
* @return uint256 Total quantity of ETH (Set to 0)
86+
* @return bytes Propose calldata
87+
*/
88+
function getDelegateCalldata(address _delegatee) external view returns (address, uint256, bytes memory) {
89+
bytes memory callData = abi.encodeWithSignature(DELEGATE_SIGNATURE, _delegatee);
90+
return (aaveToken, 0, callData);
91+
}
92+
93+
/**
94+
* Generates the calldata to create a new proposal.
95+
* The caller must have proposition power higher than PROPOSITION_THRESHOLD to create a proposal.
96+
* Executor is a contract deployed to validate proposal creation and voting.
97+
* There two types of proposals and each has it's own executor.
98+
* Critical proposals that affect governance consensus (long) and proposals affecting only protocol parameters (short).
99+
* https://docs.aave.com/developers/protocol-governance/governance#proposal-types
100+
*
101+
* @param _proposalData Byte data containing data about the proposal
102+
*
103+
* @return address Target contract address
104+
* @return uint256 Total quantity of ETH (Set to 0)
105+
* @return bytes Propose calldata
106+
*/
107+
function getProposeCalldata(bytes memory _proposalData) external view returns (address, uint256, bytes memory) {
108+
(
109+
address executor,
110+
address[] memory targets,
111+
uint256[] memory values,
112+
string[] memory signatures,
113+
bytes[] memory calldatas,
114+
bool[] memory withDelegateCalls,
115+
bytes32 ipfsHash
116+
) = abi.decode(_proposalData, (address,address[],uint256[],string[],bytes[],bool[],bytes32));
117+
118+
bytes memory callData = abi.encodeWithSignature(
119+
PROPOSE_SIGNATURE,
120+
executor,
121+
targets,
122+
values,
123+
signatures,
124+
calldatas,
125+
withDelegateCalls,
126+
ipfsHash
127+
);
128+
129+
return (aaveGovernanceV2, 0, callData);
130+
}
131+
132+
/**
133+
* Reverts as AAVE currently does not have a register mechanism in governance
134+
*/
135+
function getRegisterCalldata(address /* _setToken */) external view returns (address, uint256, bytes memory) {
136+
revert("No register available in AAVE governance");
137+
}
138+
139+
/**
140+
* Reverts as AAVE currently does not have a revoke mechanism in governance
141+
*/
142+
function getRevokeCalldata() external view returns (address, uint256, bytes memory) {
143+
revert("No revoke available in AAVE governance");
144+
}
145+
}

external/abi/aave/AaveGovernanceV2.json

Lines changed: 8 additions & 0 deletions
Large diffs are not rendered by default.

external/abi/aave/AaveTokenV2Mintable.json

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.

external/abi/aave/Executor.json

Lines changed: 9 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"contractName": "GovernanceStrategy",
3+
"abi": [{"inputs":[{"internalType":"address","name":"aave","type":"address"},{"internalType":"address","name":"stkAave","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AAVE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STK_AAVE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getPropositionPowerAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getTotalPropositionSupplyAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getTotalVotingSupplyAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getVotingPowerAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
4+
"bytecode": "60c060405234801561001057600080fd5b5060405161050738038061050783398101604081905261002f91610069565b6001600160601b0319606092831b8116608052911b1660a05261009b565b80516001600160a01b038116811461006457600080fd5b919050565b6000806040838503121561007b578182fd5b6100848361004d565b91506100926020840161004d565b90509250929050565b60805160601c60a05160601c6104356100d260003980610132528061021b52508060e8528061017c52806102bb52506104356000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806348ccda3c146100675780637a71f9d714610085578063a1076e58146100a5578063bdf2878d146100b8578063eaeded5f146100c0578063f6b50203146100d3575b600080fd5b61006f6100e6565b60405161007c91906103b3565b60405180910390f35b610098610093366004610383565b61010a565b60405161007c91906103f6565b6100986100b336600461034d565b61011b565b61006f610130565b6100986100ce36600461034d565b610154565b6100986100e1366004610383565b610162565b7f000000000000000000000000000000000000000000000000000000000000000081565b600061011582610162565b92915050565b600061012983836001610201565b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b600061012983836000610201565b604051630981b24d60e41b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063981b24d0906101b19085906004016103f6565b60206040518083038186803b1580156101c957600080fd5b505afa1580156101dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610115919061039b565b60405163c2ffbb9160e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c2ffbb9190610254908790879087906004016103c7565b60206040518083038186803b15801561026c57600080fd5b505afa158015610280573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102a4919061039b565b60405163c2ffbb9160e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c2ffbb91906102f4908890889088906004016103c7565b60206040518083038186803b15801561030c57600080fd5b505afa158015610320573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610344919061039b565b01949350505050565b6000806040838503121561035f578182fd5b82356001600160a01b0381168114610375578283fd5b946020939093013593505050565b600060208284031215610394578081fd5b5035919050565b6000602082840312156103ac578081fd5b5051919050565b6001600160a01b0391909116815260200190565b6001600160a01b03841681526020810183905260608101600283106103e857fe5b826040830152949350505050565b9081526020019056fea2646970667358221220ea89e97378d130d0949b727a972a149584329bbdd01354adc8a43c162158cdeb64736f6c63430007050033",
5+
"deployedBytecode": "",
6+
"linkReferences": {},
7+
"deployedLinkReferences": {}
8+
}
9+

0 commit comments

Comments
 (0)