@@ -16,6 +16,9 @@ contract EulerSwap is IEulerSwap, EVCUtil {
1616
1717 bytes32 public constant curve = bytes32 ("EulerSwap v1 " );
1818
19+ uint256 public constant protocolFee = 0.1e18 ;
20+ address public constant protocolFeeRecipient = address (0 );
21+
1922 address public immutable vault0;
2023 address public immutable vault1;
2124 address public immutable asset0;
@@ -24,6 +27,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
2427 uint112 public immutable equilibriumReserve0;
2528 uint112 public immutable equilibriumReserve1;
2629 uint256 public immutable feeMultiplier;
30+ uint256 private immutable feeMultiplierProtocol;
31+ uint256 private immutable feeMultiplierLP;
2732
2833 uint256 public immutable priceX;
2934 uint256 public immutable priceY;
@@ -84,6 +89,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
8489 reserve0 = params.currReserve0;
8590 reserve1 = params.currReserve1;
8691 feeMultiplier = 1e18 - params.fee;
92+ feeMultiplierProtocol = 1e18 - (params.fee * protocolFee / 1e18 );
93+ feeMultiplierLP = feeMultiplier * 1e18 / feeMultiplierProtocol;
8794
8895 // Curve params
8996
@@ -120,11 +127,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
120127
121128 // Deposit all available funds, adjust received amounts downward to collect fees
122129
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);
128132
129133 // Verify curve invariant is satisfied
130134
@@ -211,14 +215,23 @@ contract EulerSwap is IEulerSwap, EVCUtil {
211215 }
212216
213217 /// @notice Deposits assets into a vault and automatically repays any outstanding debt
218+ /// @param asset The address of the underlying asset
214219 /// @param vault The address of the vault to deposit into
215- /// @param amount The amount of assets to deposit
216220 /// @return The amount of assets successfully deposited
217221 /// @dev This function attempts to deposit assets into the specified vault.
218222 /// @dev If the deposit fails with E_ZeroShares error, it safely returns 0 (this happens with very small amounts).
219223 /// @dev After successful deposit, if the user has any outstanding controller-enabled debt, it attempts to repay it.
220224 /// @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+
222235 uint256 deposited;
223236
224237 if (IEVC (evc).isControllerEnabled (eulerAccount, vault)) {
@@ -238,13 +251,13 @@ contract EulerSwap is IEulerSwap, EVCUtil {
238251 try IEVault (vault).deposit (amount, eulerAccount) {}
239252 catch (bytes memory reason ) {
240253 require (bytes4 (reason) == EVKErrors.E_ZeroShares.selector , DepositFailure (reason));
241- return deposited ;
254+ amount = 0 ;
242255 }
243256
244257 deposited += amount;
245258 }
246259
247- return deposited;
260+ return ( deposited * feeMultiplierLP + ( 1e18 - 1 )) / 1e18 ;
248261 }
249262
250263 /// @notice Approves tokens for a given vault, supporting both standard approvals and permit2
0 commit comments