|
| 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 | +} |
0 commit comments