Skip to main content

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 = 1 second: decay starts one second after deployment.
  • beforeSwap reverts with SameSecondAsDeployment in the launch second.
  • At now >= poolStartTime + secondsToDecay + DELAY_GUARD the module returns disableMevModule = true and emits DecayPeriodOver.
  • The hook applies the module fee only if it exceeds the pool's normal fee.

Functions​

FunctionAccessDescription
initialize(PoolKey, bytes poolFeeConfig)the pool's hookStore config and start time (once per pool)
beforeSwap(PoolKey, SwapParams, bool, bytes) returns (bool disableMevModule)the pool's hookCompute the fee and call hook.mevModuleSetFee
getFee(PoolId) view returns (uint24)Current module fee (0 when not running)
feeConfig(PoolId) view, poolStartTime(PoolId) viewState
supportsInterface(bytes4) pureERC-165

Events and errors​

Events: FeeConfigSet(poolId, startingFee, endingFee, secondsToDecay), DecayPeriodOver(poolId).

Errors: OnlyHook, PoolAlreadyInitialized, StartingFeeMustBeGreaterThanZero, StartingFeeMustBeGreaterThanEndingFee, TimeDecayMustBeGreaterThanZero, OnlyZkPadHook, SameSecondAsDeployment, TimeDecayLongerThanMaxMevDelay, StartingFeeGreaterThanMaxMevFee, PoolLocked.