Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 soft launch #777

Merged
merged 35 commits into from
Sep 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c6b1f64
reorg
saucepoint Sep 7, 2024
5444ca3
formatting & notes
saucepoint Sep 7, 2024
0edb8af
organize manage liquidity
saucepoint Sep 7, 2024
2ad677f
Some early v4 deployments (#744)
saucepoint Sep 10, 2024
2d46785
v4 concepts: erc6909 (#745)
0xdevant Sep 12, 2024
b70ab81
v4 overview (#742)
saucepoint Sep 12, 2024
f0e5257
v4 concepts: flash accounting (#747)
0xdevant Sep 13, 2024
50f3d34
V4-vs-V3 (#749)
Alexhandru Sep 13, 2024
6626366
v4 guides: mint position (#743)
saucepoint Sep 13, 2024
90159df
Fee collection tutorial (#751)
Alexhandru Sep 15, 2024
3300bc7
documentation for batch modify (#764)
saucepoint Sep 17, 2024
39d7885
add BalanceDelta reference guide with mdx formatting (#763)
krisoshea-eth Sep 17, 2024
ac033b9
add BeforeSwapDelta reference guide with mdx formatting (#762)
krisoshea-eth Sep 17, 2024
03fc543
add Currency reference guide with mdx formatting (#761)
krisoshea-eth Sep 17, 2024
190dc0a
Add hooks concept doc with updated MDX formating (#752)
krisoshea-eth Sep 17, 2024
754d3e9
Add transient state library reference description with mdx formatting…
krisoshea-eth Sep 17, 2024
c27116d
Add NoOp hooks guide with mdx formatting (#756)
krisoshea-eth Sep 17, 2024
28091bd
Add PoolManager Concept doc with updated mdx formatting (#753)
krisoshea-eth Sep 17, 2024
4195b14
Add intro to dynamic fees concept doc with updated mdx formatting (#754)
krisoshea-eth Sep 17, 2024
f6654f4
Add volatility based dynamic fee hook guide with mdx formatting (#755)
krisoshea-eth Sep 17, 2024
8c267b5
add PoolKey reference guide with mdx formatting (#758)
krisoshea-eth Sep 17, 2024
6144405
add LiquidityAmounts Reference guide with mdx formatting (#759)
krisoshea-eth Sep 17, 2024
014b361
add IPoolManager reference guide with mdx formatting (#760)
krisoshea-eth Sep 17, 2024
dd04160
v4 guides: hook setup (#750)
0xdevant Sep 17, 2024
4522d97
Reorganize v4 Technical Reference (#765)
saucepoint Sep 17, 2024
1b18e0d
v4 guides: hook swap (#766)
0xdevant Sep 18, 2024
6b4aeed
Subscribers (#771)
saucepoint Sep 18, 2024
8e413bf
fixed wrong param types (#769)
Alexhandru Sep 20, 2024
a932006
complement to v4 concepts: erc6909 (#772)
0xdevant Sep 20, 2024
c08e77e
Increase liquidity (#774)
saucepoint Sep 20, 2024
9d66fe7
v4 guides: decrease liquidity (#775)
0xdevant Sep 20, 2024
506dde5
v4 guides: hook liquidity (#767)
0xdevant Sep 20, 2024
e10ca58
Burn position guide (#770)
Alexhandru Sep 20, 2024
43f8782
Unlock callback and deltas (#773)
Alexhandru Sep 20, 2024
4aed10f
Dev v4 cleanup (#776)
saucepoint Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add intro to dynamic fees concept doc with updated mdx formatting (#754)
krisoshea-eth authored Sep 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4195b14455fc795dd526b606bcdd7e71a4284ae7
61 changes: 61 additions & 0 deletions docs/contracts/v4/concepts/07-dynamic-fees.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: Introduction to Dynamic Fees
---

Uniswap v4 introduces dynamic fees, allowing for flexible and responsive fee structures managed through hooks. This feature enables pools to adapt fees to changing market conditions, potentially improving liquidity provider profitability and overall market efficiency.

# What are Dynamic Fees?

Dynamic fees in Uniswap v4 are a specific type of swap fee paid by swappers that directly accrue to liquidity providers. These fees are distinct from protocol fees and hook fees (Optional fees that can be implemented by custom hooks), and represent a significant advancement over the fee structures in previous Uniswap versions.

Unlike the static fee tiers in Uniswap v3 (0.05%, 0.30%, 1.0%) or the single fee in v2, dynamic fees in v4 offer much more flexibility. Dynamic fees can:

- Adjust in real-time based on various market conditions
- Change on a per-swap basis
- Allow for any fee percentage (e.g., 4.9 bips, 10 bips)
- Be updated at various intervals (yearly, per block, or per transaction)

This dynamic nature allows for more efficient fee pricing, potentially benefiting both liquidity providers and traders by adapting to current market conditions. By allowing fees to fluctuate based on market dynamics, Uniswap v4 aims to optimize liquidity provision and trading across a wide range of market scenarios.

# Motivation and Benefits of Dynamic Fees

1. **Improved Pricing of Volatility:** Adapt fees to market volatility, similar to traditional exchanges adjusting bid-ask spreads.
2. **Order Flow Discrimination:** Price different types of trades (e.g., arbitrage vs. uninformed) more accurately.
3. **Improved Market Efficiency and Stability:** Fees can adjust to reflect real-time market conditions, optimizing for both liquidity providers and traders. Dynamic fees could help dampen extreme market movements by adjusting incentives in real-time.
4. **Enhanced Capital Efficiency and Liquidity Provider Returns:** By optimizing fees, pools can attract more liquidity and facilitate more efficient trading. More accurate fee pricing could lead to better returns for liquidity providers, potentially attracting more capital to pools.
5. **Better Risk Management:** During high volatility, fees can increase to protect liquidity providers from impermanent loss.
6. **Customizable Strategies:** Enable complex fee strategies for specific token pairs or market segments.

# Dynamic Fees Use Cases

1. **Volatility-Based Fees:** Adjust fees based on the historical or realized volatility of the asset pair.
2. **Volume-Based Fees:** Lower fees during high-volume periods to attract more trades, and increase fees during low-volume periods to compensate liquidity providers.
3. **Time-Based Fees:** Implement different fee structures for different times of day or days of the week, based on historical trading patterns.
4. **Market Depth-Based Fees:** Adjust fees based on the current liquidity depth in the pool.
5. **Cross-Pool Arbitrage Mitigation:** Dynamically adjust fees to discourage harmful arbitrage between different pools or exchanges.
6. **Gas Price-Responsive Fees:** Adjust fees based on network congestion and gas prices to ensure profitability for liquidity providers.
7. **Event-Driven Fees:** Implement special fee structures during significant market events or token-specific occurrences.
8. **Lookback approach:** Set the fee to match the most profitable fee tier of external pools with the same asset pair over a recent period.
9. **Price oracle approach:** Use an external price oracle to determine the correct asset price and adjust fees based on how trades move the pool price relative to this external price.
10. **Price momentum approach:** Analyze recent price history and asymmetrically adjust fees based on trade direction.
11. **Asset composition approach:** Lower fees for trades that balance the pool and higher fees for trades that imbalance it.
12. **Transaction-source based approach:** Provide lower fees for transactions routed through certain aggregators or sources less likely to be arbitrage trades.

# Dynamic Fees Mechanism

In Uniswap v4, the dynamic fee capability of a pool is determined at pool creation and is immutable. This means that whether a pool uses dynamic fees or not is set when the pool is initially created and cannot be changed afterwards. For pools that do use dynamic fees, Uniswap v4 supports two primary methods for updating the fee:

1. **Periodic Updates via PoolManager:** Fees can be updated by calling the `updateDynamicLPFee` function on the PoolManager contract at specified intervals.
2. **Per-Swap Updates via beforeSwap Hook:** Fees can be dynamically set for each swap by returning the fee from the `beforeSwap` hook. This allows hooks to override the LP fee for each swap in dynamic fee pools.

These methods offer flexibility in implementing various fee strategies. For more detailed information on implementing these methods, please refer to our [Dynamic Fees Implementation Guide](https://uniswap-docs-staging.vercel.app/documentation/featured-guides/hooks/v4/guides-for-solidity-contracts/dynamic-fee-pools).

# Considerations and Best Practices

- The optimal fee depends on at least two factors: **asset volatility** and **volume of uninformed flow.**
- For volatile pairs in systems like Uniswap v3, which don't discriminate between flows, low fee-tier pools are only sensible when uninformed flow is large and asset volatility is relatively low.
- Performance implications of frequent fee updates should be carefully considered.
- Security measures should be implemented to prevent manipulation of fee-setting mechanisms.
- Balance responsiveness with gas costs to optimize for both performance and cost-effectiveness.

For more detailed implementation guidance and best practices, refer to our [Dynamic Fees Implementation Guide](https://uniswap-docs-staging.vercel.app/documentation/featured-guides/hooks/v4/guides-for-solidity-contracts/dynamic-fee-pools).