Skip to content

Commit

Permalink
Update aave dep (#3)
Browse files Browse the repository at this point in the history
* Remove deprecated aave v3-core

* forge install: aave-v3-origin

main

* Fix aave dep

* Fix snapshot

* Update snapshots, add positionPercent to event

* Update snapshot
  • Loading branch information
tsudmi authored Oct 17, 2024
1 parent c91350e commit 15c6232
Show file tree
Hide file tree
Showing 25 changed files with 37 additions and 47 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ OS_TOKEN_FLASH_LOANS=0x
OS_TOKEN_VAULT_ESCROW=0x
BALANCER_VAULT=0xBA12222222228d8Ba445958a75a0704d566BF2C8
AAVE_POOL=0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
AAVE_POOL_DATA_PROVIDER=0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3
AAVE_OS_TOKEN=0x927709711794F3De5DdBF1D176bEE2D55Ba13c21
AAVE_VAR_DEBT_ASSET_TOKEN=0xeA51d7853EEFb32b6ee06b1C12E6dcCA88Be0fFE
RESCUE_VAULT=0xAC0F906E433d58FA868F936E8A43230473652885
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
616954
566045
Original file line number Diff line number Diff line change
@@ -1 +1 @@
602239
551330
Original file line number Diff line number Diff line change
@@ -1 +1 @@
541024
509091
Original file line number Diff line number Diff line change
@@ -1 +1 @@
844571
779680
Original file line number Diff line number Diff line change
@@ -1 +1 @@
954540
906304
Original file line number Diff line number Diff line change
@@ -1 +1 @@
231043
231289
Original file line number Diff line number Diff line change
@@ -1 +1 @@
277234
277405
Original file line number Diff line number Diff line change
@@ -1 +1 @@
250542
250759
Original file line number Diff line number Diff line change
@@ -1 +1 @@
379483
370257
Original file line number Diff line number Diff line change
@@ -1 +1 @@
656018
611658
Original file line number Diff line number Diff line change
@@ -1 +1 @@
533344
500020
Original file line number Diff line number Diff line change
@@ -1 +1 @@
659362
651731
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55738
55699
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/aave-v3-core"]
path = lib/aave-v3-core
url = https://github.com/aave/aave-v3-core
[submodule "lib/forge-gas-snapshot"]
path = lib/forge-gas-snapshot
url = https://github.com/marktoda/forge-gas-snapshot
[submodule "lib/v3-core"]
path = lib/v3-core
url = https://github.com/stakewise/v3-core
[submodule "lib/aave-v3-origin"]
path = lib/aave-v3-origin
url = https://github.com/aave-dao/aave-v3-origin
branch = main
1 change: 0 additions & 1 deletion lib/aave-v3-core
Submodule aave-v3-core deleted from b74526
1 change: 1 addition & 0 deletions lib/aave-v3-origin
Submodule aave-v3-origin added at ec33f4
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/contracts/
@openzeppelin/contracts=lib/openzeppelin-contracts/contracts/
@stakewise-core/=lib/v3-core/contracts/
@aave-core/=lib/aave-v3-core/contracts/
@aave-core/=lib/aave-v3-origin/src/contracts/
3 changes: 0 additions & 3 deletions script/DeployEthAaveLeverageStrategy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ contract DeployEthAaveLeverageStrategy is Script {
address osTokenVaultEscrow;
address balancerVault;
address aavePool;
address aavePoolDataProvider;
address aaveOsToken;
address aaveVarDebtAssetToken;
address rescueVault;
Expand All @@ -39,7 +38,6 @@ contract DeployEthAaveLeverageStrategy is Script {
params.osTokenVaultEscrow = vm.envAddress('OS_TOKEN_VAULT_ESCROW');
params.balancerVault = vm.envAddress('BALANCER_VAULT');
params.aavePool = vm.envAddress('AAVE_POOL');
params.aavePoolDataProvider = vm.envAddress('AAVE_POOL_DATA_PROVIDER');
params.aaveOsToken = vm.envAddress('AAVE_OS_TOKEN');
params.aaveVarDebtAssetToken = vm.envAddress('AAVE_VAR_DEBT_ASSET_TOKEN');
params.maxVaultLtvPercent = vm.envUint('MAX_VAULT_LTV_PERCENT');
Expand Down Expand Up @@ -79,7 +77,6 @@ contract DeployEthAaveLeverageStrategy is Script {
address(strategyProxyImpl),
params.balancerVault,
params.aavePool,
params.aavePoolDataProvider,
params.aaveOsToken,
params.aaveVarDebtAssetToken
);
Expand Down
13 changes: 4 additions & 9 deletions src/leverage/AaveLeverageStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.26;

import {Math} from '@openzeppelin/contracts/utils/math/Math.sol';
import {SafeCast} from '@openzeppelin/contracts/utils/math/SafeCast.sol';
import {IPoolDataProvider} from '@aave-core/interfaces/IPoolDataProvider.sol';
import {IPool} from '@aave-core/interfaces/IPool.sol';
import {IScaledBalanceToken} from '@aave-core/interfaces/IScaledBalanceToken.sol';
import {WadRayMath} from '@aave-core/protocol/libraries/math/WadRayMath.sol';
Expand All @@ -17,8 +16,9 @@ import {LeverageStrategy} from './LeverageStrategy.sol';
* @notice Defines the Aave leverage strategy functionality
*/
abstract contract AaveLeverageStrategy is LeverageStrategy {
uint8 private constant _emodeCategory = 1;

IPool private immutable _aavePool;
IPoolDataProvider private immutable _aavePoolDataProvider;
IScaledBalanceToken private immutable _aaveOsToken;
IScaledBalanceToken private immutable _aaveVarDebtAssetToken;

Expand All @@ -34,7 +34,6 @@ abstract contract AaveLeverageStrategy is LeverageStrategy {
* @param strategyProxyImplementation The address of the StrategyProxy implementation
* @param balancerVault The address of the BalancerVault contract
* @param aavePool The address of the Aave pool contract
* @param aavePoolDataProvider The address of the Aave pool data provider contract
* @param aaveOsToken The address of the Aave OsToken contract
* @param aaveVarDebtAssetToken The address of the Aave variable debt asset token contract
*/
Expand All @@ -49,7 +48,6 @@ abstract contract AaveLeverageStrategy is LeverageStrategy {
address strategyProxyImplementation,
address balancerVault,
address aavePool,
address aavePoolDataProvider,
address aaveOsToken,
address aaveVarDebtAssetToken
)
Expand All @@ -66,16 +64,14 @@ abstract contract AaveLeverageStrategy is LeverageStrategy {
)
{
_aavePool = IPool(aavePool);
_aavePoolDataProvider = IPoolDataProvider(aavePoolDataProvider);
_aaveOsToken = IScaledBalanceToken(aaveOsToken);
_aaveVarDebtAssetToken = IScaledBalanceToken(aaveVarDebtAssetToken);
}

/// @inheritdoc LeverageStrategy
function _getBorrowLtv() internal view override returns (uint256) {
uint256 emodeCategory = _aavePoolDataProvider.getReserveEModeCategory(address(_osToken));
// convert to 1e18 precision
uint256 aaveLtv = uint256(_aavePool.getEModeCategoryData(SafeCast.toUint8(emodeCategory)).ltv) * 1e14;
uint256 aaveLtv = uint256(_aavePool.getEModeCategoryCollateralConfig(_emodeCategory).ltv) * 1e14;

// check whether there is max borrow LTV percent set in the strategy config
bytes memory maxBorrowLtvPercentConfig =
Expand Down Expand Up @@ -145,9 +141,8 @@ abstract contract AaveLeverageStrategy is LeverageStrategy {
}

// setup emode category
uint256 emodeCategory = _aavePoolDataProvider.getReserveEModeCategory(address(_osToken));
IStrategyProxy(proxy).execute(
address(_aavePool), abi.encodeWithSelector(_aavePool.setUserEMode.selector, SafeCast.toUint8(emodeCategory))
address(_aavePool), abi.encodeWithSelector(_aavePool.setUserEMode.selector, _emodeCategory)
);

// approve Aave pool to spend OsToken and AssetToken
Expand Down
3 changes: 0 additions & 3 deletions src/leverage/EthAaveLeverageStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ contract EthAaveLeverageStrategy is AaveLeverageStrategy {
* @param strategyProxyImplementation The address of the StrategyProxy implementation
* @param balancerVault The address of the BalancerVault contract
* @param aavePool The address of the Aave pool contract
* @param aavePoolDataProvider The address of the Aave pool data provider contract
* @param aaveOsToken The address of the Aave OsToken contract
* @param aaveVarDebtAssetToken The address of the Aave variable debt asset token contract
*/
Expand All @@ -42,7 +41,6 @@ contract EthAaveLeverageStrategy is AaveLeverageStrategy {
address strategyProxyImplementation,
address balancerVault,
address aavePool,
address aavePoolDataProvider,
address aaveOsToken,
address aaveVarDebtAssetToken
)
Expand All @@ -57,7 +55,6 @@ contract EthAaveLeverageStrategy is AaveLeverageStrategy {
strategyProxyImplementation,
balancerVault,
aavePool,
aavePoolDataProvider,
aaveOsToken,
aaveVarDebtAssetToken
)
Expand Down
3 changes: 0 additions & 3 deletions src/leverage/GnoAaveLeverageStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ contract GnoAaveLeverageStrategy is AaveLeverageStrategy {
* @param strategyProxyImplementation The address of the StrategyProxy implementation
* @param balancerVault The address of the BalancerVault contract
* @param aavePool The address of the Aave pool contract
* @param aavePoolDataProvider The address of the Aave pool data provider contract
* @param aaveOsToken The address of the Aave OsToken contract
* @param aaveVarDebtAssetToken The address of the Aave variable debt asset token contract
*/
Expand All @@ -40,7 +39,6 @@ contract GnoAaveLeverageStrategy is AaveLeverageStrategy {
address strategyProxyImplementation,
address balancerVault,
address aavePool,
address aavePoolDataProvider,
address aaveOsToken,
address aaveVarDebtAssetToken
)
Expand All @@ -55,7 +53,6 @@ contract GnoAaveLeverageStrategy is AaveLeverageStrategy {
strategyProxyImplementation,
balancerVault,
aavePool,
aavePoolDataProvider,
aaveOsToken,
aaveVarDebtAssetToken
)
Expand Down
2 changes: 1 addition & 1 deletion src/leverage/LeverageStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ abstract contract LeverageStrategy is Multicall, ILeverageStrategy {
isStrategyProxyExiting[proxy] = true;

// emit event
emit ExitQueueEntered(vault, user, positionTicket, block.timestamp, osTokenShares);
emit ExitQueueEntered(vault, user, positionTicket, block.timestamp, osTokenShares, positionPercent);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/leverage/interfaces/ILeverageStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ interface ILeverageStrategy is IOsTokenFlashLoanRecipient, IStrategy {
* @param positionTicket The exit position ticket
* @param timestamp The timestamp of the exit position ticket
* @param osTokenShares The amount of osToken shares to exit
* @param positionPercent The percent of the position that is exiting from strategy
*/
event ExitQueueEntered(
address indexed vault, address indexed user, uint256 positionTicket, uint256 timestamp, uint256 osTokenShares
address indexed vault,
address indexed user,
uint256 positionTicket,
uint256 timestamp,
uint256 osTokenShares,
uint256 positionPercent
);

/**
Expand Down
14 changes: 6 additions & 8 deletions test/leverage/EthAaveLeverageStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {OsTokenVaultEscrowAuth} from '../../src/OsTokenVaultEscrowAuth.sol';
import {StrategyProxy} from '../../src/StrategyProxy.sol';

contract EthAaveLeverageStrategyTest is Test, GasSnapshot {
uint256 public constant forkBlockNumber = 20_620_920;
uint256 public constant forkBlockNumber = 20_928_188;

uint64 public constant liqThresholdPercent = 0.999 ether;
uint256 public constant liqBonusPercent = 1.001 ether;
Expand All @@ -59,7 +59,6 @@ contract EthAaveLeverageStrategyTest is Test, GasSnapshot {
address public constant vaultsRegistry = 0x3a0008a588772446f6e656133C2D5029CC4FC20E;
address public constant balancerVault = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
address public constant aavePool = 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2;
address public constant aavePoolDataProvider = 0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3;
address public constant aaveOracle = 0x54586bE62E3c3580375aE3723C145253060Ca0C2;
address public constant aaveOsToken = 0x927709711794F3De5DdBF1D176bEE2D55Ba13c21;
address public constant aaveVarDebtAssetToken = 0xeA51d7853EEFb32b6ee06b1C12E6dcCA88Be0fFE;
Expand Down Expand Up @@ -128,7 +127,6 @@ contract EthAaveLeverageStrategyTest is Test, GasSnapshot {
strategyProxyImplementation,
balancerVault,
aavePool,
aavePoolDataProvider,
aaveOsToken,
aaveVarDebtAssetToken
);
Expand Down Expand Up @@ -415,7 +413,7 @@ contract EthAaveLeverageStrategyTest is Test, GasSnapshot {
State memory state1 = _getState();
int256 reward = SafeCast.toInt256(IEthVault(vault).totalAssets() * 0.03 ether / 1 ether / 12);
uint256 secondsInYear = 365 * 24 * 60 * 60;
uint256 yearApy = 0.03 ether;
uint256 yearApy = 0.04 ether;
vm.warp(vm.getBlockTimestamp() + 1 days);
IKeeperRewards.HarvestParams memory harvestParams = _setVaultRewards(vault, reward, 0, yearApy / secondsInYear);
vm.warp(vm.getBlockTimestamp() + 30 days);
Expand Down Expand Up @@ -497,7 +495,7 @@ contract EthAaveLeverageStrategyTest is Test, GasSnapshot {
strategy.updateVaultState(vault, harvestParams);

vm.expectEmit(true, true, false, false);
emit ILeverageStrategy.ExitQueueEntered(vault, address(this), 0, vm.getBlockTimestamp(), 0);
emit ILeverageStrategy.ExitQueueEntered(vault, address(this), 0, vm.getBlockTimestamp(), 0, 0.5 ether);
snapStart('EthAaveLeverageStrategyTest_test_enterExitQueue');
strategy.enterExitQueue(vault, 0.5 ether);
snapEnd();
Expand Down Expand Up @@ -541,7 +539,7 @@ contract EthAaveLeverageStrategyTest is Test, GasSnapshot {

vm.prank(address(1));
vm.expectEmit(true, true, false, false);
emit ILeverageStrategy.ExitQueueEntered(vault, address(this), 0, vm.getBlockTimestamp(), 0);
emit ILeverageStrategy.ExitQueueEntered(vault, address(this), 0, vm.getBlockTimestamp(), 0, 1 ether);
snapStart('EthAaveLeverageStrategyTest_test_forceEnterExitQueue_vaultForceExitLtvPercent');
strategy.forceEnterExitQueue(vault, address(this));
snapEnd();
Expand All @@ -558,7 +556,7 @@ contract EthAaveLeverageStrategyTest is Test, GasSnapshot {

vm.prank(address(1));
vm.expectEmit(true, true, false, false);
emit ILeverageStrategy.ExitQueueEntered(vault, address(this), 0, vm.getBlockTimestamp(), 0);
emit ILeverageStrategy.ExitQueueEntered(vault, address(this), 0, vm.getBlockTimestamp(), 0, 1 ether);
snapStart('EthAaveLeverageStrategyTest_test_forceEnterExitQueue_borrowForceExitLtvPercent');
strategy.forceEnterExitQueue(vault, address(this));
snapEnd();
Expand Down Expand Up @@ -666,7 +664,7 @@ contract EthAaveLeverageStrategyTest is Test, GasSnapshot {

// position went through the exit queue
vm.warp(timestamp + 10 days);
reward += SafeCast.toInt256(IEthVault(vault).totalAssets() * 0.03 ether / 1 ether / 12 / 3);
reward += SafeCast.toInt256(IEthVault(vault).totalAssets() * 0.04 ether / 1 ether / 12 / 3);
harvestParams = _setVaultRewards(vault, reward, 0, avgRewardPerSecond);
strategy.updateVaultState(vault, harvestParams);

Expand Down

0 comments on commit 15c6232

Please sign in to comment.