@@ -63,7 +63,7 @@ contract CoinUniV4Test is BaseTest {
6363 uint256 deadline = block .timestamp + 20 ;
6464 router.execute (commands, inputs, deadline);
6565
66- feeState = FeeEstimatorHook (address (contentCoinHook)).getFeeState ();
66+ feeState = FeeEstimatorHook (payable ( address (contentCoinHook) )).getFeeState ();
6767
6868 vm.revertToState (snapshot);
6969 }
@@ -80,8 +80,8 @@ contract CoinUniV4Test is BaseTest {
8080 uint256 deadline = block .timestamp + 20 ;
8181 router.execute (commands, inputs, deadline);
8282
83- delta = FeeEstimatorHook (address (contentCoinHook)).getFeeState ().lastDelta;
84- swapParams = FeeEstimatorHook (address (contentCoinHook)).getFeeState ().lastSwapParams;
83+ delta = FeeEstimatorHook (payable ( address (contentCoinHook) )).getFeeState ().lastDelta;
84+ swapParams = FeeEstimatorHook (payable ( address (contentCoinHook) )).getFeeState ().lastSwapParams;
8585
8686 sqrtPriceX96 = PoolStateReader.getSqrtPriceX96 (coinV4.getPoolKey (), poolManager);
8787
@@ -293,6 +293,62 @@ contract CoinUniV4Test is BaseTest {
293293 assertApproxEqAbs (mockERC20A.balanceOf (coinV4.protocolRewardRecipient ()), totalRewards.protocol, 10 , "protocol reward currency " );
294294 }
295295
296+ function test_distributesMarketRewardsInEth () public {
297+ uint64 amountIn = 0.1 ether ;
298+
299+ // Use address(0) as currency to price the coin in ETH
300+ address currency = address (0 );
301+ bytes32 salt = keccak256 (abi.encodePacked ("eth-rewards-test " ));
302+ _deployV4Coin (currency, address (0 ), salt);
303+
304+ address trader = makeAddr ("trader " );
305+
306+ // Give trader ETH
307+ vm.deal (trader, amountIn);
308+
309+ // Record initial ETH balance of payout recipient
310+ uint256 initialPayoutBalance = coinV4.payoutRecipient ().balance;
311+
312+ // Swap ETH for coin
313+ _swapSomeCurrencyForCoin (coinV4, currency, amountIn, trader);
314+
315+ // Verify that rewards were paid out in ETH
316+ assertGt (coinV4.payoutRecipient ().balance, initialPayoutBalance, "backing reward should be paid in ETH " );
317+ }
318+
319+ function test_canSwapEthForCoin (uint128 amountIn ) public {
320+ vm.assume (amountIn > 0.00001 ether);
321+ vm.assume (amountIn < 1 ether);
322+
323+ // Use address(0) as currency to price the coin in ETH
324+ address currency = address (0 );
325+ bytes32 salt = keccak256 (abi.encodePacked ("eth-coin-test " ));
326+ _deployV4Coin (currency, address (0 ), salt);
327+
328+ address trader = makeAddr ("trader " );
329+
330+ // Give trader ETH
331+ vm.deal (trader, amountIn);
332+
333+ uint256 initialEthBalance = trader.balance;
334+
335+ // Swap ETH for coin
336+ _swapSomeCurrencyForCoin (coinV4, currency, amountIn, trader);
337+
338+ // Verify the swap worked
339+ assertEq (trader.balance, initialEthBalance - amountIn, "trader should have spent ETH " );
340+ assertGt (coinV4.balanceOf (trader), 0 , "trader should have received coin " );
341+
342+ // Now swap some coin back for ETH
343+ uint128 coinBalance = uint128 (coinV4.balanceOf (trader));
344+
345+ _swapSomeCoinForCurrency (coinV4, currency, coinBalance, trader);
346+
347+ // Verify the reverse swap worked
348+ assertEq (coinV4.balanceOf (trader), 0 , "trader should have no coins left " );
349+ assertGt (trader.balance, 0 , "trader should have received ETH back " );
350+ }
351+
296352 function test_swap_emitsCoinMarketRewardsV4 (uint64 amountIn ) public {
297353 vm.assume (amountIn > 0.00001 ether);
298354 address currency = address (mockERC20A);
0 commit comments