LCOV - code coverage report
Current view: top level - protocol/configuration - PoolAddressesProvider.sol (source / functions) Coverage Total Hit
Test: lcov.info.p Lines: 100.0 % 58 58
Test Date: 2024-09-24 09:34:24 Functions: 100.0 % 23 23
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: BUSL-1.1
       2                 :             : pragma solidity ^0.8.10;
       3                 :             : 
       4                 :             : import {Ownable} from '../../dependencies/openzeppelin/contracts/Ownable.sol';
       5                 :             : import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
       6                 :             : import {InitializableImmutableAdminUpgradeabilityProxy} from '../../misc/aave-upgradeability/InitializableImmutableAdminUpgradeabilityProxy.sol';
       7                 :             : 
       8                 :             : /**
       9                 :             :  * @title PoolAddressesProvider
      10                 :             :  * @author Aave
      11                 :             :  * @notice Main registry of addresses part of or connected to the protocol, including permissioned roles
      12                 :             :  * @dev Acts as factory of proxies and admin of those, so with right to change its implementations
      13                 :             :  * @dev Owned by the Aave Governance
      14                 :             :  */
      15                 :             : contract PoolAddressesProvider is Ownable, IPoolAddressesProvider {
      16                 :             :   // Identifier of the Aave Market
      17                 :             :   string private _marketId;
      18                 :             : 
      19                 :             :   // Map of registered addresses (identifier => registeredAddress)
      20                 :             :   mapping(bytes32 => address) private _addresses;
      21                 :             : 
      22                 :             :   // Main identifiers
      23                 :             :   bytes32 private constant POOL = 'POOL';
      24                 :             :   bytes32 private constant POOL_CONFIGURATOR = 'POOL_CONFIGURATOR';
      25                 :             :   bytes32 private constant PRICE_ORACLE = 'PRICE_ORACLE';
      26                 :             :   bytes32 private constant ACL_MANAGER = 'ACL_MANAGER';
      27                 :             :   bytes32 private constant ACL_ADMIN = 'ACL_ADMIN';
      28                 :             :   bytes32 private constant PRICE_ORACLE_SENTINEL = 'PRICE_ORACLE_SENTINEL';
      29                 :             :   bytes32 private constant DATA_PROVIDER = 'DATA_PROVIDER';
      30                 :             : 
      31                 :             :   /**
      32                 :             :    * @dev Constructor.
      33                 :             :    * @param marketId The identifier of the market.
      34                 :             :    * @param owner The owner address of this contract.
      35                 :             :    */
      36                 :             :   constructor(string memory marketId, address owner) {
      37                 :         419 :     _setMarketId(marketId);
      38                 :         627 :     transferOwnership(owner);
      39                 :             :   }
      40                 :             : 
      41                 :             :   /// @inheritdoc IPoolAddressesProvider
      42                 :             :   function getMarketId() external view override returns (string memory) {
      43                 :           6 :     return _marketId;
      44                 :             :   }
      45                 :             : 
      46                 :             :   /// @inheritdoc IPoolAddressesProvider
      47                 :             :   function setMarketId(string memory newMarketId) external override onlyOwner {
      48                 :           1 :     _setMarketId(newMarketId);
      49                 :             :   }
      50                 :             : 
      51                 :             :   /// @inheritdoc IPoolAddressesProvider
      52                 :             :   function getAddress(bytes32 id) public view override returns (address) {
      53                 :     1041048 :     return _addresses[id];
      54                 :             :   }
      55                 :             : 
      56                 :             :   /// @inheritdoc IPoolAddressesProvider
      57                 :             :   function setAddress(bytes32 id, address newAddress) external override onlyOwner {
      58                 :           4 :     address oldAddress = _addresses[id];
      59                 :           4 :     _addresses[id] = newAddress;
      60                 :           4 :     emit AddressSet(id, oldAddress, newAddress);
      61                 :             :   }
      62                 :             : 
      63                 :             :   /// @inheritdoc IPoolAddressesProvider
      64                 :             :   function setAddressAsProxy(
      65                 :             :     bytes32 id,
      66                 :             :     address newImplementationAddress
      67                 :             :   ) external override onlyOwner {
      68                 :         682 :     address proxyAddress = _addresses[id];
      69                 :         682 :     address oldImplementationAddress = _getProxyImplementation(id);
      70                 :         682 :     _updateImpl(id, newImplementationAddress);
      71                 :         682 :     emit AddressSetAsProxy(id, proxyAddress, oldImplementationAddress, newImplementationAddress);
      72                 :             :   }
      73                 :             : 
      74                 :             :   /// @inheritdoc IPoolAddressesProvider
      75                 :             :   function getPool() external view override returns (address) {
      76                 :      165196 :     return getAddress(POOL);
      77                 :             :   }
      78                 :             : 
      79                 :             :   /// @inheritdoc IPoolAddressesProvider
      80                 :             :   function setPoolImpl(address newPoolImpl) external override onlyOwner {
      81                 :         683 :     address oldPoolImpl = _getProxyImplementation(POOL);
      82                 :         683 :     _updateImpl(POOL, newPoolImpl);
      83                 :         683 :     emit PoolUpdated(oldPoolImpl, newPoolImpl);
      84                 :             :   }
      85                 :             : 
      86                 :             :   /// @inheritdoc IPoolAddressesProvider
      87                 :             :   function getPoolConfigurator() external view override returns (address) {
      88                 :      649253 :     return getAddress(POOL_CONFIGURATOR);
      89                 :             :   }
      90                 :             : 
      91                 :             :   /// @inheritdoc IPoolAddressesProvider
      92                 :             :   function setPoolConfiguratorImpl(address newPoolConfiguratorImpl) external override onlyOwner {
      93                 :         683 :     address oldPoolConfiguratorImpl = _getProxyImplementation(POOL_CONFIGURATOR);
      94                 :         683 :     _updateImpl(POOL_CONFIGURATOR, newPoolConfiguratorImpl);
      95                 :         683 :     emit PoolConfiguratorUpdated(oldPoolConfiguratorImpl, newPoolConfiguratorImpl);
      96                 :             :   }
      97                 :             : 
      98                 :             :   /// @inheritdoc IPoolAddressesProvider
      99                 :             :   function getPriceOracle() external view override returns (address) {
     100                 :       71014 :     return getAddress(PRICE_ORACLE);
     101                 :             :   }
     102                 :             : 
     103                 :             :   /// @inheritdoc IPoolAddressesProvider
     104                 :             :   function setPriceOracle(address newPriceOracle) external override onlyOwner {
     105                 :         683 :     address oldPriceOracle = _addresses[PRICE_ORACLE];
     106                 :         683 :     _addresses[PRICE_ORACLE] = newPriceOracle;
     107                 :         683 :     emit PriceOracleUpdated(oldPriceOracle, newPriceOracle);
     108                 :             :   }
     109                 :             : 
     110                 :             :   /// @inheritdoc IPoolAddressesProvider
     111                 :             :   function getACLManager() external view override returns (address) {
     112                 :      119508 :     return getAddress(ACL_MANAGER);
     113                 :             :   }
     114                 :             : 
     115                 :             :   /// @inheritdoc IPoolAddressesProvider
     116                 :             :   function setACLManager(address newAclManager) external override onlyOwner {
     117                 :         683 :     address oldAclManager = _addresses[ACL_MANAGER];
     118                 :         683 :     _addresses[ACL_MANAGER] = newAclManager;
     119                 :         683 :     emit ACLManagerUpdated(oldAclManager, newAclManager);
     120                 :             :   }
     121                 :             : 
     122                 :             :   /// @inheritdoc IPoolAddressesProvider
     123                 :             :   function getACLAdmin() external view override returns (address) {
     124                 :        1711 :     return getAddress(ACL_ADMIN);
     125                 :             :   }
     126                 :             : 
     127                 :             :   /// @inheritdoc IPoolAddressesProvider
     128                 :             :   function setACLAdmin(address newAclAdmin) external override onlyOwner {
     129                 :        1383 :     address oldAclAdmin = _addresses[ACL_ADMIN];
     130                 :        1383 :     _addresses[ACL_ADMIN] = newAclAdmin;
     131                 :        1383 :     emit ACLAdminUpdated(oldAclAdmin, newAclAdmin);
     132                 :             :   }
     133                 :             : 
     134                 :             :   /// @inheritdoc IPoolAddressesProvider
     135                 :             :   function getPriceOracleSentinel() external view override returns (address) {
     136                 :       30644 :     return getAddress(PRICE_ORACLE_SENTINEL);
     137                 :             :   }
     138                 :             : 
     139                 :             :   /// @inheritdoc IPoolAddressesProvider
     140                 :             :   function setPriceOracleSentinel(address newPriceOracleSentinel) external override onlyOwner {
     141                 :          20 :     address oldPriceOracleSentinel = _addresses[PRICE_ORACLE_SENTINEL];
     142                 :          20 :     _addresses[PRICE_ORACLE_SENTINEL] = newPriceOracleSentinel;
     143                 :          20 :     emit PriceOracleSentinelUpdated(oldPriceOracleSentinel, newPriceOracleSentinel);
     144                 :             :   }
     145                 :             : 
     146                 :             :   /// @inheritdoc IPoolAddressesProvider
     147                 :             :   function getPoolDataProvider() external view override returns (address) {
     148                 :        3034 :     return getAddress(DATA_PROVIDER);
     149                 :             :   }
     150                 :             : 
     151                 :             :   /// @inheritdoc IPoolAddressesProvider
     152                 :             :   function setPoolDataProvider(address newDataProvider) external override onlyOwner {
     153                 :         683 :     address oldDataProvider = _addresses[DATA_PROVIDER];
     154                 :         683 :     _addresses[DATA_PROVIDER] = newDataProvider;
     155                 :         683 :     emit PoolDataProviderUpdated(oldDataProvider, newDataProvider);
     156                 :             :   }
     157                 :             : 
     158                 :             :   /**
     159                 :             :    * @notice Internal function to update the implementation of a specific proxied component of the protocol.
     160                 :             :    * @dev If there is no proxy registered with the given identifier, it creates the proxy setting `newAddress`
     161                 :             :    *   as implementation and calls the initialize() function on the proxy
     162                 :             :    * @dev If there is already a proxy registered, it just updates the implementation to `newAddress` and
     163                 :             :    *   calls the initialize() function via upgradeToAndCall() in the proxy
     164                 :             :    * @param id The id of the proxy to be updated
     165                 :             :    * @param newAddress The address of the new implementation
     166                 :             :    */
     167                 :             :   function _updateImpl(bytes32 id, address newAddress) internal {
     168                 :        2048 :     address proxyAddress = _addresses[id];
     169                 :        2048 :     InitializableImmutableAdminUpgradeabilityProxy proxy;
     170                 :        2048 :     bytes memory params = abi.encodeWithSignature('initialize(address)', address(this));
     171                 :             : 
     172                 :        2048 :     if (proxyAddress == address(0)) {
     173                 :        2045 :       proxy = new InitializableImmutableAdminUpgradeabilityProxy(address(this));
     174                 :        2045 :       _addresses[id] = proxyAddress = address(proxy);
     175                 :        2045 :       proxy.initialize(newAddress, params);
     176                 :        2045 :       emit ProxyCreated(id, proxyAddress, newAddress);
     177                 :             :     } else {
     178                 :           3 :       proxy = InitializableImmutableAdminUpgradeabilityProxy(payable(proxyAddress));
     179                 :           3 :       proxy.upgradeToAndCall(newAddress, params);
     180                 :             :     }
     181                 :             :   }
     182                 :             : 
     183                 :             :   /**
     184                 :             :    * @notice Updates the identifier of the Aave market.
     185                 :             :    * @param newMarketId The new id of the market
     186                 :             :    */
     187                 :             :   function _setMarketId(string memory newMarketId) internal {
     188                 :         380 :     string memory oldMarketId = _marketId;
     189                 :         377 :     _marketId = newMarketId;
     190                 :         265 :     emit MarketIdSet(oldMarketId, newMarketId);
     191                 :             :   }
     192                 :             : 
     193                 :             :   /**
     194                 :             :    * @notice Returns the the implementation contract of the proxy contract by its identifier.
     195                 :             :    * @dev It returns ZERO if there is no registered address with the given id
     196                 :             :    * @dev It reverts if the registered address with the given id is not `InitializableImmutableAdminUpgradeabilityProxy`
     197                 :             :    * @param id The id
     198                 :             :    * @return The address of the implementation contract
     199                 :             :    */
     200                 :             :   function _getProxyImplementation(bytes32 id) internal returns (address) {
     201                 :        2048 :     address proxyAddress = _addresses[id];
     202                 :        2048 :     if (proxyAddress == address(0)) {
     203                 :        2045 :       return address(0);
     204                 :             :     } else {
     205                 :           3 :       address payable payableProxyAddress = payable(proxyAddress);
     206                 :           3 :       return InitializableImmutableAdminUpgradeabilityProxy(payableProxyAddress).implementation();
     207                 :             :     }
     208                 :             :   }
     209                 :             : }
        

Generated by: LCOV version 2.1-1