@@ -13,6 +13,7 @@ import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol
1313import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol " ;
1414import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol " ;
1515import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol " ;
16+ import "../src/Events.sol " ;
1617
1718contract HookFeesTest is EulerSwapTestBase {
1819 using StateLibrary for IPoolManager;
@@ -59,6 +60,18 @@ contract HookFeesTest is EulerSwapTestBase {
5960 vm.startPrank (anyone);
6061 assetTST.approve (address (minimalRouter), amountIn);
6162
63+ vm.expectEmit (true , true , true , true );
64+ emit Swap (
65+ address (minimalRouter),
66+ amountInWithoutFee,
67+ 0 ,
68+ 0 ,
69+ amountOut,
70+ r0 + uint112 (amountInWithoutFee),
71+ r1 - uint112 (amountOut),
72+ address (poolManager)
73+ );
74+
6275 bool zeroForOne = address (assetTST) < address (assetTST2);
6376 BalanceDelta result = minimalRouter.swap (eulerSwap.poolKey (), zeroForOne, amountIn, 0 , "" );
6477 vm.stopPrank ();
@@ -83,6 +96,56 @@ contract HookFeesTest is EulerSwapTestBase {
8396 assertGt (getHolderNAV (), origNav + int256 (amountIn - amountInWithoutFee));
8497 }
8598
99+ function test_SwapExactIn_withLpFeeReverse () public {
100+ int256 origNav = getHolderNAV ();
101+ (uint112 r0 , uint112 r1 ,) = eulerSwap.getReserves ();
102+
103+ uint256 amountIn = 1e18 ;
104+ uint256 amountInWithoutFee = amountIn - (amountIn * eulerSwap.getParams ().fee / 1e18 );
105+ uint256 amountOut =
106+ periphery.quoteExactInput (address (eulerSwap), address (assetTST2), address (assetTST), amountIn);
107+
108+ assetTST2.mint (anyone, amountIn);
109+
110+ vm.startPrank (anyone);
111+ assetTST2.approve (address (minimalRouter), amountIn);
112+
113+ vm.expectEmit (true , true , true , true );
114+ emit Swap (
115+ address (minimalRouter),
116+ 0 ,
117+ amountInWithoutFee,
118+ amountOut,
119+ 0 ,
120+ r0 - uint112 (amountOut),
121+ r1 + uint112 (amountInWithoutFee),
122+ address (poolManager)
123+ );
124+
125+ bool zeroForOne = address (assetTST) < address (assetTST2);
126+ BalanceDelta result = minimalRouter.swap (eulerSwap.poolKey (), ! zeroForOne, amountIn, 0 , "" );
127+ vm.stopPrank ();
128+
129+ assertEq (assetTST2.balanceOf (anyone), 0 );
130+ assertEq (assetTST.balanceOf (anyone), amountOut);
131+
132+ assertEq (! zeroForOne ? uint256 (- int256 (result.amount0 ())) : uint256 (- int256 (result.amount1 ())), amountIn);
133+ assertEq (! zeroForOne ? uint256 (int256 (result.amount1 ())) : uint256 (int256 (result.amount0 ())), amountOut);
134+
135+ // assert fees were not added to the reserves
136+ (uint112 r0New , uint112 r1New ,) = eulerSwap.getReserves ();
137+ if (! zeroForOne) {
138+ assertEq (r0New, r0 + amountInWithoutFee);
139+ assertEq (r1New, r1 - amountOut);
140+ } else {
141+ // oneForZero, so the curve received asset1
142+ assertEq (r0New, r0 - amountOut);
143+ assertEq (r1New, r1 + amountInWithoutFee);
144+ }
145+
146+ assertGt (getHolderNAV (), origNav + int256 (amountIn - amountInWithoutFee));
147+ }
148+
86149 function test_SwapExactOut_withLpFee () public {
87150 int256 origNav = getHolderNAV ();
88151 (uint112 r0 , uint112 r1 ,) = eulerSwap.getReserves ();
0 commit comments