v4-core icon indicating copy to clipboard operation
v4-core copied to clipboard

Pass swap parameters to IDynamicFeeManager.getFee()

Open atiselsts opened this issue 2 years ago • 0 comments

Component

Hooks

Describe the suggested feature and problem it solves.

getFee() function of the IDynamicFeeManager interface takes pool key as the only parameter. The hook deployer might want to change the swap fee depending on the swap parameters itself, not just the state of the pool. For example:

  • provide a discount to "loyal customers" (with more than n swaps in the pool) or large swappers;
  • make the fee depend on the direction of the swap, for example reduce the fee if the swap makes the pool more balanced; increase the fee in the opposite direction, to penalize arbitragers;
  • etc.

Describe the desired implementation.

Replace:

function getFee(IPoolManager.PoolKey calldata key) external returns (uint24);

with

function getFee(IPoolManager.PoolKey calldata key, IPoolManager.SwapParams calldata params) external returns (uint24);

And replace:

totalSwapFee = IDynamicFeeManager(address(key.hooks)).getFee(key);

with:

totalSwapFee = IDynamicFeeManager(address(key.hooks)).getFee(key, params);

Describe alternatives.

It's already possible to implement these behaviors, because beforeSwap() does take swap params as an argument. The params can be remembered and subsequently used in getFee(). Still, passing them directly to getFee() simplifies the design of the dynamic fee hook.

Additional context.

No response

atiselsts avatar Jul 07 '23 16:07 atiselsts