Type behaviors in plain English. Our model generates audited Solidity, runs Monte Carlo simulations, and ships.
pragma solidity ^0.8.26;
import {BaseHook} from "v4-periphery/BaseHook.sol";
import {IPoolManager} from "v4-core/interfaces/IPoolManager.sol";
import {PoolKey} from "v4-core/types/PoolKey.sol";
import {VolatilityOracle} from "./oracles/VolOracle.sol";
/// @title VolatilityPunish
/// @notice Scales sell tax by realized volatility
contract VolatilityPunish is BaseHook {
uint256 constant VOL_THRESHOLD = 6e16; // 6%
uint256 constant BASE_TAX = 5e15; // 0.5%
uint256 constant MAX_TAX = 8e16; // 8.0%
uint256 constant COOLDOWN = 12; // blocks
VolatilityOracle public oracle;
event VolatilityPunish(address indexed seller, uint256 tax);
function beforeSwap(
address sender,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
bytes calldata
) external override returns (bytes4, BeforeSwapDelta, uint24) {
uint256 vol = oracle.realized(key.toId());
if (vol > VOL_THRESHOLD && params.zeroForOne) {
uint256 scale = ((vol - VOL_THRESHOLD) * MAX_TAX) /
(18e16 - VOL_THRESHOLD);
uint256 tax = BASE_TAX + scale;
_collectTax(sender, tax);
_route(tax, 4000, 3000, 3000); // burn / lp / holders
emit VolatilityPunish(sender, tax);
}
return (
IHooks.beforeSwap.selector,
BeforeSwapDeltaLibrary.ZERO_DELTA,
0
);
}
}