Skip to content

Commit

Permalink
Merge pull request #177 from fei-protocol/feat/fip-22
Browse files Browse the repository at this point in the history
Aave Liquidity and Incentives
  • Loading branch information
Joeysantoro authored Sep 20, 2021
2 parents 3b471b8 + 7828757 commit 5aa0140
Show file tree
Hide file tree
Showing 14 changed files with 1,151 additions and 3 deletions.
11 changes: 9 additions & 2 deletions contract-addresses/mainnetAddresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"aaveAddress" : {"artifact" : "IERC20", "address" : "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9"},
"aaveEthPCVDepositAddress": { "artifact": "AavePCVDeposit", "address": "0x5B86887e171bAE0C2C826e87E34Df8D558C079B9"},
"aaveEthPCVDripControllerAddress": { "artifact": "PCVDripController", "address": "0xb3D63876d95d3a5e591D4DE536dC410b97244086"},
"aaveFeiPCVDepositAddress" : { "artifact" : "AavePCVDeposit", "address" : "0xaFBd7Bd91B4c1Dd289EE47a4F030FBeDfa7ABc12"},
"aaveGovernanceV2Address" : {"artifact" : "IAaveGovernanceV2", "address" : "0xEC568fffba86c094cf06b22134B23074DFE2252c"},
"aaveIncentivesControllerAddress" : {"address": "0xd784927ff2f95ba542bfc824c8a8a98f3495f6b5"},
"aaveLendingPoolAddress" : {"address": "0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9"},
"aaveLendingPoolAddress" : {"artifact" : "ILendingPool", "address": "0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9"},
"aaveRaiPCVDeposit": {"artifact" : "AavePCVDeposit", "address": "0xd2174d78637a40448112aa6B30F9B19e6CF9d1F9"},
"aaveTribeIncentivesControllerAddress" : {"address": "0xFF865335401F12B88fa3FF5A3a51685A7f224191"},
"aaveTribeIncentivesControllerAddress" : {"artifact": "IAaveIncentivesController", "address": "0xDee5c1662bBfF8f80f7c572D8091BF251b3B0dAB"},
"aaveTribeIncentivesControllerProxyAddress" : {"artifact": "TransparentUpgradeableProxy", "address": "0xDee5c1662bBfF8f80f7c572D8091BF251b3B0dAB"},
"aaveTribeIncentivesControllerImplAddress" : {"address": "0xFF865335401F12B88fa3FF5A3a51685A7f224191"},
"aFeiAddress" : {"artifact" : "IERC20", "address": "0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3"},
"aFeiStableDebtAddress" : {"artifact" : "IERC20", "address": "0xd89cF9E8A858F8B4b31Faf793505e112d6c17449"},
"aFeiVariableDebtAddress" : {"artifact" : "IERC20", "address": "0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe"},
"aRaiAddress" : {"address": "0xc9BC48c72154ef3e5425641a3c747242112a46AF"},
"aWETHAddress" : {"address": "0x030bA81f1c18d280636F32af80b9AAd02Cf0854e"},
"bentoBoxAddress" : { "artifact" : "IMasterContractManager", "address" : "0xF5BCE5077908a1b7370B9ae04AdC565EBd643966" },
Expand Down
49 changes: 49 additions & 0 deletions contracts/external/aave/DataTypes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

library DataTypes {
// refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties.
struct ReserveData {
//stores the reserve configuration
ReserveConfigurationMap configuration;
//the liquidity index. Expressed in ray
uint128 liquidityIndex;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current supply rate. Expressed in ray
uint128 currentLiquidityRate;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
//the current stable borrow rate. Expressed in ray
uint128 currentStableBorrowRate;
uint40 lastUpdateTimestamp;
//tokens addresses
address aTokenAddress;
address stableDebtTokenAddress;
address variableDebtTokenAddress;
//address of the interest rate strategy
address interestRateStrategyAddress;
//the id of the reserve. Represents the position in the list of the active reserves
uint8 id;
}

struct ReserveConfigurationMap {
//bit 0-15: LTV
//bit 16-31: Liq. threshold
//bit 32-47: Liq. bonus
//bit 48-55: Decimals
//bit 56: Reserve is active
//bit 57: reserve is frozen
//bit 58: borrowing is enabled
//bit 59: stable rate borrowing enabled
//bit 60-63: reserved
//bit 64-79: reserve factor
uint256 data;
}

struct UserConfigurationMap {
uint256 data;
}

enum InterestRateMode {NONE, STABLE, VARIABLE}
}
44 changes: 44 additions & 0 deletions contracts/external/aave/IAaveDistributionManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;

interface IAaveDistributionManager {

event AssetConfigUpdated(address indexed asset, uint256 emission);
event AssetIndexUpdated(address indexed asset, uint256 index);
event UserIndexUpdated(address indexed user, address indexed asset, uint256 index);
event DistributionEndUpdated(uint256 newDistributionEnd);

/**
* @dev Sets the end date for the distribution
* @param distributionEnd The end date timestamp
**/
function setDistributionEnd(uint256 distributionEnd) external;

/**
* @dev Gets the end date for the distribution
* @return The end of the distribution
**/
function getDistributionEnd() external view returns (uint256);

/**
* @dev for backwards compatibility with the previous DistributionManager used
* @return The end of the distribution
**/
function DISTRIBUTION_END() external view returns(uint256);

/**
* @dev Returns the data of an user on a distribution
* @param user Address of the user
* @param asset The address of the reference asset of the distribution
* @return The new index
**/
function getUserAssetData(address user, address asset) external view returns (uint256);

/**
* @dev Returns the configuration of the distribution for a certain asset
* @param asset The address of the reference asset of the distribution
* @return The asset index, the emission per second and the last updated timestamp
**/
function getAssetData(address asset) external view returns (uint256, uint256, uint256);
}
272 changes: 272 additions & 0 deletions contracts/external/aave/IAaveGovernanceV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

// Copied from https://github.com/aave/governance-v2
// with updated solidity version and changed import to interface

interface IExecutorWithTimelock {}

interface IAaveGovernanceV2 {
enum ProposalState {Pending, Canceled, Active, Failed, Succeeded, Queued, Expired, Executed}

struct Vote {
bool support;
uint248 votingPower;
}

struct Proposal {
uint256 id;
address creator;
IExecutorWithTimelock 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;
IExecutorWithTimelock 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;
}

/**
* @dev emitted when a new proposal is created
* @param id Id of the proposal
* @param creator address of the creator
* @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 boolean, true = transaction delegatecalls the taget, else calls the target
* @param startBlock block number when vote starts
* @param endBlock block number when vote ends
* @param strategy address of the governanceStrategy contract
* @param ipfsHash IPFS hash of the proposal
**/
event ProposalCreated(
uint256 id,
address indexed creator,
IExecutorWithTimelock indexed executor,
address[] targets,
uint256[] values,
string[] signatures,
bytes[] calldatas,
bool[] withDelegatecalls,
uint256 startBlock,
uint256 endBlock,
address strategy,
bytes32 ipfsHash
);

/**
* @dev emitted when a proposal is canceled
* @param id Id of the proposal
**/
event ProposalCanceled(uint256 id);

/**
* @dev emitted when a proposal is queued
* @param id Id of the proposal
* @param executionTime time when proposal underlying transactions can be executed
* @param initiatorQueueing address of the initiator of the queuing transaction
**/
event ProposalQueued(uint256 id, uint256 executionTime, address indexed initiatorQueueing);
/**
* @dev emitted when a proposal is executed
* @param id Id of the proposal
* @param initiatorExecution address of the initiator of the execution transaction
**/
event ProposalExecuted(uint256 id, address indexed initiatorExecution);
/**
* @dev emitted when a vote is registered
* @param id Id of the proposal
* @param voter address of the voter
* @param support boolean, true = vote for, false = vote against
* @param votingPower Power of the voter/vote
**/
event VoteEmitted(uint256 id, address indexed voter, bool support, uint256 votingPower);

event GovernanceStrategyChanged(address indexed newStrategy, address indexed initiatorChange);

event VotingDelayChanged(uint256 newVotingDelay, address indexed initiatorChange);

event ExecutorAuthorized(address executor);

event ExecutorUnauthorized(address executor);

/**
* @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(
IExecutorWithTimelock 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;

/**
* @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;

/**
* @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);
}
Loading

0 comments on commit 5aa0140

Please sign in to comment.