Merge branch 'master' of gitlab.com:aave-tech/protocol-v2 into 97-create-a-utility-contract-to-deposit-withdraw-repay-with-eth

This commit is contained in:
David Racero 2020-11-03 12:51:54 +01:00
commit 6174539966
4 changed files with 12 additions and 21 deletions

View File

@ -232,15 +232,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_whenNotPaused();
ReserveLogic.ReserveData storage reserve = _reserves[asset];
if (onBehalfOf != msg.sender) {
address debtToken = reserve.getDebtTokenAddress(interestRateMode);
_borrowAllowance[debtToken][onBehalfOf][msg
.sender] = _borrowAllowance[debtToken][onBehalfOf][msg.sender].sub(
amount,
Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH
);
}
_executeBorrow(
ExecuteBorrowParams(
asset,
@ -583,14 +574,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
vars.currentAmountPlusPremium
);
} else {
if (msg.sender != onBehalfOf) {
vars.debtToken = _reserves[vars.currentAsset].getDebtTokenAddress(modes[vars.i]);
_borrowAllowance[vars.debtToken][onBehalfOf][msg.sender] = _borrowAllowance[vars
.debtToken][onBehalfOf][msg.sender]
.sub(vars.currentAmount, Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
}
//if the user didn't choose to return the funds, the system checks if there
//is enough collateral and eventually open a position
_executeBorrow(
@ -915,6 +898,14 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
oracle
);
if (vars.onBehalfOf != msg.sender) {
address debtToken = reserve.getDebtTokenAddress(vars.interestRateMode);
_borrowAllowance[debtToken][vars.onBehalfOf][msg.sender] = _borrowAllowance[debtToken][vars
.onBehalfOf][msg.sender]
.sub(vars.amount, Errors.LP_BORROW_ALLOWANCE_NOT_ENOUGH);
}
reserve.updateState();
//caching the current stable borrow rate

View File

@ -79,7 +79,7 @@ library Errors {
string public constant AT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint
string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '57';
string public constant AT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn
string public constant LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small
string public constant LP_BORROW_ALLOWANCE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small
string public constant LP_FAILED_COLLATERAL_SWAP = '60';
string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61';
string public constant LP_REENTRANCY_NOT_ALLOWED = '62';

View File

@ -138,7 +138,7 @@ export enum ProtocolErrors {
AT_INVALID_MINT_AMOUNT = '56', //invalid amount to mint
LP_FAILED_REPAY_WITH_COLLATERAL = '57',
AT_INVALID_BURN_AMOUNT = '58', //invalid amount to burn
LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '59', // User borrows on behalf, but allowance are too small
LP_BORROW_ALLOWANCE_NOT_ENOUGH = '59', // User borrows on behalf, but allowance are too small
LP_FAILED_COLLATERAL_SWAP = '60',
LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61',
LP_REENTRANCY_NOT_ALLOWED = '62',

View File

@ -24,7 +24,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
LP_INVALID_FLASHLOAN_MODE,
SAFEERC20_LOWLEVEL_CALL,
LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN,
LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH,
LP_BORROW_ALLOWANCE_NOT_ENOUGH,
} = ProtocolErrors;
before(async () => {
@ -443,7 +443,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
'0x10',
'0'
)
).to.be.revertedWith(LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
).to.be.revertedWith(LP_BORROW_ALLOWANCE_NOT_ENOUGH);
});
it('Caller takes a WETH flashloan with mode = 1 onBehalfOf user with allowance. A loan for onBehalfOf is creatd.', async () => {