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