mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
- Added batch to credit delegation
This commit is contained in:
parent
ecd2c04001
commit
edfe17bd97
|
@ -32,11 +32,11 @@ interface ILendingPool {
|
||||||
event Withdraw(address indexed reserve, address indexed user, uint256 amount);
|
event Withdraw(address indexed reserve, address indexed user, uint256 amount);
|
||||||
|
|
||||||
event BorrowAllowanceDelegated(
|
event BorrowAllowanceDelegated(
|
||||||
address indexed asset,
|
|
||||||
address indexed fromUser,
|
address indexed fromUser,
|
||||||
address indexed toUser,
|
address indexed toUser,
|
||||||
uint256 interestRateMode,
|
address[] assets,
|
||||||
uint256 amount
|
uint256[] interestRateModes,
|
||||||
|
uint256[] amounts
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* @dev emitted on borrow
|
* @dev emitted on borrow
|
||||||
|
@ -189,17 +189,17 @@ interface ILendingPool {
|
||||||
function withdraw(address reserve, uint256 amount) external;
|
function withdraw(address reserve, uint256 amount) external;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sets allowance to borrow on a certain type of debt asset for a certain user address
|
* @dev Sets allowance to borrow on a certain type of debt assets for a certain user address
|
||||||
* @param asset The underlying asset of the debt token
|
* @param assets The underlying asset of each debt token
|
||||||
* @param user The user to give allowance to
|
* @param user The user to give allowance to
|
||||||
* @param interestRateMode Type of debt: 1 for stable, 2 for variable
|
* @param interestRateModes Types of debt: 1 for stable, 2 for variable
|
||||||
* @param amount Allowance amount to borrow
|
* @param amounts Allowance amounts to borrow
|
||||||
**/
|
**/
|
||||||
function delegateBorrowAllowance(
|
function delegateBorrowAllowance(
|
||||||
address asset,
|
address[] calldata assets,
|
||||||
address user,
|
address user,
|
||||||
uint256 interestRateMode,
|
uint256[] calldata interestRateModes,
|
||||||
uint256 amount
|
uint256[] calldata amounts
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
function getBorrowAllowance(
|
function getBorrowAllowance(
|
||||||
|
|
|
@ -179,23 +179,32 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sets allowance to borrow on a certain type of debt asset for a certain user address
|
* @dev Sets allowance to borrow on a certain type of debt assets for a certain user address
|
||||||
* @param asset The underlying asset of the debt token
|
* @param assets The underlying asset of each debt token
|
||||||
* @param user The user to give allowance to
|
* @param user The user to give allowance to
|
||||||
* @param interestRateMode Type of debt: 1 for stable, 2 for variable
|
* @param interestRateModes Types of debt: 1 for stable, 2 for variable
|
||||||
* @param amount Allowance amount to borrow
|
* @param amounts Allowance amounts to borrow
|
||||||
**/
|
**/
|
||||||
function delegateBorrowAllowance(
|
function delegateBorrowAllowance(
|
||||||
address asset,
|
address[] calldata assets,
|
||||||
address user,
|
address user,
|
||||||
uint256 interestRateMode,
|
uint256[] calldata interestRateModes,
|
||||||
uint256 amount
|
uint256[] calldata amounts
|
||||||
) external override {
|
) external override {
|
||||||
_whenNotPaused();
|
_whenNotPaused();
|
||||||
address debtToken = _reserves[asset].getDebtTokenAddress(interestRateMode);
|
|
||||||
|
|
||||||
_borrowAllowance[debtToken][msg.sender][user] = amount;
|
uint256 countAssets = assets.length;
|
||||||
emit BorrowAllowanceDelegated(asset, msg.sender, user, interestRateMode, amount);
|
require(
|
||||||
|
countAssets == interestRateModes.length && countAssets == amounts.length,
|
||||||
|
Errors.INCONSISTENT_PARAMS_LENGTH
|
||||||
|
);
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < countAssets; i++) {
|
||||||
|
address debtToken = _reserves[assets[i]].getDebtTokenAddress(interestRateModes[i]);
|
||||||
|
_borrowAllowance[debtToken][msg.sender][user] = amounts[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
emit BorrowAllowanceDelegated(msg.sender, user, assets, interestRateModes, amounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -913,7 +922,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
* @dev adds a reserve to the array of the _reserves address
|
* @dev adds a reserve to the array of the _reserves address
|
||||||
**/
|
**/
|
||||||
function _addReserveToList(address asset) internal {
|
function _addReserveToList(address asset) internal {
|
||||||
|
|
||||||
uint256 reservesCount = _reservesCount;
|
uint256 reservesCount = _reservesCount;
|
||||||
|
|
||||||
require(reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED);
|
require(reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED);
|
||||||
|
|
|
@ -97,6 +97,9 @@ library Errors {
|
||||||
string public constant INVALID_DECIMALS = '73';
|
string public constant INVALID_DECIMALS = '73';
|
||||||
string public constant INVALID_RESERVE_FACTOR = '74';
|
string public constant INVALID_RESERVE_FACTOR = '74';
|
||||||
|
|
||||||
|
// Credit delegation
|
||||||
|
string public constant INCONSISTENT_PARAMS_LENGTH = '75';
|
||||||
|
|
||||||
|
|
||||||
enum CollateralManagerErrors {
|
enum CollateralManagerErrors {
|
||||||
NO_ERROR,
|
NO_ERROR,
|
||||||
|
|
|
@ -279,9 +279,9 @@ export const withdraw = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const delegateBorrowAllowance = async (
|
export const delegateBorrowAllowance = async (
|
||||||
reserveSymbol: string,
|
reserveSymbols: string[],
|
||||||
amount: string,
|
amounts: string[],
|
||||||
interestRateMode: string,
|
interestRateModes: string[],
|
||||||
user: SignerWithAddress,
|
user: SignerWithAddress,
|
||||||
receiver: tEthereumAddress,
|
receiver: tEthereumAddress,
|
||||||
expectedResult: string,
|
expectedResult: string,
|
||||||
|
@ -290,20 +290,27 @@ export const delegateBorrowAllowance = async (
|
||||||
) => {
|
) => {
|
||||||
const {pool} = testEnv;
|
const {pool} = testEnv;
|
||||||
|
|
||||||
const reserve = await getReserveAddressFromSymbol(reserveSymbol);
|
const reserves : tEthereumAddress[] = []
|
||||||
const amountToDelegate = await convertToCurrencyDecimals(reserve, amount);
|
const amountsToDelegate: tEthereumAddress[] = []
|
||||||
|
for (const reserveSymbol of reserveSymbols) {
|
||||||
|
const newLength = reserves.push(await getReserveAddressFromSymbol(reserveSymbol))
|
||||||
|
amountsToDelegate.push(await (await convertToCurrencyDecimals(reserves[newLength-1], amounts[newLength-1])).toString())
|
||||||
|
}
|
||||||
|
|
||||||
const delegateAllowancePromise = pool
|
const delegateAllowancePromise = pool
|
||||||
.connect(user.signer)
|
.connect(user.signer)
|
||||||
.delegateBorrowAllowance(reserve, receiver, interestRateMode, amountToDelegate.toString());
|
.delegateBorrowAllowance(reserves, receiver, interestRateModes, amountsToDelegate);
|
||||||
if (expectedResult === 'revert') {
|
if (expectedResult === 'revert') {
|
||||||
await expect(delegateAllowancePromise, revertMessage).to.be.reverted;
|
await expect(delegateAllowancePromise, revertMessage).to.be.reverted;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
await delegateAllowancePromise;
|
await delegateAllowancePromise;
|
||||||
|
for (const [i, reserve] of reserves.entries()) {
|
||||||
expect(
|
expect(
|
||||||
(await pool.getBorrowAllowance(user.address, receiver, reserve, interestRateMode)).toString()
|
(await pool.getBorrowAllowance(user.address, receiver, reserve, interestRateModes[i])).toString()
|
||||||
).to.be.equal(amountToDelegate.toString(), 'borrowAllowance are set incorrectly');
|
).to.be.equal(amountsToDelegate[i], 'borrowAllowance are set incorrectly');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -121,9 +121,9 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
await delegateBorrowAllowance(
|
await delegateBorrowAllowance(
|
||||||
reserve,
|
[reserve],
|
||||||
amount,
|
[amount],
|
||||||
rateMode,
|
[rateMode],
|
||||||
user,
|
user,
|
||||||
toUser,
|
toUser,
|
||||||
expected,
|
expected,
|
||||||
|
|
|
@ -132,7 +132,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
// Try to execute liquidation
|
// Try to execute liquidation
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(user.signer).delegateBorrowAllowance(dai.address, toUser.address, '1', '1')
|
pool.connect(user.signer).delegateBorrowAllowance([dai.address], toUser.address, ['1'], ['1'])
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(IS_PAUSED);
|
||||||
|
|
||||||
// Unpause the pool
|
// Unpause the pool
|
||||||
|
|
Loading…
Reference in New Issue
Block a user