Fee
| This document is better viewed on the docs page. |
Hooks for managing and customizing pool fees, including dynamic fee adjustments, fee overrides, and post-swap fee calculations.
-
BaseDynamicFee: Hook to apply a manual dynamic fee via the Uniswap’sPoolManagercontract. -
BaseOverrideFee: Hook that overrides and applies a fee before swapping automatically. -
BaseDynamicAfterFee: Hook that overrides and applies a fee based on a delta after swapping.
Hooks
BaseDynamicFee
import "uniswap-hooks/src/fee/BaseDynamicFee.sol";
Base implementation to apply a dynamic fee via the PoolManager’s `updateDynamicLPFee function.
| This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base. |
Available since v0.1.0
_getFee(struct PoolKey key) → uint24 internal
Returns a fee, denominated in hundredths of a bip, to be applied to the pool after it is initialized.
_afterInitialize(address, struct PoolKey key, uint160, int24) → bytes4 internal
Set the fee after the pool is initialized.
_poke(struct PoolKey key) internal
Updates the dynamic LP fee for the given pool
| It can be called internally at any point in the pool’s lifecycle to update the fee given the current market conditions. Alternatively, it can be wrapped and exposed publicly to be externally called by an authorized party. If exposed, it must be properly protected and access control is recommended. |
BaseOverrideFee
import "uniswap-hooks/src/fee/BaseOverrideFee.sol";
Base implementation for automatic dynamic fees applied before swaps.
| This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base. |
Available since v0.1.0
_afterInitialize(address, struct PoolKey key, uint160, int24) → bytes4 internal
Check that the pool key has a dynamic fee.
_getFee(address sender, struct PoolKey key, struct SwapParams params, bytes hookData) → uint24 internal
Returns a fee, denominated in hundredths of a bip, to be applied to a swap.
_beforeSwap(address sender, struct PoolKey key, struct SwapParams params, bytes hookData) → bytes4, BeforeSwapDelta, uint24 internal
Set the fee before the swap is processed using the override fee flag.
BaseDynamicAfterFee
import "uniswap-hooks/src/fee/BaseDynamicAfterFee.sol";
Base implementation for dynamic target hook fees applied after swaps.
Enables to enforce a dynamic target determined by _getTargetUnspecified for the unspecified currency of the swap
during _beforeSwap, where if the swap outcome results better than the target, any positive difference is taken
as a hook fee, being posteriorily handled or distributed by the hook via _afterSwapHandler.
In order to use this hook, the inheriting contract must implement _getTargetUnspecified to determine the target,
and _afterSwapHandler to handle accumulated fees.
|
| This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base. |
Available since v0.1.0
_transientTargetUnspecifiedAmount() → uint256 internal
The target unspecified amount to be enforced by the afterSwap hook.
_transientApplyTarget() → bool internal
Whether the target unspecified amount should be enforced by the afterSwap hook.
_setTransientTargetUnspecifiedAmount(uint256 value) internal
Set the target unspecified amount to be enforced by the afterSwap hook.
_beforeSwap(address sender, struct PoolKey key, struct SwapParams params, bytes hookData) → bytes4, BeforeSwapDelta, uint24 internal
Sets the target unspecified amount and apply flag to be used in the afterSwap hook.
The target unspecified amount and the apply flag are reset in the afterSwap hook.
|
_afterSwap(address sender, struct PoolKey key, struct SwapParams params, BalanceDelta delta, bytes) → bytes4, int128 internal
Enforce the target unspecified amount to the unspecified currency of the swap.
When the swap is exactInput and the unspecified target is surpassed, the difference is decreased from the
output as a hook fee. Accordingly, when the swap is exactOutput and the unspecified target is not reached, the
difference is increased to the input as a hook fee. Note that the fee is always applied to the unspecified
currency of the swap, regardless of the swap direction.
The fees are minted to this hook as ERC-6909 tokens, which can then be distributed in _afterSwapHandler
| The target unspecified amount and the apply flag are reset on purpose to avoid state overlapping across swaps. |
_getTargetUnspecified(address sender, struct PoolKey key, struct SwapParams params, bytes hookData) → uint256 targetUnspecifiedAmount, bool applyTarget internal
Return the target unspecified amount to be enforced by the afterSwap hook.