@@ -152,12 +152,12 @@ contract EulerSwap is IEulerSwap, EVCUtil {
152152 }
153153 }
154154
155+ /// @inheritdoc IEulerSwap
155156 function getReserves () external view returns (uint112 , uint112 , uint32 ) {
156157 return (reserve0, reserve1, status);
157158 }
158159
159- /// @notice Returns the address of the Ethereum Vault Connector (EVC) used by this contract.
160- /// @return The address of the EVC contract.
160+ /// @inheritdoc IEulerSwap
161161 function EVC () external view override (EVCUtil, IEulerSwap) returns (address ) {
162162 return address (evc);
163163 }
@@ -189,6 +189,13 @@ contract EulerSwap is IEulerSwap, EVCUtil {
189189 }
190190 }
191191
192+ /// @notice Withdraws assets from a vault, first using available balance and then borrowing if needed
193+ /// @param vault The address of the vault to withdraw from
194+ /// @param amount The total amount of assets to withdraw
195+ /// @param to The address that will receive the withdrawn assets
196+ /// @dev This function first checks if there's an existing balance in the vault.
197+ /// @dev If there is, it withdraws the minimum of the requested amount and available balance.
198+ /// @dev If more assets are needed after withdrawal, it enables the controller and borrows the remaining amount.
192199 function withdrawAssets (address vault , uint256 amount , address to ) internal {
193200 uint256 balance = myBalance (vault);
194201
@@ -204,6 +211,14 @@ contract EulerSwap is IEulerSwap, EVCUtil {
204211 }
205212 }
206213
214+ /// @notice Deposits assets into a vault and automatically repays any outstanding debt
215+ /// @param vault The address of the vault to deposit into
216+ /// @param amount The amount of assets to deposit
217+ /// @return The amount of assets successfully deposited
218+ /// @dev This function attempts to deposit assets into the specified vault.
219+ /// @dev If the deposit fails with E_ZeroShares error, it safely returns 0 (this happens with very small amounts).
220+ /// @dev After successful deposit, if the user has any outstanding controller-enabled debt, it attempts to repay it.
221+ /// @dev If all debt is repaid, the controller is automatically disabled to reduce gas costs in future operations.
207222 function depositAssets (address vault , uint256 amount ) internal returns (uint256 ) {
208223 try IEVault (vault).deposit (amount, eulerAccount) {}
209224 catch (bytes memory reason ) {
@@ -237,10 +252,16 @@ contract EulerSwap is IEulerSwap, EVCUtil {
237252 }
238253 }
239254
255+ /// @notice Retrieves the current debt amount for the pool's eulerAccount
256+ /// @param vault The address of the vault to check for debt
257+ /// @return The amount of debt that the Euler account has in the specified vault
240258 function myDebt (address vault ) internal view returns (uint256 ) {
241259 return IEVault (vault).debtOf (eulerAccount);
242260 }
243261
262+ /// @notice Calculates the asset balance of the pool's eulerAccount
263+ /// @param vault The address of the vault to check for balance
264+ /// @return The amount of assets that the Euler account has deposited in the specified vault
244265 function myBalance (address vault ) internal view returns (uint256 ) {
245266 uint256 shares = IEVault (vault).balanceOf (eulerAccount);
246267 return shares == 0 ? 0 : IEVault (vault).convertToAssets (shares);
0 commit comments