2020-05-29 16:45:37 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
|
|
|
pragma solidity ^0.6.8;
|
|
|
|
|
2020-10-15 13:25:27 +00:00
|
|
|
import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol';
|
2020-08-21 13:38:47 +00:00
|
|
|
import {
|
|
|
|
ILendingPoolAddressesProviderRegistry
|
|
|
|
} from '../interfaces/ILendingPoolAddressesProviderRegistry.sol';
|
2020-09-02 15:54:34 +00:00
|
|
|
import {Errors} from '../libraries/helpers/Errors.sol';
|
2020-05-29 16:45:37 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-13 08:54:08 +00:00
|
|
|
* @title LendingPoolAddressesProviderRegistry contract
|
|
|
|
* @notice contains the list of active addresses providers
|
|
|
|
* @author Aave
|
|
|
|
**/
|
2020-05-29 16:45:37 +00:00
|
|
|
|
|
|
|
contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesProviderRegistry {
|
2020-09-29 14:31:21 +00:00
|
|
|
mapping(address => uint256) private _addressesProviders;
|
|
|
|
address[] private _addressesProvidersList;
|
2020-07-13 08:54:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev returns if an addressesProvider is registered or not
|
2020-08-21 13:38:47 +00:00
|
|
|
* @param provider the addresses provider
|
2020-10-28 10:56:10 +00:00
|
|
|
* @return The id of the addresses provider or 0 if the addresses provider not registered
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-08-21 13:38:47 +00:00
|
|
|
function isAddressesProviderRegistered(address provider)
|
2020-07-13 08:54:08 +00:00
|
|
|
external
|
|
|
|
override
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
2020-09-29 14:31:21 +00:00
|
|
|
return _addressesProviders[provider];
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev returns the list of active addressesProviders
|
2020-10-28 10:56:10 +00:00
|
|
|
* @return the list of addressesProviders, potentially containing address(0) elements
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
|
|
|
function getAddressesProvidersList() external override view returns (address[] memory) {
|
2020-10-26 10:10:57 +00:00
|
|
|
address[] memory addressesProvidersList = _addressesProvidersList;
|
|
|
|
|
|
|
|
uint256 maxLength = addressesProvidersList.length;
|
2020-07-13 08:54:08 +00:00
|
|
|
|
|
|
|
address[] memory activeProviders = new address[](maxLength);
|
|
|
|
|
2020-10-26 10:10:57 +00:00
|
|
|
for (uint256 i = 0; i < maxLength; i++) {
|
|
|
|
if (_addressesProviders[addressesProvidersList[i]] > 0) {
|
|
|
|
activeProviders[i] = addressesProvidersList[i];
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
2020-05-29 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
return activeProviders;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev adds a lending pool to the list of registered lending pools
|
2020-08-21 13:38:47 +00:00
|
|
|
* @param provider the pool address to be registered
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-08-21 13:38:47 +00:00
|
|
|
function registerAddressesProvider(address provider, uint256 id) external override onlyOwner {
|
2020-10-30 12:40:06 +00:00
|
|
|
require(id != 0, Errors.LPAPR_INVALID_ADDRESSES_PROVIDER_ID);
|
2020-10-19 16:29:32 +00:00
|
|
|
|
2020-09-29 14:31:21 +00:00
|
|
|
_addressesProviders[provider] = id;
|
2020-08-21 13:38:47 +00:00
|
|
|
_addToAddressesProvidersList(provider);
|
|
|
|
emit AddressesProviderRegistered(provider);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev removes a lending pool from the list of registered lending pools
|
2020-08-21 13:38:47 +00:00
|
|
|
* @param provider the pool address to be unregistered
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-08-21 13:38:47 +00:00
|
|
|
function unregisterAddressesProvider(address provider) external override onlyOwner {
|
2020-10-14 09:03:32 +00:00
|
|
|
require(_addressesProviders[provider] > 0, Errors.LPAPR_PROVIDER_NOT_REGISTERED);
|
2020-09-29 14:31:21 +00:00
|
|
|
_addressesProviders[provider] = 0;
|
2020-08-21 13:38:47 +00:00
|
|
|
emit AddressesProviderUnregistered(provider);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev adds to the list of the addresses providers, if it wasn't already added before
|
2020-08-21 13:38:47 +00:00
|
|
|
* @param provider the pool address to be added
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-08-21 13:38:47 +00:00
|
|
|
function _addToAddressesProvidersList(address provider) internal {
|
2020-10-26 10:18:56 +00:00
|
|
|
uint256 providersCount = _addressesProvidersList.length;
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < providersCount; i++) {
|
2020-09-29 14:31:21 +00:00
|
|
|
if (_addressesProvidersList[i] == provider) {
|
2020-07-13 08:54:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-29 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 14:31:21 +00:00
|
|
|
_addressesProvidersList.push(provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Returns the id on an `addressesProvider` or address(0) if not registered
|
2020-10-28 10:56:10 +00:00
|
|
|
* @return The id or 0 if the addresses provider is not registered
|
2020-09-29 14:31:21 +00:00
|
|
|
*/
|
|
|
|
function getAddressesProviderIdByAddress(address addressesProvider)
|
|
|
|
external
|
|
|
|
override
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
|
|
|
return _addressesProviders[addressesProvider];
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
2020-05-29 16:45:37 +00:00
|
|
|
}
|