diff --git a/.gitignore b/.gitignore index 27e7ef2..302f57b 100644 --- a/.gitignore +++ b/.gitignore @@ -141,3 +141,7 @@ node_modules .env.sh *lock* + +bin +pyvenv.cfg +share diff --git a/contracts/LenderDebtManager.sol b/contracts/LenderDebtManager.sol deleted file mode 100644 index a2fa65e..0000000 --- a/contracts/LenderDebtManager.sol +++ /dev/null @@ -1,134 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity 0.8.14; - -import "./interfaces/IVault.sol"; -import "./BaseStrategy.sol"; -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; - -interface ILenderStrategy { - function aprAfterDebtChange( - uint256 _delta - ) external view returns (uint256 _apr); -} - -contract LenderDebtManager is Ownable { - IVault public vault; - IERC20 public asset; - address[] public strategies; - - uint256 public lastBlockUpdate; - - constructor(IVault _vault) { - vault = _vault; - asset = IERC20(_vault.asset()); - } - - function addStrategy(address _strategy) external { - // NOTE: if the strategy is added to the vault, it should be added here, so no need for authorizing - require(vault.strategies(_strategy).activation != 0); - - for (uint256 i = 0; i < strategies.length; ++i) { - if (strategies[i] == _strategy) return; - } - - strategies.push(_strategy); - } - - function removeStrategy(address _strategy) external { - // TODO: replace with a query to the vault to see if the account is allowed - bool _isManager = msg.sender == owner(); - // Strategy can't be active but an authorized account can force deletion if still active - require(vault.strategies(_strategy).activation == 0 || _isManager); - - uint256 strategyCount = strategies.length; - for (uint256 i = 0; i < strategyCount; ++i) { - if (strategies[i] == _strategy) { - // if not last element - if (i != strategyCount - 1) { - strategies[i] = strategies[strategyCount - 1]; - } - strategies.pop(); - return; - } - } - } - - function updateAllocations() public { - (uint256 _lowest, , uint256 _highest, ) = estimateAdjustPosition(); - - require(_lowest != _highest); // dev: no debt changes - - address _lowestStrategy = strategies[_lowest]; - address _highestStrategy = strategies[_highest]; - uint256 _lowestCurrentDebt = vault.strategies(_lowestStrategy).current_debt; - uint256 _highestCurrentDebt = vault.strategies(_highestStrategy).current_debt; - - vault.update_debt(_lowestStrategy, 0); - vault.update_debt(_highestStrategy, _lowestCurrentDebt + _highestCurrentDebt); - } - - //estimates highest and lowest apr lenders. Public for debugging purposes but not much use to general public - function estimateAdjustPosition() - public - view - returns ( - uint256 _lowest, - uint256 _lowestApr, - uint256 _highest, - uint256 _potential - ) - { - uint256 strategyCount = strategies.length; - if (strategyCount == 0) { - return (type(uint256).max, 0, type(uint256).max, 0); - } - - if (strategyCount == 1) { - ILenderStrategy _strategy = ILenderStrategy(strategies[0]); - uint256 apr = _strategy.aprAfterDebtChange(0); - return (0, apr, 0, apr); - } - - //all loose assets are to be invested - uint256 looseAssets = vault.total_idle(); - - // our simple algo - // get the lowest apr strat - // cycle through and see who could take its funds plus want for the highest apr - _lowestApr = type(uint256).max; - _lowest = 0; - uint256 lowestCurrentDebt = 0; - for (uint256 i = 0; i < strategyCount; ++i) { - ILenderStrategy _strategy = ILenderStrategy(strategies[i]); - uint256 _strategyCurrentDebt = vault - .strategies(address(_strategy)) - .current_debt; - if (_strategyCurrentDebt > 0) { - uint256 apr = _strategy.aprAfterDebtChange(0); - if (apr < _lowestApr) { - _lowestApr = apr; - _lowest = i; - lowestCurrentDebt = _strategyCurrentDebt; - } - } - } - - uint256 toAdd = lowestCurrentDebt + looseAssets; - - uint256 highestApr = 0; - _highest = 0; - - for (uint256 i = 0; i < strategyCount; ++i) { - uint256 apr; - ILenderStrategy _strategy = ILenderStrategy(strategies[i]); - apr = _strategy.aprAfterDebtChange(toAdd); - - if (apr > highestApr) { - highestApr = apr; - _highest = i; - _potential = apr; - } - } - } -} diff --git a/contracts/interfaces/CompoundV3.sol b/contracts/interfaces/CompoundV3.sol new file mode 100644 index 0000000..7525e34 --- /dev/null +++ b/contracts/interfaces/CompoundV3.sol @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.6.12; +pragma experimental ABIEncoderV2; + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +library CometStructs { + struct AssetInfo { + uint8 offset; + address asset; + address priceFeed; + uint64 scale; + uint64 borrowCollateralFactor; + uint64 liquidateCollateralFactor; + uint64 liquidationFactor; + uint128 supplyCap; + } + + struct UserBasic { + int104 principal; + uint64 baseTrackingIndex; + uint64 baseTrackingAccrued; + uint16 assetsIn; + uint8 _reserved; + } + + struct TotalsBasic { + uint64 baseSupplyIndex; + uint64 baseBorrowIndex; + uint64 trackingSupplyIndex; + uint64 trackingBorrowIndex; + uint104 totalSupplyBase; + uint104 totalBorrowBase; + uint40 lastAccrualTime; + uint8 pauseFlags; + } + + struct UserCollateral { + uint128 balance; + uint128 _reserved; + } + + struct RewardOwed { + address token; + uint owed; + } + + struct TotalsCollateral { + uint128 totalSupplyAsset; + uint128 _reserved; + } + + struct RewardConfig { + address token; + uint64 rescaleFactor; + bool shouldUpscale; + } +} + +interface Comet is IERC20 { + function baseScale() external view returns (uint); + function supply(address asset, uint amount) external; + function supplyTo(address to, address asset, uint amount) external; + function withdraw(address asset, uint amount) external; + + function getSupplyRate(uint utilization) external view returns (uint); + function getBorrowRate(uint utilization) external view returns (uint); + + function getAssetInfoByAddress(address asset) external view returns (CometStructs.AssetInfo memory); + function getAssetInfo(uint8 i) external view returns (CometStructs.AssetInfo memory); + + function borrowBalanceOf(address account) external view returns (uint256); + + function getPrice(address priceFeed) external view returns (uint128); + + function userBasic(address) external view returns (CometStructs.UserBasic memory); + function totalsBasic() external view returns (CometStructs.TotalsBasic memory); + function userCollateral(address, address) external view returns (CometStructs.UserCollateral memory); + + function baseTokenPriceFeed() external view returns (address); + + function numAssets() external view returns (uint8); + + function getUtilization() external view returns (uint); + + function baseTrackingSupplySpeed() external view returns (uint); + function baseTrackingBorrowSpeed() external view returns (uint); + + function totalSupply() override external view returns (uint256); + function totalBorrow() external view returns (uint256); + + function baseIndexScale() external pure returns (uint64); + function baseTrackingAccrued(address account) external view returns (uint64); + + function totalsCollateral(address asset) external view returns (CometStructs.TotalsCollateral memory); + + function baseMinForRewards() external view returns (uint256); + function baseToken() external view returns (address); + + function accrueAccount(address account) external; + + function isLiquidatable(address _address) external view returns(bool); + function baseBorrowMin() external view returns(uint256); +} + +interface CometRewards { + function getRewardOwed(address comet, address account) external returns (CometStructs.RewardOwed memory); + function claim(address comet, address src, bool shouldAccrue) external; + + function rewardsClaimed(address comet, address account) external view returns(uint256); + function rewardConfig(address comet) external view returns (CometStructs.RewardConfig memory); +} diff --git a/contracts/interfaces/aave/IAToken.sol b/contracts/interfaces/aave/IAToken.sol deleted file mode 100644 index 85cd9f1..0000000 --- a/contracts/interfaces/aave/IAToken.sol +++ /dev/null @@ -1,123 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {IScaledBalanceToken} from "./IScaledBalanceToken.sol"; -import {IInitializableAToken} from "./IInitializableAToken.sol"; -import {IAaveIncentivesController} from "./IAaveIncentivesController.sol"; - -interface IAToken is IERC20, IScaledBalanceToken, IInitializableAToken { - /** - * @dev Emitted after the mint action - * @param from The address performing the mint - * @param value The amount being - * @param index The new liquidity index of the reserve - **/ - event Mint(address indexed from, uint256 value, uint256 index); - - /** - * @dev Mints `amount` aTokens to `user` - * @param user The address receiving the minted tokens - * @param amount The amount of tokens getting minted - * @param index The new liquidity index of the reserve - * @return `true` if the the previous balance of the user was 0 - */ - function mint( - address user, - uint256 amount, - uint256 index - ) external returns (bool); - - /** - * @dev Emitted after aTokens are burned - * @param from The owner of the aTokens, getting them burned - * @param target The address that will receive the underlying - * @param value The amount being burned - * @param index The new liquidity index of the reserve - **/ - event Burn( - address indexed from, - address indexed target, - uint256 value, - uint256 index - ); - - /** - * @dev Emitted during the transfer action - * @param from The user whose tokens are being transferred - * @param to The recipient - * @param value The amount being transferred - * @param index The new liquidity index of the reserve - **/ - event BalanceTransfer( - address indexed from, - address indexed to, - uint256 value, - uint256 index - ); - - /** - * @dev Burns aTokens from `user` and sends the equivalent amount of underlying to `receiverOfUnderlying` - * @param user The owner of the aTokens, getting them burned - * @param receiverOfUnderlying The address that will receive the underlying - * @param amount The amount being burned - * @param index The new liquidity index of the reserve - **/ - function burn( - address user, - address receiverOfUnderlying, - uint256 amount, - uint256 index - ) external; - - /** - * @dev Mints aTokens to the reserve treasury - * @param amount The amount of tokens getting minted - * @param index The new liquidity index of the reserve - */ - function mintToTreasury(uint256 amount, uint256 index) external; - - /** - * @dev Transfers aTokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken - * @param from The address getting liquidated, current owner of the aTokens - * @param to The recipient - * @param value The amount of tokens getting transferred - **/ - function transferOnLiquidation( - address from, - address to, - uint256 value - ) external; - - /** - * @dev Transfers the underlying asset to `target`. Used by the LendingPool to transfer - * assets in borrow(), withdraw() and flashLoan() - * @param user The recipient of the underlying - * @param amount The amount getting transferred - * @return The amount transferred - **/ - function transferUnderlyingTo( - address user, - uint256 amount - ) external returns (uint256); - - /** - * @dev Invoked to execute actions on the aToken side after a repayment. - * @param user The user executing the repayment - * @param amount The amount getting repaid - **/ - function handleRepayment(address user, uint256 amount) external; - - /** - * @dev Returns the address of the incentives controller contract - **/ - function getIncentivesController() - external - view - returns (IAaveIncentivesController); - - /** - * @dev Returns the address of the underlying asset of this aToken (E.g. WETH for aWETH) - **/ - function UNDERLYING_ASSET_ADDRESS() external view returns (address); -} diff --git a/contracts/interfaces/aave/IAaveIncentivesController.sol b/contracts/interfaces/aave/IAaveIncentivesController.sol deleted file mode 100644 index 4af9c53..0000000 --- a/contracts/interfaces/aave/IAaveIncentivesController.sol +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -interface IAaveIncentivesController { - /** - * @dev Returns the total of rewards of an user, already accrued + not yet accrued - * @param user The address of the user - * @return The rewards - **/ - function getRewardsBalance(address[] calldata assets, address user) - external - view - returns (uint256); - - /** - * @dev Claims reward for an user, on all the assets of the lending pool, accumulating the pending rewards - * @param amount Amount of rewards to claim - * @param to Address that will be receiving the rewards - * @return Rewards claimed - **/ - function claimRewards( - address[] calldata assets, - uint256 amount, - address to - ) external returns (uint256); - - /** - * @dev Claims reward for an user on behalf, on all the assets of the lending pool, accumulating the pending rewards. The caller must - * be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager - * @param amount Amount of rewards to claim - * @param user Address to check and claim rewards - * @param to Address that will be receiving the rewards - * @return Rewards claimed - **/ - function claimRewardsOnBehalf( - address[] calldata assets, - uint256 amount, - address user, - address to - ) external returns (uint256); - - /** - * @dev returns the unclaimed rewards of the user - * @param user the address of the user - * @return the unclaimed user rewards - */ - function getUserUnclaimedRewards(address user) - external - view - returns (uint256); - - /** - * @dev for backward compatibility with previous implementation of the Incentives controller - */ - function REWARD_TOKEN() external view returns (address); - - function getDistributionEnd() external view returns (uint256); - - function getAssetData(address asset) - external - view - returns ( - uint256, - uint256, - uint256 - ); -} diff --git a/contracts/interfaces/aave/IInitializableAToken.sol b/contracts/interfaces/aave/IInitializableAToken.sol deleted file mode 100644 index 6fa2615..0000000 --- a/contracts/interfaces/aave/IInitializableAToken.sol +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -import {ILendingPool} from "./ILendingPool.sol"; -import {IAaveIncentivesController} from "./IAaveIncentivesController.sol"; - -/** - * @title IInitializableAToken - * @notice Interface for the initialize function on AToken - * @author Aave - **/ -interface IInitializableAToken { - /** - * @dev Emitted when an aToken is initialized - * @param underlyingAsset The address of the underlying asset - * @param pool The address of the associated lending pool - * @param treasury The address of the treasury - * @param incentivesController The address of the incentives controller for this aToken - * @param aTokenDecimals the decimals of the underlying - * @param aTokenName the name of the aToken - * @param aTokenSymbol the symbol of the aToken - * @param params A set of encoded parameters for additional initialization - **/ - event Initialized( - address indexed underlyingAsset, - address indexed pool, - address treasury, - address incentivesController, - uint8 aTokenDecimals, - string aTokenName, - string aTokenSymbol, - bytes params - ); - - /** - * @dev Initializes the aToken - * @param pool The address of the lending pool where this aToken will be used - * @param treasury The address of the Aave treasury, receiving the fees on this aToken - * @param underlyingAsset The address of the underlying asset of this aToken (E.g. WETH for aWETH) - * @param incentivesController The smart contract managing potential incentives distribution - * @param aTokenDecimals The decimals of the aToken, same as the underlying asset's - * @param aTokenName The name of the aToken - * @param aTokenSymbol The symbol of the aToken - */ - function initialize( - ILendingPool pool, - address treasury, - address underlyingAsset, - IAaveIncentivesController incentivesController, - uint8 aTokenDecimals, - string calldata aTokenName, - string calldata aTokenSymbol, - bytes calldata params - ) external; -} diff --git a/contracts/interfaces/aave/ILendingPool.sol b/contracts/interfaces/aave/ILendingPool.sol deleted file mode 100644 index 976294d..0000000 --- a/contracts/interfaces/aave/ILendingPool.sol +++ /dev/null @@ -1,437 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -import {ILendingPoolAddressesProvider} from "./ILendingPoolAddressesProvider.sol"; -import {DataTypes} from "../../libraries/aave/DataTypes.sol"; - -interface ILendingPool { - /** - * @dev Emitted on deposit() - * @param reserve The address of the underlying asset of the reserve - * @param user The address initiating the deposit - * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens - * @param amount The amount deposited - * @param referral The referral code used - **/ - event Deposit( - address indexed reserve, - address user, - address indexed onBehalfOf, - uint256 amount, - uint16 indexed referral - ); - - /** - * @dev Emitted on withdraw() - * @param reserve The address of the underlyng asset being withdrawn - * @param user The address initiating the withdrawal, owner of aTokens - * @param to Address that will receive the underlying - * @param amount The amount to be withdrawn - **/ - event Withdraw( - address indexed reserve, - address indexed user, - address indexed to, - uint256 amount - ); - - /** - * @dev Emitted on borrow() and flashLoan() when debt needs to be opened - * @param reserve The address of the underlying asset being borrowed - * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just - * initiator of the transaction on flashLoan() - * @param onBehalfOf The address that will be getting the debt - * @param amount The amount borrowed out - * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable - * @param borrowRate The numeric rate at which the user has borrowed - * @param referral The referral code used - **/ - event Borrow( - address indexed reserve, - address user, - address indexed onBehalfOf, - uint256 amount, - uint256 borrowRateMode, - uint256 borrowRate, - uint16 indexed referral - ); - - /** - * @dev Emitted on repay() - * @param reserve The address of the underlying asset of the reserve - * @param user The beneficiary of the repayment, getting his debt reduced - * @param repayer The address of the user initiating the repay(), providing the funds - * @param amount The amount repaid - **/ - event Repay( - address indexed reserve, - address indexed user, - address indexed repayer, - uint256 amount - ); - - /** - * @dev Emitted on swapBorrowRateMode() - * @param reserve The address of the underlying asset of the reserve - * @param user The address of the user swapping his rate mode - * @param rateMode The rate mode that the user wants to swap to - **/ - event Swap(address indexed reserve, address indexed user, uint256 rateMode); - - /** - * @dev Emitted on setUserUseReserveAsCollateral() - * @param reserve The address of the underlying asset of the reserve - * @param user The address of the user enabling the usage as collateral - **/ - event ReserveUsedAsCollateralEnabled( - address indexed reserve, - address indexed user - ); - - /** - * @dev Emitted on setUserUseReserveAsCollateral() - * @param reserve The address of the underlying asset of the reserve - * @param user The address of the user enabling the usage as collateral - **/ - event ReserveUsedAsCollateralDisabled( - address indexed reserve, - address indexed user - ); - - /** - * @dev Emitted on rebalanceStableBorrowRate() - * @param reserve The address of the underlying asset of the reserve - * @param user The address of the user for which the rebalance has been executed - **/ - event RebalanceStableBorrowRate( - address indexed reserve, - address indexed user - ); - - /** - * @dev Emitted on flashLoan() - * @param target The address of the flash loan receiver contract - * @param initiator The address initiating the flash loan - * @param asset The address of the asset being flash borrowed - * @param amount The amount flash borrowed - * @param premium The fee flash borrowed - * @param referralCode The referral code used - **/ - event FlashLoan( - address indexed target, - address indexed initiator, - address indexed asset, - uint256 amount, - uint256 premium, - uint16 referralCode - ); - - /** - * @dev Emitted when the pause is triggered. - */ - event Paused(); - - /** - * @dev Emitted when the pause is lifted. - */ - event Unpaused(); - - /** - * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via - * LendingPoolCollateral manager using a DELEGATECALL - * This allows to have the events in the generated ABI for LendingPool. - * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation - * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation - * @param user The address of the borrower getting liquidated - * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover - * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator - * @param liquidator The address of the liquidator - * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants - * to receive the underlying collateral asset directly - **/ - event LiquidationCall( - address indexed collateralAsset, - address indexed debtAsset, - address indexed user, - uint256 debtToCover, - uint256 liquidatedCollateralAmount, - address liquidator, - bool receiveAToken - ); - - /** - * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared - * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal, - * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it - * gets added to the LendingPool ABI - * @param reserve The address of the underlying asset of the reserve - * @param liquidityRate The new liquidity rate - * @param stableBorrowRate The new stable borrow rate - * @param variableBorrowRate The new variable borrow rate - * @param liquidityIndex The new liquidity index - * @param variableBorrowIndex The new variable borrow index - **/ - event ReserveDataUpdated( - address indexed reserve, - uint256 liquidityRate, - uint256 stableBorrowRate, - uint256 variableBorrowRate, - uint256 liquidityIndex, - uint256 variableBorrowIndex - ); - - /** - * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. - * - E.g. User deposits 100 USDC and gets in return 100 aUSDC - * @param asset The address of the underlying asset to deposit - * @param amount The amount to be deposited - * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user - * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens - * is a different wallet - * @param referralCode Code used to register the integrator originating the operation, for potential rewards. - * 0 if the action is executed directly by the user, without any middle-man - **/ - function deposit( - address asset, - uint256 amount, - address onBehalfOf, - uint16 referralCode - ) external; - - /** - * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned - * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC - * @param asset The address of the underlying asset to withdraw - * @param amount The underlying amount to be withdrawn - * - Send the value type(uint256).max in order to withdraw the whole aToken balance - * @param to Address that will receive the underlying, same as msg.sender if the user - * wants to receive it on his own wallet, or a different address if the beneficiary is a - * different wallet - * @return The final amount withdrawn - **/ - function withdraw( - address asset, - uint256 amount, - address to - ) external returns (uint256); - - /** - * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower - * already deposited enough collateral, or he was given enough allowance by a credit delegator on the - * corresponding debt token (StableDebtToken or VariableDebtToken) - * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet - * and 100 stable/variable debt tokens, depending on the `interestRateMode` - * @param asset The address of the underlying asset to borrow - * @param amount The amount to be borrowed - * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable - * @param referralCode Code used to register the integrator originating the operation, for potential rewards. - * 0 if the action is executed directly by the user, without any middle-man - * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself - * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator - * if he has been given credit delegation allowance - **/ - function borrow( - address asset, - uint256 amount, - uint256 interestRateMode, - uint16 referralCode, - address onBehalfOf - ) external; - - /** - * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned - * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address - * @param asset The address of the borrowed underlying asset previously borrowed - * @param amount The amount to repay - * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode` - * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable - * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the - * user calling the function if he wants to reduce/remove his own debt, or the address of any other - * other borrower whose debt should be removed - * @return The final amount repaid - **/ - function repay( - address asset, - uint256 amount, - uint256 rateMode, - address onBehalfOf - ) external returns (uint256); - - /** - * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa - * @param asset The address of the underlying asset borrowed - * @param rateMode The rate mode that the user wants to swap to - **/ - function swapBorrowRateMode(address asset, uint256 rateMode) external; - - /** - * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve. - * - Users can be rebalanced if the following conditions are satisfied: - * 1. Usage ratio is above 95% - * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been - * borrowed at a stable rate and depositors are not earning enough - * @param asset The address of the underlying asset borrowed - * @param user The address of the user to be rebalanced - **/ - function rebalanceStableBorrowRate(address asset, address user) external; - - /** - * @dev Allows depositors to enable/disable a specific deposited asset as collateral - * @param asset The address of the underlying asset deposited - * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise - **/ - function setUserUseReserveAsCollateral( - address asset, - bool useAsCollateral - ) external; - - /** - * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1 - * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives - * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk - * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation - * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation - * @param user The address of the borrower getting liquidated - * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover - * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants - * to receive the underlying collateral asset directly - **/ - function liquidationCall( - address collateralAsset, - address debtAsset, - address user, - uint256 debtToCover, - bool receiveAToken - ) external; - - /** - * @dev Allows smartcontracts to access the liquidity of the pool within one transaction, - * as long as the amount taken plus a fee is returned. - * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration. - * For further details please visit https://developers.aave.com - * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface - * @param assets The addresses of the assets being flash-borrowed - * @param amounts The amounts amounts being flash-borrowed - * @param modes Types of the debt to open if the flash loan is not returned: - * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver - * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address - * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address - * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2 - * @param params Variadic packed params to pass to the receiver as extra information - * @param referralCode Code used to register the integrator originating the operation, for potential rewards. - * 0 if the action is executed directly by the user, without any middle-man - **/ - function flashLoan( - address receiverAddress, - address[] calldata assets, - uint256[] calldata amounts, - uint256[] calldata modes, - address onBehalfOf, - bytes calldata params, - uint16 referralCode - ) external; - - /** - * @dev Returns the user account data across all the reserves - * @param user The address of the user - * @return totalCollateralETH the total collateral in ETH of the user - * @return totalDebtETH the total debt in ETH of the user - * @return availableBorrowsETH the borrowing power left of the user - * @return currentLiquidationThreshold the liquidation threshold of the user - * @return ltv the loan to value of the user - * @return healthFactor the current health factor of the user - **/ - function getUserAccountData( - address user - ) - external - view - returns ( - uint256 totalCollateralETH, - uint256 totalDebtETH, - uint256 availableBorrowsETH, - uint256 currentLiquidationThreshold, - uint256 ltv, - uint256 healthFactor - ); - - function initReserve( - address reserve, - address aTokenAddress, - address stableDebtAddress, - address variableDebtAddress, - address interestRateStrategyAddress - ) external; - - function setReserveInterestRateStrategyAddress( - address reserve, - address rateStrategyAddress - ) external; - - function setConfiguration(address reserve, uint256 configuration) external; - - /** - * @dev Returns the configuration of the reserve - * @param asset The address of the underlying asset of the reserve - * @return The configuration of the reserve - **/ - function getConfiguration( - address asset - ) external view returns (DataTypes.ReserveConfigurationMap memory); - - /** - * @dev Returns the configuration of the user across all the reserves - * @param user The user address - * @return The configuration of the user - **/ - function getUserConfiguration( - address user - ) external view returns (DataTypes.UserConfigurationMap memory); - - /** - * @dev Returns the normalized income normalized income of the reserve - * @param asset The address of the underlying asset of the reserve - * @return The reserve's normalized income - */ - function getReserveNormalizedIncome( - address asset - ) external view returns (uint256); - - /** - * @dev Returns the normalized variable debt per unit of asset - * @param asset The address of the underlying asset of the reserve - * @return The reserve normalized variable debt - */ - function getReserveNormalizedVariableDebt( - address asset - ) external view returns (uint256); - - /** - * @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 finalizeTransfer( - address asset, - address from, - address to, - uint256 amount, - uint256 balanceFromAfter, - uint256 balanceToBefore - ) external; - - function getReservesList() external view returns (address[] memory); - - function getAddressesProvider() - external - view - returns (ILendingPoolAddressesProvider); - - function setPause(bool val) external; - - function paused() external view returns (bool); -} diff --git a/contracts/interfaces/aave/ILendingPoolAddressesProvider.sol b/contracts/interfaces/aave/ILendingPoolAddressesProvider.sol deleted file mode 100644 index eddb95e..0000000 --- a/contracts/interfaces/aave/ILendingPoolAddressesProvider.sol +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -/** - * @title LendingPoolAddressesProvider contract - * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles - * - Acting also as factory of proxies and admin of those, so with right to change its implementations - * - Owned by the Aave Governance - * @author Aave - **/ -interface ILendingPoolAddressesProvider { - event MarketIdSet(string newMarketId); - event LendingPoolUpdated(address indexed newAddress); - event ConfigurationAdminUpdated(address indexed newAddress); - event EmergencyAdminUpdated(address indexed newAddress); - event LendingPoolConfiguratorUpdated(address indexed newAddress); - event LendingPoolCollateralManagerUpdated(address indexed newAddress); - event PriceOracleUpdated(address indexed newAddress); - event LendingRateOracleUpdated(address indexed newAddress); - event ProxyCreated(bytes32 id, address indexed newAddress); - event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy); - - function getMarketId() external view returns (string memory); - - function setMarketId(string calldata marketId) external; - - function setAddress(bytes32 id, address newAddress) external; - - function setAddressAsProxy(bytes32 id, address impl) external; - - function getAddress(bytes32 id) external view returns (address); - - function getLendingPool() external view returns (address); - - function setLendingPoolImpl(address pool) external; - - function getLendingPoolConfigurator() external view returns (address); - - function setLendingPoolConfiguratorImpl(address configurator) external; - - function getLendingPoolCollateralManager() external view returns (address); - - function setLendingPoolCollateralManager(address manager) external; - - function getPoolAdmin() external view returns (address); - - function setPoolAdmin(address admin) external; - - function getEmergencyAdmin() external view returns (address); - - function setEmergencyAdmin(address admin) external; - - function getPriceOracle() external view returns (address); - - function setPriceOracle(address priceOracle) external; - - function getLendingRateOracle() external view returns (address); - - function setLendingRateOracle(address lendingRateOracle) external; -} diff --git a/contracts/interfaces/aave/IPriceOracle.sol b/contracts/interfaces/aave/IPriceOracle.sol deleted file mode 100644 index 102b0e3..0000000 --- a/contracts/interfaces/aave/IPriceOracle.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -interface IPriceOracle { - function getAssetPrice(address _asset) external view returns (uint256); - - function getAssetsPrices(address[] calldata _assets) - external - view - returns (uint256[] memory); - - function getSourceOfAsset(address _asset) external view returns (address); - - function getFallbackOracle() external view returns (address); -} diff --git a/contracts/interfaces/aave/IPriceOracleGetter.sol b/contracts/interfaces/aave/IPriceOracleGetter.sol deleted file mode 100644 index 53d6927..0000000 --- a/contracts/interfaces/aave/IPriceOracleGetter.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -/************ -@title IPriceOracleGetter interface -@notice Interface for the Aave price oracle.*/ -interface IPriceOracleGetter { - function getAssetPrice(address _asset) external view returns (uint256); - - function getAssetsPrices(address[] calldata _assets) - external - view - returns (uint256[] memory); - - function getSourceOfAsset(address _asset) external view returns (address); - - function getFallbackOracle() external view returns (address); -} diff --git a/contracts/interfaces/aave/IProtocolDataProvider.sol b/contracts/interfaces/aave/IProtocolDataProvider.sol deleted file mode 100644 index 4c2d19e..0000000 --- a/contracts/interfaces/aave/IProtocolDataProvider.sol +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -import {ILendingPoolAddressesProvider} from "./ILendingPoolAddressesProvider.sol"; - -interface IProtocolDataProvider { - struct TokenData { - string symbol; - address tokenAddress; - } - - function ADDRESSES_PROVIDER() - external - view - returns (ILendingPoolAddressesProvider); - - function getAllReservesTokens() external view returns (TokenData[] memory); - - function getAllATokens() external view returns (TokenData[] memory); - - function getReserveConfigurationData( - address asset - ) - external - view - returns ( - uint256 decimals, - uint256 ltv, - uint256 liquidationThreshold, - uint256 liquidationBonus, - uint256 reserveFactor, - bool usageAsCollateralEnabled, - bool borrowingEnabled, - bool stableBorrowRateEnabled, - bool isActive, - bool isFrozen - ); - - function getReserveData( - address asset - ) - external - view - returns ( - uint256 availableLiquidity, - uint256 totalStableDebt, - uint256 totalVariableDebt, - uint256 liquidityRate, - uint256 variableBorrowRate, - uint256 stableBorrowRate, - uint256 averageStableBorrowRate, - uint256 liquidityIndex, - uint256 variableBorrowIndex, - uint40 lastUpdateTimestamp - ); - - function getUserReserveData( - address asset, - address user - ) - external - view - returns ( - uint256 currentATokenBalance, - uint256 currentStableDebt, - uint256 currentVariableDebt, - uint256 principalStableDebt, - uint256 scaledVariableDebt, - uint256 stableBorrowRate, - uint256 liquidityRate, - uint40 stableRateLastUpdated, - bool usageAsCollateralEnabled - ); - - function getReserveTokensAddresses( - address asset - ) - external - view - returns ( - address aTokenAddress, - address stableDebtTokenAddress, - address variableDebtTokenAddress - ); -} diff --git a/contracts/interfaces/aave/IReserveInterestRateStrategy.sol b/contracts/interfaces/aave/IReserveInterestRateStrategy.sol deleted file mode 100644 index f29deb9..0000000 --- a/contracts/interfaces/aave/IReserveInterestRateStrategy.sol +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -/** - * @title IReserveInterestRateStrategyInterface interface - * @dev Interface for the calculation of the interest rates - * @author Aave - */ -interface IReserveInterestRateStrategy { - function OPTIMAL_UTILIZATION_RATE() external view returns (uint256); - - function EXCESS_UTILIZATION_RATE() external view returns (uint256); - - function variableRateSlope1() external view returns (uint256); - - function variableRateSlope2() external view returns (uint256); - - function baseVariableBorrowRate() external view returns (uint256); - - function getMaxVariableBorrowRate() external view returns (uint256); - - function calculateInterestRates( - address reserve, - uint256 utilizationRate, - uint256 totalStableDebt, - uint256 totalVariableDebt, - uint256 averageStableBorrowRate, - uint256 reserveFactor - ) - external - view - returns ( - uint256 liquidityRate, - uint256 stableBorrowRate, - uint256 variableBorrowRate - ); -} diff --git a/contracts/interfaces/aave/IScaledBalanceToken.sol b/contracts/interfaces/aave/IScaledBalanceToken.sol deleted file mode 100644 index 1566a96..0000000 --- a/contracts/interfaces/aave/IScaledBalanceToken.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -interface IScaledBalanceToken { - /** - * @dev Returns the scaled balance of the user. The scaled balance is the sum of all the - * updated stored balance divided by the reserve's liquidity index at the moment of the update - * @param user The user whose balance is calculated - * @return The scaled balance of the user - **/ - function scaledBalanceOf(address user) external view returns (uint256); - - /** - * @dev Returns the scaled balance of the user and the scaled total supply. - * @param user The address of the user - * @return The scaled balance of the user - * @return The scaled balance and the scaled total supply - **/ - function getScaledUserBalanceAndSupply(address user) - external - view - returns (uint256, uint256); - - /** - * @dev Returns the scaled total supply of the variable debt token. Represents sum(debt/index) - * @return The scaled total supply - **/ - function scaledTotalSupply() external view returns (uint256); -} diff --git a/contracts/interfaces/aave/IStakedAave.sol b/contracts/interfaces/aave/IStakedAave.sol deleted file mode 100644 index cba1b66..0000000 --- a/contracts/interfaces/aave/IStakedAave.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.14; - -interface IStakedAave { - function stake(address to, uint256 amount) external; - - function redeem(address to, uint256 amount) external; - - function cooldown() external; - - function claimRewards(address to, uint256 amount) external; - - function getTotalRewardsBalance(address) external view returns (uint256); - - function COOLDOWN_SECONDS() external view returns (uint256); - - function stakersCooldowns(address) external view returns (uint256); - - function UNSTAKE_WINDOW() external view returns (uint256); -} diff --git a/contracts/interfaces/aave/IVariableDebtToken.sol b/contracts/interfaces/aave/IVariableDebtToken.sol deleted file mode 100644 index 8ff3000..0000000 --- a/contracts/interfaces/aave/IVariableDebtToken.sol +++ /dev/null @@ -1,70 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -import {IScaledBalanceToken} from "./IScaledBalanceToken.sol"; -import {IAaveIncentivesController} from "./IAaveIncentivesController.sol"; -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - -/** - * @title IVariableDebtToken - * @author Aave - * @notice Defines the basic interface for a variable debt token. - **/ -interface IVariableDebtToken is IERC20, IScaledBalanceToken { - /** - * @dev Emitted after the mint action - * @param from The address performing the mint - * @param onBehalfOf The address of the user on which behalf minting has been performed - * @param value The amount to be minted - * @param index The last index of the reserve - **/ - event Mint( - address indexed from, - address indexed onBehalfOf, - uint256 value, - uint256 index - ); - - /** - * @dev Mints debt token to the `onBehalfOf` address - * @param user The address receiving the borrowed underlying, being the delegatee in case - * of credit delegate, or same as `onBehalfOf` otherwise - * @param onBehalfOf The address receiving the debt tokens - * @param amount The amount of debt being minted - * @param index The variable debt index of the reserve - * @return `true` if the the previous balance of the user is 0 - **/ - function mint( - address user, - address onBehalfOf, - uint256 amount, - uint256 index - ) external returns (bool); - - /** - * @dev Emitted when variable debt is burnt - * @param user The user which debt has been burned - * @param amount The amount of debt being burned - * @param index The index of the user - **/ - event Burn(address indexed user, uint256 amount, uint256 index); - - /** - * @dev Burns user variable debt - * @param user The user which debt is burnt - * @param index The variable debt index of the reserve - **/ - function burn( - address user, - uint256 amount, - uint256 index - ) external; - - /** - * @dev Returns the address of the incentives controller contract - **/ - function getIncentivesController() - external - view - returns (IAaveIncentivesController); -} diff --git a/contracts/libraries/SupportStructs.sol b/contracts/libraries/SupportStructs.sol deleted file mode 100644 index b554ac7..0000000 --- a/contracts/libraries/SupportStructs.sol +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -library SupportStructs { - struct CalcMaxDebtLocalVars { - uint256 availableLiquidity; - uint256 totalStableDebt; - uint256 totalVariableDebt; - uint256 totalDebt; - uint256 utilizationRate; - uint256 totalLiquidity; - uint256 targetUtilizationRate; - uint256 maxProtocolDebt; - } - - struct IrsVars { - uint256 optimalRate; - uint256 baseRate; - uint256 slope1; - uint256 slope2; - } -} diff --git a/contracts/libraries/aave/DataTypes.sol b/contracts/libraries/aave/DataTypes.sol deleted file mode 100644 index 32c415f..0000000 --- a/contracts/libraries/aave/DataTypes.sol +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.8.14; - -library DataTypes { - // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties. - struct ReserveData { - //stores the reserve configuration - ReserveConfigurationMap configuration; - //the liquidity index. Expressed in ray - uint128 liquidityIndex; - //variable borrow index. Expressed in ray - uint128 variableBorrowIndex; - //the current supply rate. Expressed in ray - uint128 currentLiquidityRate; - //the current variable borrow rate. Expressed in ray - uint128 currentVariableBorrowRate; - //the current stable borrow rate. Expressed in ray - uint128 currentStableBorrowRate; - uint40 lastUpdateTimestamp; - //tokens addresses - address aTokenAddress; - address stableDebtTokenAddress; - address variableDebtTokenAddress; - //address of the interest rate strategy - address interestRateStrategyAddress; - //the id of the reserve. Represents the position in the list of the active reserves - uint8 id; - } - - struct ReserveConfigurationMap { - //bit 0-15: LTV - //bit 16-31: Liq. threshold - //bit 32-47: Liq. bonus - //bit 48-55: Decimals - //bit 56: Reserve is active - //bit 57: reserve is frozen - //bit 58: borrowing is enabled - //bit 59: stable rate borrowing enabled - //bit 60-63: reserved - //bit 64-79: reserve factor - uint256 data; - } - - struct UserConfigurationMap { - uint256 data; - } - - enum InterestRateMode {NONE, STABLE, VARIABLE} -}