mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'fix/123' into 'master'
Resolve "Add check that amount != 0 in validateBorrow()" Closes #123 See merge request aave-tech/protocol-v2!141
This commit is contained in:
commit
3fc261037a
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,11 @@ interface ILendingPoolAddressesProvider {
|
|||
|
||||
function setAddress(
|
||||
bytes32 id,
|
||||
address newAddress,
|
||||
address newAddress
|
||||
) external;
|
||||
|
||||
function setAddressAsProxy(
|
||||
bytes32 id,
|
||||
address impl
|
||||
) external;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ library Errors {
|
|||
string public constant BORROW_ALLOWANCE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small
|
||||
|
||||
//contract specific errors
|
||||
string public constant VL_AMOUNT_NOT_GREATER_THAN_0 = '1'; // 'Amount must be greater than 0'
|
||||
string public constant VL_INVALID_AMOUNT = '1'; // 'Amount must be greater than 0'
|
||||
string public constant VL_NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve'
|
||||
string public constant VL_RESERVE_FROZEN = '3'; // 'Action cannot be performed because the reserve is frozen'
|
||||
string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough'
|
||||
|
|
|
@ -36,7 +36,7 @@ library ValidationLogic {
|
|||
function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount) external view {
|
||||
(bool isActive, bool isFrozen, , ) = reserve.configuration.getFlags();
|
||||
|
||||
require(amount > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
|
||||
require(amount != 0, Errors.VL_INVALID_AMOUNT);
|
||||
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||
require(!isFrozen, Errors.VL_RESERVE_FROZEN);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ library ValidationLogic {
|
|||
uint256 reservesCount,
|
||||
address oracle
|
||||
) external view {
|
||||
require(amount > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
|
||||
require(amount != 0, Errors.VL_INVALID_AMOUNT);
|
||||
|
||||
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
|
||||
|
||||
|
@ -139,6 +139,7 @@ library ValidationLogic {
|
|||
|
||||
require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||
require(!vars.isFrozen, Errors.VL_RESERVE_FROZEN);
|
||||
require(amount != 0, Errors.VL_INVALID_AMOUNT);
|
||||
|
||||
require(vars.borrowingEnabled, Errors.VL_BORROWING_NOT_ENABLED);
|
||||
|
||||
|
@ -232,7 +233,7 @@ library ValidationLogic {
|
|||
|
||||
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||
|
||||
require(amountSent > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
|
||||
require(amountSent > 0, Errors.VL_INVALID_AMOUNT);
|
||||
|
||||
require(
|
||||
(stableDebt > 0 &&
|
||||
|
|
|
@ -86,7 +86,7 @@ export enum ProtocolErrors {
|
|||
CALLER_NOT_POOL_ADMIN = '33', // 'The caller must be the pool admin'
|
||||
|
||||
//contract specific errors
|
||||
VL_AMOUNT_NOT_GREATER_THAN_0 = '1', // 'Amount must be greater than 0'
|
||||
VL_INVALID_AMOUNT = '1', // 'Amount must be greater than 0'
|
||||
VL_NO_ACTIVE_RESERVE = '2', // 'Action requires an active reserve'
|
||||
VL_RESERVE_FROZEN = '3', // 'Action requires an unfrozen reserve'
|
||||
VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4', // 'The current liquidity is not enough'
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user