pragma solidity ^0.8.26;
import {Test} from "forge-std/Test.sol";
import {IPoolManager} from "v4-core/interfaces/IPoolManager.sol";
import {PoolKey} from "v4-core/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "v4-core/types/PoolId.sol";
import {SwapParams} from "v4-core/types/PoolOperation.sol";
import {Currency, CurrencyLibrary} from "v4-core/types/Currency.sol";
import {ReFiSwapRebateHook} from "../src/RebateFiHook.sol";
contract FeeInversionTest is Test {
using CurrencyLibrary for Currency;
ReFiSwapRebateHook hook;
PoolKey poolKey;
address refiToken = address(0x123);
address otherToken = address(0x456);
function setUp() public {
IPoolManager poolManager = IPoolManager(address(0x789));
hook = new ReFiSwapRebateHook(poolManager, refiToken);
poolKey = PoolKey({
currency0: Currency.wrap(otherToken),
currency1: Currency.wrap(refiToken),
fee: 0x800000,
tickSpacing: 60,
hooks: hook
});
}
function testSellReFiChargesZeroFee() public {
SwapParams memory params = SwapParams({
zeroForOne: false,
amountSpecified: -1000e18,
sqrtPriceLimitX96: 0
});
(, , uint24 appliedFee) = hook.beforeSwap(
address(this),
poolKey,
params,
""
);
assertEq(appliedFee & 0xFFFFFF, 0, "Sell incorrectly charged 0% instead of 3%");
}
function testBuyReFiChargesThreePercent() public {
SwapParams memory params = SwapParams({
zeroForOne: true,
amountSpecified: -1000e18,
sqrtPriceLimitX96: 0
});
(, , uint24 appliedFee) = hook.beforeSwap(
address(this),
poolKey,
params,
""
);
assertEq(appliedFee & 0xFFFFFF, 3000, "Buy incorrectly charged 3% instead of 0%");
}
}