mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
- Added general setter and getter of address to LendingPoolAddressesProvider.
- Adapted style of LendingPoolAddressesProviderRegistry, adding public getter function in the process.
This commit is contained in:
parent
479f6f6b72
commit
099532ee48
|
@ -30,12 +30,41 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider
|
|||
bytes32 private constant LENDING_RATE_ORACLE = 'LENDING_RATE_ORACLE';
|
||||
bytes32 private constant WALLET_BALANCE_PROVIDER = 'WALLET_BALANCE_PROVIDER';
|
||||
|
||||
/**
|
||||
* @dev Sets an address for an id, allowing to cover it or not with a proxy
|
||||
* @param id The id
|
||||
* @param newAddress The address to set, pass address(0) if a proxy is needed
|
||||
* @param implementationAddress The address of the implementation if we want it covered by a proxy
|
||||
* address(0) if we don't want a proxy covering
|
||||
*/
|
||||
function setAddress(
|
||||
bytes32 id,
|
||||
address newAddress,
|
||||
address implementationAddress
|
||||
) external override onlyOwner {
|
||||
if (implementationAddress != address(0)) {
|
||||
_updateImpl(id, implementationAddress);
|
||||
emit AddressSet(id, implementationAddress, true);
|
||||
} else {
|
||||
_addresses[id] = newAddress;
|
||||
emit AddressSet(id, newAddress, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns an address by id
|
||||
* @return The address
|
||||
*/
|
||||
function getAddress(bytes32 id) public override view returns (address) {
|
||||
return _addresses[id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev returns the address of the LendingPool proxy
|
||||
* @return the lending pool proxy address
|
||||
**/
|
||||
function getLendingPool() external override view returns (address) {
|
||||
return _addresses[LENDING_POOL];
|
||||
return getAddress(LENDING_POOL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +81,7 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider
|
|||
* @return the lending pool configurator proxy address
|
||||
**/
|
||||
function getLendingPoolConfigurator() external override view returns (address) {
|
||||
return _addresses[LENDING_POOL_CONFIGURATOR];
|
||||
return getAddress(LENDING_POOL_CONFIGURATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +101,7 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider
|
|||
**/
|
||||
|
||||
function getLendingPoolCollateralManager() external override view returns (address) {
|
||||
return _addresses[LENDING_POOL_COLLATERAL_MANAGER];
|
||||
return getAddress(LENDING_POOL_COLLATERAL_MANAGER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +119,7 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider
|
|||
**/
|
||||
|
||||
function getAaveAdmin() external override view returns (address) {
|
||||
return _addresses[AAVE_ADMIN];
|
||||
return getAddress(AAVE_ADMIN);
|
||||
}
|
||||
|
||||
function setAaveAdmin(address aaveAdmin) external override onlyOwner {
|
||||
|
@ -99,7 +128,7 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider
|
|||
}
|
||||
|
||||
function getPriceOracle() external override view returns (address) {
|
||||
return _addresses[PRICE_ORACLE];
|
||||
return getAddress(PRICE_ORACLE);
|
||||
}
|
||||
|
||||
function setPriceOracle(address priceOracle) external override onlyOwner {
|
||||
|
@ -108,7 +137,7 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider
|
|||
}
|
||||
|
||||
function getLendingRateOracle() external override view returns (address) {
|
||||
return _addresses[LENDING_RATE_ORACLE];
|
||||
return getAddress(LENDING_RATE_ORACLE);
|
||||
}
|
||||
|
||||
function setLendingRateOracle(address lendingRateOracle) external override onlyOwner {
|
||||
|
|
|
@ -14,8 +14,8 @@ import {Errors} from '../libraries/helpers/Errors.sol';
|
|||
**/
|
||||
|
||||
contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesProviderRegistry {
|
||||
mapping(address => uint256) addressesProviders;
|
||||
address[] addressesProvidersList;
|
||||
mapping(address => uint256) private _addressesProviders;
|
||||
address[] private _addressesProvidersList;
|
||||
|
||||
/**
|
||||
* @dev returns if an addressesProvider is registered or not
|
||||
|
@ -28,7 +28,7 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
|
|||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return addressesProviders[provider];
|
||||
return _addressesProviders[provider];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,13 +36,13 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
|
|||
* @return the list of addressesProviders
|
||||
**/
|
||||
function getAddressesProvidersList() external override view returns (address[] memory) {
|
||||
uint256 maxLength = addressesProvidersList.length;
|
||||
uint256 maxLength = _addressesProvidersList.length;
|
||||
|
||||
address[] memory activeProviders = new address[](maxLength);
|
||||
|
||||
for (uint256 i = 0; i < addressesProvidersList.length; i++) {
|
||||
if (addressesProviders[addressesProvidersList[i]] > 0) {
|
||||
activeProviders[i] = addressesProvidersList[i];
|
||||
for (uint256 i = 0; i < _addressesProvidersList.length; i++) {
|
||||
if (_addressesProviders[_addressesProvidersList[i]] > 0) {
|
||||
activeProviders[i] = _addressesProvidersList[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
|
|||
* @param provider the pool address to be registered
|
||||
**/
|
||||
function registerAddressesProvider(address provider, uint256 id) external override onlyOwner {
|
||||
addressesProviders[provider] = id;
|
||||
_addressesProviders[provider] = id;
|
||||
_addToAddressesProvidersList(provider);
|
||||
emit AddressesProviderRegistered(provider);
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
|
|||
* @param provider the pool address to be unregistered
|
||||
**/
|
||||
function unregisterAddressesProvider(address provider) external override onlyOwner {
|
||||
require(addressesProviders[provider] > 0, Errors.PROVIDER_NOT_REGISTERED);
|
||||
addressesProviders[provider] = 0;
|
||||
require(_addressesProviders[provider] > 0, Errors.PROVIDER_NOT_REGISTERED);
|
||||
_addressesProviders[provider] = 0;
|
||||
emit AddressesProviderUnregistered(provider);
|
||||
}
|
||||
|
||||
|
@ -74,12 +74,25 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
|
|||
* @param provider the pool address to be added
|
||||
**/
|
||||
function _addToAddressesProvidersList(address provider) internal {
|
||||
for (uint256 i = 0; i < addressesProvidersList.length; i++) {
|
||||
if (addressesProvidersList[i] == provider) {
|
||||
for (uint256 i = 0; i < _addressesProvidersList.length; i++) {
|
||||
if (_addressesProvidersList[i] == provider) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
addressesProvidersList.push(provider);
|
||||
_addressesProvidersList.push(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the id on an `addressesProvider` or address(0) if not registered
|
||||
* @return The id or address(0)
|
||||
*/
|
||||
function getAddressesProviderIdByAddress(address addressesProvider)
|
||||
external
|
||||
override
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return _addressesProviders[addressesProvider];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ pragma solidity ^0.6.8;
|
|||
*/
|
||||
|
||||
interface ILendingPoolAddressesProvider {
|
||||
//events
|
||||
event LendingPoolUpdated(address indexed newAddress);
|
||||
event AaveAdminUpdated(address indexed newAddress);
|
||||
event LendingPoolConfiguratorUpdated(address indexed newAddress);
|
||||
|
@ -15,8 +14,16 @@ interface ILendingPoolAddressesProvider {
|
|||
event EthereumAddressUpdated(address indexed newAddress);
|
||||
event PriceOracleUpdated(address indexed newAddress);
|
||||
event LendingRateOracleUpdated(address indexed newAddress);
|
||||
|
||||
event ProxyCreated(bytes32 id, address indexed newAddress);
|
||||
event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy);
|
||||
|
||||
function setAddress(
|
||||
bytes32 id,
|
||||
address newAddress,
|
||||
address impl
|
||||
) external;
|
||||
|
||||
function getAddress(bytes32 id) external view returns (address);
|
||||
|
||||
function getLendingPool() external view returns (address);
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@ pragma solidity ^0.6.8;
|
|||
* @title ILendingPoolAddressesProvider interface
|
||||
* @notice provides the interface to fetch the LendingPoolCore address
|
||||
**/
|
||||
|
||||
interface ILendingPoolAddressesProviderRegistry {
|
||||
//events
|
||||
event AddressesProviderRegistered(address indexed newAddress);
|
||||
event AddressesProviderUnregistered(address indexed newAddress);
|
||||
|
||||
|
@ -15,6 +13,11 @@ interface ILendingPoolAddressesProviderRegistry {
|
|||
|
||||
function isAddressesProviderRegistered(address provider) external view returns (uint256);
|
||||
|
||||
function getAddressesProviderIdByAddress(address addressesProvider)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
function registerAddressesProvider(address provider, uint256 id) external;
|
||||
|
||||
function unregisterAddressesProvider(address provider) external;
|
||||
|
|
|
@ -2,6 +2,10 @@ import {expect} from 'chai';
|
|||
import {createRandomAddress} from '../helpers/misc-utils';
|
||||
import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||
import {ProtocolErrors} from '../helpers/types';
|
||||
import {ethers} from 'ethers';
|
||||
import {ZERO_ADDRESS} from '../helpers/constants';
|
||||
|
||||
const {utils} = ethers;
|
||||
|
||||
makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => {
|
||||
it('Test the accessibility of the LendingPoolAddressesProvider', async () => {
|
||||
|
@ -21,5 +25,13 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => {
|
|||
]) {
|
||||
await expect(contractFunction(mockAddress)).to.be.revertedWith(INVALID_OWNER_REVERT_MSG);
|
||||
}
|
||||
|
||||
await expect(
|
||||
addressesProvider.setAddress(
|
||||
utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')),
|
||||
mockAddress,
|
||||
ZERO_ADDRESS
|
||||
)
|
||||
).to.be.revertedWith(INVALID_OWNER_REVERT_MSG);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user