Skip to content

Commit f8bedf8

Browse files
committed
wip testing
1 parent 97f1e5c commit f8bedf8

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/HookFees.t.sol

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
1717
contract HookFeesTest is EulerSwapTestBase {
1818
using StateLibrary for IPoolManager;
1919

20+
address protocolFeeRecipient = makeAddr("protocolFeeRecipient");
21+
2022
EulerSwap public eulerSwap;
2123

2224
IPoolManager public poolManager;
@@ -120,4 +122,53 @@ contract HookFeesTest is EulerSwapTestBase {
120122

121123
assertGt(getHolderNAV(), origNav + int256(amountIn - amountInWithoutFee));
122124
}
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+
}
123174
}

0 commit comments

Comments
 (0)