Skip to content

Commit 598a1fb

Browse files
committed
fix quoting when borrowVault is address(0)
Spearbit #15
1 parent 0e1b1a2 commit 598a1fb

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/libraries/QuoteLib.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ library QuoteLib {
129129
{
130130
IEVault supplyVault = IEVault(asset0IsInput ? sParams.supplyVault0 : sParams.supplyVault1);
131131
IEVault borrowVault = IEVault(asset0IsInput ? sParams.borrowVault0 : sParams.borrowVault1);
132-
uint256 maxDeposit = borrowVault.debtOf(eulerAccount) + supplyVault.maxDeposit(eulerAccount);
132+
uint256 maxDeposit = supplyVault.maxDeposit(eulerAccount);
133+
if (address(borrowVault) != address(0)) maxDeposit += borrowVault.debtOf(eulerAccount);
133134
if (maxDeposit < inLimit) inLimit = maxDeposit;
134135
}
135136

@@ -153,12 +154,13 @@ library QuoteLib {
153154
if (supplyCash < outLimit) outLimit = supplyCash;
154155
} else {
155156
// Sufficient cash to cover full withdrawal, so limiting factor is cash in borrowVault
156-
uint256 cashLimit = supplyBalance + borrowVault.cash();
157+
uint256 cashLimit = supplyBalance;
158+
if (address(borrowVault) != address(0)) cashLimit += borrowVault.cash();
157159
if (cashLimit < outLimit) outLimit = cashLimit;
158160
}
159161
}
160162

161-
{
163+
if (address(borrowVault) != address(0)) {
162164
(, uint16 borrowCapEncoded) = borrowVault.caps();
163165
uint256 borrowCap = decodeCap(uint256(borrowCapEncoded));
164166
if (borrowCap != type(uint256).max) {

test/SplitVaults.t.sol

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ contract SplitVaults is EulerSwapTestBase {
3838
mintAndDeposit(depositor, eTST_alt, 50e18);
3939
mintAndDeposit(depositor, eTST2_alt, 50e18);
4040

41+
installAltBorrowVaults(eTST_alt, eTST2_alt);
42+
}
43+
44+
function installAltBorrowVaults(IEVault bv0, IEVault bv1) internal {
4145
// Setup EulerSwap
4246
uint112 reserve0 = 60e18;
4347
uint112 reserve1 = 60e18;
@@ -46,8 +50,8 @@ contract SplitVaults is EulerSwapTestBase {
4650
getEulerSwapParams(reserve0, reserve1, 1e18, 1e18, 0.85e18, 0.85e18, 0, address(0), 0, address(0));
4751
IEulerSwap.InitialState memory initialState = IEulerSwap.InitialState({reserve0: reserve0, reserve1: reserve1});
4852

49-
sParams.borrowVault0 = address(eTST_alt);
50-
sParams.borrowVault1 = address(eTST2_alt);
53+
sParams.borrowVault0 = address(bv0);
54+
sParams.borrowVault1 = address(bv1);
5155

5256
eulerSwap = createEulerSwapFull(sParams, dParams, initialState);
5357
}
@@ -155,4 +159,16 @@ contract SplitVaults is EulerSwapTestBase {
155159

156160
validateOutputSwapPossible(assetTST, assetTST2, 3e18 - 1);
157161
}
162+
163+
function test_splitVault_nullBorrowVault0() public isSwappable {
164+
installAltBorrowVaults(IEVault(address(0)), eTST2_alt);
165+
}
166+
167+
function test_splitVault_nullBorrowVault1() public isSwappable {
168+
installAltBorrowVaults(eTST_alt, IEVault(address(0)));
169+
}
170+
171+
function test_splitVault_nullBorrowVaultBoth() public isSwappable {
172+
installAltBorrowVaults(IEVault(address(0)), IEVault(address(0)));
173+
}
158174
}

0 commit comments

Comments
 (0)