@@ -43,6 +43,7 @@ contract EulerSwapHookTest is EulerSwapTestBase {
43
43
}
44
44
45
45
function test_SwapExactIn_withLpFee () public {
46
+ int256 origNav = getHolderNAV ();
46
47
(uint112 r0 , uint112 r1 ,) = eulerSwap.getReserves ();
47
48
48
49
uint256 amountIn = 1e18 ;
@@ -75,15 +76,20 @@ contract EulerSwapHookTest is EulerSwapTestBase {
75
76
assertEq (r0New, r0 - amountOut);
76
77
assertEq (r1New, r1 + amountInWithoutFee);
77
78
}
79
+
80
+ assertGt (getHolderNAV (), origNav + int256 (amountIn - amountInWithoutFee));
78
81
}
79
82
80
83
function test_SwapExactOut_withLpFee () public {
84
+ int256 origNav = getHolderNAV ();
81
85
(uint112 r0 , uint112 r1 ,) = eulerSwap.getReserves ();
82
86
83
87
uint256 amountOut = 1e18 ;
84
88
uint256 amountIn =
85
89
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 ;
87
93
88
94
assetTST.mint (anyone, amountIn);
89
95
@@ -103,13 +109,15 @@ contract EulerSwapHookTest is EulerSwapTestBase {
103
109
// assert fees were not added to the reserves
104
110
(uint112 r0New , uint112 r1New ,) = eulerSwap.getReserves ();
105
111
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);
108
114
} else {
109
115
// 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);
112
118
}
119
+
120
+ assertGt (getHolderNAV (), origNav + int256 (amountIn - amountInWithoutFee));
113
121
}
114
122
115
123
function _swap (PoolKey memory key , bool zeroForOne , bool exactInput , uint256 amount ) internal {
0 commit comments