diff --git a/interfaces/aave/Aave.sol b/interfaces/aave/Aave.sol index 6b1bc2ae..8491affa 100644 --- a/interfaces/aave/Aave.sol +++ b/interfaces/aave/Aave.sol @@ -1,6 +1,100 @@ pragma solidity ^0.5.17; interface Aave { + /** + * @dev deposits The underlying asset into the reserve. A corresponding amount of the overlying asset (aTokens) + * is minted. + * @param _reserve the address of the reserve + * @param _amount the amount to be deposited + * @param _referralCode integrators are assigned a referral code and can potentially receive rewards. + **/ + function deposit( + address _reserve, + uint256 _amount, + uint16 _referralCode + ) external payable; + + /** + * @dev Redeems the underlying amount of assets requested by _user. + * This function is executed by the overlying aToken contract in response to a redeem action. + * @param _reserve the address of the reserve + * @param _user the address of the user performing the action + * @param _amount the underlying amount to be redeemed + **/ + function redeemUnderlying( + address _reserve, + address payable _user, + uint256 _amount, + uint256 _aTokenBalanceAfterRedeem + ) external; + + /** + * @dev borrowers can user this function to swap between stable and variable borrow rate modes. + * @param _reserve the address of the reserve on which the user borrowed + **/ + function swapBorrowRateMode(address _reserve) external; + + /** + * @dev rebalances the stable interest rate of a user if current liquidity rate > user stable rate. + * this is regulated by Aave to ensure that the protocol is not abused, and the user is paying a fair + * rate. Anyone can call this function though. + * @param _reserve the address of the reserve + * @param _user the address of the user to be rebalanced + **/ + function rebalanceStableBorrowRate(address _reserve, address _user) external; + + /** + * @dev users can invoke this function to liquidate an undercollateralized position. + * @param _reserve the address of the collateral to liquidated + * @param _reserve the address of the principal reserve + * @param _user the address of the borrower + * @param _purchaseAmount the amount of principal that the liquidator wants to repay + * @param _receiveAToken true if the liquidators wants to receive the aTokens, false if + * he wants to receive the underlying asset directly + **/ + function liquidationCall( + address _collateral, + address _reserve, + address _user, + uint256 _purchaseAmount, + bool _receiveAToken + ) external payable; + + function getReserveConfigurationData(address _reserve) + external + view + returns ( + uint256 ltv, + uint256 liquidationThreshold, + uint256 liquidationBonus, + address interestRateStrategyAddress, + bool usageAsCollateralEnabled, + bool borrowingEnabled, + bool stableBorrowRateEnabled, + bool isActive + ); + + function getReserveData(address _reserve) + external + view + returns ( + uint256 totalLiquidity, + uint256 availableLiquidity, + uint256 totalBorrowsStable, + uint256 totalBorrowsVariable, + uint256 liquidityRate, + uint256 variableBorrowRate, + uint256 stableBorrowRate, + uint256 averageStableBorrowRate, + uint256 utilizationRate, + uint256 liquidityIndex, + uint256 variableBorrowIndex, + address aTokenAddress, + uint40 lastUpdateTimestamp + ); + + function getReserves() external view returns (address[] memory); + function borrow( address _reserve, uint256 _amount, diff --git a/interfaces/aave/AaveToken.sol b/interfaces/aave/AaveToken.sol index 4daf9847..113d3a24 100644 --- a/interfaces/aave/AaveToken.sol +++ b/interfaces/aave/AaveToken.sol @@ -1,5 +1,121 @@ pragma solidity ^0.5.17; interface AaveToken { + /** + * @dev redirects the interest generated to a target address. + * when the interest is redirected, the user balance is added to + * the recepient redirected balance. + * @param _to the address to which the interest will be redirected + **/ + function redirectInterestStream(address _to) external; + + /** + * @dev redirects the interest generated by _from to a target address. + * when the interest is redirected, the user balance is added to + * the recepient redirected balance. The caller needs to have allowance on + * the interest redirection to be able to execute the function. + * @param _from the address of the user whom interest is being redirected + * @param _to the address to which the interest will be redirected + **/ + function redirectInterestStreamOf(address _from, address _to) external; + + /** + * @dev gives allowance to an address to execute the interest redirection + * on behalf of the caller. + * @param _to the address to which the interest will be redirected. Pass address(0) to reset + * the allowance. + **/ + function allowInterestRedirectionTo(address _to) external; + + /** + * @dev redeems aToken for the underlying asset + * @param _amount the amount being redeemed + **/ + function redeem(uint256 _amount) external; + + /** + * @dev mints token in the event of users depositing the underlying asset into the lending pool + * only lending pools can call this function + * @param _account the address receiving the minted tokens + * @param _amount the amount of tokens to mint + */ + function mintOnDeposit(address _account, uint256 _amount) external; + + /** + * @dev burns token in the event of a borrow being liquidated, in case the liquidators reclaims the underlying asset + * Transfer of the liquidated asset is executed by the lending pool contract. + * only lending pools can call this function + * @param _account the address from which burn the aTokens + * @param _value the amount to burn + **/ + function burnOnLiquidation(address _account, uint256 _value) external; + + /** + * @dev transfers tokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken + * only lending pools can call this function + * @param _from the address from which transfer the aTokens + * @param _to the destination address + * @param _value the amount to transfer + **/ + function transferOnLiquidation( + address _from, + address _to, + uint256 _value + ) external; + + /** + * @dev calculates the balance of the user, which is the + * principal balance + interest generated by the principal balance + interest generated by the redirected balance + * @param _user the user for which the balance is being calculated + * @return the total balance of the user + **/ + function balanceOf(address _user) external view returns (uint256); + + /** + * @dev returns the principal balance of the user. The principal balance is the last + * updated stored balance, which does not consider the perpetually accruing interest. + * @param _user the address of the user + * @return the principal balance of the user + **/ + function principalBalanceOf(address _user) external view returns (uint256); + + /** + * @dev calculates the total supply of the specific aToken + * since the balance of every single user increases over time, the total supply + * does that too. + * @return the current total supply + **/ + function totalSupply() external view returns (uint256); + + /** + * @dev Used to validate transfers before actually executing them. + * @param _user address of the user to check + * @param _amount the amount to check + * @return true if the _user can transfer _amount, false otherwise + **/ + function isTransferAllowed(address _user, uint256 _amount) external view returns (bool); + + /** + * @dev returns the last index of the user, used to calculate the balance of the user + * @param _user address of the user + * @return the last user index + **/ + function getUserIndex(address _user) external view returns (uint256); + + /** + * @dev returns the address to which the interest is redirected + * @param _user address of the user + * @return 0 if there is no redirection, an address otherwise + **/ + function getInterestRedirectionAddress(address _user) external view returns (address); + + /** + * @dev returns the redirected balance of the user. The redirected balance is the balance + * redirected by other accounts to the user, that is accrueing interest for him. + * @param _user address of the user + * @return the total redirected balance + **/ + function getRedirectedBalance(address _user) external view returns (uint256); + function underlyingAssetAddress() external view returns (address); } diff --git a/interfaces/aave/LendingPoolAddressesProvider.sol b/interfaces/aave/LendingPoolAddressesProvider.sol index abbf4c12..de929109 100644 --- a/interfaces/aave/LendingPoolAddressesProvider.sol +++ b/interfaces/aave/LendingPoolAddressesProvider.sol @@ -1,9 +1,110 @@ pragma solidity ^0.5.17; -interface LendingPoolAddressesProvider { +/** +@title ILendingPoolAddressesProvider interface +@notice provides the interface to fetch the LendingPoolCore address + */ + +contract LendingPoolAddressesProvider { + /** + * @dev returns the address of the LendingPool proxy + * @return the lending pool proxy address + **/ function getLendingPool() external view returns (address); - function getLendingPoolCore() external view returns (address); + /** + * @dev updates the implementation of the lending pool + * @param _pool the new lending pool implementation + **/ + function setLendingPoolImpl(address _pool) external; + + /** + * @dev returns the address of the LendingPoolCore proxy + * @return the lending pool core proxy address + */ + function getLendingPoolCore() external view returns (address payable); + + /** + * @dev updates the implementation of the lending pool core + * @param _lendingPoolCore the new lending pool core implementation + **/ + function setLendingPoolCoreImpl(address _lendingPoolCore) external; + + /** + * @dev returns the address of the LendingPoolConfigurator proxy + * @return the lending pool configurator proxy address + **/ + function getLendingPoolConfigurator() external view returns (address); + + /** + * @dev updates the implementation of the lending pool configurator + * @param _configurator the new lending pool configurator implementation + **/ + function setLendingPoolConfiguratorImpl(address _configurator) external; + + /** + * @dev returns the address of the LendingPoolDataProvider proxy + * @return the lending pool data provider proxy address + */ + function getLendingPoolDataProvider() external view returns (address); + + /** + * @dev updates the implementation of the lending pool data provider + * @param _provider the new lending pool data provider implementation + **/ + function setLendingPoolDataProviderImpl(address _provider) external; + + /** + * @dev returns the address of the LendingPoolParametersProvider proxy + * @return the address of the Lending pool parameters provider proxy + **/ + function getLendingPoolParametersProvider() external view returns (address); + + /** + * @dev updates the implementation of the lending pool parameters provider + * @param _parametersProvider the new lending pool parameters provider implementation + **/ + function setLendingPoolParametersProviderImpl(address _parametersProvider) external; + + function getTokenDistributor() external view returns (address); + + function setTokenDistributor(address _tokenDistributor) external; + + /** + * @dev returns the address of the FeeProvider proxy + * @return the address of the Fee provider proxy + **/ + function getFeeProvider() external view returns (address); + + /** + * @dev updates the implementation of the FeeProvider proxy + * @param _feeProvider the new lending pool fee provider implementation + **/ + function setFeeProviderImpl(address _feeProvider) external; + + /** + * @dev returns the address of the LendingPoolLiquidationManager. Since the manager is used + * through delegateCall within the LendingPool contract, the proxy contract pattern does not work properly hence + * the addresses are changed directly. + * @return the address of the Lending pool liquidation manager + **/ + function getLendingPoolLiquidationManager() external view returns (address); + + /** + * @dev updates the address of the Lending pool liquidation manager + * @param _manager the new lending pool liquidation manager address + **/ + function setLendingPoolLiquidationManager(address _manager) external; + + function getLendingPoolManager() external view returns (address); + + function setLendingPoolManager(address _lendingPoolManager) 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/interfaces/compound/Token.sol b/interfaces/compound/Token.sol index e3bc9c6d..7653ee73 100644 --- a/interfaces/compound/Token.sol +++ b/interfaces/compound/Token.sol @@ -3,6 +3,90 @@ pragma solidity ^0.5.17; interface cToken { + /** + * @notice Transfer `amount` tokens from `msg.sender` to `dst` + * @param dst The address of the destination account + * @param amount The number of tokens to transfer + * @return Whether or not the transfer succeeded + */ + function transfer(address dst, uint256 amount) external returns (bool); + + /** + * @notice Transfer `amount` tokens from `src` to `dst` + * @param src The address of the source account + * @param dst The address of the destination account + * @param amount The number of tokens to transfer + * @return Whether or not the transfer succeeded + */ + function transferFrom( + address src, + address dst, + uint256 amount + ) external returns (bool); + + /** + * @notice Approve `spender` to transfer up to `amount` from `src` + * @dev This will overwrite the approval amount for `spender` + * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) + * @param spender The address of the account which may transfer tokens + * @param amount The number of tokens that are approved (-1 means infinite) + * @return Whether or not the approval succeeded + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @notice Get the current allowance from `owner` for `spender` + * @param owner The address of the account which owns the tokens to be spent + * @param spender The address of the account which may transfer tokens + * @return The number of tokens allowed to be spent (-1 means infinite) + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @notice Returns the current per-block borrow interest rate for this cToken + * @return The borrow interest rate per block, scaled by 1e18 + */ + function borrowRatePerBlock() external view returns (uint256); + + /** + * @notice Returns the current per-block supply interest rate for this cToken + * @return The supply interest rate per block, scaled by 1e18 + */ + function supplyRatePerBlock() external view returns (uint256); + + /** + * @notice Returns the current total borrows plus accrued interest + * @return The total borrows with interest + */ + function totalBorrowsCurrent() external returns (uint256); + + /** + * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex + * @param account The address whose balance should be calculated after updating borrowIndex + * @return The calculated balance + */ + function borrowBalanceCurrent(address account) external returns (uint256); + + /** + * @notice Return the borrow balance of account based on stored data + * @param account The address whose balance should be calculated + * @return The calculated balance + */ + function borrowBalanceStored(address account) external view returns (uint256); + + /** + * @notice Get cash balance of this cToken in the underlying asset + * @return The quantity of underlying asset owned by this contract + */ + function getCash() external view returns (uint256); + + /** + * @notice Applies accrued interest to total borrows and reserves + * @dev This calculates interest accrued from the last checkpointed block + * up to the current block and writes new checkpoint to storage. + */ + function accrueInterest() external returns (uint256); + function mint(uint256 mintAmount) external returns (uint256); function redeem(uint256 redeemTokens) external returns (uint256); @@ -13,9 +97,49 @@ interface cToken { function repayBorrow(uint256 repayAmount) external returns (uint256); + /** + * @notice Accrue interest then return the up-to-date exchange rate + * @return Calculated exchange rate scaled by 1e18 + */ + function exchangeRateCurrent() external returns (uint256); + + /** + * @notice Calculates the exchange rate from the underlying to the CToken + * @dev This function does not accrue interest before calculating the exchange rate + * @return Calculated exchange rate scaled by 1e18 + */ function exchangeRateStored() external view returns (uint256); + /** + * @notice Get the token balance of the `owner` + * @param _owner The address of the account to query + * @return The number of tokens owned by `owner` + */ function balanceOf(address _owner) external view returns (uint256); + /** + * @notice Get the underlying balance of the `owner` + * @dev This also accrues interest in a transaction + * @param owner The address of the account to query + * @return The amount of underlying owned by `owner` + */ + function balanceOfUnderlying(address owner) external returns (uint256); + + /** + * @notice Get a snapshot of the account's balances, and the cached exchange rate + * @dev This is used by comptroller to more efficiently perform liquidity checks. + * @param account Address of the account to snapshot + * @return (possible error, token balance, borrow balance, exchange rate mantissa) + */ + function getAccountSnapshot(address account) + external + view + returns ( + uint256, + uint256, + uint256, + uint256 + ); + function underlying() external view returns (address); } diff --git a/interfaces/cream/CToken.sol b/interfaces/cream/CToken.sol new file mode 100644 index 00000000..7870220e --- /dev/null +++ b/interfaces/cream/CToken.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.5.17; + +interface CToken { + function decimals() external view returns (uint8); + + function totalSupply() external view returns (uint256); + + function underlying() external view returns (address); + + function balanceOfUnderlying(address) external returns (uint256); + + function supplyRatePerBlock() external returns (uint256); + + function exchangeRateCurrent() external returns (uint256); + + function mint(uint256) external returns (uint256); + + function balanceOf(address) external view returns (uint256); + + function redeemUnderlying(uint256) external returns (uint256); + + function redeem(uint256) external returns (uint256); + + function approve(address, uint256) external returns (bool); +} diff --git a/interfaces/cream/Controller.sol b/interfaces/cream/Controller.sol index 1d2caab6..017f0de7 100644 --- a/interfaces/cream/Controller.sol +++ b/interfaces/cream/Controller.sol @@ -2,6 +2,34 @@ pragma solidity ^0.5.17; +import "./CToken.sol"; + interface Creamtroller { + /** + * @notice Claim all the comp accrued by holder in all markets + * @param holder The address to claim COMP for + */ function claimComp(address holder) external; + + /** + * @notice Returns the assets an account has entered + * @param account The address of the account to pull assets for + * @return A dynamic list with the assets the account has entered + */ + function getAssetsIn(address account) external view returns (CToken[] memory); + + /** + * @notice Returns whether the given account is entered in the given asset + * @param account The address of the account to check + * @param cToken The cToken to check + * @return True if the account is in the asset, otherwise false. + */ + function checkMembership(address account, CToken cToken) external view returns (bool); + + /** + * @notice Add assets to be included in account liquidity calculation + * @param cTokens The list of addresses of the cToken markets to be enabled + * @return Success indicator for whether each corresponding market was entered + */ + function enterMarkets(address[] calldata cTokens) external returns (uint256[] memory); } diff --git a/interfaces/uniswap/Uni.sol b/interfaces/uniswap/Uni.sol index f644d0a1..0ff1375b 100644 --- a/interfaces/uniswap/Uni.sol +++ b/interfaces/uniswap/Uni.sol @@ -3,11 +3,202 @@ pragma solidity ^0.5.17; interface Uni { + function factory() external view returns (address); + + function WETH() external view returns (address); + + function addLiquidity( + address tokenA, + address tokenB, + uint256 amountADesired, + uint256 amountBDesired, + uint256 amountAMin, + uint256 amountBMin, + address to, + uint256 deadline + ) + external + returns ( + uint256 amountA, + uint256 amountB, + uint256 liquidity + ); + + function addLiquidityETH( + address token, + uint256 amountTokenDesired, + uint256 amountTokenMin, + uint256 amountETHMin, + address to, + uint256 deadline + ) + external + payable + returns ( + uint256 amountToken, + uint256 amountETH, + uint256 liquidity + ); + + // **** REMOVE LIQUIDITY **** + function removeLiquidity( + address tokenA, + address tokenB, + uint256 liquidity, + uint256 amountAMin, + uint256 amountBMin, + address to, + uint256 deadline + ) external returns (uint256 amountA, uint256 amountB); + + function removeLiquidityETH( + address token, + uint256 liquidity, + uint256 amountTokenMin, + uint256 amountETHMin, + address to, + uint256 deadline + ) external returns (uint256 amountToken, uint256 amountETH); + + function removeLiquidityWithPermit( + address tokenA, + address tokenB, + uint256 liquidity, + uint256 amountAMin, + uint256 amountBMin, + address to, + uint256 deadline, + bool approveMax, + uint8 v, + bytes32 r, + bytes32 s + ) external returns (uint256 amountA, uint256 amountB); + + function removeLiquidityETHWithPermit( + address token, + uint256 liquidity, + uint256 amountTokenMin, + uint256 amountETHMin, + address to, + uint256 deadline, + bool approveMax, + uint8 v, + bytes32 r, + bytes32 s + ) external returns (uint256 amountToken, uint256 amountETH); + + // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) **** + function removeLiquidityETHSupportingFeeOnTransferTokens( + address token, + uint256 liquidity, + uint256 amountTokenMin, + uint256 amountETHMin, + address to, + uint256 deadline + ) external returns (uint256 amountETH); + + function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( + address token, + uint256 liquidity, + uint256 amountTokenMin, + uint256 amountETHMin, + address to, + uint256 deadline, + bool approveMax, + uint8 v, + bytes32 r, + bytes32 s + ) external returns (uint256 amountETH); + function swapExactTokensForTokens( - uint256, - uint256, - address[] calldata, - address, - uint256 + uint256 amountIn, + uint256 amountOutMin, + address[] calldata path, + address to, + uint256 deadline + ) external returns (uint256[] memory amounts); + + function swapTokensForExactTokens( + uint256 amountOut, + uint256 amountInMax, + address[] calldata path, + address to, + uint256 deadline + ) external returns (uint256[] memory amounts); + + function swapExactETHForTokens( + uint256 amountOutMin, + address[] calldata path, + address to, + uint256 deadline + ) external payable returns (uint256[] memory amounts); + + function swapTokensForExactETH( + uint256 amountOut, + uint256 amountInMax, + address[] calldata path, + address to, + uint256 deadline + ) external returns (uint256[] memory amounts); + + function swapExactTokensForETH( + uint256 amountIn, + uint256 amountOutMin, + address[] calldata path, + address to, + uint256 deadline + ) external returns (uint256[] memory amounts); + + function swapETHForExactTokens( + uint256 amountOut, + address[] calldata path, + address to, + uint256 deadline + ) external payable returns (uint256[] memory amounts); + + function swapExactTokensForTokensSupportingFeeOnTransferTokens( + uint256 amountIn, + uint256 amountOutMin, + address[] calldata path, + address to, + uint256 deadline + ) external; + + function swapExactETHForTokensSupportingFeeOnTransferTokens( + uint256 amountOutMin, + address[] calldata path, + address to, + uint256 deadline + ) external payable; + + function swapExactTokensForETHSupportingFeeOnTransferTokens( + uint256 amountIn, + uint256 amountOutMin, + address[] calldata path, + address to, + uint256 deadline ) external; + + // **** LIBRARY FUNCTIONS **** + function quote( + uint256 amountA, + uint256 reserveA, + uint256 reserveB + ) external pure returns (uint256 amountB); + + function getAmountOut( + uint256 amountIn, + uint256 reserveIn, + uint256 reserveOut + ) external pure returns (uint256 amountOut); + + function getAmountIn( + uint256 amountOut, + uint256 reserveIn, + uint256 reserveOut + ) external pure returns (uint256 amountIn); + + function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); + + function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } diff --git a/interfaces/weth/WETH.sol b/interfaces/weth/WETH.sol index 4479cc9d..aa4a479b 100644 --- a/interfaces/weth/WETH.sol +++ b/interfaces/weth/WETH.sol @@ -3,8 +3,19 @@ pragma solidity ^0.5.17; interface WETH { function deposit() external payable; - function withdraw(uint256 wad) external; + function withdraw(uint256) external; - event Deposit(address indexed dst, uint256 wad); - event Withdrawal(address indexed src, uint256 wad); + function totalSupply() external view returns (uint256); + + function approve(address to, uint256 value) external returns (bool); + + function transfer(address to, uint256 value) external returns (bool); + + function transferFrom( + address src, + address dst, + uint256 wad + ) external returns (bool); + + function balanceOf(address user) external returns (uint256); }