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:
The-3D 2020-08-21 13:03:47 +00:00
commit dfa64d63f3
2 changed files with 64 additions and 64 deletions

View File

@ -22,94 +22,94 @@ contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable {
event FallbackOracleUpdated(address indexed fallbackOracle); event FallbackOracleUpdated(address indexed fallbackOracle);
mapping(address => IChainlinkAggregator) private assetsSources; mapping(address => IChainlinkAggregator) private assetsSources;
IPriceOracleGetter private fallbackOracle; IPriceOracleGetter private _fallbackOracle;
/// @notice Constructor /// @notice Constructor
/// @param _assets The addresses of the assets /// @param assets The addresses of the assets
/// @param _sources The address of the source of each asset /// @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 fallbackOracle The address of the fallback oracle to use if the data of an
/// aggregator is not consistent /// aggregator is not consistent
constructor( constructor(
address[] memory _assets, address[] memory assets,
address[] memory _sources, address[] memory sources,
address _fallbackOracle address fallbackOracle
) public { ) public {
internalSetFallbackOracle(_fallbackOracle); _setFallbackOracle(fallbackOracle);
internalSetAssetsSources(_assets, _sources); _setAssetsSources(assets, sources);
} }
/// @notice External function called by the Aave governance to set or replace sources of assets /// @notice External function called by the Aave governance to set or replace sources of assets
/// @param _assets The addresses of the assets /// @param assets The addresses of the assets
/// @param _sources The address of the source of each asset /// @param sources The address of the source of each asset
function setAssetSources(address[] calldata _assets, address[] calldata _sources) function setAssetSources(address[] calldata assets, address[] calldata sources)
external external
onlyOwner onlyOwner
{ {
internalSetAssetsSources(_assets, _sources); _setAssetsSources(assets, sources);
} }
/// @notice Sets the fallbackOracle /// @notice Sets the fallbackOracle
/// - Callable only by the Aave governance /// - Callable only by the Aave governance
/// @param _fallbackOracle The address of the fallbackOracle /// @param fallbackOracle The address of the fallbackOracle
function setFallbackOracle(address _fallbackOracle) external onlyOwner { function setFallbackOracle(address fallbackOracle) external onlyOwner {
internalSetFallbackOracle(_fallbackOracle); _setFallbackOracle(fallbackOracle);
} }
/// @notice Internal function to set the sources for each asset /// @notice Internal function to set the sources for each asset
/// @param _assets The addresses of the assets /// @param assets The addresses of the assets
/// @param _sources The address of the source of each asset /// @param sources The address of the source of each asset
function internalSetAssetsSources(address[] memory _assets, address[] memory _sources) internal { function _setAssetsSources(address[] memory assets, address[] memory sources) internal {
require(_assets.length == _sources.length, 'INCONSISTENT_PARAMS_LENGTH'); require(assets.length == sources.length, 'INCONSISTENT_PARAMS_LENGTH');
for (uint256 i = 0; i < _assets.length; i++) { for (uint256 i = 0; i < assets.length; i++) {
assetsSources[_assets[i]] = IChainlinkAggregator(_sources[i]); assetsSources[assets[i]] = IChainlinkAggregator(sources[i]);
emit AssetSourceUpdated(_assets[i], _sources[i]); emit AssetSourceUpdated(assets[i], sources[i]);
} }
} }
/// @notice Internal function to set the fallbackOracle /// @notice Internal function to set the fallbackOracle
/// @param _fallbackOracle The address of the fallbackOracle /// @param fallbackOracle The address of the fallbackOracle
function internalSetFallbackOracle(address _fallbackOracle) internal { function _setFallbackOracle(address fallbackOracle) internal {
fallbackOracle = IPriceOracleGetter(_fallbackOracle); _fallbackOracle = IPriceOracleGetter(fallbackOracle);
emit FallbackOracleUpdated(_fallbackOracle); emit FallbackOracleUpdated(fallbackOracle);
} }
/// @notice Gets an asset price by address /// @notice Gets an asset price by address
/// @param _asset The asset address /// @param asset The asset address
function getAssetPrice(address _asset) public override view returns (uint256) { function getAssetPrice(address asset) public override view returns (uint256) {
IChainlinkAggregator source = assetsSources[_asset]; IChainlinkAggregator source = assetsSources[asset];
// If there is no registered source for the asset, call the fallbackOracle // If there is no registered source for the asset, call the fallbackOracle
if (address(source) == address(0)) { if (address(source) == address(0)) {
return IPriceOracleGetter(fallbackOracle).getAssetPrice(_asset); return _fallbackOracle.getAssetPrice(asset);
} else { } else {
int256 _price = IChainlinkAggregator(source).latestAnswer(); int256 price = IChainlinkAggregator(source).latestAnswer();
if (_price > 0) { if (price > 0) {
return uint256(_price); return uint256(price);
} else { } else {
return IPriceOracleGetter(fallbackOracle).getAssetPrice(_asset); return _fallbackOracle.getAssetPrice(asset);
} }
} }
} }
/// @notice Gets a list of prices from a list of assets addresses /// @notice Gets a list of prices from a list of assets addresses
/// @param _assets The list of assets addresses /// @param assets The list of assets addresses
function getAssetsPrices(address[] calldata _assets) external view returns (uint256[] memory) { function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory) {
uint256[] memory prices = new uint256[](_assets.length); uint256[] memory prices = new uint256[](assets.length);
for (uint256 i = 0; i < _assets.length; i++) { for (uint256 i = 0; i < assets.length; i++) {
prices[i] = getAssetPrice(_assets[i]); prices[i] = getAssetPrice(assets[i]);
} }
return prices; return prices;
} }
/// @notice Gets the address of the source for an asset address /// @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 /// @return address The address of the source
function getSourceOfAsset(address _asset) external view returns (address) { function getSourceOfAsset(address asset) external view returns (address) {
return address(assetsSources[_asset]); return address(assetsSources[asset]);
} }
/// @notice Gets the address of the fallback oracle /// @notice Gets the address of the fallback oracle
/// @return address The addres of the fallback oracle /// @return address The addres of the fallback oracle
function getFallbackOracle() external view returns (address) { function getFallbackOracle() external view returns (address) {
return address(fallbackOracle); return address(_fallbackOracle);
} }
} }

View File

@ -20,10 +20,10 @@ contract WalletBalanceProvider {
using Address for address; using Address for address;
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
LendingPoolAddressesProvider provider; LendingPoolAddressesProvider internal immutable _provider;
constructor(LendingPoolAddressesProvider _provider) public { constructor(LendingPoolAddressesProvider provider) public {
provider = _provider; _provider = provider;
} }
/** /**
@ -40,10 +40,10 @@ contract WalletBalanceProvider {
Returns the balance of the token for user. Avoids possible errors: Returns the balance of the token for user. Avoids possible errors:
- return 0 on non-contract address - 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 // check if token is actually a contract
if (_token.isContract()) { if (token.isContract()) {
return IERC20(_token).balanceOf(_user); return IERC20(token).balanceOf(user);
} else { } else {
return 0; return 0;
} }
@ -51,24 +51,24 @@ contract WalletBalanceProvider {
/** /**
* @notice Fetches, for a list of _users and _tokens (ETH included with mock address), the balances * @notice Fetches, for a list of _users and _tokens (ETH included with mock address), the balances
* @param _users The list of users * @param users The list of users
* @param _tokens The list of tokens * @param tokens The list of tokens
* @return And array with the concatenation of, for each user, his/her balances * @return And array with the concatenation of, for each user, his/her balances
**/ **/
function batchBalanceOf(address[] memory _users, address[] memory _tokens) function batchBalanceOf(address[] calldata users, address[] calldata tokens)
public external
view view
returns (uint256[] memory) 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 i = 0; i < users.length; i++) {
for (uint256 j = 0; j < _tokens.length; j++) { for (uint256 j = 0; j < tokens.length; j++) {
uint256 _offset = i * _tokens.length; uint256 _offset = i * tokens.length;
if (!_tokens[j].isContract()) { if (!tokens[j].isContract()) {
revert('INVALID_TOKEN'); revert('INVALID_TOKEN');
} else { } 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 @dev provides balances of user wallet for all reserves available on the pool
*/ */
function getUserWalletBalances(address _user) function getUserWalletBalances(address user)
public external
view view
returns (address[] memory, uint256[] memory) returns (address[] memory, uint256[] memory)
{ {
ILendingPool pool = ILendingPool(provider.getLendingPool()); ILendingPool pool = ILendingPool(_provider.getLendingPool());
address[] memory reserves = pool.getReserves(); address[] memory reserves = pool.getReserves();
@ -97,7 +97,7 @@ contract WalletBalanceProvider {
balances[j] = 0; balances[j] = 0;
continue; continue;
} }
balances[j] = balanceOf(_user, reserves[j]); balances[j] = balanceOf(user, reserves[j]);
} }
return (reserves, balances); return (reserves, balances);