ZkPadMevDescendingFees
Source: contracts/src/mev/ZkPadMevDescendingFees.sol · Interfaces: IZkPadMevModule,
IZkPadMevDescendingFees · Port of Clanker v4 ClankerMevDescendingFees. GPL-2.0-or-later.
User-level explanation: anti-sniper descending fee.
Configuration
struct FeeConfig {
uint24 startingFee; // pips, > 0, >= endingFee, <= hook.MAX_MEV_FEE() (800_000)
uint24 endingFee; // pips, normally the pool's fee F
uint256 secondsToDecay; // > 0, <= hook.MAX_MEV_MODULE_DELAY() (120)
}
Passed as MevModuleConfig.mevModuleData = abi.encode(FeeConfig).
Fee curve
timeDecay = secondsToDecay - (now - (poolStartTime + DELAY_GUARD))
fee = endingFee + (startingFee - endingFee) * (timeDecay / secondsToDecay)^2
DELAY_GUARD = 1second: decay starts one second after deployment.beforeSwapreverts withSameSecondAsDeploymentin the launch second.- At
now >= poolStartTime + secondsToDecay + DELAY_GUARDthe module returnsdisableMevModule = trueand emitsDecayPeriodOver. - The hook applies the module fee only if it exceeds the pool's normal fee.
Functions
| Function | Access | Description |
|---|---|---|
initialize(PoolKey, bytes poolFeeConfig) | the pool's hook | Store config and start time (once per pool) |
beforeSwap(PoolKey, SwapParams, bool, bytes) returns (bool disableMevModule) | the pool's hook | Compute the fee and call hook.mevModuleSetFee |
getFee(PoolId) view returns (uint24) | Current module fee (0 when not running) | |
feeConfig(PoolId) view, poolStartTime(PoolId) view | State | |
supportsInterface(bytes4) pure | ERC-165 |
Events and errors
Events: FeeConfigSet(poolId, startingFee, endingFee, secondsToDecay), DecayPeriodOver(poolId).
Errors: OnlyHook, PoolAlreadyInitialized, StartingFeeMustBeGreaterThanZero,
StartingFeeMustBeGreaterThanEndingFee, TimeDecayMustBeGreaterThanZero, OnlyZkPadHook,
SameSecondAsDeployment, TimeDecayLongerThanMaxMevDelay, StartingFeeGreaterThanMaxMevFee,
PoolLocked.