@@ -23,7 +23,9 @@ contract EulerSwap is IEulerSwap, EVCUtil {
2323    address  public  immutable  eulerAccount;
2424    uint112  public  immutable  equilibriumReserve0;
2525    uint112  public  immutable  equilibriumReserve1;
26-     uint256  public  immutable  feeMultiplier;
26+     uint256  public  immutable  fee;
27+     uint256  public  immutable  protocolFee;
28+     address  public  immutable  protocolFeeRecipient;
2729
2830    uint256  public  immutable  priceX;
2931    uint256  public  immutable  priceY;
@@ -83,7 +85,9 @@ contract EulerSwap is IEulerSwap, EVCUtil {
8385        equilibriumReserve1 =  params.equilibriumReserve1;
8486        reserve0 =  params.currReserve0;
8587        reserve1 =  params.currReserve1;
86-         feeMultiplier =  1e18  -  params.fee;
88+         fee =  params.fee;
89+         protocolFee =  0.1e18 ;
90+         protocolFeeRecipient =  address (0 );
8791
8892        // Curve params 
8993
@@ -120,11 +124,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
120124
121125        // Deposit all available funds, adjust received amounts downward to collect fees 
122126
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);
128129
129130        // Verify curve invariant is satisfied 
130131
@@ -211,14 +212,29 @@ contract EulerSwap is IEulerSwap, EVCUtil {
211212    }
212213
213214    /// @notice Deposits assets into a vault and automatically repays any outstanding debt 
215+     /// @param asset The address of the underlying asset 
214216    /// @param vault The address of the vault to deposit into 
215-     /// @param amount The amount of assets to deposit 
216217    /// @return The amount of assets successfully deposited 
217218    /// @dev This function attempts to deposit assets into the specified vault. 
218219    /// @dev If the deposit fails with E_ZeroShares error, it safely returns 0 (this happens with very small amounts). 
219220    /// @dev After successful deposit, if the user has any outstanding controller-enabled debt, it attempts to repay it. 
220221    /// @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+ 
222238        uint256  deposited;
223239
224240        if  (IEVC (evc).isControllerEnabled (eulerAccount, vault)) {
@@ -238,13 +254,13 @@ contract EulerSwap is IEulerSwap, EVCUtil {
238254            try  IEVault (vault).deposit (amount, eulerAccount) {}
239255            catch  (bytes  memory  reason ) {
240256                require (bytes4 (reason) ==  EVKErrors.E_ZeroShares.selector , DepositFailure (reason));
241-                 return  deposited ;
257+                 amount  =   0 ;
242258            }
243259
244260            deposited +=  amount;
245261        }
246262
247-         return  deposited;
263+         return  deposited  >  feeAmount  ?  deposited  -  feeAmount  :  0 ;
248264    }
249265
250266    /// @notice Approves tokens for a given vault, supporting both standard approvals and permit2 
0 commit comments