feat: added authorized flashloaners

This commit is contained in:
Hadrien Charlanes 2021-05-12 13:08:18 +02:00
parent ec77fc3db4
commit ccad06fc94
5 changed files with 45 additions and 2 deletions

View File

@ -458,4 +458,10 @@ interface ILendingPool {
function setPause(bool val) external;
function paused() external view returns (bool);
function authorizeFlashloaner(address flashloaner) external;
function unauthorizeFlashloaner(address flashloaner) external;
function isFlashloanerAuthorized(address flashloaner) external view returns (bool);
}

View File

@ -207,9 +207,17 @@ interface ILendingPoolConfigurator {
event RiskAdminUnregistered(address indexed admin);
event FlashloanerAuthorized(address indexed flashloaner);
event FlashloanerUnauthorized(address indexed flashloaner);
function registerRiskAdmin(address admin) external;
function unregisterRiskAdmin(address admin) external;
function authorizeFlashloaner(address flashloaner) external;
function unauthorizeFlashloaner(address flashloaner) external;
function isRiskAdmin(address admin) external view returns (bool);
}

View File

@ -435,6 +435,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
uint256 currentPremium;
uint256 currentAmountPlusPremium;
address debtToken;
uint256 flashloanPremiumTotal;
}
/**
@ -469,13 +470,13 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
address[] memory aTokenAddresses = new address[](assets.length);
uint256[] memory premiums = new uint256[](assets.length);
vars.receiver = IFlashLoanReceiver(receiverAddress);
vars.flashloanPremiumTotal = _authorizedFlashloaners[msg.sender] ? 0 : _flashLoanPremiumTotal;
for (vars.i = 0; vars.i < assets.length; vars.i++) {
aTokenAddresses[vars.i] = _reserves[assets[vars.i]].aTokenAddress;
premiums[vars.i] = amounts[vars.i].mul(_flashLoanPremiumTotal).div(10000);
premiums[vars.i] = amounts[vars.i].mul(vars.flashloanPremiumTotal).div(10000);
IAToken(aTokenAddresses[vars.i]).transferUnderlyingTo(receiverAddress, amounts[vars.i]);
}
@ -821,6 +822,22 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}
}
function authorizeFlashloaner(address flashloaner) external override onlyLendingPoolConfigurator {
_authorizedFlashloaners[flashloaner] = true;
}
function unauthorizeFlashloaner(address flashloaner)
external
override
onlyLendingPoolConfigurator
{
_authorizedFlashloaners[flashloaner] = false;
}
function isFlashloanerAuthorized(address flashloaner) external view override returns (bool) {
return _authorizedFlashloaners[flashloaner];
}
struct ExecuteBorrowParams {
address asset;
address user;

View File

@ -537,6 +537,16 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
emit RiskAdminUnregistered(admin);
}
function authorizeFlashloaner(address flashloaner) external override onlyPoolAdmin {
pool.authorizeFlashloaner(flashloaner);
emit FlashloanerAuthorized(flashloaner);
}
function unauthorizeFlashloaner(address flashloaner) external override onlyPoolAdmin {
pool.unauthorizeFlashloaner(flashloaner);
emit FlashloanerUnauthorized(flashloaner);
}
function isRiskAdmin(address admin) external view override onlyPoolAdmin returns (bool) {
return _riskAdmins[admin];
}

View File

@ -29,4 +29,6 @@ contract LendingPoolStorage {
uint256 internal _flashLoanPremiumTotal;
uint256 internal _maxNumberOfReserves;
mapping(address => bool) _authorizedFlashloaners;
}