@@ -16,6 +16,9 @@ contract EulerSwap is IEulerSwap, EVCUtil {
16
16
17
17
bytes32 public constant curve = bytes32 ("EulerSwap v1 " );
18
18
19
+ uint256 public constant protocolFee = 0.1e18 ;
20
+ address public constant protocolFeeRecipient = address (0 );
21
+
19
22
address public immutable vault0;
20
23
address public immutable vault1;
21
24
address public immutable asset0;
@@ -24,6 +27,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
24
27
uint112 public immutable equilibriumReserve0;
25
28
uint112 public immutable equilibriumReserve1;
26
29
uint256 public immutable feeMultiplier;
30
+ uint256 private immutable feeMultiplierProtocol;
31
+ uint256 private immutable feeMultiplierLP;
27
32
28
33
uint256 public immutable priceX;
29
34
uint256 public immutable priceY;
@@ -84,6 +89,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
84
89
reserve0 = params.currReserve0;
85
90
reserve1 = params.currReserve1;
86
91
feeMultiplier = 1e18 - params.fee;
92
+ feeMultiplierProtocol = 1e18 - (params.fee * protocolFee / 1e18 );
93
+ feeMultiplierLP = feeMultiplier * 1e18 / feeMultiplierProtocol;
87
94
88
95
// Curve params
89
96
@@ -120,11 +127,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
120
127
121
128
// Deposit all available funds, adjust received amounts downward to collect fees
122
129
123
- uint256 amount0In = IERC20 (asset0).balanceOf (address (this ));
124
- if (amount0In > 0 ) amount0In = depositAssets (vault0, amount0In) * feeMultiplier / 1e18 ;
125
-
126
- uint256 amount1In = IERC20 (asset1).balanceOf (address (this ));
127
- if (amount1In > 0 ) amount1In = depositAssets (vault1, amount1In) * feeMultiplier / 1e18 ;
130
+ uint256 amount0In = depositAssets (asset0, vault0);
131
+ uint256 amount1In = depositAssets (asset1, vault1);
128
132
129
133
// Verify curve invariant is satisfied
130
134
@@ -211,14 +215,23 @@ contract EulerSwap is IEulerSwap, EVCUtil {
211
215
}
212
216
213
217
/// @notice Deposits assets into a vault and automatically repays any outstanding debt
218
+ /// @param asset The address of the underlying asset
214
219
/// @param vault The address of the vault to deposit into
215
- /// @param amount The amount of assets to deposit
216
220
/// @return The amount of assets successfully deposited
217
221
/// @dev This function attempts to deposit assets into the specified vault.
218
222
/// @dev If the deposit fails with E_ZeroShares error, it safely returns 0 (this happens with very small amounts).
219
223
/// @dev After successful deposit, if the user has any outstanding controller-enabled debt, it attempts to repay it.
220
224
/// @dev If all debt is repaid, the controller is automatically disabled to reduce gas costs in future operations.
221
- function depositAssets (address vault , uint256 amount ) internal returns (uint256 ) {
225
+ function depositAssets (address asset , address vault ) internal returns (uint256 ) {
226
+ uint256 amount = IERC20 (asset).balanceOf (address (this ));
227
+ if (amount == 0 ) return 0 ;
228
+
229
+ {
230
+ uint256 feeAmount = amount - (amount * feeMultiplierProtocol / 1e18 );
231
+ IERC20 (asset).transfer (protocolFeeRecipient, feeAmount);
232
+ amount -= feeAmount;
233
+ }
234
+
222
235
uint256 deposited;
223
236
224
237
if (IEVC (evc).isControllerEnabled (eulerAccount, vault)) {
@@ -238,13 +251,13 @@ contract EulerSwap is IEulerSwap, EVCUtil {
238
251
try IEVault (vault).deposit (amount, eulerAccount) {}
239
252
catch (bytes memory reason ) {
240
253
require (bytes4 (reason) == EVKErrors.E_ZeroShares.selector , DepositFailure (reason));
241
- return deposited ;
254
+ amount = 0 ;
242
255
}
243
256
244
257
deposited += amount;
245
258
}
246
259
247
- return deposited;
260
+ return ( deposited * feeMultiplierLP + ( 1e18 - 1 )) / 1e18 ;
248
261
}
249
262
250
263
/// @notice Approves tokens for a given vault, supporting both standard approvals and permit2
0 commit comments