Poopman (๐Ÿ’ฉ๐Ÿงฑโœจ)
Poopman (๐Ÿ’ฉ๐Ÿงฑโœจ)

@poopmandefi

25 Tweets 14 reads Jun 20, 2023
2 years ago, Uniswap V3 introduced concentrated liquidity to improve capital efficiency.
Today, Uniswap V4 is bringing customization & optimisation to the AMM space.
If you care about DeFi and its future ๐Ÿฆ„
You need to read this ๐Ÿ”ฅ
A deep dive thread on @Uniswap V4 ๐Ÿงต (x/23)
1/
Uniswap has always been at the forefront of AMM innovation since the birth of DeFi.
Throughout its 5-year journey, @Uniswap has undergone 3 verison of changes ๐Ÿช„
V1 = Innovated ERC20 - ETH pools & AMM
V2 = Enabled ERC20/ERC20 pools & Flash swap
V3 = Concentrated liquidity
2/
Today, with the launch of Uniswap V4,
Uniswap is set to revolutionize the space with 3 new concepts ๐Ÿ”ฅ , including:
1๏ธโƒฃ The Hooks ๐Ÿช
2๏ธโƒฃ Singleton Structure ๐Ÿ“ฆ
3๏ธโƒฃ Flash Accounting โšก๏ธ
Don't worry, I will explain it part by part.
3/
But first, let's understand why do we even need V4 โœ‹:
In V2 / V3, the lack of customizability has always been a problem โš ๏ธ.
Ideas such as volatility oracles and limit orders could not be added by third-party developers in V2 / V3 due to technical complexity.
4/
In V4, Uniswap is trying to solve this problem with a new feature call Hooks ๐Ÿช
What is Hooks๐Ÿช?
Hooks is an external smart contracts that can execute logic at different "keypoints" in a pool.
Keypoints refer to actions before/after swap, or when LP deposit / withdraw etc.
5/
With hooks, pool creators can adjust pool parameters and introduce new functions to the AMM ๐Ÿ”€
More than that, the implementation of hooks can also shifts the curve and allowing various strategies to be built on top of Uniswap, ultimately benefiting LPs / swapper even more.
6/
Example use cases include ๐Ÿ‘‡
๐Ÿ”น Create limit orders at the smallest possible change in price, known as tick price.
๐Ÿ”น Market making via TWAMM by natively breaking down the order into smaller pieces.
๐Ÿ”น Dynamic fees during high volatility to encourage balancing the pool.
7/
Hooks can even allow customized oracle implementations and distribute internalized MEV to LP holdersโ€ฆ..
Anyway, enough of alien language ๐Ÿ‘ฝ.
If you want to learn more, this thread from @interchainriley will help:
8/
Besides 1๏ธโƒฃ hooks, V4 has another feature, known as action hooks that can call out logic during their execution.
Action hooks are contracts that can only be triggered and run when the "flag" condition is fulfilled and turned "True" โœ….
Let's use an example ๐Ÿ‘‡:
9/
Referring to the flow chart below:
1. Before the swap, the contract checks the Flag to assess the pool's volatility.
2. If the volatility is high, the Flag turns "True" and runs the action hooks โœ….
3. If not, the Flag turns False and the swap remains unchanged โŒ.
10/
By doing so, action hooks enable a more gas-efficient method to determine the desired hooks to execute ๐Ÿ”ฅ.
Right now, V4 allows action hooks to be implemented in 8 different scenarios๐Ÿ‘‡:
11/
On the other hand, Singleton structure and Flash accounting will enable a cheaper swapping and deploying experience in V4.
But how, poopman ๐Ÿ’ฉ?
Let's look at it part by part โ˜•
12/
2๏ธโƒฃ Singleton Structure ๐Ÿ“ฆ
In V3, you have to deploy a new contract every time you create a pool, and it's pretty expensive to deploy ๐Ÿ’ธ.
In V4, the singleton structure holds all pools in one contract, which makes pool deployment 99% cheaper than V3 ๐Ÿ“ฅ
13/
3๏ธโƒฃ Flash accounting:
In V3, each swap/LP staking ended with the action "transfer token."
In short, you transfer your token after every operation.
In multi-hop swapping, it can be REALLY painful as swappers need to consume a huge amount of gas fees during each operation ๐Ÿซจ
14/
With Flash accounting in V4, each operation (swap/deploy) will only result in an internal balance update ๐Ÿงฎ, in which the balance is denominated in the unit "delta".
By the end of the swap, it will only swap out the net "delta" balance after a series of calculations ๐Ÿค™.
15/
By requiring no tokens owned by the pool manager by the end of the transfer, flash accounting ensures the solvency of the pools.
Along with singleton structure, the architecture can simplify multi-hop swapping and complex pool operations, making V4 much more user-friendly โœ…
16/
Unfortunately โš ๏ธ, the flash accounting model is still expensive, as users require paying gas for internal balance updates once the storage refund cap is exceeded ๐Ÿ”ด.
To suppress gas fees, @Uniswap needs the transient storage upgrades from EIP-1153 ๐Ÿ”‘.
17/
WTF is transient storage ?
In simple words, it is a method to provide a temporary storage area within a transactionโ€™s execution context ๐Ÿ“ฆ, and the storage disappears after the transaction is completed ๐Ÿƒ.
18/
Not only does it help to reduce the overall gas fee, but it also helps to streamline smart contracts and improve their interaction.
19/
More notable upgrades in V4 include ๐Ÿ‘‡
๐Ÿ”บ Bringing back the Native ETH swapping
๐Ÿ”บIntroducing the donate function (Tipping LPs, etc.)
๐Ÿ”บ Governance updates to control the cap of the swapping fee
20/
In a nutshell, Uniswap V4 has enabled a more customizable, flexible, and efficient AMM that has never been seen in the space before.
I expect more DApps will leverage the flexibility of V4 & design optimized strategies to benefit their LPs or improve capital efficiency.
21/
That's a wrap!
I hope my thread helped you to learn more about the newest Uni upgrade.
I'm soo excited for all the new innovations being built on top of Uniswap V4 and look forward to seeing a active ecosystem soon.
Please consider liking and supporting me by retweeting!22

Loading suggestions...