Skip to content

Commit 62bdbce

Browse files
committed
fix for when controller enabled but debt is 0
1 parent 12efc8a commit 62bdbce

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/EulerSwap.sol

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,15 @@ contract EulerSwap is IEulerSwap, EVCUtil {
219219
/// @dev After successful deposit, if the user has any outstanding controller-enabled debt, it attempts to repay it.
220220
/// @dev If all debt is repaid, the controller is automatically disabled to reduce gas costs in future operations.
221221
function depositAssets(address vault, uint256 amount) internal returns (uint256) {
222-
uint256 debt = myDebt(vault);
223222
uint256 deposited;
224223

225-
if (debt > 0) {
226-
uint256 repayAmount = amount > debt ? debt : amount;
224+
if (IEVC(evc).isControllerEnabled(eulerAccount, vault)) {
225+
uint256 debt = myDebt(vault);
226+
uint256 repaid = IEVault(vault).repay(amount > debt ? debt : amount, eulerAccount);
227227

228-
IEVault(vault).repay(repayAmount, eulerAccount);
229-
230-
amount -= repayAmount;
231-
debt -= repayAmount;
232-
deposited += repayAmount;
228+
amount -= repaid;
229+
debt -= repaid;
230+
deposited += repaid;
233231

234232
if (debt == 0) {
235233
IEVC(evc).call(vault, eulerAccount, 0, abi.encodeCall(IRiskManager.disableController, ()));

test/DepositFailures.t.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,26 @@ contract DepositFailuresTest is EulerSwapTestBase {
8585

8686
assertEq(assetTST2.balanceOf(address(eulerSwap)), 1); // griefing transfer was untouched
8787
}
88+
89+
function test_manualEnableController() public monotonicHolderNAV {
90+
vm.prank(holder);
91+
evc.enableController(holder, address(eTST));
92+
93+
uint256 amountIn = 50e18;
94+
uint256 amountOut =
95+
periphery.quoteExactInput(address(eulerSwap), address(assetTST), address(assetTST2), amountIn);
96+
97+
assetTST.mint(address(this), amountIn);
98+
assetTST.transfer(address(eulerSwap), amountIn);
99+
eulerSwap.swap(0, amountOut, address(this), "");
100+
101+
// Swap the other way to measure gas impact
102+
103+
amountIn = 100e18;
104+
amountOut = periphery.quoteExactInput(address(eulerSwap), address(assetTST2), address(assetTST), amountIn);
105+
106+
assetTST2.mint(address(this), amountIn);
107+
assetTST2.transfer(address(eulerSwap), amountIn);
108+
eulerSwap.swap(amountOut, 0, address(this), "");
109+
}
88110
}

0 commit comments

Comments
 (0)