mirror of
				https://github.com/Instadapp/aave-protocol-v2.git
				synced 2024-07-29 21:47:30 +00:00 
			
		
		
		
	Merge branch 'fix/misc-guideline' into 'master'
Refactoring misc folder to fit current guideline See merge request aave-tech/protocol-v2!26
This commit is contained in:
		
						commit
						dfa64d63f3
					
				|  | @ -22,94 +22,94 @@ contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable { | |||
|   event FallbackOracleUpdated(address indexed fallbackOracle); | ||||
| 
 | ||||
|   mapping(address => IChainlinkAggregator) private assetsSources; | ||||
|   IPriceOracleGetter private fallbackOracle; | ||||
|   IPriceOracleGetter private _fallbackOracle; | ||||
| 
 | ||||
|   /// @notice Constructor | ||||
|   /// @param _assets The addresses of the assets | ||||
|   /// @param _sources The address of the source of each asset | ||||
|   /// @param _fallbackOracle The address of the fallback oracle to use if the data of an | ||||
|   /// @param assets The addresses of the assets | ||||
|   /// @param sources The address of the source of each asset | ||||
|   /// @param fallbackOracle The address of the fallback oracle to use if the data of an | ||||
|   ///        aggregator is not consistent | ||||
|   constructor( | ||||
|     address[] memory _assets, | ||||
|     address[] memory _sources, | ||||
|     address _fallbackOracle | ||||
|     address[] memory assets, | ||||
|     address[] memory sources, | ||||
|     address fallbackOracle | ||||
|   ) public { | ||||
|     internalSetFallbackOracle(_fallbackOracle); | ||||
|     internalSetAssetsSources(_assets, _sources); | ||||
|     _setFallbackOracle(fallbackOracle); | ||||
|     _setAssetsSources(assets, sources); | ||||
|   } | ||||
| 
 | ||||
|   /// @notice External function called by the Aave governance to set or replace sources of assets | ||||
|   /// @param _assets The addresses of the assets | ||||
|   /// @param _sources The address of the source of each asset | ||||
|   function setAssetSources(address[] calldata _assets, address[] calldata _sources) | ||||
|   /// @param assets The addresses of the assets | ||||
|   /// @param sources The address of the source of each asset | ||||
|   function setAssetSources(address[] calldata assets, address[] calldata sources) | ||||
|     external | ||||
|     onlyOwner | ||||
|   { | ||||
|     internalSetAssetsSources(_assets, _sources); | ||||
|     _setAssetsSources(assets, sources); | ||||
|   } | ||||
| 
 | ||||
|   /// @notice Sets the fallbackOracle | ||||
|   /// - Callable only by the Aave governance | ||||
|   /// @param _fallbackOracle The address of the fallbackOracle | ||||
|   function setFallbackOracle(address _fallbackOracle) external onlyOwner { | ||||
|     internalSetFallbackOracle(_fallbackOracle); | ||||
|   /// @param fallbackOracle The address of the fallbackOracle | ||||
|   function setFallbackOracle(address fallbackOracle) external onlyOwner { | ||||
|     _setFallbackOracle(fallbackOracle); | ||||
|   } | ||||
| 
 | ||||
|   /// @notice Internal function to set the sources for each asset | ||||
|   /// @param _assets The addresses of the assets | ||||
|   /// @param _sources The address of the source of each asset | ||||
|   function internalSetAssetsSources(address[] memory _assets, address[] memory _sources) internal { | ||||
|     require(_assets.length == _sources.length, 'INCONSISTENT_PARAMS_LENGTH'); | ||||
|     for (uint256 i = 0; i < _assets.length; i++) { | ||||
|       assetsSources[_assets[i]] = IChainlinkAggregator(_sources[i]); | ||||
|       emit AssetSourceUpdated(_assets[i], _sources[i]); | ||||
|   /// @param assets The addresses of the assets | ||||
|   /// @param sources The address of the source of each asset | ||||
|   function _setAssetsSources(address[] memory assets, address[] memory sources) internal { | ||||
|     require(assets.length == sources.length, 'INCONSISTENT_PARAMS_LENGTH'); | ||||
|     for (uint256 i = 0; i < assets.length; i++) { | ||||
|       assetsSources[assets[i]] = IChainlinkAggregator(sources[i]); | ||||
|       emit AssetSourceUpdated(assets[i], sources[i]); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /// @notice Internal function to set the fallbackOracle | ||||
|   /// @param _fallbackOracle The address of the fallbackOracle | ||||
|   function internalSetFallbackOracle(address _fallbackOracle) internal { | ||||
|     fallbackOracle = IPriceOracleGetter(_fallbackOracle); | ||||
|     emit FallbackOracleUpdated(_fallbackOracle); | ||||
|   /// @param fallbackOracle The address of the fallbackOracle | ||||
|   function _setFallbackOracle(address fallbackOracle) internal { | ||||
|     _fallbackOracle = IPriceOracleGetter(fallbackOracle); | ||||
|     emit FallbackOracleUpdated(fallbackOracle); | ||||
|   } | ||||
| 
 | ||||
|   /// @notice Gets an asset price by address | ||||
|   /// @param _asset The asset address | ||||
|   function getAssetPrice(address _asset) public override view returns (uint256) { | ||||
|     IChainlinkAggregator source = assetsSources[_asset]; | ||||
|   /// @param asset The asset address | ||||
|   function getAssetPrice(address asset) public override view returns (uint256) { | ||||
|     IChainlinkAggregator source = assetsSources[asset]; | ||||
|     // If there is no registered source for the asset, call the fallbackOracle | ||||
|     if (address(source) == address(0)) { | ||||
|       return IPriceOracleGetter(fallbackOracle).getAssetPrice(_asset); | ||||
|       return _fallbackOracle.getAssetPrice(asset); | ||||
|     } else { | ||||
|       int256 _price = IChainlinkAggregator(source).latestAnswer(); | ||||
|       if (_price > 0) { | ||||
|         return uint256(_price); | ||||
|       int256 price = IChainlinkAggregator(source).latestAnswer(); | ||||
|       if (price > 0) { | ||||
|         return uint256(price); | ||||
|       } else { | ||||
|         return IPriceOracleGetter(fallbackOracle).getAssetPrice(_asset); | ||||
|         return _fallbackOracle.getAssetPrice(asset); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /// @notice Gets a list of prices from a list of assets addresses | ||||
|   /// @param _assets The list of assets addresses | ||||
|   function getAssetsPrices(address[] calldata _assets) external view returns (uint256[] memory) { | ||||
|     uint256[] memory prices = new uint256[](_assets.length); | ||||
|     for (uint256 i = 0; i < _assets.length; i++) { | ||||
|       prices[i] = getAssetPrice(_assets[i]); | ||||
|   /// @param assets The list of assets addresses | ||||
|   function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory) { | ||||
|     uint256[] memory prices = new uint256[](assets.length); | ||||
|     for (uint256 i = 0; i < assets.length; i++) { | ||||
|       prices[i] = getAssetPrice(assets[i]); | ||||
|     } | ||||
|     return prices; | ||||
|   } | ||||
| 
 | ||||
|   /// @notice Gets the address of the source for an asset address | ||||
|   /// @param _asset The address of the asset | ||||
|   /// @param asset The address of the asset | ||||
|   /// @return address The address of the source | ||||
|   function getSourceOfAsset(address _asset) external view returns (address) { | ||||
|     return address(assetsSources[_asset]); | ||||
|   function getSourceOfAsset(address asset) external view returns (address) { | ||||
|     return address(assetsSources[asset]); | ||||
|   } | ||||
| 
 | ||||
|   /// @notice Gets the address of the fallback oracle | ||||
|   /// @return address The addres of the fallback oracle | ||||
|   function getFallbackOracle() external view returns (address) { | ||||
|     return address(fallbackOracle); | ||||
|     return address(_fallbackOracle); | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -20,10 +20,10 @@ contract WalletBalanceProvider { | |||
|   using Address for address; | ||||
|   using SafeERC20 for IERC20; | ||||
| 
 | ||||
|   LendingPoolAddressesProvider provider; | ||||
|   LendingPoolAddressesProvider internal immutable _provider; | ||||
| 
 | ||||
|   constructor(LendingPoolAddressesProvider _provider) public { | ||||
|     provider = _provider; | ||||
|   constructor(LendingPoolAddressesProvider provider) public { | ||||
|     _provider = provider; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|  | @ -40,10 +40,10 @@ contract WalletBalanceProvider { | |||
|     Returns the balance of the token for user. Avoids possible errors: | ||||
|       - return 0 on non-contract address | ||||
|     **/ | ||||
|   function balanceOf(address _user, address _token) public view returns (uint256) { | ||||
|   function balanceOf(address user, address token) public view returns (uint256) { | ||||
|     // check if token is actually a contract | ||||
|     if (_token.isContract()) { | ||||
|       return IERC20(_token).balanceOf(_user); | ||||
|     if (token.isContract()) { | ||||
|       return IERC20(token).balanceOf(user); | ||||
|     } else { | ||||
|       return 0; | ||||
|     } | ||||
|  | @ -51,24 +51,24 @@ contract WalletBalanceProvider { | |||
| 
 | ||||
|   /** | ||||
|    * @notice Fetches, for a list of _users and _tokens (ETH included with mock address), the balances | ||||
|    * @param _users The list of users | ||||
|    * @param _tokens The list of tokens | ||||
|    * @param users The list of users | ||||
|    * @param tokens The list of tokens | ||||
|    * @return And array with the concatenation of, for each user, his/her balances | ||||
|    **/ | ||||
|   function batchBalanceOf(address[] memory _users, address[] memory _tokens) | ||||
|     public | ||||
|   function batchBalanceOf(address[] calldata users, address[] calldata tokens) | ||||
|     external | ||||
|     view | ||||
|     returns (uint256[] memory) | ||||
|   { | ||||
|     uint256[] memory balances = new uint256[](_users.length * _tokens.length); | ||||
|     uint256[] memory balances = new uint256[](users.length * tokens.length); | ||||
| 
 | ||||
|     for (uint256 i = 0; i < _users.length; i++) { | ||||
|       for (uint256 j = 0; j < _tokens.length; j++) { | ||||
|         uint256 _offset = i * _tokens.length; | ||||
|         if (!_tokens[j].isContract()) { | ||||
|     for (uint256 i = 0; i < users.length; i++) { | ||||
|       for (uint256 j = 0; j < tokens.length; j++) { | ||||
|         uint256 _offset = i * tokens.length; | ||||
|         if (!tokens[j].isContract()) { | ||||
|           revert('INVALID_TOKEN'); | ||||
|         } else { | ||||
|           balances[_offset + j] = balanceOf(_users[i], _tokens[j]); | ||||
|           balances[_offset + j] = balanceOf(users[i], tokens[j]); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | @ -79,12 +79,12 @@ contract WalletBalanceProvider { | |||
|   /** | ||||
|     @dev provides balances of user wallet for all reserves available on the pool | ||||
|     */ | ||||
|   function getUserWalletBalances(address _user) | ||||
|     public | ||||
|   function getUserWalletBalances(address user) | ||||
|     external | ||||
|     view | ||||
|     returns (address[] memory, uint256[] memory) | ||||
|   { | ||||
|     ILendingPool pool = ILendingPool(provider.getLendingPool()); | ||||
|     ILendingPool pool = ILendingPool(_provider.getLendingPool()); | ||||
| 
 | ||||
|     address[] memory reserves = pool.getReserves(); | ||||
| 
 | ||||
|  | @ -97,7 +97,7 @@ contract WalletBalanceProvider { | |||
|         balances[j] = 0; | ||||
|         continue; | ||||
|       } | ||||
|       balances[j] = balanceOf(_user, reserves[j]); | ||||
|       balances[j] = balanceOf(user, reserves[j]); | ||||
|     } | ||||
| 
 | ||||
|     return (reserves, balances); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 The-3D
						The-3D