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

Feat/leveraged steth #159

Merged
merged 33 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8b41dfe
Add levereged wstETH adapter
Andreadinenno Feb 29, 2024
6396941
Fix ltv calculation
Andreadinenno Feb 29, 2024
6b8be44
Fix deposit and leverage bugs. Add deposit flow tests
Andreadinenno Mar 1, 2024
b4b3444
Refactor initialization. Rename lendingPool
Andreadinenno Mar 1, 2024
715f8ce
Use flashloans to leverage up and down
Andreadinenno Mar 5, 2024
aa6cbe7
Derive amount to flash loan on chain
Andreadinenno Mar 5, 2024
cae3f9c
Fix amount calculation in withdraw
Andreadinenno Mar 6, 2024
e4326c5
Add max LTV param, fix total assets and full withdrawals
Andreadinenno Mar 6, 2024
f971a22
Use dust ETH when leveraging, add func to withdraw dust. Format code
Andreadinenno Mar 8, 2024
7a881c7
Tests - wip
Andreadinenno Mar 8, 2024
ff92830
Fix withdraw bug
Andreadinenno Mar 11, 2024
d31ff99
Split tests and improve
Andreadinenno Mar 11, 2024
47370e9
init
RedVeil Mar 13, 2024
8c2a2d8
small cleanup
RedVeil Mar 13, 2024
2fb0e75
reordered function + added mangement functions
RedVeil Mar 13, 2024
dd03123
added admin functions
RedVeil Mar 14, 2024
b680c80
added admin call in test
RedVeil Mar 14, 2024
fd49f1d
Fix total assets
Andreadinenno Mar 14, 2024
9dd16c4
test setLeverageValues
RedVeil Mar 15, 2024
b66a06a
Merge branch 'feat/leveraged-steth' into suggestions/lever-wstETH
RedVeil Mar 15, 2024
f7b44d9
Merge pull request #163 from Popcorn-Limited/suggestions/lever-wstETH
RedVeil Mar 15, 2024
b264bc7
Add initiator and sender checks on flash loan callback
Andreadinenno Mar 18, 2024
f2bd91a
Set weth and stETH constant values
Andreadinenno Mar 18, 2024
bc1ed45
Remove commented aave addresses
Andreadinenno Mar 18, 2024
13ac7c0
Remove unused import. Fix comments
Andreadinenno Mar 18, 2024
b34f22d
Fix bug on accounting dust
Andreadinenno Mar 18, 2024
4e798f2
Add morpho adapter - wip
Andreadinenno Mar 18, 2024
30daf39
Add stETH to ETH ratio when accounting
Andreadinenno Mar 19, 2024
a46abb2
Add inceasePricePerShare in test
Andreadinenno Mar 20, 2024
44a1a09
Add stETH to ETH rate
Andreadinenno Mar 20, 2024
6964911
Enable user eMode. Add slippage setter
Andreadinenno Mar 20, 2024
fd9f961
Remove morpho adapters, out of scope now
Andreadinenno Mar 20, 2024
718f328
Add harvest func
Andreadinenno Mar 21, 2024
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
116 changes: 115 additions & 1 deletion src/vault/adapter/aave/aaveV3/IAaveV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,39 @@ interface ILendingPool {
address to
) external returns (uint256);

function repay(
address asset,
uint256 amount,
uint256 rateMode,
address onBehalfOf
) external returns (uint256);

function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) external;

function flashLoan(
address receiverAddress,
address[] memory assets,
uint256[] memory amounts,
uint256[] memory interestRateModes,
address onBehalfOf,
bytes calldata params,
uint16 referralCode
) external;

function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external;

/**
* @dev Returns the state and configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The state of the reserve
**/
function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);
function getReserveData(address asset) external view returns (DataTypes.ReserveData2 memory);

function getReserveNormalizedIncome(address asset) external view returns (uint256);
}
Expand All @@ -93,3 +120,90 @@ interface IProtocolDataProvider {
address variableDebtTokenAddress
);
}

interface IFlashLoanReceiver {
/**
* @notice Executes an operation after receiving the flash-borrowed assets
* @dev Ensure that the contract can return the debt + premium, e.g., has
* enough funds to repay and has approved the Pool to pull the total amount
* @param assets The addresses of the flash-borrowed assets
* @param amounts The amounts of the flash-borrowed assets
* @param premiums The fee of each flash-borrowed asset
* @param initiator The address of the flashloan initiator
* @param params The byte-encoded params passed when initiating the flashloan
* @return True if the execution of the operation succeeds, false otherwise
*/
function executeOperation(
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata premiums,
address initiator,
bytes calldata params
) external returns (bool);

function ADDRESSES_PROVIDER() external view returns (IPoolAddressesProvider);

function POOL() external view returns (ILendingPool);
}

/**
* @title IPoolAddressesProvider
* @author Aave
* @notice Defines the basic interface for a Pool Addresses Provider.
*/
interface IPoolAddressesProvider {
/**
* @notice Returns the id of the Aave market to which this contract points to.
* @return The market id
*/
function getMarketId() external view returns (string memory);

/**
* @notice Associates an id with a specific PoolAddressesProvider.
* @dev This can be used to create an onchain registry of PoolAddressesProviders to
* identify and validate multiple Aave markets.
* @param newMarketId The market id
*/
function setMarketId(string calldata newMarketId) external;

/**
* @notice Returns an address by its identifier.
* @dev The returned address might be an EOA or a contract, potentially proxied
* @dev It returns ZERO if there is no registered address with the given id
* @param id The id
* @return The address of the registered for the specified id
*/
function getAddress(bytes32 id) external view returns (address);

/**
* @notice General function to update the implementation of a proxy registered with
* certain `id`. If there is no proxy registered, it will instantiate one and
* set as implementation the `newImplementationAddress`.
* @dev IMPORTANT Use this function carefully, only for ids that don't have an explicit
* setter function, in order to avoid unexpected consequences
* @param id The id
* @param newImplementationAddress The address of the new implementation
*/
function setAddressAsProxy(bytes32 id, address newImplementationAddress) external;

/**
* @notice Sets an address for an id replacing the address saved in the addresses map.
* @dev IMPORTANT Use this function carefully, as it will do a hard replacement
* @param id The id
* @param newAddress The address to set
*/
function setAddress(bytes32 id, address newAddress) external;

/**
* @notice Returns the address of the Pool proxy.
* @return The Pool proxy address
*/
function getPool() external view returns (address);

/**
* @notice Updates the implementation of the Pool, or creates a proxy
* setting the new `pool` implementation when the function is called for the first time.
* @param newPoolImpl The new Pool implementation
*/
function setPoolImpl(address newPoolImpl) external;
}
33 changes: 33 additions & 0 deletions src/vault/adapter/aave/aaveV3/lib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@ library DataTypes {
uint8 id;
}

struct ReserveData2 {
//stores the reserve configuration
ReserveConfigurationMap configuration;
//the liquidity index. Expressed in ray
uint128 liquidityIndex;
//the current supply rate. Expressed in ray
uint128 currentLiquidityRate;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
//the current stable borrow rate. Expressed in ray
uint128 currentStableBorrowRate;
//timestamp of last update
uint40 lastUpdateTimestamp;
//the id of the reserve. Represents the position in the list of the active reserves
uint16 id;
//aToken address
address aTokenAddress;
//stableDebtToken address
address stableDebtTokenAddress;
//variableDebtToken address
address variableDebtTokenAddress;
//address of the interest rate strategy
address interestRateStrategyAddress;
//the current treasury balance, scaled
uint128 accruedToTreasury;
//the outstanding unbacked aTokens minted through the bridging feature
uint128 unbacked;
//the outstanding debt borrowed against this asset in isolation mode
uint128 isolationModeTotalDebt;
}

struct ReserveConfigurationMap {
//bit 0-15: LTV
//bit 16-31: Liq. threshold
Expand Down
14 changes: 14 additions & 0 deletions src/vault/adapter/lido/IwstETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.15;

interface IwstETH {
// Returns amount of wstETH for a given amount of stETH
function getWstETHByStETH(uint256 _stETHAmount) external view returns (uint256);

// Returns amount of stETH for a given amount of wstETH
function getStETHByWstETH(uint256 _wstETHAmount) external view returns (uint256);

// Exchanges wstETH to stETH - return amount of stETH received
function unwrap(uint256 _wstETHAmount) external returns (uint256);
}
Loading
Loading