@@ -152,12 +152,12 @@ contract EulerSwap is IEulerSwap, EVCUtil {
152
152
}
153
153
}
154
154
155
+ /// @inheritdoc IEulerSwap
155
156
function getReserves () external view returns (uint112 , uint112 , uint32 ) {
156
157
return (reserve0, reserve1, status);
157
158
}
158
159
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
161
161
function EVC () external view override (EVCUtil, IEulerSwap) returns (address ) {
162
162
return address (evc);
163
163
}
@@ -189,6 +189,13 @@ contract EulerSwap is IEulerSwap, EVCUtil {
189
189
}
190
190
}
191
191
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.
192
199
function withdrawAssets (address vault , uint256 amount , address to ) internal {
193
200
uint256 balance = myBalance (vault);
194
201
@@ -204,6 +211,14 @@ contract EulerSwap is IEulerSwap, EVCUtil {
204
211
}
205
212
}
206
213
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.
207
222
function depositAssets (address vault , uint256 amount ) internal returns (uint256 ) {
208
223
try IEVault (vault).deposit (amount, eulerAccount) {}
209
224
catch (bytes memory reason ) {
@@ -237,10 +252,16 @@ contract EulerSwap is IEulerSwap, EVCUtil {
237
252
}
238
253
}
239
254
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
240
258
function myDebt (address vault ) internal view returns (uint256 ) {
241
259
return IEVault (vault).debtOf (eulerAccount);
242
260
}
243
261
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
244
265
function myBalance (address vault ) internal view returns (uint256 ) {
245
266
uint256 shares = IEVault (vault).balanceOf (eulerAccount);
246
267
return shares == 0 ? 0 : IEVault (vault).convertToAssets (shares);
0 commit comments