From fa11327b5919a85e6975cc1ee91ff711d5479b2c Mon Sep 17 00:00:00 2001 From: eboado Date: Thu, 26 Nov 2020 13:09:49 +0100 Subject: [PATCH 1/3] - Added marketId and setter on LendingPoolAddressesProvider --- .../ILendingPoolAddressesProvider.sol | 3 +++ .../LendingPoolAddressesProvider.sol | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/contracts/interfaces/ILendingPoolAddressesProvider.sol b/contracts/interfaces/ILendingPoolAddressesProvider.sol index e54973c1..3c826c52 100644 --- a/contracts/interfaces/ILendingPoolAddressesProvider.sol +++ b/contracts/interfaces/ILendingPoolAddressesProvider.sol @@ -9,6 +9,7 @@ pragma solidity 0.6.12; * @author Aave **/ interface ILendingPoolAddressesProvider { + event MarketIdSet(string newMarketId); event LendingPoolUpdated(address indexed newAddress); event ConfigurationAdminUpdated(address indexed newAddress); event EmergencyAdminUpdated(address indexed newAddress); @@ -19,6 +20,8 @@ interface ILendingPoolAddressesProvider { event ProxyCreated(bytes32 id, address indexed newAddress); event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy); + function setMarketId(string calldata marketId) external; + function setAddress(bytes32 id, address newAddress) external; function setAddressAsProxy(bytes32 id, address impl) external; diff --git a/contracts/protocol/configuration/LendingPoolAddressesProvider.sol b/contracts/protocol/configuration/LendingPoolAddressesProvider.sol index f6f7bef2..520a0513 100644 --- a/contracts/protocol/configuration/LendingPoolAddressesProvider.sol +++ b/contracts/protocol/configuration/LendingPoolAddressesProvider.sol @@ -17,6 +17,7 @@ import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddres * @author Aave **/ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider { + string private _marketId; mapping(bytes32 => address) private _addresses; bytes32 private constant LENDING_POOL = 'LENDING_POOL'; @@ -27,6 +28,18 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider bytes32 private constant PRICE_ORACLE = 'PRICE_ORACLE'; bytes32 private constant LENDING_RATE_ORACLE = 'LENDING_RATE_ORACLE'; + constructor(string memory marketId) public { + _setMarketId(marketId); + } + + /** + * @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); + } + /** * @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 @@ -186,4 +199,9 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider proxy.upgradeToAndCall(newAddress, params); } } + + function _setMarketId(string memory marketId) internal { + _marketId = marketId; + emit MarketIdSet(marketId); + } } From 43712d8a2bb8c3d409d1131bd33f129317899f82 Mon Sep 17 00:00:00 2001 From: David Racero Date: Thu, 26 Nov 2020 16:11:40 +0100 Subject: [PATCH 2/3] Support marketId argument --- helpers/contracts-deployments.ts | 6 +++--- helpers/types.ts | 2 +- markets/aave/commons.ts | 2 +- markets/aave/index.ts | 8 ++++---- tasks/dev/2_address_provider_registry.ts | 9 +++++---- tasks/full/1_address_provider.ts | 16 ++++++++-------- test/__setup.spec.ts | 2 +- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index f29a347b..a813d293 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -65,11 +65,11 @@ const readArtifact = async (id: string) => { } return (DRE as HardhatRuntimeEnvironment).artifacts.readArtifact(id); }; -export const deployLendingPoolAddressesProvider = async (verify?: boolean) => +export const deployLendingPoolAddressesProvider = async (marketId: string, verify?: boolean) => withSaveAndVerify( - await new LendingPoolAddressesProviderFactory(await getFirstSigner()).deploy(), + await new LendingPoolAddressesProviderFactory(await getFirstSigner()).deploy(marketId), eContractid.LendingPoolAddressesProvider, - [], + [marketId], verify ); diff --git a/helpers/types.ts b/helpers/types.ts index 5467cb94..553911fe 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -345,7 +345,7 @@ export interface ILendingRate { } export interface ICommonConfiguration { - ConfigName: string; + MarketId: string; ProviderId: number; ProtocolGlobalParams: IProtocolGlobalConfig; Mocks: IMocksConfig; diff --git a/markets/aave/commons.ts b/markets/aave/commons.ts index f87e5943..7b2875b2 100644 --- a/markets/aave/commons.ts +++ b/markets/aave/commons.ts @@ -30,7 +30,7 @@ const MOCK_CHAINLINK_AGGREGATORS_PRICES = { // ---------------- export const CommonsConfig: ICommonConfiguration = { - ConfigName: 'Commons', + MarketId: 'Commons', ProviderId: 0, ProtocolGlobalParams: { TokenDistributorPercentageBase: '10000', diff --git a/markets/aave/index.ts b/markets/aave/index.ts index ece2485e..11b401ef 100644 --- a/markets/aave/index.ts +++ b/markets/aave/index.ts @@ -1,7 +1,7 @@ -import {oneRay, ZERO_ADDRESS} from '../../helpers/constants'; -import {IAaveConfiguration, EthereumNetwork, eEthereumNetwork} from '../../helpers/types'; +import { oneRay, ZERO_ADDRESS } from '../../helpers/constants'; +import { IAaveConfiguration, EthereumNetwork, eEthereumNetwork } from '../../helpers/types'; -import {CommonsConfig} from './commons'; +import { CommonsConfig } from './commons'; import { stablecoinStrategyBUSD, stablecoinStrategyDAI, @@ -29,7 +29,7 @@ import { export const AaveConfig: IAaveConfiguration = { ...CommonsConfig, - ConfigName: 'Aave', + MarketId: 'Aave genesis market', ProviderId: 1, ReservesConfig: { AAVE: strategyAAVE, diff --git a/tasks/dev/2_address_provider_registry.ts b/tasks/dev/2_address_provider_registry.ts index c386b8cf..42f42a7b 100644 --- a/tasks/dev/2_address_provider_registry.ts +++ b/tasks/dev/2_address_provider_registry.ts @@ -1,21 +1,22 @@ -import {task} from 'hardhat/config'; +import { task } from 'hardhat/config'; import { deployLendingPoolAddressesProvider, deployLendingPoolAddressesProviderRegistry, } from '../../helpers/contracts-deployments'; -import {waitForTx} from '../../helpers/misc-utils'; +import { waitForTx } from '../../helpers/misc-utils'; +import { AaveConfig } from '../../markets/aave'; task( 'dev:deploy-address-provider', 'Deploy address provider, registry and fee provider for dev enviroment' ) .addFlag('verify', 'Verify contracts at Etherscan') - .setAction(async ({verify}, localBRE) => { + .setAction(async ({ verify }, localBRE) => { await localBRE.run('set-DRE'); const admin = await (await localBRE.ethers.getSigners())[0].getAddress(); - const addressesProvider = await deployLendingPoolAddressesProvider(verify); + const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId, verify); await waitForTx(await addressesProvider.setPoolAdmin(admin)); const addressesProviderRegistry = await deployLendingPoolAddressesProviderRegistry(verify); diff --git a/tasks/full/1_address_provider.ts b/tasks/full/1_address_provider.ts index 1ff368af..ea196f57 100644 --- a/tasks/full/1_address_provider.ts +++ b/tasks/full/1_address_provider.ts @@ -1,18 +1,18 @@ -import {task} from 'hardhat/config'; -import {getParamPerNetwork} from '../../helpers/contracts-helpers'; +import { task } from 'hardhat/config'; +import { getParamPerNetwork } from '../../helpers/contracts-helpers'; import { deployLendingPoolAddressesProvider, deployLendingPoolAddressesProviderRegistry, } from '../../helpers/contracts-deployments'; -import {notFalsyOrZeroAddress, waitForTx} from '../../helpers/misc-utils'; +import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils'; import { ConfigNames, loadPoolConfig, getGenesisPoolAdmin, getEmergencyAdmin, } from '../../helpers/configuration'; -import {eEthereumNetwork} from '../../helpers/types'; -import {getLendingPoolAddressesProviderRegistry} from '../../helpers/contracts-getters'; +import { eEthereumNetwork } from '../../helpers/types'; +import { getLendingPoolAddressesProviderRegistry } from '../../helpers/contracts-getters'; task( 'full:deploy-address-provider', @@ -20,16 +20,16 @@ task( ) .addFlag('verify', 'Verify contracts at Etherscan') .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) - .setAction(async ({verify, pool}, DRE) => { + .setAction(async ({ verify, pool }, DRE) => { await DRE.run('set-DRE'); const network = DRE.network.name; const poolConfig = loadPoolConfig(pool); - const {ProviderId} = poolConfig; + const { ProviderId, MarketId } = poolConfig; const providerRegistryAddress = getParamPerNetwork(poolConfig.ProviderRegistry, network); // Deploy address provider and set genesis manager - const addressesProvider = await deployLendingPoolAddressesProvider(verify); + const addressesProvider = await deployLendingPoolAddressesProvider(MarketId, verify); await waitForTx(await addressesProvider.setPoolAdmin(await getGenesisPoolAdmin(poolConfig))); await waitForTx(await addressesProvider.setEmergencyAdmin(await getEmergencyAdmin(poolConfig))); diff --git a/test/__setup.spec.ts b/test/__setup.spec.ts index 04bf3636..ad9f9388 100644 --- a/test/__setup.spec.ts +++ b/test/__setup.spec.ts @@ -91,7 +91,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const mockTokens = await deployAllMockTokens(deployer); - const addressesProvider = await deployLendingPoolAddressesProvider(); + const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId); await waitForTx(await addressesProvider.setPoolAdmin(aaveAdmin)); //setting users[1] as emergency admin, which is in position 2 in the DRE addresses list From 3d6150a729e9c19c9d676e5d88c9b4617a1b9c52 Mon Sep 17 00:00:00 2001 From: eboado Date: Thu, 26 Nov 2020 17:08:09 +0100 Subject: [PATCH 3/3] - Added test for onlyOwner on setMarketId() --- test/lending-pool-addresses-provider.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lending-pool-addresses-provider.spec.ts b/test/lending-pool-addresses-provider.spec.ts index 97327d4f..f87ccaf1 100644 --- a/test/lending-pool-addresses-provider.spec.ts +++ b/test/lending-pool-addresses-provider.spec.ts @@ -18,6 +18,7 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { await addressesProvider.transferOwnership(users[1].address); for (const contractFunction of [ + addressesProvider.setMarketId, addressesProvider.setLendingPoolImpl, addressesProvider.setLendingPoolConfiguratorImpl, addressesProvider.setLendingPoolCollateralManager,