diff --git a/contracts/configuration/LendingPoolAddressesProvider.sol b/contracts/configuration/LendingPoolAddressesProvider.sol index ee4435bc..43796d36 100644 --- a/contracts/configuration/LendingPoolAddressesProvider.sol +++ b/contracts/configuration/LendingPoolAddressesProvider.sol @@ -28,24 +28,30 @@ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider bytes32 private constant LENDING_RATE_ORACLE = 'LENDING_RATE_ORACLE'; /** - * @dev Sets an address for an id, allowing to cover it or not with a proxy + * @dev Sets an address for an id by updating a proxy implementation * @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( + function setAddressAsProxy( 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); - } + _updateImpl(id, implementationAddress); + emit AddressSet(id, implementationAddress, true); + } + + /** + * @dev Sets an address for an id replacing the address saved in the addresses map + * @param id The id + * @param newAddress The address to set, pass address(0) if a proxy is needed + */ + function setAddress( + bytes32 id, + address newAddress + ) external override onlyOwner { + _addresses[id] = newAddress; + emit AddressSet(id, newAddress, false); } /** diff --git a/contracts/interfaces/ILendingPoolAddressesProvider.sol b/contracts/interfaces/ILendingPoolAddressesProvider.sol index c0d180e3..c1a7ab78 100644 --- a/contracts/interfaces/ILendingPoolAddressesProvider.sol +++ b/contracts/interfaces/ILendingPoolAddressesProvider.sol @@ -20,7 +20,11 @@ interface ILendingPoolAddressesProvider { function setAddress( bytes32 id, - address newAddress, + address newAddress + ) external; + + function setAddressAsProxy( + bytes32 id, address impl ) external; diff --git a/test/lending-pool-addresses-provider.spec.ts b/test/lending-pool-addresses-provider.spec.ts index ac70c6a0..97327d4f 100644 --- a/test/lending-pool-addresses-provider.spec.ts +++ b/test/lending-pool-addresses-provider.spec.ts @@ -31,28 +31,61 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { await expect( addressesProvider.setAddress( utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')), - mockAddress, - ZERO_ADDRESS + mockAddress ) ).to.be.revertedWith(INVALID_OWNER_REVERT_MSG); + + await expect( + addressesProvider.setAddressAsProxy( + utils.keccak256(utils.toUtf8Bytes('RANDOM_ID')), + mockAddress + ) + ).to.be.revertedWith(INVALID_OWNER_REVERT_MSG); + }); - it('Tests adding both a proxied and non-proxied addres with `setAddress()`', async () => { + it('Tests adding a proxied address with `setAddressAsProxy()`', async () => { const {addressesProvider, users} = testEnv; const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors; const currentAddressesProviderOwner = users[1]; - const mockNonProxiedAddress = createRandomAddress(); - const nonProxiedAddressId = utils.keccak256(utils.toUtf8Bytes('RANDOM_NON_PROXIED')); const mockLendingPool = await deployLendingPool(); const proxiedAddressId = utils.keccak256(utils.toUtf8Bytes('RANDOM_PROXIED')); + const proxiedAddressSetReceipt = await waitForTx( + await addressesProvider + .connect(currentAddressesProviderOwner.signer) + .setAddressAsProxy(proxiedAddressId, mockLendingPool.address) + ); + + if (!proxiedAddressSetReceipt.events || proxiedAddressSetReceipt.events?.length < 1) { + throw new Error('INVALID_EVENT_EMMITED'); + } + + expect(proxiedAddressSetReceipt.events[0].event).to.be.equal('ProxyCreated'); + expect(proxiedAddressSetReceipt.events[1].event).to.be.equal('AddressSet'); + expect(proxiedAddressSetReceipt.events[1].args?.id).to.be.equal(proxiedAddressId); + expect(proxiedAddressSetReceipt.events[1].args?.newAddress).to.be.equal( + mockLendingPool.address + ); + expect(proxiedAddressSetReceipt.events[1].args?.hasProxy).to.be.equal(true); + }); + + + it('Tests adding a non proxied address with `setAddress()`', async () => { + const {addressesProvider, users} = testEnv; + const {INVALID_OWNER_REVERT_MSG} = ProtocolErrors; + + const currentAddressesProviderOwner = users[1]; + const mockNonProxiedAddress = createRandomAddress(); + const nonProxiedAddressId = utils.keccak256(utils.toUtf8Bytes('RANDOM_NON_PROXIED')); + const nonProxiedAddressSetReceipt = await waitForTx( await addressesProvider .connect(currentAddressesProviderOwner.signer) - .setAddress(nonProxiedAddressId, mockNonProxiedAddress, ZERO_ADDRESS) + .setAddress(nonProxiedAddressId, mockNonProxiedAddress) ); expect(mockNonProxiedAddress.toLowerCase()).to.be.equal( @@ -70,22 +103,5 @@ makeSuite('LendingPoolAddressesProvider', (testEnv: TestEnv) => { ); expect(nonProxiedAddressSetReceipt.events[0].args?.hasProxy).to.be.equal(false); - const proxiedAddressSetReceipt = await waitForTx( - await addressesProvider - .connect(currentAddressesProviderOwner.signer) - .setAddress(proxiedAddressId, ZERO_ADDRESS, mockLendingPool.address) - ); - - if (!proxiedAddressSetReceipt.events || proxiedAddressSetReceipt.events?.length < 2) { - throw new Error('INVALID_EVENT_EMMITED'); - } - - expect(proxiedAddressSetReceipt.events[0].event).to.be.equal('ProxyCreated'); - expect(proxiedAddressSetReceipt.events[1].event).to.be.equal('AddressSet'); - expect(proxiedAddressSetReceipt.events[1].args?.id).to.be.equal(proxiedAddressId); - expect(proxiedAddressSetReceipt.events[1].args?.newAddress).to.be.equal( - mockLendingPool.address - ); - expect(proxiedAddressSetReceipt.events[1].args?.hasProxy).to.be.equal(true); }); });