Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usdc and usdt ready for review #191

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion contracts/interfaces/aave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ interface IAaveIncentivesController {
function claimRewards(
address[] calldata assets,
uint256 amount,
address to
address to,
address reward
) external returns (uint256);

function claimAllRewards(
address[] calldata assets,
address to
) external view returns (uint256);

function claimRewardsOnBehalf(
address[] calldata assets,
uint256 amount,
Expand All @@ -73,6 +79,9 @@ interface IAaveIncentivesController {
view
returns (uint256);

function getUserAccruedRewards(address user, address reward)
external view returns (uint256);

function REWARD_TOKEN() external view returns (address);
}

Expand Down
119 changes: 67 additions & 52 deletions contracts/strategies/aave/strategy-aave-daie.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ import "../strategy-base.sol";
import "../strategy-joe-farm-base.sol";

contract StrategyAaveDaiE is StrategyBase, Exponential {
address public constant avdai = 0x47AFa96Cdc9fAb46904A55a6ad4bf6660B53c38a;
address public constant dai = 0xd586E7F844cEa2F87f50152665BCbc2C279D8d70;
address public constant variableDebtDai =
0x1852DC24d1a8956a0B356AA18eDe954c7a0Ca5ae;
address public constant lendingPool =
0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C;
address public constant incentivesController =
0x01D83Fe6A10D2f2B7AF17034343746188272cAc9;

uint256 public constant DAI_COLFACTOR = 750000000000000000;
uint16 public constant REFERRAL_CODE = 0xaa;
address public constant avdaie = 0x82E64f49Ed5EC1bC6e43DAD4FC8Af9bb3A2312EE;
address public constant daie = 0xd586E7F844cEa2F87f50152665BCbc2C279D8d70;
address public constant variableDebtDaie = 0x8619d80FB0141ba7F184CbF22fd724116D9f7ffC;

address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD;

address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e;

uint256 public constant daie_COLFACTOR = 800000000000000000;
uint16 public constant REFERRAL_CODE = 0;

// Require a 0.04 buffer between
// market collateral factor and strategy's collateral factor
Expand All @@ -43,7 +42,7 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
address _timelock
)
public
StrategyBase(dai, _governance, _strategist, _controller, _timelock)
StrategyBase(daie, _governance, _strategist, _controller, _timelock)
{}

// **** Modifiers **** //
Expand All @@ -62,17 +61,26 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
// **** Views **** //

function getName() external pure override returns (string memory) {
return "StrategyAaveDaiV3";
return "StrategyAaveDaiE";
}

/**
* @notice Returns the amount of tokens being supplied
*/
function getSuppliedView() public view returns (uint256) {
return IERC20(avdai).balanceOf(address(this));
return IERC20(avdaie).balanceOf(address(this));
}

/**
* @notice Returns the amount of tokens being borrowed
*/
function getBorrowedView() public view returns (uint256) {
return IERC20(variableDebtDai).balanceOf(address(this));
return IERC20(variableDebtDaie).balanceOf(address(this));
}

/**
* @notice Returns the balance of the pool which is the difference between tokens supplied and borrowed
*/
function balanceOfPool() public view override returns (uint256) {
uint256 supplied = getSuppliedView();
uint256 borrowed = getBorrowedView();
Expand Down Expand Up @@ -102,7 +110,7 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
}

function getMarketColFactor() public pure returns (uint256) {
return DAI_COLFACTOR;
return daie_COLFACTOR;
}

// Max leverage we can go up to, w.r.t safe buffer
Expand All @@ -121,15 +129,11 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
As such there are pseudo view methods where you can retrieve the
results by calling `callStatic`.
*/

function getWavaxAccrued() public view returns (uint256) {
address[] memory avTokens = new address[](1);
avTokens[0] = avdai;

return
IAaveIncentivesController(incentivesController).getRewardsBalance(
avTokens,
address(this)
IAaveIncentivesController(incentivesController).getUserAccruedRewards(
address(this),
wavax
);
}

Expand All @@ -147,12 +151,18 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
return supplied.sub(borrowed);
}

/**
* @notice Returns the amount of tokens being supplied
*/
function getSupplied() public view returns (uint256) {
return IERC20(avdai).balanceOf(address(this));
return IERC20(avdaie).balanceOf(address(this));
}

/**
* @notice Returns the amount of tokens being borrowed
*/
function getBorrowed() public view returns (uint256) {
return IERC20(variableDebtDai).balanceOf(address(this));
return IERC20(variableDebtDaie).balanceOf(address(this));
}

function getBorrowable() public view returns (uint256) {
Expand Down Expand Up @@ -242,11 +252,11 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
}

// Leverages until we're supplying <x> amount
// 1. Redeem <x> DAI
// 2. Repay <x> DAI
// 1. Redeem <x> daie
// 2. Repay <x> daie
function leverageUntil(uint256 _supplyAmount) public onlyKeepers {
// 1. Borrow out <X> DAI
// 2. Supply <X> DAI
// 1. Borrow out <X> daie
// 2. Supply <X> daie

uint256 leverage = getMaxLeverage();
uint256 unleveragedSupply = getSuppliedUnleveraged();
Expand All @@ -268,7 +278,7 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
}

ILendingPool(lendingPool).borrow(
dai,
daie,
_borrowAndSupply,
uint256(DataTypes.InterestRateMode.VARIABLE),
REFERRAL_CODE,
Expand All @@ -286,8 +296,8 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
}

// Deleverages until we're supplying <x> amount
// 1. Redeem <x> DAI
// 2. Repay <x> DAI
// 1. Redeem <x> daie
// 2. Repay <x> daie
function deleverageUntil(uint256 _supplyAmount) public onlyKeepers {
uint256 unleveragedSupply = getSuppliedUnleveraged();
uint256 supplied = getSupplied();
Expand All @@ -311,20 +321,20 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
// withdraw
require(
ILendingPool(lendingPool).withdraw(
dai,
daie,
_redeemAndRepay,
address(this)
) != 0,
"!withdraw"
);

IERC20(dai).safeApprove(lendingPool, 0);
IERC20(dai).safeApprove(lendingPool, _redeemAndRepay);
IERC20(daie).safeApprove(lendingPool, 0);
IERC20(daie).safeApprove(lendingPool, _redeemAndRepay);

// repay
require(
ILendingPool(lendingPool).repay(
dai,
daie,
_redeemAndRepay,
uint256(DataTypes.InterestRateMode.VARIABLE),
address(this)
Expand All @@ -339,15 +349,20 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
}
}

/**
* @notice Harvests the reward tokens for redeposit
*/
function harvest() public override onlyBenevolent {
address[] memory avTokens = new address[](1);
avTokens[0] = avdai;
avTokens[0] = avdaie;

IAaveIncentivesController(incentivesController).claimRewards(
avTokens,
uint256(-1),
address(this)
address(this),
wavax
);

uint256 _wavax = IERC20(wavax).balanceOf(address(this));
if (_wavax > 0) {
uint256 _keep = _wavax.mul(keep).div(keepMax);
Expand All @@ -356,25 +371,25 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
}

_wavax = IERC20(wavax).balanceOf(address(this));

IERC20(wavax).safeApprove(pangolinRouter, 0);
IERC20(wavax).safeApprove(pangolinRouter, _wavax);

_swapPangolin(wavax, want, _wavax);

}

_distributePerformanceFeesAndDeposit();
}

/**
* @notice Deposits DAIE tokens inside the lendingPool
*/
function deposit() public override {
uint256 _want = IERC20(want).balanceOf(address(this));
if (_want > 0) {
IERC20(want).safeApprove(lendingPool, 0);
IERC20(want).safeApprove(lendingPool, _want);
uint256 _daie = IERC20(daie).balanceOf(address(this));
if (_daie > 0) {
IERC20(daie).safeApprove(lendingPool, 0);
IERC20(daie).safeApprove(lendingPool, _daie);

ILendingPool(lendingPool).deposit(
dai,
_want,
daie,
_daie,
address(this),
REFERRAL_CODE
);
Expand Down Expand Up @@ -402,17 +417,17 @@ contract StrategyAaveDaiE is StrategyBase, Exponential {
if (borrowedToBeFree > borrowed) {
this.deleverageToMin();
} else {
// Otherwise just keep freeing up borrowed amounts until
// we hit a safe number to redeem our underlying
this.deleverageUntil(supplied.sub(borrowedToBeFree));
// Otherwise just keep freeing up borrowed amounts until
// we hit a safe number to redeem our underlying
this.deleverageUntil(supplied.sub(borrowedToBeFree));
}
}


// withdraw
require(
ILendingPool(lendingPool).withdraw(
dai,
daie,
_redeem,
address(this)
) != 0,
Expand Down
Loading