<details>
<summary>POC</summary>
1. Add this tests to `RebateFiHookTest.t.sol` test file.
The first test proves that `buyFee` is applied instead of `sellFee` when user sells ReFi token while ReFi is currency0 .
```javascript
function test_isReFiBuy_WhenReFiIsCurrency0() public view {
PoolKey memory fakeKey;
fakeKey.currency0 = reFiCurrency;
fakeKey.currency1 = tokenCurrency;
bool zeroForOne = true;
bool IsReFiCurrency0 = (
Currency.unwrap(fakeKey.currency0) == address(reFiToken)
);
bool isReFiBuy;
if (IsReFiCurrency0) {
isReFiBuy = zeroForOne;
} else {
isReFiBuy = !zeroForOne;
}
(uint24 buyFee, uint24 sellFee) = rebateHook.getFeeConfig();
uint24 appliedFee = isReFiBuy ? buyFee : sellFee;
console.log("-------------------------------------------");
console.log("Simulated SELL ReFi (zeroForOne = true)");
console.log("ReFi considered as currency0");
console.log("Hook classification (isReFiBuy):", isReFiBuy);
console.log("Applied fee would be:", appliedFee);
console.log("-------------------------------------------");
assertEq(
appliedFee,
buyFee,
"BUG: Hook should incorrectly apply BUY fee instead of SELL fee"
);
}
```
The second test proves that `sellFee` is applied instead of `buyFee` when user buys ReFi token while ReFi is currency1.
```javascript
function test_isReFiBuy_WhenReFiIsCurrency1() public view {
PoolKey memory fakeKey;
fakeKey.currency0 = tokenCurrency;
fakeKey.currency1 = reFiCurrency;
bool zeroForOne = true;
bool IsReFiCurrency0 = (
Currency.unwrap(fakeKey.currency0) == address(reFiToken)
);
bool isReFiBuy;
if (IsReFiCurrency0) {
isReFiBuy = zeroForOne;
} else {
isReFiBuy = !zeroForOne;
}
(uint24 buyFee, uint24 sellFee) = rebateHook.getFeeConfig();
uint24 appliedFee = isReFiBuy ? buyFee : sellFee;
console.log("-------------------------------------------");
console.log("Simulated BUY ReFi (zeroForOne = true)");
console.log("ReFi is currency1");
console.log("Hook classification (isReFiBuy):", isReFiBuy);
console.log("Applied fee:", appliedFee);
console.log("Expected bug: sellFee should be applied instead of buyFee");
console.log("-------------------------------------------");
assertEq(
appliedFee,
sellFee,
"BUG: Hook wrongly applies SELL fee (3000) during a BUY operation"
);
}
```
</details>
1.Modify the `_isReFiBuy` function so that the verification is working correctly.
```diff
/// @notice Determines if a swap is buying or selling ReFi
/// @param key The pool key containing currency information
/// @param zeroForOne The swap direction
/// @return True if buying ReFi, false if selling
function _isReFiBuy(PoolKey calldata key, bool zeroForOne) internal view returns (bool) {
- bool IsReFiCurrency0 = Currency.unwrap(key.currency0) == ReFi;
- if (IsReFiCurrency0) {
- return zeroForOne;
- } else {
- return !zeroForOne;
- }
+ Currency input = zeroForOne ? key.currency0 : key.currency1;
+ Currency output = zeroForOne ? key.currency1 : key.currency0;
+
+ return Currency.unwrap(output) == ReFi;
}
```