📜 [專欄新文章] 從 Rollups 來聊聊以太坊 Layer2 的演進
✍️ Kimi Wu
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Photo by Clark Van Der Beken on Unsplash
去年 Defi summer 的熱潮後,以太上 Defi 應用呈現爆炸性成長,造就高昂的交易手續費,為了有更快的交易速度及可負擔的交易費用,人們對側鏈、Layer2 的需求更加強烈。Rollups 是 Layer2 的一種技術,在今年相當熱門,幾個耕耘已久的專案 zkSync、Optimism、Arbitrum 等也開始廣為人知。今天想來聊聊以太坊上 Layer2 技術的演進。
State Channel
state channel 最一開始是建立在 Bitcoin 上,最廣為人知的就是 lightning network。簡單來說,就是兩方在私下建立一條可以互相轉帳的通道,轉帳完畢後把通道關閉,接著將交易後的狀態更新到鏈上。若交易一筆後即關閉通道,那交易成本就跟在鏈上一樣,所以在實務上,通道一直開著(或是一段時間),交易數筆、數百筆後再上鏈更新狀態,藉此平均每筆的交易手續費就大幅降低。也因為只需通道雙方驗證交易內容,交易速度能大幅提升,讓小額支付能夠實現,就不需等10分鐘(Bitcoin)後交易才會被打包,甚至要等6個區塊的時間。而最早在以太上的 state channel 是 Raiden。
對於 Raiden 技術有興趣的可以參考這篇文章。
Plasma
Plasma 於2017年8月由 V 跟 Joseph Poon (Lightning Network的創始人之一)所提出,概念上是可以有鏈中鏈中鏈(就是Layer2 → Layer3 → … LayerN),藉此可達到百萬級甚至更高的交易量,不過概念太美好,沒人知道怎麼實作。
隔年1月 V 提出了 Plasma 的第一個版本 Plasma MVP,是以 UTXOs 模型的設計,接著3月提出了第二個版本 Plasma Cash,同年(2018)Plasma 的提案數呈現著爆炸性的成長(絕大部分都是基於 Plasma MVP 跟 Plasma Cash 做改進)(如下圖),強大的社群力量,讓大部分關鍵的問題在同年年底都找到了解答。也為之後的 Optimistic Rollup 打下了基礎。
而較著名的開發團隊,除了 EF 出來的 Plasma Group 外,還有 OmiseGo 跟 Matic(現在的 Polygon)。
對 Plasma 技術有興趣的,可以參考這篇、這篇跟這篇
https://ethresear.ch/t/plasma-world-map-the-hitchhiker-s-guide-to-the-plasma/4333
Plasma 看似一切美好,但因為資料的可取得性(data availability)的問題,使得在使用者體驗上有點糟糕。
Plasma 的所有交易資料都在 Plasma 鏈上,而 Plasma 鏈的礦工(即operator)只需繳交 Merkle root 到 L1 的合約作公證就好。因此若 operator 作惡,在 Plasma 鏈上交易者,就需有能力證明 operator 作惡。
在 Plasma 設計中有”所有者”的概念(UTXOs 的設計中,收款者需要到拿送款者的轉出證明,才能動用這筆款項,轉出證明只有收款人會擁有),如果該所有者不關心自己的資產,就可能造成資產無效的結果(account-based 的設計,若你不理你的帳號,別人一樣可以轉帳到你的戶頭中)。因此每個交易者須有能力自行提出證明,無法委託第三方。
而要證明這件事,用戶需要把 Plasma 鏈上的交易都下載下來,才能證明 operator 做了一件不合法的行為,也才能產生詐欺證明(fraud proof)到 L1 上的合約來證明 operator 作惡。而這個送出的詐欺證明,必需要被確保可以安全地送到 L1 上的合約被執行,因此需要有一段挑戰期,讓使用者可以下載及驗證資料(或是網路塞車造成詐欺證明無法被合約執行)。
題外話,Eth 2.0 light client利用了 ECC (Error Correction Code)的原理,所以只需要部分資料就可以驗證正確性。
Rollups
同年(2018) 9月,在支線專注隱私性的開發的 Barry Whitehat 提出了 zk Rollup,隨後 V 也在以太坊研究員論壇發了一篇文章,解釋 zk Rollup 是如何運作的,並以On-chain scaling to potentially ~500 tx/sec through mass tx validation 為標題,也因此開啟了 Layer2 新的一頁。隔年(2019)三月,Matter Labs 獲得了 EF 的 grant 將 zk Rollup 產品化,也就是大家所知的 zkSync。
所謂的 rollups,一樣是在 Layer2 上做交易,不同的是 L1 上會記錄每一筆的交易紀錄。什麼!如果每一筆交易紀錄都上鏈,跟一般 L1 交易有什麼不同?想了解細節可以看這篇。簡單來說,在合約裡用了一顆樹來記錄每個帳號的狀態,樹的第幾片葉子(index)代表一個帳號地址,因此帳號就從20 bytes 的地址變成了幾個 bytes 的 index。以 ZK Rollups 來說,交易都是在 Layer2 被驗證過的,所以簽章資訊(65 bytes)也不用上鏈,Optimistic Rollups 會利用簽章聚合的技術,數百個簽章最終會被聚合成一個。因此,交易資料從原本100多 bytes 變成了10幾個 bytes。因為交易紀錄都 ”放上鏈“,資料可取得性也就不是問題了。
”放上鏈”指的是利用 calldata 的方式放在鏈上,並非一般認知的寫進合約裡。非0值的 calldata 每 byte 需要耗費 16 gas,而合約寫進一個 32bytes 的資料需要花 20,000(新增) or 5,000(修改) gas,相當於每個 byte 的成本為625 or 156 gas,約為 calldata 的 40 or 10倍。
同年(2019)六月 John Adler 在以太坊研究者論壇提出了Minimal Viable Merged Consensus,也就是大家熟知的 Optimistic Rollups 的原型,接著 Plasma Group 基於John Adler 的提案,提出了 OVM,從此 Layer2 上除了單純的轉帳外,還可以執行合約,也奠定了 Rollups 在 Layer2 的地位,開啟 rollups 的新世代。
StarkWare 團隊建立了可評估的數學模型,驗證了 calldata 的成本從64 gas 降到 16 gas並不會對鏈的安全造成危害,提出了 EIP-2028(在 Istanbul 上線),也是推動 rollups 可行性的重要一環。
Validity Proof v.s. Fraud Proof
Optimistic Rollups 跟 ZK Rollups 最近有很多文章在介紹跟比較,這邊就不贅述。這邊想聊的是資料的有效性,這篇文章解釋地很好,這裏擷取部分敘述。ZK Rollups 保證了上鏈的資料都是正確的,資料必須被驗證過是合法的(例如沒有被雙花)才會改變使用者的狀態(例如 balance),跟現在各個主鏈的設計是一樣的,稱作有效性證明(Validity Proof),這種設計假設大家都是壞人,要通過驗證才會相信你,確認資料是百分之百的正確聽起來很理所當然,但是背後要維護資料的正確性,需要相當高的成本。
Optimistic Rollups 則是相反,假設大家都是好人,送上鏈的交易都接受,當發現有人作弊,再靠檢舉機制來更正狀態,這稱作詐欺證明(Fraud Proof)。這樣的機制系統維護成本較低(L1 上不需要驗證每一筆資料的正確性),但需要多一個爪耙子的角色來維護系統的安全,也就多一個系統潛在的風險。而要確保爪耙子有足過的時間反應,就不能讓使用者即時地離開系統,這是 Optimistic Rollups 最被詬病的一點,提款要等七天(現在有第三方流動性提供者,使用者可以請第三方流動性提供者預付使用者的提款。使用者支付手續費來換取快速提款的服務,而流動性提供者則承擔資產鎖住七天的風險來賺取手續費。不過在 protocol 層以安全性為主要考量,還是需要較長的挑戰期)。
ZK Rollups 的實作上,也有數個小時的提款期,不過那是基於成本考量,而非安全性。
此外對照於 Plasma, rollups 的設計是 account-based,交易也都公開在鏈上,每個人都可以參與監督及提出詐欺證明。
ZK Rollups v.s. Optimistic Rollups
ZK Rollups 從資料的有效性來看勝過 Optimistic Rollups,離開系統時不需要額外的挑戰期,能即時提款離開系統,不過付出的代價就是交易延遲上鏈。因為產生 zkp 證明需要龐大的運算量,產生一次證明,大約需要10 ~ 20分鐘,所以說在 Layer2 上做一筆交易,10分鐘後你的交易才是有 L1 的安全性。
為了能盡早得知發出的交易是否完成,實作上會把完成的交易先丟上鏈,等zkp 證明產生後再上鏈驗證其正確性,若驗證成功,則交易視同有 L1 的安全性。
但是在通用性上,Optimistic Rollups 沒有複雜的 zkp 電路的限制,對於合約的支援度上更好,而且 zkp(SNAKRKs)在使用前需要一個盛大的啟用典禮(trusted setup ceremony)。
zkSync
zkSync 1.0 在去年(2020) 六月上線,因為不能執行合約,使用的專案並不多。同年的年初,Matter Labs 已經默默在開發一種新語言 Zinc,是可以在 zkSync 上開發合約的語言。年底,與 Defi 專案 Curve 合作,發表了在 zkSync上可以跑基本版的 Curve(兩幣交換)。今年(2021)三月,Matter Labs 發表了令人振奮的消息,zkSync 支援 EVM!只需要部分修改現有的合約就可以部署到 zkSync 上,測試網今年五月已經上線,主網預計8月上線。不過目前測試網上的交易量非常地少,相信在初期還是有相當多問題或是困難,以短期來看,Optimistic Rollups 陣營的速度跟支援度略勝一籌,不過個人相信長期會是 ZK Rollups 的世代(私心認為 lol),但最終還是由生態系的大小來決定贏家。
在 ZK 這個陣線上有延伸出不同的設計,為了加快速度及減少上鏈成本,StarkWare 提出了 Validium 的概念,資料不上鏈但使用 zkp 確保資料的正確性,像是 StarkWare 的 Volition 跟 Matter Labs 的 zkPorter 都是同樣概念的實作,不過不是本篇的重點,就不多解釋。
ETH 2
V在2020年10月提出了 A Rollup Centric Ethereum,rollup 也因此進到 Eth2 的規劃中。Eth2 的設計中 shard chain 是資料層,而在 phase 2 後才有執行層(也就是才能執行合約),V 的提案 除了讓 shard chain 當資料層外,也會內建 rollups 的邏輯。至於會採用哪種 rollups 目前沒看到結論,不過 V 本人是傾向 ZK Rollups。如果成真,那未來數百個 rollups 之間的溝通,將會是另一個挑戰 。
專案比較
ZK Rollups 有目前這幾個較知名的專案: zkSync(Matter Labs)、 Hermez(Iden3)、 Loopring(Loopring)、 StarkNet(StarkWare)跟 Aztec(Aztec)。
Optimistic Rollups 目前幾個專案 Optimism(Optimisim,前Plasma Group 成員)、 Arbitrum(Offchain Labs)、 Fuel(Fuel)。
這是目前幾大 rollups 的生態系(今年3月時的統計),比較值得一提的是,Uniswap 團隊因為社群的投票,也將會在 Arbitrum 上面部署,對於整個 Arbitrum 的生態,相信有很大的影響。
https://www.chainnews.com/articles/872971457746.htm
感謝 NIC Lin 及 Chih-Cheng Liang 的審查跟建議。若有錯誤或不同觀點,歡迎指教。
從 Rollups 來聊聊以太坊 Layer2 的演進 was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
「curve defi教學」的推薦目錄:
- 關於curve defi教學 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於curve defi教學 在 動區動趨 BlockTempo - 由社群而生的區塊鏈媒體 - Media for Blockchain Facebook 的最讚貼文
- 關於curve defi教學 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於curve defi教學 在 區塊先生Mr.Block - Blockchain & Tech. - Facebook 的評價
- 關於curve defi教學 在 [挖礦] 收益DeFi流動性挖礦為何錢會越來越多- DigiCurrency 的評價
- 關於curve defi教學 在 [發錢] FANTOM DeFi 生態初探介紹- 看板DigiCurrency 的評價
curve defi教學 在 動區動趨 BlockTempo - 由社群而生的區塊鏈媒體 - Media for Blockchain Facebook 的最讚貼文
#Uniswap #v3 #體驗教學 #Defi
【手把手教學|以太坊 AMM 之王 Uniswap v3 更新:全新的金融做市體驗】
🔰本文將為讀者整理出手把手教學,依「如何在 V3 中交易?」以及「如何在 V3 中提供流動性」、「如何建構範圍訂單?」等 5 個部分帶大家逐步體驗 Uniswap V3 的改變......
-
#同場加映
①Polygon宣布「1.5億美元DeFi基金」啟動!招攬Aave、Curve後,MATIC 3天翻漲一倍
https://pse.is/3g8hdm
②觀點|以太坊 DeFi 溢出效應強烈,「跨鏈宇宙」來襲!解析這輪牛市的板塊輪動
https://pse.is/3gnuxf
-
✅ 即時新聞鎖定 #動區Telegram
https://t.me/blocktemponews
✅ 每日新聞精選訂閱 #LINE:
https://line.me/R/ti/p/%40kgx9780p
✅ 右轉動區 #千人投資討論群:
https://line.me/ti/g2/htySqS7SoKOuGGFx4Gn9dg
curve defi教學 在 Taipei Ethereum Meetup Facebook 的最佳貼文
📜 [專欄新文章] Uniswap v3 Features Explained in Depth
✍️ 田少谷 Shao
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Once again the game-changing DEX 🦄 👑
Image source: https://uniswap.org/blog/uniswap-v3/
Outline
0. Intro1. Uniswap & AMM recap2. Ticks 3. Concentrated liquidity4. Range orders: reversible limit orders5. Impacts of v36. Conclusion
0. Intro
The announcement of Uniswap v3 is no doubt one of the most exciting news in the DeFi place recently 🔥🔥🔥
While most have talked about the impact v3 can potentially bring on the market, seldom explain the delicate implementation techniques to realize all those amazing features, such as concentrated liquidity, limit-order-like range orders, etc.
Since I’ve covered Uniswap v1 & v2 (if you happen to know Mandarin, here are v1 & v2), there’s no reason for me to not cover v3 as well ✅
Thus, this article aims to guide readers through Uniswap v3, based on their official whitepaper and examples made on the announcement page. However, one needs not to be an engineer, as not many codes are involved, nor a math major, as the math involved is definitely taught in your high school, to fully understand the following content 😊😊😊
If you really make it through but still don’t get shxt, feedbacks are welcomed! 🙏
There should be another article focusing on the codebase, so stay tuned and let’s get started with some background noise!
1. Uniswap & AMM recap
Before diving in, we have to first recap the uniqueness of Uniswap and compare it to traditional order book exchanges.
Uniswap v1 & v2 are a kind of AMMs (automated market marker) that follow the constant product equation x * y = k, with x & y stand for the amount of two tokens X and Y in a pool and k as a constant.
Comparing to order book exchanges, AMMs, such as the previous versions of Uniswap, offer quite a distinct user experience:
AMMs have pricing functions that offer the price for the two tokens, which make their users always price takers, while users of order book exchanges can be both makers or takers.
Uniswap as well as most AMMs have infinite liquidity¹, while order book exchanges don’t. The liquidity of Uniswap v1 & v2 is provided throughout the price range [0,∞]².
Uniswap as well as most AMMs have price slippage³ and it’s due to the pricing function, while there isn’t always price slippage on order book exchanges as long as an order is fulfilled within one tick.
In an order book, each price (whether in green or red) is a tick. Image source: https://ftx.com/trade/BTC-PERP
¹ though the price gets worse over time; AMM of constant sum such as mStable does not have infinite liquidity
² the range is in fact [-∞,∞], while a price in most cases won’t be negative
³ AMM of constant sum does not have price slippage
2. Tick
The whole innovation of Uniswap v3 starts from ticks.
For those unfamiliar with what is a tick:
Source: https://www.investopedia.com/terms/t/tick.asp
By slicing the price range [0,∞] into numerous granular ticks, trading on v3 is highly similar to trading on order book exchanges, with only three differences:
The price range of each tick is predefined by the system instead of being proposed by users.
Trades that happen within a tick still follows the pricing function of the AMM, while the equation has to be updated once the price crosses the tick.
Orders can be executed with any price within the price range, instead of being fulfilled at the same one price on order book exchanges.
With the tick design, Uniswap v3 possesses most of the merits of both AMM and an order book exchange! 💯💯💯
So, how is the price range of a tick decided?
This question is actually somewhat related to the tick explanation above: the minimum tick size for stocks trading above 1$ is one cent.
The underlying meaning of a tick size traditionally being one cent is that one cent (1% of 1$) is the basis point of price changes between ticks, ex: 1.02 — 1.01 = 0.1.
Uniswap v3 employs a similar idea: compared to the previous/next price, the price change should always be 0.01% = 1 basis point.
However, notice the difference is that in the traditional basis point, the price change is defined with subtraction, while here in Uniswap it’s division.
This is how price ranges of ticks are decided⁴:
Image source: https://uniswap.org/whitepaper-v3.pdf
With the above equation, the tick/price range can be recorded in the index form [i, i+1], instead of some crazy numbers such as 1.0001¹⁰⁰ = 1.0100496621.
As each price is the multiplication of 1.0001 of the previous price, the price change is always 1.0001 — 1 = 0.0001 = 0.01%.
For example, when i=1, p(1) = 1.0001; when i=2, p(2) = 1.00020001.
p(2) / p(1) = 1.00020001 / 1.0001 = 1.0001
See the connection between the traditional basis point 1 cent (=1% of 1$) and Uniswap v3’s basis point 0.01%?
Image source: https://tenor.com/view/coin-master-cool-gif-19748052
But sir, are prices really granular enough? There are many shitcoins with prices less than 0.000001$. Will such prices be covered as well?
Price range: max & min
To know if an extremely small price is covered or not, we have to figure out the max & min price range of v3 by looking into the spec: there is a int24 tick state variable in UniswapV3Pool.sol.
Image source: https://uniswap.org/whitepaper-v3.pdf
The reason for a signed integer int instead of an uint is that negative power represents prices less than 1 but greater than 0.
24 bits can cover the range between 1.0001 ^ (2²³ — 1) and 1.0001 ^ -(2)²³. Even Google cannot calculate such numbers, so allow me to offer smaller values to have a rough idea of the whole price range:
1.0001 ^ (2¹⁸) = 242,214,459,604.341
1.0001 ^ -(2¹⁷) = 0.000002031888943
I think it’s safe to say that with a int24 the range can cover > 99.99% of the prices of all assets in the universe 👌
⁴ For implementation concern, however, a square root is added to both sides of the equation.
How about finding out which tick does a price belong to?
Tick index from price
The answer to this question is rather easy, as we know that p(i) = 1.0001^i, simply takes a log with base 1.0001 on both sides of the equation⁴:
Image source: https://www.codecogs.com/latex/eqneditor.php
Let’s try this out, say we wanna find out the tick index of 1000000.
Image source: https://ncalculators.com/number-conversion/log-logarithm-calculator.htm
Now, 1.0001¹³⁸¹⁶² = 999,998.678087146. Voila!
⁵ This formula is also slightly modified to fit the real implementation usage.
3. Concentrated liquidity
Now that we know how ticks and price ranges are decided, let’s talk about how orders are executed in a tick, what is concentrated liquidity and how it enables v3 to compete with stablecoin-specialized DEXs (decentralized exchange), such as Curve, by improving the capital efficiency.
Concentrated liquidity means LPs (liquidity providers) can provide liquidity to any price range/tick at their wish, which causes the liquidity to be imbalanced in ticks.
As each tick has a different liquidity depth, the corresponding pricing function x * y = k also won’t be the same!
Each tick has its own liquidity depth. Image source: https://uniswap.org/blog/uniswap-v3/
Mmm… examples are always helpful for abstract descriptions 😂
Say the original pricing function is 100(x) * 1000(y) = 100000(k), with the price of X token 1000 / 100 = 10 and we’re now in the price range [9.08, 11.08].
If the liquidity of the price range [11.08, 13.08] is the same as [9.08, 11.08], we don’t have to modify the pricing function if the price goes from 10 to 11.08, which is the boundary between two ticks.
The price of X is 1052.63 / 95 = 11.08 when the equation is 1052.63 * 95 = 100000.
However, if the liquidity of the price range [11.08, 13.08] is two times that of the current range [9.08, 11.08], balances of x and y should be doubled, which makes the equation become 2105.26 * 220 = 400000, which is (1052.63 * 2) * (110 * 2) = (100000 * 2 * 2).
We can observe the following two points from the above example:
Trades always follow the pricing function x * y = k, while once the price crosses the current price range/tick, the liquidity/equation has to be updated.
√(x * y) = √k = L is how we represent the liquidity, as I say the liquidity of x * y = 400000 is two times the liquidity of x * y = 100000, as √(400000 / 100000) = 2.
What’s more, compared to liquidity on v1 & v2 is always spread across [0,∞], liquidity on v3 can be concentrated within certain price ranges and thus results in higher capital efficiency from traders’ swapping fees!
Let’s say if I provide liquidity in the range [1200, 2800], the capital efficiency will then be 4.24x higher than v2 with the range [0,∞] 😮😮😮 There’s a capital efficiency comparison calculator, make sure to try it out!
Image source: https://uniswap.org/blog/uniswap-v3/
It’s worth noticing that the concept of concentrated liquidity was proposed and already implemented by Kyper, prior to Uniswap, which is called Automated Price Reserve in their case.⁵
⁶ Thanks to Yenwen Feng for the information.
4. Range orders: reversible limit orders
As explained in the above section, LPs of v3 can provide liquidity to any price range/tick at their wish. Depending on the current price and the targeted price range, there are three scenarios:
current price < the targeted price range
current price > the targeted price range
current price belongs to the targeted price range
The first two scenarios are called range orders. They have unique characteristics and are essentially fee-earning reversible limit orders, which will be explained later.
The last case is the exact same liquidity providing mechanism as the previous versions: LPs provide liquidity in both tokens of the same value (= amount * price).
There’s also an identical product to the case: grid trading, a very powerful investment tool for a time of consolidation. Dunno what’s grid trading? Check out Binance’s explanation on this, as this topic won’t be covered!
In fact, LPs of Uniswap v1 & v2 are grid trading with a range of [0,∞] and the entry price as the baseline.
Range orders
To understand range orders, we’d have to first revisit how price is discovered on Uniswap with the equation x * y = k, for x & y stand for the amount of two tokens X and Y and k as a constant.
The price of X compared to Y is y / x, which means how many Y one can get for 1 unit of X, and vice versa the price of Y compared to X is x / y.
For the price of X to go up, y has to increase and x decrease.
With this pricing mechanism in mind, it’s example time!
Say an LP plans to place liquidity in the price range [15.625, 17.313], higher than the current price of X 10, when 100(x) * 1000(y) = 100000(k).
The price of X is 1250 / 80 = 15.625 when the equation is 80 * 1250 = 100000.
The price of X is 1315.789 / 76 = 17.313 when the equation is 76 * 1315.789 = 100000.
If now the price of X reaches 15.625, the only way for the price of X to go even higher is to further increase y and decrease x, which means exchanging a certain amount of X for Y.
Thus, to provide liquidity in the range [15.625, 17.313], an LP needs only to prepare 80 — 76 = 4 of X. If the price exceeds 17.313, all 4 X of the LP is swapped into 1315.789 — 1250 = 65.798 Y, and then the LP has nothing more to do with the pool, as his/her liquidity is drained.
What if the price stays in the range? It’s exactly what LPs would love to see, as they can earn swapping fees for all transactions in the range! Also, the balance of X will swing between [76, 80] and the balance of Y between [1250, 1315.789].
This might not be obvious, but the example above shows an interesting insight: if the liquidity of one token is provided, only when the token becomes more valuable will it be exchanged for the less valuable one.
…wut? 🤔
Remember that if 4 X is provided within [15.625, 17.313], only when the price of X goes up from 15.625 to 17.313 is 4 X gradually swapped into Y, the less valuable one!
What if the price of X drops back immediately after reaching 17.313? As X becomes less valuable, others are going to exchange Y for X.
The below image illustrates the scenario of DAI/USDC pair with a price range of [1.001, 1.002] well: the pool is always composed entirely of one token on both sides of the tick, while in the middle 1.001499⁶ is of both tokens.
Image source: https://uniswap.org/blog/uniswap-v3/
Similarly, to provide liquidity in a price range < current price, an LP has to prepare a certain amount of Y for others to exchange Y for X within the range.
To wrap up such an interesting feature, we know that:
Only one token is required for range orders.
Only when the current price is within the range of the range order can LP earn trading fees. This is the main reason why most people believe LPs of v3 have to monitor the price more actively to maximize their income, which also means that LPs of v3 have become arbitrageurs 🤯
I will be discussing more the impacts of v3 in 5. Impacts of v3.
⁷ 1.001499988 = √(1.0001 * 1.0002) is the geometric mean of 1.0001 and 1.0002. The implication is that the geometric mean of two prices is the average execution price within the range of the two prices.
Reversible limit orders
As the example in the last section demonstrates, if there is 4 X in range [15.625, 17.313], the 4 X will be completely converted into 65.798 Y when the price goes over 17.313.
We all know that a price can stay in a wide range such as [10, 11] for quite some time, while it’s unlikely so in a narrow range such as [15.625, 15.626].
Thus, if an LP provides liquidity in [15.625, 15.626], we can expect that once the price of X goes over 15.625 and immediately also 15.626, and does not drop back, all X are then forever converted into Y.
The concept of having a targeted price and the order will be executed after the price is crossed is exactly the concept of limit orders! The only difference is that if the range of a range order is not narrow enough, it’s highly possible that the conversion of tokens will be reverted once the price falls back to the range.
As price ranges follow the equation p(i) = 1.0001 ^ i, the range can be quite narrow and a range order can thus effectively serve as a limit order:
When i = 27490, 1.0001²⁷⁴⁹⁰ = 15.6248.⁸
When i = 27491, 1.0001²⁷⁴⁹¹ = 15.6264.⁸
A range of 0.0016 is not THAT narrow but can certainly satisfy most limit order use cases!
⁸ As mentioned previously in note #4, there is a square root in the equation of the price and index, thus the numbers here are for explantion only.
5. Impacts of v3
Higher capital efficiency, LPs become arbitrageurs… as v3 has made tons of radical changes, I’d like to summarize my personal takes of the impacts of v3:
Higher capital efficiency makes one of the most frequently considered indices in DeFi: TVL, total value locked, becomes less meaningful, as 1$ on Uniswap v3 might have the same effect as 100$ or even 2000$ on v2.
The ease of spot exchanging between spot exchanges used to be a huge advantage of spot markets over derivative markets. As LPs will take up the role of arbitrageurs and arbitraging is more likely to happen on v3 itself other than between DEXs, this gap is narrowed … to what extent? No idea though.
LP strategies and the aggregation of NFT of Uniswap v3 liquidity token are becoming the blue ocean for new DeFi startups: see Visor and Lixir. In fact, this might be the turning point for both DeFi and NFT: the two main reasons of blockchain going mainstream now come to the alignment of interest: solving the $$ problem 😏😏😏
In the right venue, which means a place where transaction fees are low enough, such as Optimism, we might see Algo trading firms coming in to share the market of designing LP strategies on Uniswap v3, as I believe Algo trading is way stronger than on-chain strategies or DAO voting to add liquidity that sort of thing.
After reading this article by Parsec.finance: The Dex to Rule Them All, I cannot help but wonder: maybe there is going to be centralized crypto exchanges adopting v3’s approach. The reason is that since orders of LPs in the same tick are executed pro-rata, the endless front-running speeding-competition issue in the Algo trading world, to some degree, is… solved? 🤔
Anyway, personal opinions can be biased and seriously wrong 🙈 I’m merely throwing out a sprat to catch a whale. Having a different voice? Leave your comment down below!
6. Conclusion
That was kinda tough, isn’t it? Glad you make it through here 🥂🥂🥂
There are actually many more details and also a huge section of Oracle yet to be covered. However, since this article is more about features and targeting normal DeFi users, I’ll leave those to the next one; hope there is one 😅
If you have any doubt or find any mistake, please feel free to reach out to me and I’d try to reply AFAP!
Stay tuned and in the meantime let’s wait and see how Uniswap v3 is again pioneering the innovation of DeFi 🌟
Uniswap v3 Features Explained in Depth was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
curve defi教學 在 [挖礦] 收益DeFi流動性挖礦為何錢會越來越多- DigiCurrency 的推薦與評價
1000U內開始你的被動收入,Polygon鏈新玩法,超穩定收益DeFi流動性挖礦教學, 去中心化 ... 16樓 → ppppp367: Polygon 有個IRON defi 穩定幣lp 有333% 資金都進去這了 ... ... <看更多>
curve defi教學 在 [發錢] FANTOM DeFi 生態初探介紹- 看板DigiCurrency 的推薦與評價
4、穩定幣存池與交換Curve & Popsicle($ICE) 老牌的curve 有上來開ftm.curve.fi,可以在存池後,丟到冰棒popscile 上領ICE 獎勵,穩定幣無impermanent ... ... <看更多>
curve defi教學 在 區塊先生Mr.Block - Blockchain & Tech. - Facebook 的推薦與評價
【區塊先生】 Curve GOV + DAO 使用 教學 《區塊鏈- DeFi 》(#186集) - - - ☄議題- - - 步驟一:https://dao. curve.fi/minter/gauges 步驟 ... ... <看更多>