Skip to content

Commit 7abb85d

Browse files
committed
add NAV assertion & fix exact out fee math
1 parent 822a54b commit 7abb85d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

test/EulerSwapHook.fees.t.sol

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ contract EulerSwapHookTest is EulerSwapTestBase {
4343
}
4444

4545
function test_SwapExactIn_withLpFee() public {
46+
int256 origNav = getHolderNAV();
4647
(uint112 r0, uint112 r1,) = eulerSwap.getReserves();
4748

4849
uint256 amountIn = 1e18;
@@ -75,15 +76,20 @@ contract EulerSwapHookTest is EulerSwapTestBase {
7576
assertEq(r0New, r0 - amountOut);
7677
assertEq(r1New, r1 + amountInWithoutFee);
7778
}
79+
80+
assertGt(getHolderNAV(), origNav + int256(amountIn - amountInWithoutFee));
7881
}
7982

8083
function test_SwapExactOut_withLpFee() public {
84+
int256 origNav = getHolderNAV();
8185
(uint112 r0, uint112 r1,) = eulerSwap.getReserves();
8286

8387
uint256 amountOut = 1e18;
8488
uint256 amountIn =
8589
periphery.quoteExactOutput(address(eulerSwap), address(assetTST), address(assetTST2), amountOut);
86-
uint256 amountInWithoutFee = (amountIn * 1e18) / (2e18 - eulerSwap.feeMultiplier());
90+
91+
// inverse of the fee math in Periphery
92+
uint256 amountInWithoutFee = (amountIn * eulerSwap.feeMultiplier() - eulerSwap.feeMultiplier()) / 1e18;
8793

8894
assetTST.mint(anyone, amountIn);
8995

@@ -103,13 +109,15 @@ contract EulerSwapHookTest is EulerSwapTestBase {
103109
// assert fees were not added to the reserves
104110
(uint112 r0New, uint112 r1New,) = eulerSwap.getReserves();
105111
if (zeroForOne) {
106-
assertEq(r0New, r0 + amountInWithoutFee, "A");
107-
assertEq(r1New, r1 - amountOut, "B");
112+
assertEq(r0New, r0 + amountInWithoutFee + 1); // 1 wei of imprecision
113+
assertEq(r1New, r1 - amountOut);
108114
} else {
109115
// oneForZero, so the curve received asset1
110-
assertEq(r0New, r0 - amountOut, "C");
111-
assertEq(r1New, r1 + amountInWithoutFee, "D");
116+
assertEq(r0New, r0 - amountOut);
117+
assertEq(r1New, r1 + amountInWithoutFee);
112118
}
119+
120+
assertGt(getHolderNAV(), origNav + int256(amountIn - amountInWithoutFee));
113121
}
114122

115123
function _swap(PoolKey memory key, bool zeroForOne, bool exactInput, uint256 amount) internal {

0 commit comments

Comments
 (0)