mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #30 from Instadapp/staked-aave
AAVE rewards + Staked AAVE connectors
This commit is contained in:
commit
dd9e6f6e1d
10
contracts/mainnet/connectors/aave/aave-rewards/events.sol
Normal file
10
contracts/mainnet/connectors/aave/aave-rewards/events.sol
Normal file
|
@ -0,0 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogClaimed(
|
||||
address[] assets,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
12
contracts/mainnet/connectors/aave/aave-rewards/helpers.sol
Normal file
12
contracts/mainnet/connectors/aave/aave-rewards/helpers.sol
Normal file
|
@ -0,0 +1,12 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { DSMath } from "../../../common/math.sol";
|
||||
import { Basic } from "../../../common/basic.sol";
|
||||
import { AaveIncentivesInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
/**
|
||||
* @dev Aave Incentives
|
||||
*/
|
||||
AaveIncentivesInterface internal constant incentives = AaveIncentivesInterface(0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
interface AaveIncentivesInterface {
|
||||
function claimRewards(
|
||||
address[] calldata assets,
|
||||
uint256 amount,
|
||||
address to
|
||||
) external returns (uint256);
|
||||
}
|
39
contracts/mainnet/connectors/aave/aave-rewards/main.sol
Normal file
39
contracts/mainnet/connectors/aave/aave-rewards/main.sol
Normal file
|
@ -0,0 +1,39 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import { Stores } from "../../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract IncentivesResolver is Helpers, Events {
|
||||
|
||||
/**
|
||||
* @dev Claim Pending Rewards.
|
||||
* @notice Claim Pending Rewards from Aave incentives contract.
|
||||
* @param assets The list of assets supplied and borrowed.
|
||||
* @param amt The amount of reward to claim. (uint(-1) for max)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of rewards claimed.
|
||||
*/
|
||||
function claim(
|
||||
address[] calldata assets,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
require(assets.length > 0, "invalid-assets");
|
||||
|
||||
_amt = incentives.claimRewards(assets, _amt, address(this));
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogClaimed(address[],uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(assets, _amt, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2AaveIncentives is IncentivesResolver {
|
||||
string public constant name = "Aave-Incentives-v1";
|
||||
}
|
15
contracts/mainnet/connectors/aave/staked-aave/events.sol
Normal file
15
contracts/mainnet/connectors/aave/staked-aave/events.sol
Normal file
|
@ -0,0 +1,15 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogClaim(uint amt, uint getId, uint setId);
|
||||
event LogStake(uint amt, uint getId, uint setId);
|
||||
event LogCooldown();
|
||||
event LogRedeem(uint amt, uint getId, uint setId);
|
||||
event LogDelegate(
|
||||
address delegatee,
|
||||
bool delegateAave,
|
||||
bool delegateStkAave,
|
||||
uint8 aaveDelegationType,
|
||||
uint8 stkAaveDelegationType
|
||||
);
|
||||
}
|
78
contracts/mainnet/connectors/aave/staked-aave/helpers.sol
Normal file
78
contracts/mainnet/connectors/aave/staked-aave/helpers.sol
Normal file
|
@ -0,0 +1,78 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { DSMath } from "../../../common/math.sol";
|
||||
import { Basic } from "../../../common/basic.sol";
|
||||
import { StakedAaveInterface, AaveInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
|
||||
enum DelegationType {VOTING_POWER, PROPOSITION_POWER, BOTH}
|
||||
|
||||
/**
|
||||
* @dev Staked Aave Token
|
||||
*/
|
||||
StakedAaveInterface internal constant stkAave = StakedAaveInterface(0x4da27a545c0c5B758a6BA100e3a049001de870f5);
|
||||
|
||||
/**
|
||||
* @dev Aave Token
|
||||
*/
|
||||
AaveInterface internal constant aave = AaveInterface(0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9);
|
||||
|
||||
function _delegateAave(address _delegatee, DelegationType _type) internal {
|
||||
if (_type == DelegationType.BOTH) {
|
||||
require(
|
||||
aave.getDelegateeByType(address(this), 0) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
require(
|
||||
aave.getDelegateeByType(address(this), 1) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
|
||||
aave.delegate(_delegatee);
|
||||
} else if (_type == DelegationType.VOTING_POWER) {
|
||||
require(
|
||||
aave.getDelegateeByType(address(this), 0) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
|
||||
aave.delegateByType(_delegatee, 0);
|
||||
} else {
|
||||
require(
|
||||
aave.getDelegateeByType(address(this), 1) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
|
||||
aave.delegateByType(_delegatee, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function _delegateStakedAave(address _delegatee, DelegationType _type) internal {
|
||||
if (_type == DelegationType.BOTH) {
|
||||
require(
|
||||
stkAave.getDelegateeByType(address(this), 0) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
require(
|
||||
stkAave.getDelegateeByType(address(this), 1) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
|
||||
stkAave.delegate(_delegatee);
|
||||
} else if (_type == DelegationType.VOTING_POWER) {
|
||||
require(
|
||||
stkAave.getDelegateeByType(address(this), 0) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
|
||||
stkAave.delegateByType(_delegatee, 0);
|
||||
} else {
|
||||
require(
|
||||
stkAave.getDelegateeByType(address(this), 1) != _delegatee,
|
||||
"already-delegated"
|
||||
);
|
||||
|
||||
stkAave.delegateByType(_delegatee, 1);
|
||||
}
|
||||
}
|
||||
}
|
16
contracts/mainnet/connectors/aave/staked-aave/interface.sol
Normal file
16
contracts/mainnet/connectors/aave/staked-aave/interface.sol
Normal file
|
@ -0,0 +1,16 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
|
||||
interface AaveInterface is TokenInterface {
|
||||
function delegate(address delegatee) external;
|
||||
function delegateByType(address delegatee, uint8 delegationType) external;
|
||||
function getDelegateeByType(address delegator, uint8 delegationType) external view returns (address);
|
||||
}
|
||||
|
||||
interface StakedAaveInterface is AaveInterface {
|
||||
function stake(address onBehalfOf, uint256 amount) external;
|
||||
function redeem(address to, uint256 amount) external;
|
||||
function cooldown() external;
|
||||
function claimRewards(address to, uint256 amount) external;
|
||||
}
|
123
contracts/mainnet/connectors/aave/staked-aave/main.sol
Normal file
123
contracts/mainnet/connectors/aave/staked-aave/main.sol
Normal file
|
@ -0,0 +1,123 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract AaveResolver is Helpers, Events {
|
||||
|
||||
/**
|
||||
* @dev Claim Accrued AAVE.
|
||||
* @notice Claim Accrued AAVE Token rewards.
|
||||
* @param amount The amount of rewards to claim. uint(-1) for max.
|
||||
* @param getId ID to retrieve amount.
|
||||
* @param setId ID stores the amount of tokens claimed.
|
||||
*/
|
||||
function claim(
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amount);
|
||||
|
||||
uint intialBal = aave.balanceOf(address(this));
|
||||
stkAave.claimRewards(address(this), _amt);
|
||||
uint finalBal = aave.balanceOf(address(this));
|
||||
_amt = sub(finalBal, intialBal);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogClaim(uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Stake AAVE Token
|
||||
* @notice Stake AAVE Token in Aave security module
|
||||
* @param amount The amount of AAVE to stake. uint(-1) for max.
|
||||
* @param getId ID to retrieve amount.
|
||||
* @param setId ID stores the amount of tokens staked.
|
||||
*/
|
||||
function stake(
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amount);
|
||||
|
||||
_amt = _amt == uint(-1) ? aave.balanceOf(address(this)) : _amt;
|
||||
stkAave.stake(address(this), _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogStake(uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Initiate cooldown to unstake
|
||||
* @notice Initiate cooldown to unstake from Aave security module
|
||||
*/
|
||||
function cooldown() external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(stkAave.balanceOf(address(this)) > 0, "no-staking");
|
||||
|
||||
stkAave.cooldown();
|
||||
|
||||
_eventName = "LogCooldown()";
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Redeem tokens from Staked AAVE
|
||||
* @notice Redeem AAVE tokens from Staked AAVE after cooldown period is over
|
||||
* @param amount The amount of AAVE to redeem. uint(-1) for max.
|
||||
* @param getId ID to retrieve amount.
|
||||
* @param setId ID stores the amount of tokens redeemed.
|
||||
*/
|
||||
function redeem(
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amount);
|
||||
|
||||
uint intialBal = aave.balanceOf(address(this));
|
||||
stkAave.redeem(address(this), _amt);
|
||||
uint finalBal = aave.balanceOf(address(this));
|
||||
_amt = sub(finalBal, intialBal);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogRedeem(uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Delegate AAVE or stkAAVE
|
||||
* @notice Delegate AAVE or stkAAVE
|
||||
* @param delegatee The address of the delegatee
|
||||
* @param delegateAave Whether to delegate Aave balance
|
||||
* @param delegateStkAave Whether to delegate Staked Aave balance
|
||||
* @param aaveDelegationType Aave delegation type. Voting power - 0, Proposition power - 1, Both - 2
|
||||
* @param stkAaveDelegationType Staked Aave delegation type. Values similar to aaveDelegationType
|
||||
*/
|
||||
function delegate(
|
||||
address delegatee,
|
||||
bool delegateAave,
|
||||
bool delegateStkAave,
|
||||
uint8 aaveDelegationType,
|
||||
uint8 stkAaveDelegationType
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(delegateAave || delegateStkAave, "invalid-delegate");
|
||||
require(delegatee != address(0), "invalid-delegatee");
|
||||
|
||||
if (delegateAave) {
|
||||
_delegateAave(delegatee, Helpers.DelegationType(aaveDelegationType));
|
||||
}
|
||||
|
||||
if (delegateStkAave) {
|
||||
_delegateStakedAave(delegatee, Helpers.DelegationType(stkAaveDelegationType));
|
||||
}
|
||||
|
||||
_eventName = "LogDelegate(address,bool,bool,uint8,uint8)";
|
||||
_eventParam = abi.encode(delegatee, delegateAave, delegateStkAave, aaveDelegationType, stkAaveDelegationType);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user