From 50387a7465d7962c17be7fb9bba6ed0c7a1821bf Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 21 Apr 2022 18:44:55 -0500 Subject: [PATCH 1/4] usdc and usdt ready for review --- contracts/interfaces/aave.sol | 11 +- .../strategies/aave/strategy-aave-daie.sol | 119 ++++++++++-------- .../strategies/aave/strategy-aave-usdc.sol | 75 ++++++----- .../strategies/aave/strategy-aave-usdt.sol | 68 ++++++---- ...ax.sol => strategy-aave-wavax.sol.disable} | 0 ...btc.sol => strategy-aave-wbtc.sol.disable} | 0 ...eth.sol => strategy-aave-weth.sol.disable} | 0 test/FoldingStrats/aave.ts | 42 ++++--- test/strategy-test.ts | 4 +- 9 files changed, 190 insertions(+), 129 deletions(-) rename contracts/strategies/aave/{strategy-aave-wavax.sol => strategy-aave-wavax.sol.disable} (100%) rename contracts/strategies/aave/{strategy-aave-wbtc.sol => strategy-aave-wbtc.sol.disable} (100%) rename contracts/strategies/aave/{strategy-aave-weth.sol => strategy-aave-weth.sol.disable} (100%) diff --git a/contracts/interfaces/aave.sol b/contracts/interfaces/aave.sol index d9761fd01..c8fd7ff0e 100644 --- a/contracts/interfaces/aave.sol +++ b/contracts/interfaces/aave.sol @@ -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, @@ -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); } diff --git a/contracts/strategies/aave/strategy-aave-daie.sol b/contracts/strategies/aave/strategy-aave-daie.sol index 31c6b2375..4d928211b 100644 --- a/contracts/strategies/aave/strategy-aave-daie.sol +++ b/contracts/strategies/aave/strategy-aave-daie.sol @@ -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 @@ -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 **** // @@ -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(); @@ -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 @@ -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 ); } @@ -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) { @@ -242,11 +252,11 @@ contract StrategyAaveDaiE is StrategyBase, Exponential { } // Leverages until we're supplying amount - // 1. Redeem DAI - // 2. Repay DAI + // 1. Redeem daie + // 2. Repay daie function leverageUntil(uint256 _supplyAmount) public onlyKeepers { - // 1. Borrow out DAI - // 2. Supply DAI + // 1. Borrow out daie + // 2. Supply daie uint256 leverage = getMaxLeverage(); uint256 unleveragedSupply = getSuppliedUnleveraged(); @@ -268,7 +278,7 @@ contract StrategyAaveDaiE is StrategyBase, Exponential { } ILendingPool(lendingPool).borrow( - dai, + daie, _borrowAndSupply, uint256(DataTypes.InterestRateMode.VARIABLE), REFERRAL_CODE, @@ -286,8 +296,8 @@ contract StrategyAaveDaiE is StrategyBase, Exponential { } // Deleverages until we're supplying amount - // 1. Redeem DAI - // 2. Repay DAI + // 1. Redeem daie + // 2. Repay daie function deleverageUntil(uint256 _supplyAmount) public onlyKeepers { uint256 unleveragedSupply = getSuppliedUnleveraged(); uint256 supplied = getSupplied(); @@ -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) @@ -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); @@ -356,10 +371,6 @@ 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); } @@ -367,14 +378,18 @@ contract StrategyAaveDaiE is StrategyBase, Exponential { _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 ); @@ -402,9 +417,9 @@ 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)); } } @@ -412,7 +427,7 @@ contract StrategyAaveDaiE is StrategyBase, Exponential { // withdraw require( ILendingPool(lendingPool).withdraw( - dai, + daie, _redeem, address(this) ) != 0, diff --git a/contracts/strategies/aave/strategy-aave-usdc.sol b/contracts/strategies/aave/strategy-aave-usdc.sol index d2ba18bda..7b21ce37d 100644 --- a/contracts/strategies/aave/strategy-aave-usdc.sol +++ b/contracts/strategies/aave/strategy-aave-usdc.sol @@ -14,17 +14,16 @@ import "../strategy-base.sol"; import "../strategy-joe-farm-base.sol"; contract StrategyAaveUsdc is StrategyBase, Exponential { - address public constant avusdc = 0x46A51127C3ce23fb7AB1DE06226147F446e4a857; - address public constant usdc = 0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664; - address public constant variableDebtUsdc = - 0x848c080d2700CBE1B894a3374AD5E887E5cCb89c; - address public constant lendingPool = - 0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C; - address public constant incentivesController = - 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9; - - uint256 public constant usdc_COLFACTOR = 750000000000000000; - uint16 public constant REFERRAL_CODE = 0xaa; + address public constant avusdc = 0x625E7708f30cA75bfd92586e17077590C60eb4cD; + address public constant usdc = 0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E; + address public constant variableDebtUsdc = 0xFCCf3cAbbe80101232d343252614b6A3eE81C989; + + address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + + address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; + + uint256 public constant usdc_COLFACTOR = 850000000000000000; + uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between // market collateral factor and strategy's collateral factor @@ -62,17 +61,26 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { // **** Views **** // function getName() external pure override returns (string memory) { - return "StrategyAaveUsdtV3"; + return "StrategyAaveUsdc"; } + /** + * @notice Returns the amount of tokens being supplied + */ function getSuppliedView() public view returns (uint256) { return IERC20(avusdc).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowedView() public view returns (uint256) { return IERC20(variableDebtUsdc).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(); @@ -121,15 +129,11 @@ contract StrategyAaveUsdc 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] = avusdc; - return - IAaveIncentivesController(incentivesController).getRewardsBalance( - avTokens, - address(this) + IAaveIncentivesController(incentivesController).getUserAccruedRewards( + address(this), + wavax ); } @@ -147,10 +151,16 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { return supplied.sub(borrowed); } + /** + * @notice Returns the amount of tokens being supplied + */ function getSupplied() public view returns (uint256) { return IERC20(avusdc).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowed() public view returns (uint256) { return IERC20(variableDebtUsdc).balanceOf(address(this)); } @@ -339,6 +349,9 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { } } + /** + * @notice Harvests the reward tokens for redeposit + */ function harvest() public override onlyBenevolent { address[] memory avTokens = new address[](1); avTokens[0] = avusdc; @@ -346,22 +359,18 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { 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); - IERC20(wavax).safeApprove(pangolinRouter, 0); - IERC20(wavax).safeApprove(pangolinRouter, _wavax); if (_keep > 0) { _takeFeeWavaxToSnob(_keep); } _wavax = IERC20(wavax).balanceOf(address(this)); - - IERC20(wavax).safeApprove(pangolinRouter, 0); - IERC20(wavax).safeApprove(pangolinRouter, _wavax); - _swapPangolin(wavax, want, _wavax); } @@ -369,14 +378,18 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { _distributePerformanceFeesAndDeposit(); } + /** + * @notice Deposits USDC 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 _usdc = IERC20(usdc).balanceOf(address(this)); + if (_usdc > 0) { + IERC20(usdc).safeApprove(lendingPool, 0); + IERC20(usdc).safeApprove(lendingPool, _usdc); + ILendingPool(lendingPool).deposit( usdc, - _want, + _usdc, address(this), REFERRAL_CODE ); diff --git a/contracts/strategies/aave/strategy-aave-usdt.sol b/contracts/strategies/aave/strategy-aave-usdt.sol index aa37f79da..0b05aabca 100644 --- a/contracts/strategies/aave/strategy-aave-usdt.sol +++ b/contracts/strategies/aave/strategy-aave-usdt.sol @@ -14,17 +14,16 @@ import "../strategy-base.sol"; import "../strategy-joe-farm-base.sol"; contract StrategyAaveUsdt is StrategyBase, Exponential { - address public constant avusdt = 0x532E6537FEA298397212F09A61e03311686f548e; - address public constant usdt = 0xc7198437980c041c805A1EDcbA50c1Ce5db95118; - address public constant variableDebtUsdt = - 0xfc1AdA7A288d6fCe0d29CcfAAa57Bc9114bb2DbE; - address public constant lendingPool = - 0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C; - address public constant incentivesController = - 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9; - - uint256 public constant usdt_COLFACTOR = 0; - uint16 public constant REFERRAL_CODE = 0xaa; + address public constant avusdt = 0x6ab707Aca953eDAeFBc4fD23bA73294241490620; + address public constant usdt = 0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7; + address public constant variableDebtUsdt = 0xfb00AC187a8Eb5AFAE4eACE434F493Eb62672df7; + + address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + + address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; + + uint256 public constant usdt_COLFACTOR = 800000000000000000; + uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between // market collateral factor and strategy's collateral factor @@ -62,17 +61,26 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { // **** Views **** // function getName() external pure override returns (string memory) { - return "StrategyAaveUsdtV3"; + return "StrategyAaveUsdt"; } + /** + * @notice Returns the amount of tokens being supplied + */ function getSuppliedView() public view returns (uint256) { return IERC20(avusdt).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowedView() public view returns (uint256) { return IERC20(variableDebtUsdt).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(); @@ -123,13 +131,11 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { */ function getWavaxAccrued() public view returns (uint256) { - address[] memory avTokens = new address[](1); - avTokens[0] = avusdt; return - IAaveIncentivesController(incentivesController).getRewardsBalance( - avTokens, - address(this) + IAaveIncentivesController(incentivesController).getUserAccruedRewards( + address(this), + wavax ); } @@ -147,10 +153,16 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { return supplied.sub(borrowed); } + /** + * @notice Returns the amount of tokens being supplied + */ function getSupplied() public view returns (uint256) { return IERC20(avusdt).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowed() public view returns (uint256) { return IERC20(variableDebtUsdt).balanceOf(address(this)); } @@ -346,8 +358,10 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { 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); @@ -356,10 +370,6 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { } _wavax = IERC20(wavax).balanceOf(address(this)); - - IERC20(wavax).safeApprove(pangolinRouter, 0); - IERC20(wavax).safeApprove(pangolinRouter, _wavax); - _swapPangolin(wavax, want, _wavax); } @@ -367,14 +377,18 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { _distributePerformanceFeesAndDeposit(); } + + /** + * @notice Deposits USDT 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 _usdt = IERC20(usdt).balanceOf(address(this)); + if (_usdt > 0) { + IERC20(usdt).safeApprove(lendingPool, 0); + IERC20(usdt).safeApprove(lendingPool, _usdt); ILendingPool(lendingPool).deposit( usdt, - _want, + _usdt, address(this), REFERRAL_CODE ); diff --git a/contracts/strategies/aave/strategy-aave-wavax.sol b/contracts/strategies/aave/strategy-aave-wavax.sol.disable similarity index 100% rename from contracts/strategies/aave/strategy-aave-wavax.sol rename to contracts/strategies/aave/strategy-aave-wavax.sol.disable diff --git a/contracts/strategies/aave/strategy-aave-wbtc.sol b/contracts/strategies/aave/strategy-aave-wbtc.sol.disable similarity index 100% rename from contracts/strategies/aave/strategy-aave-wbtc.sol rename to contracts/strategies/aave/strategy-aave-wbtc.sol.disable diff --git a/contracts/strategies/aave/strategy-aave-weth.sol b/contracts/strategies/aave/strategy-aave-weth.sol.disable similarity index 100% rename from contracts/strategies/aave/strategy-aave-weth.sol rename to contracts/strategies/aave/strategy-aave-weth.sol.disable diff --git a/test/FoldingStrats/aave.ts b/test/FoldingStrats/aave.ts index 40785a528..c7bbca482 100644 --- a/test/FoldingStrats/aave.ts +++ b/test/FoldingStrats/aave.ts @@ -11,17 +11,27 @@ const tests = [ // fold: true, // controller: "aave", // }, - // { - // name: "AaveUsdc", - // fold: true, - // controller: "optimizer", - // }, - // { - // name: "AaveUsdt", - // fold: false, - // controller: "optimizer", - // slot: 0 - // }, + { + name: "AaveUsdc", + fold: true, + timelockIsStrategist: true, + slot: 9, + controller: "aave", + }, + { + name: "AaveUsdt", + fold: true, + timelockIsStrategist: true, + controller: "aave", + slot: 51 + }, + { + name: "AaveDaiE", + fold: true, + timelockIsStrategist: true, + controller: "aave", + slot: 0 + }, // { // name: "AaveWbtc", // slot: 0, @@ -34,11 +44,11 @@ const tests = [ // fold: true, // controller: "optimizer", // }, - { - name: "AaveWavax", - controller:"optimizer", - slot: 3 - }, + // { + // name: "AaveWavax", + // controller:"optimizer", + // slot: 3 + // }, ]; diff --git a/test/strategy-test.ts b/test/strategy-test.ts index 72f9777ab..4f64ef64c 100644 --- a/test/strategy-test.ts +++ b/test/strategy-test.ts @@ -63,7 +63,7 @@ export function doStrategyTest(test_case: TestableStrategy) { let timelock_addr: string; let snapshotId: string; - let txnAmt: string = "25000000000000000000000"; + let txnAmt: string = "250000000000"; describe( "Tests for: " + name, async () => { @@ -151,12 +151,12 @@ export function doStrategyTest(test_case: TestableStrategy) { await assetContract.connect(walletSigner).approve(snowglobe_addr, amt); await SnowGlobe.connect(walletSigner).depositAll(); - let userBal = await assetContract.connect(walletSigner).balanceOf(wallet_addr); expect(userBal).to.be.equals(BigNumber.from("0x0")); let balAfter = await assetContract.connect(walletSigner).balanceOf(snowglobe_addr); + expect(balBefore).to.be.lt(balAfter); await SnowGlobe.connect(walletSigner).earn(); From 73de720f5bf0cde1057dec02890a0e79cd1dbd26 Mon Sep 17 00:00:00 2001 From: zeroecksYeti Date: Fri, 22 Apr 2022 11:54:48 -0700 Subject: [PATCH 2/4] update remaining aave strats --- ...ax.sol.disable => strategy-aave-wavax.sol} | 49 ++++++++------- ...btc.sol.disable => strategy-aave-wbtc.sol} | 18 +++--- ...eth.sol.disable => strategy-aave-weth.sol} | 18 +++--- test/FoldingStrats/aave.ts | 60 ++++++++++--------- 4 files changed, 72 insertions(+), 73 deletions(-) rename contracts/strategies/aave/{strategy-aave-wavax.sol.disable => strategy-aave-wavax.sol} (89%) rename contracts/strategies/aave/{strategy-aave-wbtc.sol.disable => strategy-aave-wbtc.sol} (96%) rename contracts/strategies/aave/{strategy-aave-weth.sol.disable => strategy-aave-weth.sol} (96%) diff --git a/contracts/strategies/aave/strategy-aave-wavax.sol.disable b/contracts/strategies/aave/strategy-aave-wavax.sol similarity index 89% rename from contracts/strategies/aave/strategy-aave-wavax.sol.disable rename to contracts/strategies/aave/strategy-aave-wavax.sol index c252fbe70..497b7d91c 100644 --- a/contracts/strategies/aave/strategy-aave-wavax.sol.disable +++ b/contracts/strategies/aave/strategy-aave-wavax.sol @@ -14,17 +14,13 @@ import "../strategy-base.sol"; import "../strategy-joe-farm-base.sol"; contract StrategyAaveWavax is StrategyBase, Exponential { - address public constant avwavax = - 0xDFE521292EcE2A4f44242efBcD66Bc594CA9714B; - address public constant variableDebtWavax = - 0x66A0FE52Fb629a6cB4D10B8580AFDffE888F5Fd4; - address public constant lendingPool = - 0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C; - address public constant incentivesController = - 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9; - - uint256 public constant wavax_COLFACTOR = 500000000000000000; - uint16 public constant REFERRAL_CODE = 0xaa; + address public constant avwavax = 0x6d80113e533a2C0fe82EaBD35f1875DcEA89Ea97; + address public constant variableDebtWavax = 0x4a1c3aD6Ed28a636ee1751C69071f6be75DEb8B8; + address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; + + uint256 public constant wavax_COLFACTOR = 700000000000000000; + uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between // market collateral factor and strategy's collateral factor @@ -60,27 +56,29 @@ contract StrategyAaveWavax is StrategyBase, Exponential { } // **** Views **** // - + ///@notice Return the strategy name function getName() external pure override returns (string memory) { return "StrategyAaveWavaxV3"; } - + + ///@notice Return the amount of tokens being supplied function getSuppliedView() public view returns (uint256) { return IERC20(avwavax).balanceOf(address(this)); } - + + ///@notice Return the amount of tokens being borrowed function getBorrowedView() public view returns (uint256) { return IERC20(variableDebtWavax).balanceOf(address(this)); } + ///@notice Return 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(); return supplied.sub(borrowed); } - // Given an unleveraged supply balance, return the target - // leveraged supply balance which is still within the safety buffer + ///@notice Given an unleveraged supply balance, return the target leveraged supply balance which is still within the safety buffer function getLeveragedSupplyTarget(uint256 supplyBalance) public view @@ -147,10 +145,12 @@ contract StrategyAaveWavax is StrategyBase, Exponential { return supplied.sub(borrowed); } + ///@notice Return the amount of tokens being supplied function getSupplied() public view returns (uint256) { return IERC20(avwavax).balanceOf(address(this)); } + ///@notice Return the amount of tokens being borrowed function getBorrowed() public view returns (uint256) { return IERC20(variableDebtWavax).balanceOf(address(this)); } @@ -216,8 +216,7 @@ contract StrategyAaveWavax is StrategyBase, Exponential { // **** State mutations **** // - // Do a `callStatic` on this. - // If it returns true then run it for realz. (i.e. eth_signedTx, not eth_call) + ///@notice Do a `callStatic` on this. If it returns true then run it for realz. (i.e. eth_signedTx, not eth_call) function sync() public returns (bool) { uint256 colFactor = getColFactor(); uint256 safeLeverageColFactor = getSafeLeverageColFactor(); @@ -241,7 +240,7 @@ contract StrategyAaveWavax is StrategyBase, Exponential { leverageUntil(idealSupply); } - // Leverages until we're supplying amount + ///@notice Leverages until we're supplying amount // 1. Redeem wavax // 2. Repay wavax function leverageUntil(uint256 _supplyAmount) public onlyKeepers { @@ -256,8 +255,7 @@ contract StrategyAaveWavax is StrategyBase, Exponential { "!leverage" ); - // Since we're only leveraging one asset - // Supplied = borrowed + // Since we're only leveraging one asset, supplied = borrowed uint256 _borrowAndSupply; uint256 supplied = getSupplied(); while (supplied < _supplyAmount) { @@ -285,7 +283,7 @@ contract StrategyAaveWavax is StrategyBase, Exponential { deleverageUntil(unleveragedSupply); } - // Deleverages until we're supplying amount + ///@notice Deleverages until we're supplying amount // 1. Redeem wavax // 2. Repay wavax function deleverageUntil(uint256 _supplyAmount) public onlyKeepers { @@ -299,7 +297,7 @@ contract StrategyAaveWavax is StrategyBase, Exponential { // Market collateral factor uint256 marketColFactor = getMarketColFactor(); - // How much can we redeem + // How much can we redeem? uint256 _redeemAndRepay = getRedeemable(); while (supplied > _supplyAmount) { // If the amount we're redeeming is exceeding the @@ -346,7 +344,8 @@ contract StrategyAaveWavax is StrategyBase, Exponential { IAaveIncentivesController(incentivesController).claimRewards( avTokens, uint256(-1), - address(this) + address(this), + wavax ); uint256 _wavax = IERC20(wavax).balanceOf(address(this)); if (_wavax > 0) { @@ -394,7 +393,7 @@ contract StrategyAaveWavax is StrategyBase, Exponential { if (borrowedToBeFree > borrowed) { this.deleverageToMin(); } else { - // Otherwise just keep freeing up borrowed amounts until + // Keep freeing up borrowed amounts until // we hit a safe number to redeem our underlying this.deleverageUntil(supplied.sub(borrowedToBeFree)); } diff --git a/contracts/strategies/aave/strategy-aave-wbtc.sol.disable b/contracts/strategies/aave/strategy-aave-wbtc.sol similarity index 96% rename from contracts/strategies/aave/strategy-aave-wbtc.sol.disable rename to contracts/strategies/aave/strategy-aave-wbtc.sol index 8d6b4303e..e7945c2ea 100644 --- a/contracts/strategies/aave/strategy-aave-wbtc.sol.disable +++ b/contracts/strategies/aave/strategy-aave-wbtc.sol @@ -14,17 +14,14 @@ import "../strategy-base.sol"; import "../strategy-joe-farm-base.sol"; contract StrategyAaveWbtc is StrategyBase, Exponential { - address public constant avwbtc = 0x686bEF2417b6Dc32C50a3cBfbCC3bb60E1e9a15D; + address public constant avwbtc = 0x078f358208685046a11C85e8ad32895DED33A249; address public constant wbtc = 0x50b7545627a5162F82A992c33b87aDc75187B218; - address public constant variableDebtWbtc = - 0x2dc0E35eC3Ab070B8a175C829e23650Ee604a9eB; - address public constant lendingPool = - 0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C; - address public constant incentivesController = - 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9; + address public constant variableDebtWbtc = 0x92b42c66840C7AD907b4BF74879FF3eF7c529473; + address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; - uint256 public constant wbtc_COLFACTOR = 600000000000000000; - uint16 public constant REFERRAL_CODE = 0xaa; + uint256 public constant wbtc_COLFACTOR = 750000000000000000; + uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between // market collateral factor and strategy's collateral factor @@ -346,7 +343,8 @@ contract StrategyAaveWbtc is StrategyBase, Exponential { IAaveIncentivesController(incentivesController).claimRewards( avTokens, uint256(-1), - address(this) + address(this), + wavax ); uint256 _wavax = IERC20(wavax).balanceOf(address(this)); if (_wavax > 0) { diff --git a/contracts/strategies/aave/strategy-aave-weth.sol.disable b/contracts/strategies/aave/strategy-aave-weth.sol similarity index 96% rename from contracts/strategies/aave/strategy-aave-weth.sol.disable rename to contracts/strategies/aave/strategy-aave-weth.sol index 3fb974b28..f0a4eed94 100644 --- a/contracts/strategies/aave/strategy-aave-weth.sol.disable +++ b/contracts/strategies/aave/strategy-aave-weth.sol @@ -14,16 +14,13 @@ import "../strategy-base.sol"; import "../strategy-joe-farm-base.sol"; contract StrategyAaveWeth is StrategyBase, Exponential { - address public constant avweth = 0x53f7c5869a859F0AeC3D334ee8B4Cf01E3492f21; + address public constant avweth = 0xe50fA9b3c56FfB159cB0FCA61F5c9D750e8128c8; address public constant weth = 0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB; - address public constant variableDebtWeth = - 0x4e575CacB37bc1b5afEc68a0462c4165A5268983; - address public constant lendingPool = - 0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C; - address public constant incentivesController = - 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9; - - uint256 public constant weth_COLFACTOR = 800000000000000000; + address public constant variableDebtWeth = 0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351; + address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; + + uint256 public constant weth_COLFACTOR = 825000000000000000; uint16 public constant REFERRAL_CODE = 0xaa; // Require a 0.04 buffer between @@ -346,7 +343,8 @@ contract StrategyAaveWeth is StrategyBase, Exponential { IAaveIncentivesController(incentivesController).claimRewards( avTokens, uint256(-1), - address(this) + address(this), + wavax ); uint256 _wavax = IERC20(wavax).balanceOf(address(this)); if (_wavax > 0) { diff --git a/test/FoldingStrats/aave.ts b/test/FoldingStrats/aave.ts index c7bbca482..a012fd4a0 100644 --- a/test/FoldingStrats/aave.ts +++ b/test/FoldingStrats/aave.ts @@ -11,42 +11,46 @@ const tests = [ // fold: true, // controller: "aave", // }, - { - name: "AaveUsdc", - fold: true, - timelockIsStrategist: true, - slot: 9, - controller: "aave", - }, - { - name: "AaveUsdt", - fold: true, - timelockIsStrategist: true, - controller: "aave", - slot: 51 - }, - { - name: "AaveDaiE", - fold: true, - timelockIsStrategist: true, - controller: "aave", - slot: 0 - }, // { - // name: "AaveWbtc", - // slot: 0, + // name: "AaveUsdc", // fold: true, - // controller: "optimizer", + // timelockIsStrategist: true, + // slot: 9, + // controller: "aave", // }, // { - // name: "AaveWeth", - // slot: 0, + // name: "AaveUsdt", // fold: true, - // controller: "optimizer", + // timelockIsStrategist: true, + // controller: "aave", + // slot: 51 + // }, + // { + // name: "AaveDaiE", + // fold: true, + // timelockIsStrategist: true, + // controller: "aave", + // slot: 0 + // }, + // { + // name: "AaveWbtc", + // fold: true, + // timelockIsStrategist: true, + // slot: 0, + // controller: "aave", // }, + { + name: "AaveWeth", + fold: true, + timelockIsStrategist: true, + slot: 0, + controller: "aave" + }, // { // name: "AaveWavax", - // controller:"optimizer", + // fold: true, + // timelockIsStrategist: true, + // controller:"aave", // slot: 3 // }, From 7e5c9971a02ee4a985d9d9a3c378dbf54dc5d121 Mon Sep 17 00:00:00 2001 From: zeroecksYeti Date: Fri, 22 Apr 2022 16:53:38 -0700 Subject: [PATCH 3/4] update colfactor on aave strats --- contracts/strategies/aave/strategy-aave-usdc.sol | 2 +- contracts/strategies/aave/strategy-aave-usdt.sol | 2 +- contracts/strategies/aave/strategy-aave-wavax.sol | 2 +- contracts/strategies/aave/strategy-aave-wbtc.sol | 2 +- contracts/strategies/aave/strategy-aave-weth.sol | 12 +++++++++--- test/strategy-test.ts | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/contracts/strategies/aave/strategy-aave-usdc.sol b/contracts/strategies/aave/strategy-aave-usdc.sol index 7b21ce37d..f4f0b9e46 100644 --- a/contracts/strategies/aave/strategy-aave-usdc.sol +++ b/contracts/strategies/aave/strategy-aave-usdc.sol @@ -22,7 +22,7 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; - uint256 public constant usdc_COLFACTOR = 850000000000000000; + uint256 public constant usdc_COLFACTOR = 82500000000000000000; uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between diff --git a/contracts/strategies/aave/strategy-aave-usdt.sol b/contracts/strategies/aave/strategy-aave-usdt.sol index 0b05aabca..c811528b0 100644 --- a/contracts/strategies/aave/strategy-aave-usdt.sol +++ b/contracts/strategies/aave/strategy-aave-usdt.sol @@ -22,7 +22,7 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; - uint256 public constant usdt_COLFACTOR = 800000000000000000; + uint256 public constant usdt_COLFACTOR = 75000000000000000000; uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between diff --git a/contracts/strategies/aave/strategy-aave-wavax.sol b/contracts/strategies/aave/strategy-aave-wavax.sol index 497b7d91c..8295e1c26 100644 --- a/contracts/strategies/aave/strategy-aave-wavax.sol +++ b/contracts/strategies/aave/strategy-aave-wavax.sol @@ -19,7 +19,7 @@ contract StrategyAaveWavax is StrategyBase, Exponential { address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; - uint256 public constant wavax_COLFACTOR = 700000000000000000; + uint256 public constant wavax_COLFACTOR = 65000000000000000000; uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between diff --git a/contracts/strategies/aave/strategy-aave-wbtc.sol b/contracts/strategies/aave/strategy-aave-wbtc.sol index e7945c2ea..ade7b1a09 100644 --- a/contracts/strategies/aave/strategy-aave-wbtc.sol +++ b/contracts/strategies/aave/strategy-aave-wbtc.sol @@ -20,7 +20,7 @@ contract StrategyAaveWbtc is StrategyBase, Exponential { address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; - uint256 public constant wbtc_COLFACTOR = 750000000000000000; + uint256 public constant wbtc_COLFACTOR = 70000000000000000000; uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between diff --git a/contracts/strategies/aave/strategy-aave-weth.sol b/contracts/strategies/aave/strategy-aave-weth.sol index f0a4eed94..10e4e7ab0 100644 --- a/contracts/strategies/aave/strategy-aave-weth.sol +++ b/contracts/strategies/aave/strategy-aave-weth.sol @@ -13,6 +13,8 @@ import "../../interfaces/aave.sol"; import "../strategy-base.sol"; import "../strategy-joe-farm-base.sol"; +import "hardhat/console.sol"; + contract StrategyAaveWeth is StrategyBase, Exponential { address public constant avweth = 0xe50fA9b3c56FfB159cB0FCA61F5c9D750e8128c8; address public constant weth = 0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB; @@ -20,8 +22,8 @@ contract StrategyAaveWeth is StrategyBase, Exponential { address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; - uint256 public constant weth_COLFACTOR = 825000000000000000; - uint16 public constant REFERRAL_CODE = 0xaa; + uint256 public constant weth_COLFACTOR = 80000000000000000000; + uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between // market collateral factor and strategy's collateral factor @@ -247,6 +249,8 @@ contract StrategyAaveWeth is StrategyBase, Exponential { uint256 leverage = getMaxLeverage(); uint256 unleveragedSupply = getSuppliedUnleveraged(); + console.log("This is the unleveragedSupply balance:", unleveragedSupply); + require( _supplyAmount >= unleveragedSupply && _supplyAmount <= unleveragedSupply.mul(leverage).div(1e18), @@ -259,10 +263,12 @@ contract StrategyAaveWeth is StrategyBase, Exponential { uint256 supplied = getSupplied(); while (supplied < _supplyAmount) { _borrowAndSupply = getBorrowable(); + console.log("This is the borrowAndSupply value:", _borrowAndSupply); if (supplied.add(_borrowAndSupply) > _supplyAmount) { _borrowAndSupply = _supplyAmount.sub(supplied); } + console.log("This is the supplyAmount:", _supplyAmount); ILendingPool(lendingPool).borrow( weth, @@ -364,9 +370,9 @@ contract StrategyAaveWeth is StrategyBase, Exponential { _distributePerformanceFeesAndDeposit(); } - function deposit() public override { uint256 _want = IERC20(want).balanceOf(address(this)); + console.log("This is the Want balance", _want); if (_want > 0) { IERC20(want).safeApprove(lendingPool, 0); IERC20(want).safeApprove(lendingPool, _want); diff --git a/test/strategy-test.ts b/test/strategy-test.ts index 4f64ef64c..68fac7fa8 100644 --- a/test/strategy-test.ts +++ b/test/strategy-test.ts @@ -63,7 +63,7 @@ export function doStrategyTest(test_case: TestableStrategy) { let timelock_addr: string; let snapshotId: string; - let txnAmt: string = "250000000000"; + let txnAmt: string = "25000000000000000000000"; describe( "Tests for: " + name, async () => { From bbfa845e79f0d31512b68285ecaa46ccce0f0e47 Mon Sep 17 00:00:00 2001 From: zeroecksYeti Date: Wed, 27 Apr 2022 09:54:04 -0700 Subject: [PATCH 4/4] deploy usdc and usdt strats --- flat/aave/snowglobe-aave-usdc.sol | 2 +- flat/aave/snowglobe-aave-usdt.sol | 2 +- flat/aave/strategy-aave-usdc.sol | 162 +++++++++++++++++++++++------- flat/aave/strategy-aave-usdt.sol | 155 ++++++++++++++++++++++------ scripts/flatten-strategy-globe.js | 5 +- test/FoldingStrats/aave.ts | 40 ++++---- 6 files changed, 276 insertions(+), 90 deletions(-) diff --git a/flat/aave/snowglobe-aave-usdc.sol b/flat/aave/snowglobe-aave-usdc.sol index 110be912e..8e67c3cef 100644 --- a/flat/aave/snowglobe-aave-usdc.sol +++ b/flat/aave/snowglobe-aave-usdc.sol @@ -1,4 +1,4 @@ -// Sources flattened with hardhat v2.8.0 https://hardhat.org +// Sources flattened with hardhat v2.8.3 https://hardhat.org // File contracts/interfaces/controller.sol diff --git a/flat/aave/snowglobe-aave-usdt.sol b/flat/aave/snowglobe-aave-usdt.sol index 40a033ac5..fb6b4035b 100644 --- a/flat/aave/snowglobe-aave-usdt.sol +++ b/flat/aave/snowglobe-aave-usdt.sol @@ -1,4 +1,4 @@ -// Sources flattened with hardhat v2.8.0 https://hardhat.org +// Sources flattened with hardhat v2.8.3 https://hardhat.org // File contracts/interfaces/controller.sol diff --git a/flat/aave/strategy-aave-usdc.sol b/flat/aave/strategy-aave-usdc.sol index 191c72e77..fffaebb11 100644 --- a/flat/aave/strategy-aave-usdc.sol +++ b/flat/aave/strategy-aave-usdc.sol @@ -1,4 +1,4 @@ -// Sources flattened with hardhat v2.8.0 https://hardhat.org +// Sources flattened with hardhat v2.8.3 https://hardhat.org // File contracts/lib/safe-math.sol @@ -1585,9 +1585,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, @@ -1600,6 +1606,9 @@ interface IAaveIncentivesController { view returns (uint256); + function getUserAccruedRewards(address user, address reward) + external view returns (uint256); + function REWARD_TOKEN() external view returns (address); } @@ -2377,9 +2386,8 @@ pragma solidity ^0.6.7; // interface for MasterChefJoeV2 contract interface IMasterChefJoeV2 { - /* Reads */ - function userInfo(uint256, address) external view returns ( + function userInfo(uint256 pid, address) external view returns ( uint256 amount, uint256 rewardDebt ); @@ -2435,6 +2443,66 @@ interface IMasterChefJoeV2 { ) external; } +// interface for MasterChefJoe contracts +interface IMasterChefJoe { + + /* Reads */ + function userInfo(uint256 pid, address) external view returns ( + uint256 amount, + uint256 rewardDebt, + uint256 factor + ); + + function poolInfo(uint256 pid) external view returns ( + IERC20 lpToken, // Address of LP token contract. + uint256 allocPoint, // How many allocation points assigned to this poolInfo. SUSHI to distribute per block. + uint256 lastRewardTimestamp, // Last block timestamp that SUSHI distribution occurs. + uint256 accJoePerShare, // Accumulated SUSHI per share, times 1e12. See below. + address rewarder + ); + + function totalAllocPoint() external view returns (uint256); + + function poolLength() external view returns (uint256); + + function pendingTokens(uint256 _pid, address _user) + external + view + returns ( + uint256 pendingJoe, + address bonusTokenAddress, + string memory bonusTokenSymbol, + uint256 pendingBonusToken + ); + + /* Writes */ + + function add( + uint256 _allocPoint, + address _lpToken, + address _rewarder + ) external; + + function set( + uint256 _pid, + uint256 _allocPoint, + IJoeRewarder _rewarder, + bool overwrite + ) external; + + function updatePool(uint256 _pid) external; + + function deposit( + uint256 _pid, + uint256 _amount + ) external; + + function withdraw( + uint256 _pid, + uint256 _amount + ) external; +} + // File contracts/interfaces/joe.sol @@ -2443,6 +2511,14 @@ pragma solidity ^0.6.2; interface IJoeRouter { + ///@param tokenA is the first token in the lp + ///@param tokenB is the second token in the lp + ///@param amountADesired is the amount of token A to be deposited in the lp + ///@param amountBDesired is the amount of token B to be deposited in the lp + ///@param amountAMin is the minimum amount of token A we expect to be deposited in the lp + ///@param amountBMin is the minimum amount of token B we expect to be deposited in the lp + ///@param to address we're depositing to + ///@param deadline the timeout length of the addLiquidity call function addLiquidity( address tokenA, address tokenB, @@ -2741,6 +2817,9 @@ abstract contract StrategyJoeFarmBase is StrategyBase { ) internal { require(_to != address(0)); + IERC20(_from).safeApprove(joeRouter, 0); + IERC20(_from).safeApprove(joeRouter, _amount); + address[] memory path; if (_from == wavax || _to == wavax) { @@ -2811,17 +2890,16 @@ pragma solidity ^0.6.7; contract StrategyAaveUsdc is StrategyBase, Exponential { - address public constant avusdc = 0x46A51127C3ce23fb7AB1DE06226147F446e4a857; - address public constant usdc = 0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664; - address public constant variableDebtUsdc = - 0x848c080d2700CBE1B894a3374AD5E887E5cCb89c; - address public constant lendingPool = - 0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C; - address public constant incentivesController = - 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9; - - uint256 public constant usdc_COLFACTOR = 750000000000000000; - uint16 public constant REFERRAL_CODE = 0xaa; + address public constant avusdc = 0x625E7708f30cA75bfd92586e17077590C60eb4cD; + address public constant usdc = 0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E; + address public constant variableDebtUsdc = 0xFCCf3cAbbe80101232d343252614b6A3eE81C989; + + address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + + address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; + + uint256 public constant usdc_COLFACTOR = 82500000000000000000; + uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between // market collateral factor and strategy's collateral factor @@ -2859,17 +2937,26 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { // **** Views **** // function getName() external pure override returns (string memory) { - return "StrategyAaveUsdtV3"; + return "StrategyAaveUsdc"; } + /** + * @notice Returns the amount of tokens being supplied + */ function getSuppliedView() public view returns (uint256) { return IERC20(avusdc).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowedView() public view returns (uint256) { return IERC20(variableDebtUsdc).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(); @@ -2918,15 +3005,11 @@ contract StrategyAaveUsdc 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] = avusdc; - return - IAaveIncentivesController(incentivesController).getRewardsBalance( - avTokens, - address(this) + IAaveIncentivesController(incentivesController).getUserAccruedRewards( + address(this), + wavax ); } @@ -2944,10 +3027,16 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { return supplied.sub(borrowed); } + /** + * @notice Returns the amount of tokens being supplied + */ function getSupplied() public view returns (uint256) { return IERC20(avusdc).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowed() public view returns (uint256) { return IERC20(variableDebtUsdc).balanceOf(address(this)); } @@ -3136,6 +3225,9 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { } } + /** + * @notice Harvests the reward tokens for redeposit + */ function harvest() public override onlyBenevolent { address[] memory avTokens = new address[](1); avTokens[0] = avusdc; @@ -3143,22 +3235,18 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { 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); - IERC20(wavax).safeApprove(pangolinRouter, 0); - IERC20(wavax).safeApprove(pangolinRouter, _wavax); if (_keep > 0) { _takeFeeWavaxToSnob(_keep); } _wavax = IERC20(wavax).balanceOf(address(this)); - - IERC20(wavax).safeApprove(pangolinRouter, 0); - IERC20(wavax).safeApprove(pangolinRouter, _wavax); - _swapPangolin(wavax, want, _wavax); } @@ -3166,14 +3254,18 @@ contract StrategyAaveUsdc is StrategyBase, Exponential { _distributePerformanceFeesAndDeposit(); } + /** + * @notice Deposits USDC 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 _usdc = IERC20(usdc).balanceOf(address(this)); + if (_usdc > 0) { + IERC20(usdc).safeApprove(lendingPool, 0); + IERC20(usdc).safeApprove(lendingPool, _usdc); + ILendingPool(lendingPool).deposit( usdc, - _want, + _usdc, address(this), REFERRAL_CODE ); diff --git a/flat/aave/strategy-aave-usdt.sol b/flat/aave/strategy-aave-usdt.sol index 4d221b288..365678177 100644 --- a/flat/aave/strategy-aave-usdt.sol +++ b/flat/aave/strategy-aave-usdt.sol @@ -1,4 +1,4 @@ -// Sources flattened with hardhat v2.8.0 https://hardhat.org +// Sources flattened with hardhat v2.8.3 https://hardhat.org // File contracts/lib/safe-math.sol @@ -1585,9 +1585,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, @@ -1600,6 +1606,9 @@ interface IAaveIncentivesController { view returns (uint256); + function getUserAccruedRewards(address user, address reward) + external view returns (uint256); + function REWARD_TOKEN() external view returns (address); } @@ -2377,9 +2386,8 @@ pragma solidity ^0.6.7; // interface for MasterChefJoeV2 contract interface IMasterChefJoeV2 { - /* Reads */ - function userInfo(uint256, address) external view returns ( + function userInfo(uint256 pid, address) external view returns ( uint256 amount, uint256 rewardDebt ); @@ -2435,6 +2443,66 @@ interface IMasterChefJoeV2 { ) external; } +// interface for MasterChefJoe contracts +interface IMasterChefJoe { + + /* Reads */ + function userInfo(uint256 pid, address) external view returns ( + uint256 amount, + uint256 rewardDebt, + uint256 factor + ); + + function poolInfo(uint256 pid) external view returns ( + IERC20 lpToken, // Address of LP token contract. + uint256 allocPoint, // How many allocation points assigned to this poolInfo. SUSHI to distribute per block. + uint256 lastRewardTimestamp, // Last block timestamp that SUSHI distribution occurs. + uint256 accJoePerShare, // Accumulated SUSHI per share, times 1e12. See below. + address rewarder + ); + + function totalAllocPoint() external view returns (uint256); + + function poolLength() external view returns (uint256); + + function pendingTokens(uint256 _pid, address _user) + external + view + returns ( + uint256 pendingJoe, + address bonusTokenAddress, + string memory bonusTokenSymbol, + uint256 pendingBonusToken + ); + + /* Writes */ + + function add( + uint256 _allocPoint, + address _lpToken, + address _rewarder + ) external; + + function set( + uint256 _pid, + uint256 _allocPoint, + IJoeRewarder _rewarder, + bool overwrite + ) external; + + function updatePool(uint256 _pid) external; + + function deposit( + uint256 _pid, + uint256 _amount + ) external; + + function withdraw( + uint256 _pid, + uint256 _amount + ) external; +} + // File contracts/interfaces/joe.sol @@ -2443,6 +2511,14 @@ pragma solidity ^0.6.2; interface IJoeRouter { + ///@param tokenA is the first token in the lp + ///@param tokenB is the second token in the lp + ///@param amountADesired is the amount of token A to be deposited in the lp + ///@param amountBDesired is the amount of token B to be deposited in the lp + ///@param amountAMin is the minimum amount of token A we expect to be deposited in the lp + ///@param amountBMin is the minimum amount of token B we expect to be deposited in the lp + ///@param to address we're depositing to + ///@param deadline the timeout length of the addLiquidity call function addLiquidity( address tokenA, address tokenB, @@ -2741,6 +2817,9 @@ abstract contract StrategyJoeFarmBase is StrategyBase { ) internal { require(_to != address(0)); + IERC20(_from).safeApprove(joeRouter, 0); + IERC20(_from).safeApprove(joeRouter, _amount); + address[] memory path; if (_from == wavax || _to == wavax) { @@ -2811,17 +2890,16 @@ pragma solidity ^0.6.7; contract StrategyAaveUsdt is StrategyBase, Exponential { - address public constant avusdt = 0x532E6537FEA298397212F09A61e03311686f548e; - address public constant usdt = 0xc7198437980c041c805A1EDcbA50c1Ce5db95118; - address public constant variableDebtUsdt = - 0xfc1AdA7A288d6fCe0d29CcfAAa57Bc9114bb2DbE; - address public constant lendingPool = - 0x4F01AeD16D97E3aB5ab2B501154DC9bb0F1A5A2C; - address public constant incentivesController = - 0x01D83Fe6A10D2f2B7AF17034343746188272cAc9; - - uint256 public constant usdt_COLFACTOR = 0; - uint16 public constant REFERRAL_CODE = 0xaa; + address public constant avusdt = 0x6ab707Aca953eDAeFBc4fD23bA73294241490620; + address public constant usdt = 0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7; + address public constant variableDebtUsdt = 0xfb00AC187a8Eb5AFAE4eACE434F493Eb62672df7; + + address public constant lendingPool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + + address public constant incentivesController = 0x929EC64c34a17401F460460D4B9390518E5B473e; + + uint256 public constant usdt_COLFACTOR = 75000000000000000000; + uint16 public constant REFERRAL_CODE = 0; // Require a 0.04 buffer between // market collateral factor and strategy's collateral factor @@ -2859,17 +2937,26 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { // **** Views **** // function getName() external pure override returns (string memory) { - return "StrategyAaveUsdtV3"; + return "StrategyAaveUsdt"; } + /** + * @notice Returns the amount of tokens being supplied + */ function getSuppliedView() public view returns (uint256) { return IERC20(avusdt).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowedView() public view returns (uint256) { return IERC20(variableDebtUsdt).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(); @@ -2920,13 +3007,11 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { */ function getWavaxAccrued() public view returns (uint256) { - address[] memory avTokens = new address[](1); - avTokens[0] = avusdt; return - IAaveIncentivesController(incentivesController).getRewardsBalance( - avTokens, - address(this) + IAaveIncentivesController(incentivesController).getUserAccruedRewards( + address(this), + wavax ); } @@ -2944,10 +3029,16 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { return supplied.sub(borrowed); } + /** + * @notice Returns the amount of tokens being supplied + */ function getSupplied() public view returns (uint256) { return IERC20(avusdt).balanceOf(address(this)); } + /** + * @notice Returns the amount of tokens being borrowed + */ function getBorrowed() public view returns (uint256) { return IERC20(variableDebtUsdt).balanceOf(address(this)); } @@ -3143,8 +3234,10 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { 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); @@ -3153,10 +3246,6 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { } _wavax = IERC20(wavax).balanceOf(address(this)); - - IERC20(wavax).safeApprove(pangolinRouter, 0); - IERC20(wavax).safeApprove(pangolinRouter, _wavax); - _swapPangolin(wavax, want, _wavax); } @@ -3164,14 +3253,18 @@ contract StrategyAaveUsdt is StrategyBase, Exponential { _distributePerformanceFeesAndDeposit(); } + + /** + * @notice Deposits USDT 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 _usdt = IERC20(usdt).balanceOf(address(this)); + if (_usdt > 0) { + IERC20(usdt).safeApprove(lendingPool, 0); + IERC20(usdt).safeApprove(lendingPool, _usdt); ILendingPool(lendingPool).deposit( usdt, - _want, + _usdt, address(this), REFERRAL_CODE ); diff --git a/scripts/flatten-strategy-globe.js b/scripts/flatten-strategy-globe.js index 3eaaa5bc2..bb506a51a 100644 --- a/scripts/flatten-strategy-globe.js +++ b/scripts/flatten-strategy-globe.js @@ -1,9 +1,10 @@ const {exec} = require('child_process'); async function main() { - const platform = "traderJoe"; + const platform = "aave"; const names = [ - "joe-sjoe" + "aave-usdc", + "aave-usdt" ]; const flatten = name => { diff --git a/test/FoldingStrats/aave.ts b/test/FoldingStrats/aave.ts index a012fd4a0..b05738f8e 100644 --- a/test/FoldingStrats/aave.ts +++ b/test/FoldingStrats/aave.ts @@ -11,41 +11,41 @@ const tests = [ // fold: true, // controller: "aave", // }, + { + name: "AaveUsdc", + fold: true, + timelockIsStrategist: true, + slot: 9, + controller: "aave", + }, + { + name: "AaveUsdt", + fold: true, + timelockIsStrategist: true, + controller: "aave", + slot: 51 + }, // { - // name: "AaveUsdc", - // fold: true, - // timelockIsStrategist: true, - // slot: 9, - // controller: "aave", - // }, - // { - // name: "AaveUsdt", + // name: "AaveDaiE", // fold: true, // timelockIsStrategist: true, // controller: "aave", - // slot: 51 + // slot: 0 // }, // { - // name: "AaveDaiE", + // name: "AaveWbtc", // fold: true, // timelockIsStrategist: true, + // slot: 0, // controller: "aave", - // slot: 0 // }, // { - // name: "AaveWbtc", + // name: "AaveWeth", // fold: true, // timelockIsStrategist: true, // slot: 0, - // controller: "aave", + // controller: "aave" // }, - { - name: "AaveWeth", - fold: true, - timelockIsStrategist: true, - slot: 0, - controller: "aave" - }, // { // name: "AaveWavax", // fold: true,