Skip to content

Commit cb85a5e

Browse files
fmt + deploy
1 parent 4cabf3f commit cb85a5e

File tree

3 files changed

+85
-215
lines changed

3 files changed

+85
-215
lines changed
Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22
pragma solidity ^0.8.28;
33

4-
interface IRouter {
5-
enum TokenType {
6-
Native,
7-
ERC20,
8-
ERC721,
9-
ERC1155
10-
}
11-
12-
struct Token {
13-
TokenType tokenType;
14-
bytes data;
15-
}
16-
17-
function routeSingle(
18-
Token calldata tokenIn,
19-
bytes calldata data
20-
) external payable returns (bytes memory response);
21-
}
22-
234
interface IERC3156FlashBorrower {
245
function onFlashLoan(
256
address initiator,
267
address token,
278
uint256 amount,
289
uint256 fee,
2910
bytes calldata data
30-
) external returns (bytes32);
11+
)
12+
external
13+
returns (bytes32);
3114
}
3215

3316
interface IMorpho {
34-
function flashLoan(
35-
address token,
36-
uint256 assets,
37-
bytes calldata data
38-
) external;
17+
function flashLoan(address token, uint256 assets, bytes calldata data) external;
3918
}
4019

4120
interface IEVault {
@@ -48,7 +27,8 @@ interface IBalancerV2Vault {
4827
address[] memory tokens,
4928
uint256[] memory amounts,
5029
bytes memory userData
51-
) external;
30+
)
31+
external;
5232
}
5333

5434
interface IAaveV3Pool {
@@ -60,5 +40,6 @@ interface IAaveV3Pool {
6040
uint256 amount,
6141
bytes calldata params,
6242
uint16 referralCode
63-
) external;
43+
)
44+
external;
6445
}
Lines changed: 49 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22
pragma 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

1213
enum 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

Comments
 (0)