11// SPDX-License-Identifier: GPL-3.0-only
22pragma solidity ^ 0.8.28 ;
33
4- import "./EnsoFlashloanInterfaces.sol " ;
4+ import { IAaveV3Pool, IBalancerV2Vault, IERC3156FlashBorrower , IEVault, IMorpho } from "./EnsoFlashloanInterfaces.sol " ;
55
6- import {VM } from "enso-weiroll/VM.sol " ;
6+ import { VM } from "enso-weiroll/VM.sol " ;
77
8- import {ERC1155Holder } from "openzeppelin-contracts/token/ERC1155/utils/ERC1155Holder.sol " ;
9- import {ERC721Holder } from "openzeppelin-contracts/token/ERC721/utils/ERC721Holder.sol " ;
10- import {IERC20 , SafeERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol " ;
8+ import { ERC1155Holder } from "openzeppelin-contracts/token/ERC1155/utils/ERC1155Holder.sol " ;
9+
10+ import { IERC20 , SafeERC20 } from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol " ;
11+ import { ERC721Holder } from "openzeppelin-contracts/token/ERC721/utils/ERC721Holder.sol " ;
1112
1213enum FlashloanProtocols {
1314 Euler,
@@ -29,7 +30,10 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
2930 bytes calldata data ,
3031 bytes32 [] calldata commands ,
3132 bytes [] calldata state
32- ) external payable {
33+ )
34+ external
35+ payable
36+ {
3337 if (protocol == FlashloanProtocols.Euler) {
3438 _executeEulerFlashLoan (excessReceiver, data, commands, state);
3539 } else if (protocol == FlashloanProtocols.BalancerV2) {
@@ -55,19 +59,12 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
5559 bytes calldata data ,
5660 bytes32 [] calldata commands ,
5761 bytes [] calldata state
58- ) private {
59- (IEVault EulerVault , address token , uint256 amount ) = abi.decode (
60- data,
61- (IEVault, address , uint256 )
62- );
63-
64- bytes memory eulerCallback = abi.encode (
65- amount,
66- token,
67- excessReceiver,
68- commands,
69- state
70- );
62+ )
63+ private
64+ {
65+ (IEVault EulerVault , address token , uint256 amount ) = abi.decode (data, (IEVault, address , uint256 ));
66+
67+ bytes memory eulerCallback = abi.encode (amount, token, excessReceiver, commands, state);
7168
7269 EulerVault.flashLoan (amount, eulerCallback);
7370 }
@@ -77,18 +74,13 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
7774 bytes calldata data ,
7875 bytes32 [] calldata commands ,
7976 bytes [] calldata state
80- ) private {
81- (
82- IBalancerV2Vault Vault ,
83- address [] memory tokens ,
84- uint256 [] memory amounts
85- ) = abi.decode (data, (IBalancerV2Vault, address [], uint256 []));
86-
87- bytes memory balancerV2Callback = abi.encode (
88- excessReceiver,
89- commands,
90- state
91- );
77+ )
78+ private
79+ {
80+ (IBalancerV2Vault Vault , address [] memory tokens , uint256 [] memory amounts ) =
81+ abi.decode (data, (IBalancerV2Vault, address [], uint256 []));
82+
83+ bytes memory balancerV2Callback = abi.encode (excessReceiver, commands, state);
9284
9385 Vault.flashLoan (address (this ), tokens, amounts, balancerV2Callback);
9486 }
@@ -98,17 +90,11 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
9890 bytes calldata data ,
9991 bytes32 [] calldata commands ,
10092 bytes [] calldata state
101- ) private {
102- (IMorpho morpho , address token , uint256 amount ) = abi.decode (
103- data,
104- (IMorpho, address , uint256 )
105- );
106- bytes memory morphoCallback = abi.encode (
107- token,
108- excessReceiver,
109- commands,
110- state
111- );
93+ )
94+ private
95+ {
96+ (IMorpho morpho , address token , uint256 amount ) = abi.decode (data, (IMorpho, address , uint256 ));
97+ bytes memory morphoCallback = abi.encode (token, excessReceiver, commands, state);
11298
11399 morpho.flashLoan (token, amount, morphoCallback);
114100 }
@@ -118,11 +104,10 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
118104 bytes calldata data ,
119105 bytes32 [] calldata commands ,
120106 bytes [] calldata state
121- ) private {
122- (IAaveV3Pool Pool , address token , uint256 amount ) = abi.decode (
123- data,
124- (IAaveV3Pool, address , uint256 )
125- );
107+ )
108+ private
109+ {
110+ (IAaveV3Pool Pool , address token , uint256 amount ) = abi.decode (data, (IAaveV3Pool, address , uint256 ));
126111
127112 bytes memory aaveCallback = abi.encode (excessReceiver, commands, state);
128113
@@ -133,13 +118,8 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
133118
134119 // Euler
135120 function onFlashLoan (bytes calldata data ) external {
136- (
137- uint256 amount ,
138- IERC20 token ,
139- address excessReceiver ,
140- bytes32 [] memory commands ,
141- bytes [] memory state
142- ) = abi.decode (data, (uint256 , IERC20 , address , bytes32 [], bytes []));
121+ (uint256 amount , IERC20 token , address excessReceiver , bytes32 [] memory commands , bytes [] memory state ) =
122+ abi.decode (data, (uint256 , IERC20 , address , bytes32 [], bytes []));
143123
144124 this .execute (commands, state);
145125
@@ -154,12 +134,11 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
154134 uint256 [] calldata amounts ,
155135 uint256 [] calldata feeAmounts ,
156136 bytes calldata data
157- ) external {
158- (
159- address excessReceiver ,
160- bytes32 [] memory commands ,
161- bytes [] memory state
162- ) = abi.decode (data, (address , bytes32 [], bytes []));
137+ )
138+ external
139+ {
140+ (address excessReceiver , bytes32 [] memory commands , bytes [] memory state ) =
141+ abi.decode (data, (address , bytes32 [], bytes []));
163142
164143 this .execute (commands, state);
165144
@@ -172,12 +151,8 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
172151
173152 // Morpho
174153 function onMorphoFlashLoan (uint256 amount , bytes calldata data ) external {
175- (
176- IERC20 token ,
177- address excessReceiver ,
178- bytes32 [] memory commands ,
179- bytes [] memory state
180- ) = abi.decode (data, (IERC20 , address , bytes32 [], bytes []));
154+ (IERC20 token , address excessReceiver , bytes32 [] memory commands , bytes [] memory state ) =
155+ abi.decode (data, (IERC20 , address , bytes32 [], bytes []));
181156
182157 this .execute (commands, state);
183158
@@ -193,13 +168,13 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
193168 uint256 premium ,
194169 address initiator ,
195170 bytes calldata data
196- ) external returns (bool ) {
171+ )
172+ external
173+ returns (bool )
174+ {
197175 require (initiator == address (this ), NotAuthorized ());
198- (
199- address excessReceiver ,
200- bytes32 [] memory commands ,
201- bytes [] memory state
202- ) = abi.decode (data, (address , bytes32 [], bytes []));
176+ (address excessReceiver , bytes32 [] memory commands , bytes [] memory state ) =
177+ abi.decode (data, (address , bytes32 [], bytes []));
203178
204179 this .execute (commands, state);
205180
@@ -210,11 +185,7 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
210185 return true ;
211186 }
212187
213- function _returnExcessAssets (
214- IERC20 token ,
215- uint256 flashloanAmount ,
216- address receiver
217- ) private {
188+ function _returnExcessAssets (IERC20 token , uint256 flashloanAmount , address receiver ) private {
218189 uint256 flashloanAssetBalance = token.balanceOf (address (this ));
219190 if (flashloanAssetBalance > flashloanAmount) {
220191 uint256 excessAmount;
@@ -225,5 +196,5 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
225196 }
226197 }
227198
228- receive () external payable {}
199+ receive () external payable { }
229200}
0 commit comments