Skip to content

Commit

Permalink
feat: renamed simpleFlashloan and data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
The-3D committed Oct 8, 2021
1 parent f00e109 commit 9cc4d0c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ interface IPool {
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
**/
function simpleFlashLoan(
function flashLoanSimple(
address receiverAddress,
address asset,
uint256 amount,
Expand Down
23 changes: 12 additions & 11 deletions contracts/protocol/libraries/logic/FlashLoanLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,28 @@ library FlashLoanLogic {

struct SimpleFlashLoanLocalVars {
ISimpleFlashLoanReceiver receiver;
address aTokenAddress;
uint256 totalPremium;
uint256 premiumToLP;
uint256 premiumToProtocol;
uint256 amountPlusPremium;
}

function executeSimpleFlashLoan(
function executeFlashLoanSimple(
DataTypes.ReserveData storage reserve,
DataTypes.SimpleFlashloanParams memory params
DataTypes.FlashloanSimpleParams memory params
) external {
SimpleFlashLoanLocalVars memory vars;

ValidationLogic.validateSimpleFlashloan(reserve);
DataTypes.ReserveCache memory reserveCache = reserve.cache();
reserve.updateState(reserveCache);

ValidationLogic.validateFlashloanSimple(reserveCache);

vars.receiver = ISimpleFlashLoanReceiver(params.receiverAddress);

vars.aTokenAddress = reserve.aTokenAddress;
vars.totalPremium = params.amount.percentMul(params.flashLoanPremiumTotal);
vars.amountPlusPremium = params.amount + vars.totalPremium;
IAToken(vars.aTokenAddress).transferUnderlyingTo(params.receiverAddress, params.amount);
IAToken(reserveCache.aTokenAddress).transferUnderlyingTo(params.receiverAddress, params.amount);

require(
vars.receiver.executeOperation(
Expand All @@ -210,10 +211,10 @@ library FlashLoanLogic {
vars.premiumToProtocol = params.amount.percentMul(params.flashLoanPremiumToProtocol);
vars.premiumToLP = vars.totalPremium - vars.premiumToProtocol;

DataTypes.ReserveCache memory reserveCache = reserve.cache();

reserve.updateState(reserveCache);
reserve.cumulateToLiquidityIndex(IERC20(vars.aTokenAddress).totalSupply(), vars.premiumToLP);
reserve.cumulateToLiquidityIndex(
IERC20(reserveCache.aTokenAddress).totalSupply(),
vars.premiumToLP
);

reserve.accruedToTreasury =
reserve.accruedToTreasury +
Expand All @@ -223,7 +224,7 @@ library FlashLoanLogic {

IERC20(params.asset).safeTransferFrom(
params.receiverAddress,
vars.aTokenAddress,
reserveCache.aTokenAddress,
vars.amountPlusPremium
);

Expand Down
7 changes: 4 additions & 3 deletions contracts/protocol/libraries/logic/ValidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,11 @@ library ValidationLogic {

/**
* @notice Validates a flashloan action
* @param reserveData The state of the reserve
* @param reserveCache The cached data of the reserve
*/
function validateSimpleFlashloan(DataTypes.ReserveData storage reserveData) internal view {
require(!reserveData.configuration.getPaused(), Errors.VL_RESERVE_PAUSED);
function validateFlashloanSimple(DataTypes.ReserveCache memory reserveCache) internal view {
require(!reserveCache.reserveConfiguration.getPaused(), Errors.VL_RESERVE_PAUSED);
require(reserveCache.reserveConfiguration.getActive(), Errors.VL_NO_ACTIVE_RESERVE);
}

struct ValidateLiquidationCallLocalVars {
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/libraries/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ library DataTypes {
bool isAuthorizedFlashBorrower;
}

struct SimpleFlashloanParams {
struct FlashloanSimpleParams {
address receiverAddress;
address asset;
uint256 amount;
Expand Down
6 changes: 3 additions & 3 deletions contracts/protocol/pool/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,14 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
}

/// @inheritdoc IPool
function simpleFlashLoan(
function flashLoanSimple(
address receiverAddress,
address asset,
uint256 amount,
bytes calldata params,
uint16 referralCode
) external override {
DataTypes.SimpleFlashloanParams memory flashParams = DataTypes.SimpleFlashloanParams(
DataTypes.FlashloanSimpleParams memory flashParams = DataTypes.FlashloanSimpleParams(
receiverAddress,
asset,
amount,
Expand All @@ -396,7 +396,7 @@ contract Pool is VersionedInitializable, IPool, PoolStorage {
_flashLoanPremiumToProtocol,
_flashLoanPremiumTotal
);
FlashLoanLogic.executeSimpleFlashLoan(_reserves[asset], flashParams);
FlashLoanLogic.executeFlashLoanSimple(_reserves[asset], flashParams);
}

/// @inheritdoc IPool
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const hardhatConfig: HardhatUserConfig = {
settings: {
optimizer: {
enabled: true,
runs: 4000,
runs: 100000,
},
evmVersion: 'london',
},
Expand Down

0 comments on commit 9cc4d0c

Please sign in to comment.