1
1
// SPDX-License-Identifier: GPL-3.0-only
2
2
pragma solidity ^ 0.8.28 ;
3
3
4
- import "./EnsoFlashloanInterfaces.sol " ;
4
+ import { IAaveV3Pool, IBalancerV2Vault, IERC3156FlashBorrower , IEVault, IMorpho } from "./EnsoFlashloanInterfaces.sol " ;
5
5
6
- import {VM } from "enso-weiroll/VM.sol " ;
6
+ import { VM } from "enso-weiroll/VM.sol " ;
7
7
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 " ;
11
12
12
13
enum FlashloanProtocols {
13
14
Euler,
@@ -29,7 +30,10 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
29
30
bytes calldata data ,
30
31
bytes32 [] calldata commands ,
31
32
bytes [] calldata state
32
- ) external payable {
33
+ )
34
+ external
35
+ payable
36
+ {
33
37
if (protocol == FlashloanProtocols.Euler) {
34
38
_executeEulerFlashLoan (excessReceiver, data, commands, state);
35
39
} else if (protocol == FlashloanProtocols.BalancerV2) {
@@ -55,19 +59,12 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
55
59
bytes calldata data ,
56
60
bytes32 [] calldata commands ,
57
61
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);
71
68
72
69
EulerVault.flashLoan (amount, eulerCallback);
73
70
}
@@ -77,18 +74,13 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
77
74
bytes calldata data ,
78
75
bytes32 [] calldata commands ,
79
76
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);
92
84
93
85
Vault.flashLoan (address (this ), tokens, amounts, balancerV2Callback);
94
86
}
@@ -98,17 +90,11 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
98
90
bytes calldata data ,
99
91
bytes32 [] calldata commands ,
100
92
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);
112
98
113
99
morpho.flashLoan (token, amount, morphoCallback);
114
100
}
@@ -118,11 +104,10 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
118
104
bytes calldata data ,
119
105
bytes32 [] calldata commands ,
120
106
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 ));
126
111
127
112
bytes memory aaveCallback = abi.encode (excessReceiver, commands, state);
128
113
@@ -133,13 +118,8 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
133
118
134
119
// Euler
135
120
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 []));
143
123
144
124
this .execute (commands, state);
145
125
@@ -154,12 +134,11 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
154
134
uint256 [] calldata amounts ,
155
135
uint256 [] calldata feeAmounts ,
156
136
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 []));
163
142
164
143
this .execute (commands, state);
165
144
@@ -172,12 +151,8 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
172
151
173
152
// Morpho
174
153
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 []));
181
156
182
157
this .execute (commands, state);
183
158
@@ -193,13 +168,13 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
193
168
uint256 premium ,
194
169
address initiator ,
195
170
bytes calldata data
196
- ) external returns (bool ) {
171
+ )
172
+ external
173
+ returns (bool )
174
+ {
197
175
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 []));
203
178
204
179
this .execute (commands, state);
205
180
@@ -210,11 +185,7 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
210
185
return true ;
211
186
}
212
187
213
- function _returnExcessAssets (
214
- IERC20 token ,
215
- uint256 flashloanAmount ,
216
- address receiver
217
- ) private {
188
+ function _returnExcessAssets (IERC20 token , uint256 flashloanAmount , address receiver ) private {
218
189
uint256 flashloanAssetBalance = token.balanceOf (address (this ));
219
190
if (flashloanAssetBalance > flashloanAmount) {
220
191
uint256 excessAmount;
@@ -225,5 +196,5 @@ contract EnsoFlashloanShortcuts is VM, ERC721Holder, ERC1155Holder {
225
196
}
226
197
}
227
198
228
- receive () external payable {}
199
+ receive () external payable { }
229
200
}
0 commit comments