@@ -17,6 +17,8 @@ import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
17
17
contract HookFeesTest is EulerSwapTestBase {
18
18
using StateLibrary for IPoolManager;
19
19
20
+ address protocolFeeRecipient = makeAddr ("protocolFeeRecipient " );
21
+
20
22
EulerSwap public eulerSwap;
21
23
22
24
IPoolManager public poolManager;
@@ -120,4 +122,53 @@ contract HookFeesTest is EulerSwapTestBase {
120
122
121
123
assertGt (getHolderNAV (), origNav + int256 (amountIn - amountInWithoutFee));
122
124
}
125
+
126
+ function test_protocolFee () public {
127
+ IEulerSwap.Params memory params = eulerSwap.getParams ();
128
+ vm.prank (params.eulerAccount);
129
+ eulerSwapFactory.uninstallPool ();
130
+
131
+ // set protocol fee to 10% of the LP fee
132
+ eulerSwapFactory.setProtocolFee (0.1e18 );
133
+ eulerSwapFactory.setProtocolFeeRecipient (protocolFeeRecipient);
134
+
135
+ // set swap fee to 10 bips and activate the pool
136
+ eulerSwap = createEulerSwapHook (60e18 , 60e18 , 0.001e18 , 1e18 , 1e18 , 0.4e18 , 0.85e18 );
137
+
138
+ int256 origNav = getHolderNAV ();
139
+ (uint112 r0 , uint112 r1 ,) = eulerSwap.getReserves ();
140
+
141
+ uint256 amountIn = 1e18 ;
142
+ uint256 amountInWithoutFee = amountIn - (amountIn * eulerSwap.getParams ().fee / 1e18 );
143
+ uint256 amountOut =
144
+ periphery.quoteExactInput (address (eulerSwap), address (assetTST), address (assetTST2), amountIn);
145
+
146
+ assetTST.mint (anyone, amountIn);
147
+
148
+ vm.startPrank (anyone);
149
+ assetTST.approve (address (minimalRouter), amountIn);
150
+
151
+ bool zeroForOne = address (assetTST) < address (assetTST2);
152
+ BalanceDelta result = minimalRouter.swap (eulerSwap.poolKey (), zeroForOne, amountIn, 0 , "" );
153
+ vm.stopPrank ();
154
+
155
+ assertEq (assetTST.balanceOf (anyone), 0 );
156
+ assertEq (assetTST2.balanceOf (anyone), amountOut);
157
+
158
+ assertEq (zeroForOne ? uint256 (- int256 (result.amount0 ())) : uint256 (- int256 (result.amount1 ())), amountIn);
159
+ assertEq (zeroForOne ? uint256 (int256 (result.amount1 ())) : uint256 (int256 (result.amount0 ())), amountOut);
160
+
161
+ // assert fees were not added to the reserves
162
+ (uint112 r0New , uint112 r1New ,) = eulerSwap.getReserves ();
163
+ if (zeroForOne) {
164
+ assertEq (r0New, r0 + amountInWithoutFee);
165
+ assertEq (r1New, r1 - amountOut);
166
+ } else {
167
+ // oneForZero, so the curve received asset1
168
+ assertEq (r0New, r0 - amountOut);
169
+ assertEq (r1New, r1 + amountInWithoutFee);
170
+ }
171
+
172
+ assertGt (getHolderNAV (), origNav + int256 (amountIn - amountInWithoutFee));
173
+ }
123
174
}
0 commit comments