2020-05-29 16:45:37 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
2020-11-20 10:45:20 +00:00
|
|
|
pragma solidity 0.6.12;
|
2020-05-29 16:45:37 +00:00
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
import {Ownable} from '../../dependencies/openzeppelin/contracts/Ownable.sol';
|
2020-11-02 13:45:00 +00:00
|
|
|
|
|
|
|
// Prettier ignore to prevent buidler flatter bug
|
|
|
|
// prettier-ignore
|
|
|
|
import {InitializableImmutableAdminUpgradeabilityProxy} from '../libraries/aave-upgradeability/InitializableImmutableAdminUpgradeabilityProxy.sol';
|
2020-05-29 16:45:37 +00:00
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
2020-05-29 16:45:37 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-13 08:54:08 +00:00
|
|
|
* @title LendingPoolAddressesProvider contract
|
2020-11-19 13:21:36 +00:00
|
|
|
* @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
|
2020-11-19 11:52:34 +00:00
|
|
|
* - Owned by the Aave Governance
|
2020-07-13 08:54:08 +00:00
|
|
|
* @author Aave
|
|
|
|
**/
|
2020-08-19 12:53:00 +00:00
|
|
|
contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider {
|
2020-11-26 12:09:49 +00:00
|
|
|
string private _marketId;
|
2020-08-19 12:53:00 +00:00
|
|
|
mapping(bytes32 => address) private _addresses;
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
bytes32 private constant LENDING_POOL = 'LENDING_POOL';
|
|
|
|
bytes32 private constant LENDING_POOL_CONFIGURATOR = 'LENDING_POOL_CONFIGURATOR';
|
2020-11-05 11:35:50 +00:00
|
|
|
bytes32 private constant POOL_ADMIN = 'POOL_ADMIN';
|
|
|
|
bytes32 private constant EMERGENCY_ADMIN = 'EMERGENCY_ADMIN';
|
2020-09-16 12:09:42 +00:00
|
|
|
bytes32 private constant LENDING_POOL_COLLATERAL_MANAGER = 'COLLATERAL_MANAGER';
|
2020-07-13 08:54:08 +00:00
|
|
|
bytes32 private constant PRICE_ORACLE = 'PRICE_ORACLE';
|
|
|
|
bytes32 private constant LENDING_RATE_ORACLE = 'LENDING_RATE_ORACLE';
|
|
|
|
|
2020-11-26 12:09:49 +00:00
|
|
|
constructor(string memory marketId) public {
|
|
|
|
_setMarketId(marketId);
|
|
|
|
}
|
|
|
|
|
2020-11-27 09:00:11 +00:00
|
|
|
/**
|
|
|
|
* @dev Returns the id of the Aave market to which this contracts points to
|
|
|
|
* @return The market id
|
|
|
|
**/
|
2020-11-30 08:23:31 +00:00
|
|
|
function getMarketId() external view override returns (string memory) {
|
2020-11-27 09:00:11 +00:00
|
|
|
return _marketId;
|
|
|
|
}
|
|
|
|
|
2020-11-26 12:09:49 +00:00
|
|
|
/**
|
|
|
|
* @dev Allows to set the market which this LendingPoolAddressesProvider represents
|
|
|
|
* @param marketId The market id
|
|
|
|
*/
|
|
|
|
function setMarketId(string memory marketId) external override onlyOwner {
|
|
|
|
_setMarketId(marketId);
|
|
|
|
}
|
|
|
|
|
2020-09-29 14:31:21 +00:00
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev General function to update the implementation of a proxy registered with
|
|
|
|
* certain `id`. If there is no proxy registered, it will instantiate one and
|
|
|
|
* set as implementation the `implementationAddress`
|
|
|
|
* IMPORTANT Use this function carefully, only for ids that don't have an explicit
|
|
|
|
* setter function, in order to avoid unexpected consequences
|
2020-09-29 14:31:21 +00:00
|
|
|
* @param id The id
|
2020-11-19 11:52:34 +00:00
|
|
|
* @param implementationAddress The address of the new implementation
|
2020-09-29 14:31:21 +00:00
|
|
|
*/
|
2020-11-19 11:52:34 +00:00
|
|
|
function setAddressAsProxy(bytes32 id, address implementationAddress)
|
|
|
|
external
|
|
|
|
override
|
|
|
|
onlyOwner
|
|
|
|
{
|
2020-11-10 13:57:09 +00:00
|
|
|
_updateImpl(id, implementationAddress);
|
|
|
|
emit AddressSet(id, implementationAddress, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Sets an address for an id replacing the address saved in the addresses map
|
2020-11-19 11:52:34 +00:00
|
|
|
* IMPORTANT Use this function carefully, as it will do a hard replacement
|
2020-11-10 13:57:09 +00:00
|
|
|
* @param id The id
|
2020-11-19 11:52:34 +00:00
|
|
|
* @param newAddress The address to set
|
2020-11-10 13:57:09 +00:00
|
|
|
*/
|
2020-11-19 11:52:34 +00:00
|
|
|
function setAddress(bytes32 id, address newAddress) external override onlyOwner {
|
2020-11-10 13:57:09 +00:00
|
|
|
_addresses[id] = newAddress;
|
|
|
|
emit AddressSet(id, newAddress, false);
|
2020-09-29 14:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Returns an address by id
|
|
|
|
* @return The address
|
|
|
|
*/
|
2020-11-23 10:28:57 +00:00
|
|
|
function getAddress(bytes32 id) public view override returns (address) {
|
2020-09-29 14:31:21 +00:00
|
|
|
return _addresses[id];
|
|
|
|
}
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev Returns the address of the LendingPool proxy
|
|
|
|
* @return The LendingPool proxy address
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-11-23 10:28:57 +00:00
|
|
|
function getLendingPool() external view override returns (address) {
|
2020-09-29 14:31:21 +00:00
|
|
|
return getAddress(LENDING_POOL);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev Updates the implementation of the LendingPool, or creates the proxy
|
|
|
|
* setting the new `pool` implementation on the first time calling it
|
|
|
|
* @param pool The new LendingPool implementation
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-08-19 12:53:00 +00:00
|
|
|
function setLendingPoolImpl(address pool) external override onlyOwner {
|
2020-08-21 16:18:12 +00:00
|
|
|
_updateImpl(LENDING_POOL, pool);
|
2020-08-19 12:53:00 +00:00
|
|
|
emit LendingPoolUpdated(pool);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev Returns the address of the LendingPoolConfigurator proxy
|
|
|
|
* @return The LendingPoolConfigurator proxy address
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-11-23 10:28:57 +00:00
|
|
|
function getLendingPoolConfigurator() external view override returns (address) {
|
2020-09-29 14:31:21 +00:00
|
|
|
return getAddress(LENDING_POOL_CONFIGURATOR);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev Updates the implementation of the LendingPoolConfigurator, or creates the proxy
|
|
|
|
* setting the new `configurator` implementation on the first time calling it
|
|
|
|
* @param configurator The new LendingPoolConfigurator implementation
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-08-19 12:53:00 +00:00
|
|
|
function setLendingPoolConfiguratorImpl(address configurator) external override onlyOwner {
|
2020-08-21 16:18:12 +00:00
|
|
|
_updateImpl(LENDING_POOL_CONFIGURATOR, configurator);
|
2020-08-19 12:53:00 +00:00
|
|
|
emit LendingPoolConfiguratorUpdated(configurator);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev Returns the address of the LendingPoolCollateralManager. Since the manager is used
|
2020-07-13 08:54:08 +00:00
|
|
|
* through delegateCall within the LendingPool contract, the proxy contract pattern does not work properly hence
|
2020-11-19 11:52:34 +00:00
|
|
|
* the addresses are changed directly
|
|
|
|
* @return The address of the LendingPoolCollateralManager
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
function getLendingPoolCollateralManager() external view override returns (address) {
|
2020-09-29 14:31:21 +00:00
|
|
|
return getAddress(LENDING_POOL_COLLATERAL_MANAGER);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev Updates the address of the LendingPoolCollateralManager
|
|
|
|
* @param manager The new LendingPoolCollateralManager address
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-09-16 10:41:12 +00:00
|
|
|
function setLendingPoolCollateralManager(address manager) external override onlyOwner {
|
2020-09-16 12:09:42 +00:00
|
|
|
_addresses[LENDING_POOL_COLLATERAL_MANAGER] = manager;
|
2020-09-16 10:41:12 +00:00
|
|
|
emit LendingPoolCollateralManagerUpdated(manager);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev The functions below are getters/setters of addresses that are outside the context
|
|
|
|
* of the protocol hence the upgradable proxy pattern is not used
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
function getPoolAdmin() external view override returns (address) {
|
2020-11-05 11:35:50 +00:00
|
|
|
return getAddress(POOL_ADMIN);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 11:35:50 +00:00
|
|
|
function setPoolAdmin(address admin) external override onlyOwner {
|
|
|
|
_addresses[POOL_ADMIN] = admin;
|
|
|
|
emit ConfigurationAdminUpdated(admin);
|
|
|
|
}
|
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
function getEmergencyAdmin() external view override returns (address) {
|
2020-11-05 11:35:50 +00:00
|
|
|
return getAddress(EMERGENCY_ADMIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setEmergencyAdmin(address emergencyAdmin) external override onlyOwner {
|
|
|
|
_addresses[EMERGENCY_ADMIN] = emergencyAdmin;
|
|
|
|
emit EmergencyAdminUpdated(emergencyAdmin);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
function getPriceOracle() external view override returns (address) {
|
2020-09-29 14:31:21 +00:00
|
|
|
return getAddress(PRICE_ORACLE);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 12:53:00 +00:00
|
|
|
function setPriceOracle(address priceOracle) external override onlyOwner {
|
|
|
|
_addresses[PRICE_ORACLE] = priceOracle;
|
|
|
|
emit PriceOracleUpdated(priceOracle);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
function getLendingRateOracle() external view override returns (address) {
|
2020-09-29 14:31:21 +00:00
|
|
|
return getAddress(LENDING_RATE_ORACLE);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 12:53:00 +00:00
|
|
|
function setLendingRateOracle(address lendingRateOracle) external override onlyOwner {
|
|
|
|
_addresses[LENDING_RATE_ORACLE] = lendingRateOracle;
|
|
|
|
emit LendingRateOracleUpdated(lendingRateOracle);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-19 11:52:34 +00:00
|
|
|
* @dev Internal function to update the implementation of a specific proxied component of the protocol
|
|
|
|
* - If there is no proxy registered in the given `id`, it creates the proxy setting `newAdress`
|
|
|
|
* as implementation and calls the initialize() function on the proxy
|
|
|
|
* - If there is already a proxy registered, it just updates the implementation to `newAddress` and
|
|
|
|
* calls the initialize() function via upgradeToAndCall() in the proxy
|
|
|
|
* @param id The id of the proxy to be updated
|
|
|
|
* @param newAddress The address of the new implementation
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-08-21 16:18:12 +00:00
|
|
|
function _updateImpl(bytes32 id, address newAddress) internal {
|
2020-08-19 12:53:00 +00:00
|
|
|
address payable proxyAddress = payable(_addresses[id]);
|
2020-07-13 08:54:08 +00:00
|
|
|
|
2020-11-23 10:28:57 +00:00
|
|
|
InitializableImmutableAdminUpgradeabilityProxy proxy =
|
|
|
|
InitializableImmutableAdminUpgradeabilityProxy(proxyAddress);
|
2020-07-13 08:54:08 +00:00
|
|
|
bytes memory params = abi.encodeWithSignature('initialize(address)', address(this));
|
|
|
|
|
|
|
|
if (proxyAddress == address(0)) {
|
2020-10-13 08:38:22 +00:00
|
|
|
proxy = new InitializableImmutableAdminUpgradeabilityProxy(address(this));
|
|
|
|
proxy.initialize(newAddress, params);
|
2020-08-19 12:53:00 +00:00
|
|
|
_addresses[id] = address(proxy);
|
|
|
|
emit ProxyCreated(id, address(proxy));
|
2020-07-13 08:54:08 +00:00
|
|
|
} else {
|
2020-08-19 12:53:00 +00:00
|
|
|
proxy.upgradeToAndCall(newAddress, params);
|
2020-07-13 08:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-26 12:09:49 +00:00
|
|
|
|
|
|
|
function _setMarketId(string memory marketId) internal {
|
|
|
|
_marketId = marketId;
|
|
|
|
emit MarketIdSet(marketId);
|
|
|
|
}
|
2020-05-29 16:45:37 +00:00
|
|
|
}
|