bitpie比特派钱包官网|uniswapv3网址

bitpie比特派钱包官网 2024-03-16 09:24:58

Home | Uniswap Protocol

| Uniswap ProtocolEcosystemCommunityGovernanceDevelopersBlogFAQJobsLaunch AppMenuUNISWAP PROTOCOLSwap, earn, and build on the leading decentralized crypto trading protocol.Launch App$489B+Trade Volume71M+All Time Trades300+Integrations4,400+Community DelegatesUNISWAP ECOSYSTEM →A growing network of DeFi Apps.Developers, traders, and liquidity providers participate together in a financial marketplace that is open and accessible to all.300+IntegrationsExplore all ↗DEVELOPERS →Superpowers for DeFi developers.Build Defi apps and tools on the largest crypto project on Ethereum. Get started with quick start guides, protocol documentation, a Javascript SDK, and fully open source code.Documentation ↗V3 WhitepaperGithubApply for funding from the Uniswap Grants ProgramGet paid to build the future of finance. Uniswap Governance offers grant funding for people building apps, tools, and activities on the Uniswap Protocol.Learn more ↗PROTOCOL GOVERNANCE ->Governed by the community.The Uniswap Protocol is managed by a global community of UNI token holders and delegates.Read more ↗Governance Forum Participate by proposing upgrades and discussing the future of the protocol with the Uniswap community.Sybil Vote on offchain proposals with the Snapshot interface. Votes are weighted by the number of UNI delegates.Governance Portal Vote on official Uniswap governance proposals and view past proposals. EcosystemCommunityGovernanceDevelopersBlogFAQPrivacy PolicyTrademark PolicySecurityMedia inquires for Uniswap Labs - Contact [email protect

Uniswap Interface

wap InterfaceYou need to enable JavaScript to run this ap

Introducing Uniswap v3

oducing Uniswap v3 Uniswap Labs BlogLaunch AppBackIntroducing Uniswap v3 March 23, 2021# ProtocolsUniswap v1 was launched in November 2018 as a proof of concept for automated market makers (AMMs), a type of exchange where anyone can pool assets into shared market making strategies.

In May 2020, Uniswap v2 introduced new features and optimizations, setting the stage for exponential growth in AMM adoption. Less than one year since its launch, v2 has facilitated over $135bn in trading volume, ranking as one of the largest cryptocurrency spot exchanges in the world.

Uniswap now serves as critical infrastructure for decentralized finance, empowering developers, traders, and liquidity providers to participate in a secure and robust financial marketplace.

Today, we are excited to present an overview of Uniswap v3. We are targeting an L1 Ethereum mainnet launch on May 5, with an L2 deployment on Optimism set to follow shortly after.

Uniswap v3 introduces:

Concentrated liquidity, giving individual LPs granular control over what price ranges their capital is allocated to. Individual positions are aggregated together into a single pool, forming one combined curve for users to trade against

Multiple fee tiers, allowing LPs to be appropriately compensated for taking on varying degrees of risk

These features make Uniswap v3 the most flexible and efficient AMM ever designed:

LPs can provide liquidity with up to 4000x capital efficiency relative to Uniswap v2, earning higher returns on their capital

Capital efficiency paves the way for low-slippage trade execution that can surpass both centralized exchanges and stablecoin-focused AMMs

LPs can significantly increase their exposure to preferred assets and reduce their downside risk

LPs can sell one asset for another by adding liquidity to a price range entirely above or below the market price, approximating a fee-earning limit order that executes along a smooth curve

Uniswap's oracles are now far easier and cheaper to integrate. V3 oracles are capable of providing time-weighted average prices (TWAPs) on demand for any period within the last ~9 days. This removes the need for integrators to checkpoint historical values.

Even with these groundbreaking design improvements, the gas cost of v3 swaps on Ethereum mainnet is slightly cheaper than v2. Transactions made on the Optimism deployment will likely be significantly cheaper!

Read on for more details on Uniswap v3. For a deeper technical overview check out the Uniswap v3 Core whitepaper, the Uniswap v3 Core smart contracts.

Concentrated Liquidity

In Uniswap v2, liquidity is distributed evenly along an x*y=k price curve, with assets reserved for all prices between 0 and infinity. For most pools, a majority of this liquidity is never put to use. As an example, the v2 DAI/USDC pair reserves just ~0.50% of capital for trading between $0.99 and $1.01 , the price range in which LPs would expect to see the most volume and consequently earn the most fees.

V2 LPs only earn fees on a small portion of their capital, which can fail to appropriately compensate for the price risk ("impermanent loss") they take by holding large inventories in both tokens. Additionally, traders are often subject to high degrees of slippage as liquidity is spread thin across all price ranges.

In Uniswap v3, LP's can concentrate their capital within custom price ranges, providing greater amounts of liquidity at desired prices. In doing so, LPs construct individualized price curves that reflect their own preferences.

LPs can combine any number of distinct concentrated positions within a single pool. For example, an LP in the ETH/DAI pool may choose to allocate $100 to the price ranges $1,000-$2,000 and an additional $50 to the ranges $1,500-$1,750.

By doing so, an LP can approximate the shape of any automated market maker or active order book.

Users trade against the combined liquidity of all individual curves with no gas cost increase per liquidity provider. Trading fees collected at a given price range are split pro-rata by LPs proportional to the amount of liquidity they contributed to that range.

Capital Efficiency

By concentrating their liquidity, LPs can provide the same liquidity depth as v2 within specified price ranges while putting far less capital at risk. The capital saved can be held externally, invested in different assets, deposited elsewhere in DeFi, or used to increase exposure within the specified price range to earn more trading fees.

Let's illustrate with an example:

Alice and Bob both want to provide liquidity in an ETH/DAI pool on Uniswap v3. They each have $1m. The current price of ETH is 1,500 DAI.

Alice decides to deploy her capital across the entire price range (as she would have in Uniswap v2). She deposits 500,000 DAI and 333.33 ETH (worth a total of $1m).

Bob instead creates a concentrated position, depositing only within the price range from 1,000 to 2,250. He deposits 91,751 DAI and 61.17 ETH, worth a total of about $183,500. He keeps the other $816,500 himself, investing it however he prefers.

While Alice has put down 5.44x as much capital as Bob, they earn the same amount of fees, as long as the ETH/DAI price stays within the 1,000 to 2,250 range.

Bob's custom position also acts as a kind of stop-loss for his liquidity. Both Alice and Bob's liquidity will be entirely denominated in ETH if the price of ETH falls to $0. However, Bob will have lost just $159,000, versus Alice's $1m. Bob can use his additional $816,500 to hedge against downside exposure or to invest in any other conceivable strategy.

Instead of providing equivalent liquidity depth as a v2 LPs with less capital, v3 LPs can choose to provide greater depth with the same amount of capital as their v2 counterparts. This requires taking on more price risk ("impermanent loss") while supporting greater amounts of trading and earning higher fees.

LPs in more stable pools will likely provide liquidity in particularly narrow ranges. If the ~$25m currently held in the Uniswap v2 DAI/USDC pair was instead concentrated between 0.99 — 1.01 in v3, it would provide the same depth as $5bn in Uniswap v2 as long as the price stayed within that range. If the ~$25m was concentrated into the 0.999 - 1.001 range it would provide the same depth as $50b in Uniswap v2.

The tool below calculates the capital efficiency gains of a concentrated liquidity position (centered around the current price) relative to allocating capital across the entire price curve.

Liquidity Deposit ValueValue of paired tokens$Select ETH price rangeCurrent Price: $1,820V3 Range PositionCapital Required$150,000Fees per $ vs. V25.24xV2 PositionCapital Required$785,779These two positions will earn equal fees and perform idenitcally while the price remains between $1200 and $2800.

At launch, capital efficiency gains will max out at 4000x for LPs providing liquidity within a single 0.10% price range. The v3 pool factory is technically capable of supporting ranges as granular as 0.02%, translating to a maximum 20,000x capital efficiency gains relative to v2. However, more granular pools can increase swap gas costs and might be more useful on Layer 2.

Active Liquidity

If market prices move outside an LP's specified price range, their liquidity is effectively removed from the pool and is no longer earning fees. In this state, an LP's liquidity is composed entirely of the less valuable of the two assets, until the market price moves back into their specified price range or they decide to update their range to account for current prices.

In v3, it is theoretically possible for no liquidity to exist in a given price range. However, we expect rational LPs to continuously update their price ranges to cover the current market price.

Range Orders

v3's LP customizability opens up a novel order feature to complement market orders, which we are calling "range orders".

LPs can deposit a single token in a custom price range above or below the current price: if the market price enters into their specified range, they sell one asset for another along a smooth curve while earning swap fees in the process.

Depositing to a narrow range feels similar to a traditional limit order. For example, if the current price of DAI is below 1.001 USDC, Alice could add $10m worth of DAI to the range of 1.001 — 1.002 DAI/USDC.

Once DAI trades above 1.002 DAI/USDC, Alice's liquidity will have fully converted into USDC. Alice must withdraw her liquidity (or use a third-party service to withdraw on her behalf) to avoid automatically converting back into DAI if DAI/USDC starts trading below 1.002.

The average execution price of a fully executed range order is the geometric average of the minimum and maximum price: in Alice's case, the execution price equals 1.001499 DAI/USDC for a total of $1,001,499. This execution price does not account for additional swap fees earned during the period in which prices trade within the 1.001 — 1.002 DAI/USDC range.

Range orders within wider ranges may prove particularly useful for profit-taking, buying the dip, and primary issuance events: in the later use case, issuers are now able to deposit liquidity in a single asset and specify the exact range of prices across which they wish to sell their tokens.

Non-Fungible Liquidity

As a byproduct of per-LP custom price curves, liquidity positions are no longer fungible and are not represented as ERC20 tokens in the core protocol.

Instead, LP positions will be represented by non-fungible tokens (NFTs). However, common shared positions can be made fungible (ERC20) via peripheral contracts or through other partner protocols. Additionally, trading fees are no longer automatically reinvested back into the pool on LPs' behalf.

Over time we expect increasingly sophisticated strategies to be tokenized, making it possible for LPs to participate while maintaining a passive user experience. This could include multi-positions, auto-rebalancing to concentrate around the market price, fee reinvestment, lending, and more.

Flexible Fees

Uniswap v3 offers LPs three separate fee tiers per pair — 0.05%, 0.30%, and 1.00%. This array of options ensures that LPs tailor their margins according to expected pair volatility: LPs take on more risk in non-correlated pairs like ETH/DAI and, conversely, take on minimal risk in correlated pairs like USDC/DAI.

Although distinct fee tiers may lead to some degree of liquidity fragmentation, we believe that most pairs will calibrate to an obvious fee tier, which then serves as the canonical market. We expect like-kind asset pairs to congregate around the 0.05% fee tier and pairs like ETH/DAI to use 0.30%, while exotic assets might find 1.00% swap fees more appropriate. governance can add additional fee tiers as needed.

Uniswap v2 introduced a protocol fee switch, which allowed a flat 5 basis point (16.66% of LP fees) fee to be turned on by governance. Uniswap v3 protocol fees are far more flexible. Fees will be off by default, but can be turned on by governance on a per-pool basis and set between 10% and 25% of LP fees.

Advanced Oracles

Uniswap v2 introduced time weighted average price (TWAP) oracles. These oracles serve as a critical piece of DeFi infrastructure, and have been integrated into dozens of projects, including Compound and Reflexer.

V2 oracles work by storing cumulative sums of Uniswap pair prices on a per-second basis. These price sums can be checked once at the beginning of a period and once at the end to calculate an accurate TWAP over that period.

Uniswap v3 offers significant improvements to the TWAP oracle, making it possible to calculate any recent TWAP within the past ~9 days in a single on-chain call. This is achieved by storing an array of cumulative sums instead of just one.

This array of historical price accumulators makes it far easier and cheaper to create more advanced oracles that include simple-moving averages (SMA), exponential moving averages (EMA), outlier filtering, and more.

Despite this major improvement, the gas cost to Uniswap traders for keeping oracles up to date has been reduced by ~50% relative to v2. The costs for calculating TWAPs in external smart contracts is significantly cheaper as well.

License

We strongly believe decentralized financial infrastructure should ultimately be free, open-source software. At the same time, we think the Uniswap community should be the first to build an ecosystem around the Uniswap v3 Core codebase.

With this in mind, Uniswap v3 Core will launch under the Business Source License 1.1—effectively a time-delayed GPL-2.0-or-later license. The license limits use of the v3 source code in a commercial or production setting for up to two years, at which point it will convert to a GPL license into perpetuity.

Uniswap governance can accelerate the change to GPL or grant exemptions to the license at any time by updating the files at _ v3-core-license-date.uniswap.eth _ and _ v3-core-license-grants.uniswap.eth _.

Note that the BUSL 1.1 license does not affect integrations. All code that may be needed for external integrations has been licensed under GPL or MIT , including math libraries, peripheral contracts, interfaces, and the developer sdk. Any wallet, interface, mobile app, protocol, or other project will be able to integrate with v3 as expected.

For more information on this license, see this FAQ.

Audits and Bug Bounty

Our team believes security is of the utmost importance — it took hundreds of hours of testing for us to feel comfortable with launching Uniswap v3.

Our security process for v3 included:

A full-length audit from Trail of Bits

A full-length audit from ABDK

A full audit from samczsun (no report)

An auditing and review process from our engineering team

A comprehensive test suite, including the automated tools Echidna and Manticore

Major bugs discovered as part of the testing and auditing process were fixed. However, we would like to note that Uniswap v3 is an extremely complex protocol and we cannot guarantee all bugs have already been discovered and resolved.

To help find any open vulnerabilities, a public bug bounty will run over the next 30 days, with up to $500,000 offered for critical bugs. More detail on the public bug bounty can be found here.

Launch Details

The Uniswap v3 smart contracts will be deployed to the Ropsten, Rinkeby, Kovan, and Görli testnets in the coming days, giving developers time to begin experimenting with the protocol before the official launch.

The Uniswap v3 Core repository contains the essential, low-level smart contracts that power the protocol.

The Uniswap v3 Periphery repository contains a collection of smart contracts designed to ease user interaction with core contracts.

A liquidity provider migration portal will be available at launch, allowing v2 LPs to seamlessly transfer their liquidity to the new protocol.

In the meantime, there are few outstanding items to complete:

Partners and integrations can begin building on Uniswap v3 immediately, in preparation for mainnet launch!

The interface, analytics site, API, and developer SDK are being redesigned to work with Uniswap v3.

The initial Uniswap v3 router and position manager contracts are almost complete. While still subject to change, they are available here.

Documentation, guides, and further examples are in progress.

Additional infrastructure to support fungibile positions, liquidity mining, more complex strategies, and various other use cases will be built by Uniswap Labs together with the Uniswap community after mainnet launch

Reach out

On Friday, March 26 at 2pm ET we will host an AMA on the official Uniswap Discord, where we hope to answer any outstanding questions you may have around Uniswap v3. Questions can be submitted ahead of time here.

We will be releasing further updates, additional information, and initial documentation over the coming days and welcome all feedback and involvement from our community.

If you are integrating and wish to get in touch, please fill out this form and we will try to respond as soon as possible. Alternatively, reach out in the #v3-integrations channel in the community Discord

To get involved and stay up to date:

Join the Uniswap community discord

Follow Uniswap on Twitter

Subscribe to the Uniswap blog

Register as a delegate Sybil

Participate in Uniswap governance

Uniswap Team

Concentrated LiquidityCapital EfficiencyActive LiquidityRange OrdersNon-Fungible LiquidityFlexible FeesAdvanced OraclesLicenseAudits and Bug BountyLaunch DetailsReach outRelated posts May 05, 2021Uniswap v3 Mainnet launch March 23, 2020Uniswap v2 Overview June 01, 2023Uniswap 101: What is Uniswap? | Uniswap L

Uniswap v3 Mainnet launch

wap v3 Mainnet launch Uniswap Labs BlogLaunch AppBackUniswap v3 Mainnet launch May 05, 2021# ProtocolsWe're thrilled to announce that Uniswap v3 has been deployed to the Ethereum mainnet! All relevant contract addresses can be found here.

Uniswap v3 is the most powerful version of the protocol yet, with Concentrated Liquidity offering unprecedented capital efficiency for liquidity providers, better execution for traders, and superior infrastructure at the heart of decentralized finance.

For a full description of v3's features, please refer to our announcement blog post. Audit reports for the core and periphery contracts can be found here and here. After 6 weeks, the Uniswap v3 bug bounty has returned no major findings. However, we would like to note that v3 is a complex new protocol and we cannot guarantee all bugs have been found and resolved.

Traders

The swap interface now routes trades through Uniswap v3 and will alert you when a better exchange rate is available on Uniswap v2.

The Uniswap analytics platform — info.uniswap.org — now tracks v3 performance. You can continue to review v2 stats here.

Liquidity providers

The pool interface now supports the creation of Uniswap v3 positions with multiple fee tiers and concentrated liquidity ranges. Each position is represented as an NFT and comes with a unique piece of on-chain generative art. Look out for rare sparkles!

We have also released a migration portal for Uniswap v2 and Sushiswap LPs to seamlessly migrate their assets over to v3. Due to the introduction of concentrated liquidity, the migration portal requires LPs to specify a fee tier and price range for their allocated liquidity. A migration walkthrough guide can be found here.

Developers

Developers can begin building on Uniswap v3 immediately!

Initial documentation and example projects can be found here. Additionally, the Uniswap Labs team will be available to answer integration-related questions in our Discord's #integrations channel.

Contact

The Uniswap Labs team will be available to answer questions in the Uniswap community Discord.

Follow the Uniswap Labs Twitter account for more updates!

FAQ:

1. What happens to the Uniswap v2 protocol?

The Uniswap v2 Protocol will remain functional and available for use as long as the Ethereum network continues to exist. However, we expect that over time the advantages of Uniswap v3 will draw a majority of liquidity and trading volume away from v2.

2. Do I have to migrate my liquidity?

You are not required to migrate your v2 liquidity if you so choose. The Uniswap v2 protocol will remain active and functional in perpetuity. However, it may be advantageous to migrate liquidity as we expect a majority of trading volume — and, consequently, LP fee generation — to take place on v3.

3. Will the updated Uniswap interface only execute trades through v3?

The updated interface will default to executing on v3 but will always alert you if a better trade is available on v2.

4. Is there a v3 liquidity mining program?

There is no v3 liquidity mining program scheduled at launch. Uniswap governance may introduce a liquidity mining program at any time through the standard Uniswap governance process.

To get involved and stay up to date:

Join the Uniswap community discord

Follow Uniswap on Twitter

Subscribe to the Uniswap blog

Register as a delegate Sybil

Participate in Uniswap governance

Uniswap Team

TradersLiquidity providersDevelopersContactFAQ:Related posts May 18, 2020Uniswap v2 Mainnet Launch March 23, 2021Introducing Uniswap v3 June 01, 2023Uniswap 101: What is Uniswap? | Uniswap L

深入认识 UniswapV3,看这一篇文章就够了 - 知乎

深入认识 UniswapV3,看这一篇文章就够了 - 知乎切换模式写文章登录/注册深入认识 UniswapV3,看这一篇文章就够了知乎观察这篇文章主要是对UniswapV3进行深入的分析和对未来的展望。UniswapV3, 使得Uniswap地位超越了其他去中心化交易所(DEX, Decentralized Exchange)。UniswapV3新功能:1. 集中资金池 (Concentrated Liquidity): 让流动性提供者 (LP, Liquidity Provider) 自行决定将提供的资产注入在哪个价格区间。2. 三级手续费 (Multiple fee tiers): 根据自己提供的币种价格浮动风险,LP可以选择收取不同的手续费。好处:减低价格滑动 (Slippage)增加LP回报提供限价盘的可能性文章目录1. Uniswap简介2. Uniswap V2的问题3. Uniswap V3的主要新功能4. 其他新功能5. 给参与者带来的好处6. Uniswap V3的不足7. Uniswap V3未来发展8. 关于DEX创新平台的发展1. Uniswap简介Uniswap是一个去中心化加密货币交易平台,利用Automated Market Makers (AMM)方式运作。让大众将加密货币注入流动资金池成为LP,为流动资金池提供资金也同时赚取交易手续费用。Uniswap的AMM模式不需要传统加密货币交易平台这样将买家卖家对接,V1以及V2的Uniswap依靠单一常数方程式 (Constant Product Formula) ,去计算每个资金池所需要的加密货币组合(Trading Pairs)数量比例以及货币价格:x * y =kUniswap V1、V2就是靠这条简单方程式去运作,x和y分别代别一个交易对的资金池的数量,而x与y的积k就是一个永恒不变的数字。2. Uniswap V2问题AMM绝对是一个十分聪明的做法,有效以去中心化方式让用户交换(Swap)加密货币,同时让LP赚取回报。可是,这简单的方程式有两个大问题:滑点、低效的资金池。滑点是预计交易价格同实际交易价格的差异,一般造成这种差异是由于流动性不足,这个情况无论是传统买卖盘对接平台或者AMM去中心化交易方式都会出现。举例:假设今天1ETH=2,500DAI,而整个Uniswap V2里面只有1ETH及2,500DAI(极端例子比较容易理解),我要在Uniswap买0.2ETH相当于买了整个资金池20%的ETH;根据上述的方程式计算,我买入0.2ETH便需要付出625DAI(被买了0.2ETH后资金池剩下0.8ETH, 当x变成0.8, k要维持2,500, y便变成3,125, 也就我要注入625DAI到资金池换取0.2ETH),即是ETH价格由2,500DAI变了3,125DAI。相信大家如果有在Uniswap进行大额交易,亲身领会过Uniswap V2 滑点问题有多严重。低效的资金池滑点对交易者有影响,同时对LP也有影响。那条简单的方程式其实是意味住将资金平均分布在x*y=k这条曲线上面,资产价格由0至无限大,因此实质大部份资产都无被利用去赚取手续费用。举例:假设今天1ETH=2,500DAI,而整个Uniswap V2里面这次有比较充裕的资金池: 100ETH和250,000DAI,如果仍然有人要买0.2ETH,这次便不会有很大的滑点,只需付出501DAI便可以(计算方法同上),即是价格相等于2,505DAI。但如果要买10ETH情况又如何?价格便升至2,778DAI,滑点超过11%。作为一个精明的消费者,看到那么高滑点,自然不会交易。这个例子就正好说明资金池内大部份的资金根本用不着,未能有效赚取交易手续费用。3. Uniswap V3新功能Uniswap V3 主要增加了2个新功能:集中资金池 (Concentrated Liquidity) : 让LP自己选择将资金注入在一个自定义的价格范围,只有实际价格在范围之内先分享到交易手续费,但变相令注入的资金更集中赚取回报,减少浪费。不同收费选择 (Multiple fee tiers) : 让LP根据注入资金的风险设定收取的回报。集中资金池 (Concentrated Liquidity)Uniswap V2将资金池的资金平均地分布在 x*y=k 这条公式上,价格由0到无限大都有同等的资产备用。而由于大部份资产价格其实一般都只是一个细的范围浮动,所以变相大部份注入的流动性都无充份利用到。最极端的例子就是稳定币同稳定币的组合,例如USDC-DAI的价格就维持在$0.99 - $1.01,大部份注入的资产就浪费了,但赚取不到回报。Uniswap V3比LP将流动资金池集中在一个自定义的价格范围,只要实际价格在这个范围里面浮动就可以赚到手续费。而且每个LP可以注资到不只一个价格范围,例如我可以将$100注资到ETH/DAI $1,000-$1,500这范围,同时间将$80注资到ETH/DAI $1,400-$1,800这范围。利用这个集中流动性,就是由LP决定不同价格资金池的运作。假设LP会留意巿况而作出调整,可以预期最多资金会停留于离现价最近的范围,越远离则越少资金,大大提升资产在资金池的作用。因为资金集中了,与V2比较只需要较少的资金就可以达到同样的回报效果。例如我将$100放到ETH/DAI $1,512-$2,208这范围,所得到的手续费的回报是UniswapV2的11.07倍。大家可以到Uniswap提供的“资金效能比较计算机”去输入不同范围比较一下,范围越窄,资金发挥的效能也越大!价格离开设定范围刚才讲的例子都是实际价格一直处于设定的范围内浮动,如果价格离开自定义的范围又如何呢?首先,如果实际价格超越(高于或者低于)设定范围,LP便不会赚取交易费用。LP注入的两个货币的数量会随价格变动,到超越范围时,所有资产会转换成为价格较低的货币,直至价格再次回到范围内才会再转换回去。三级收费 (Multiple fee tiers)Uniswap V3 的LP注入资金池时自行选择每对货币的三个级别交易费用,分别係0.05%、 0.30%、1.00%。本质上就是LP根据注入的资产价格的稳定程度收取不同回报。例如:稳定币的币对风险相对低,所收取回报就自然最低。一般的币对,例如ETH/DAI,就收取0.30%;而一些较高风险的货币,例如新发行货币,就可以选择1%作为回报。LP可以选择手续费,但是交易者就不可以选择。Uniswap V3 会根据你需要交易的数量,按照价格范围资金池的情况计算手续费用。笔者就试过同样的交易ETH/DAI,交易0.1ETH的交易费用是0.05%,但是10 ETH就会变成0.3%。4. 其他新功能Tick(挂单簿)不可替代资金池 (Non-Fungible Liquidity)更先进的Oracles使用准证 (License)TickTick是证券巿场用语,形容证券价格向上/向下浮动的最低价格,简单来说就是挂单簿上面的每一行就是一个Tick。Uniswap V3将AMM上的价格都分为Ticks。有别于传统挂单簿,每个Tick是由系统定义价格范围而不是由投资者自定义(LP输入价格范围时会见到系统自动微调个数字,这个微调就是调校到最接近的Tick),每个Tick之内的交易都是根据AMM的价格方程式去计算。因此每个交易会在滑点范围之内根据AMM方程式计算,而不需要根据挂单簿上投资者自订的价格去成交。Tick是Uniswap加入的一个价格浮动单位,加入Tick使得Uniswap可以同时兼备AMM和中心化交易所的好处。不可替代资金池 (Non-Fungible Liquidity)现在每个LP都有不同Price 曲线,LP会以Non-Fungible Tokens (NFT)来代表。而同V2不同,LP赚到的手续费不再包含在流动性里面,而是分开显示。OraclesUniswap在Defi中扮演着一个重要角色: 价格提供者。向不同Defi,例如Compound, 透过他们的Price Oracle提供加密货币的价格。Uniswap V2推出了Time Weighted Average Price (TWAP) Oracles – Uniswap每秒记录的每对加密货币价格,只要设定开始时间及一个结束时间,就可以获取这段时间的TWAP。Uniswap V3的orcales就变得更加弹性,无需要设定开始时间,在任意一个时间点都可以获取9日之内的TWAP。LicenseUniswap V3的Business Source License 1.1发布,Uniswap V3的源码被禁止任何商业或者开发用途,直至两年后才会完全开源。虽然Uniswap没有明言,但不难想像这个做法是为了防止上次Sushiswap事件再次发生。5. 给参与者带来的好处降低滑点最直接的好处就是降低买/卖价格滑点。弥补了Uniswap V2的不足。“限价盘”Range Order买/卖家可以做“限价盘”,Uniswap称之为 “Range Order”。上面讲到,如果实际价格超越(高于/低于)LP设定的价格范围,属于他的资金池里面的资产会全部被转换成价格较低的一个资产。LP因此可以利用这个特性设定一个很小的价格范围做到限价盘的效果。举例:假设今天ETH/DAI=1,500,我想设定在ETH/DAI=1,300时买入价值$10,000的ETH。我就要将$10,000资金注入到ETH/DAI资金池,然后设定一个很小的价范围,例如 1,300-1,305。当ETH价格下降到1,305, 这个LP就开始成为能够赚取手续费的有效LP,而当ETH价格继续下滑,降到1,300, LP里面DAI的数量就会随着价格方程式下滑全数转换成为ETH。增加LP回报有了集中资金池,LP注入的资金不再被浪费掉,因此注入较少资金已经可以达到V2相同的回报,资金效能发挥得更高水平。最高可以将LP价格范围缩窄到0.1%,资金效能是V2的4000倍。6. Uniswap V3的不足面临更大无尝损失的风险相信大家如果认识Uniswap,对无尝损失绝不会陌生。当LP的资产价格浮动,资产数量根据AMM 价格方程式作出变化,这个变化会令流动性提供者可能遭受损失。V2的价格方程式 x*y=k在这个范围[0,∞],而V3 的集中资金池,每一个自定义价格范围里面都有自己的价格方程式。当LP的价格范围由[0,∞]缩小到一个自定义的范围,无尝损失的风险就会变得更大。7.未来发展Uniswap V3在ETH主网上线了,即将在币安智能链 (BSC)上线。这会使得交易的gas降低到ETH主网的10%,有利于Uniswap V3的发展。8. 关于 DEX 创新平台的发展Uinswap的源码许可证即将到期,不久又会有不少更新型的AMM项目出现。Defi最近这几年可以拿得出来说的项目基本没有,期望今年会有新的突破。在DEX,笔者最近关注到一个 DefiEarning 的项目,一个在 PancakeSwap 上面做量化交易的平台,是一个国外知名量化交易团队打造的,充值和提现都是 usdt。这个项目的具体信息可以在 google 查询。 发布于 2023-02-03 13:16・IP 属地广东社论​赞同 5​​1 条评论​分享​喜欢​收藏​申请

Uniswap Wallet

Uniswap Wallet

Uniswap in your pocket.

Safe, simple swapping & self-custody.

Uniswap in your pocket.

Safe, simple swapping & self-custody.

Uniswap in your pocket.

Safe, simple swapping & self-custody.

Learn more

Swap on multiple chains

Supports Ethereum, Polygon, Optimism, and Arbitrum.

One simple wallet

All your NFTs, tokens, and wallets in one place

Safe and secure by design

Built by the most trusted team in DeFi.

Swap on multiple chains

Supports Ethereum, Polygon, Optimism, and Arbitrum.

One simple wallet

All your NFTs, tokens, and wallets in one place

Safe and secure by design

Built by the most trusted team in DeFi.

Swap onmultiple chains

Supports Ethereum, Polygon, Optimism, and Arbitrum.

One simple wallet

All your NFTs, tokens, and wallets in one place

Safe and secure

Built by the most trusted team in DeFi.

Resources

Download

Support

Other Products

Swap Tokens

Explore NFTs

Learn more

Blog

Discord

Twitter

© Universal Navigation Inc.

Resources

Download

Support

Other Products

Swap Tokens

Explore NFTs

Learn more

Blog

Discord

Twitter

© Universal Navigation Inc.

Resources

Download

Support

Other Products

Swap Tokens

Explore NFTs

Learn more

Blog

Discord

Twitter

© Universal Navigation Inc.

Uniswap V3 | Uniswap V3 Book 中文版

wap V3 | Uniswap V3 Book 中文版

Uniswap V3 Book 中文版Milestone 0. 简介交易市场简介恒定函数做市商(CFMM)Uniswap V3开发环境Milestone 1. 第一笔交易简介计算流动性提供流动性第一笔交易管理合约部署合约用户界面Milestone 2. 第二笔交易简介输出金额计算Solidity中的数学运算Tick Bitmap Index通用mint通用swap报价合约用户界面Milestone 3. 跨tick交易简介不同价格区间跨tick交易滑点保护流动性计算关于定点数的拓展闪电贷用户界面Milestone 4. 多池子交易简介工厂合约交易路径多池子交易用户界面Tick 舍入Milestone 5. 费率和价格预言机简介交易费率闪电贷费率协议费率价格预言机用户界面Milestone 6: NFT positions简介ERC721 概述NFT 管理员合约NFT 渲染器补充资料中英名词对照

Uniswap V3

Uniswap V3简介集中流动性Uniswap V3 的数学原理价格Ticks

\[ \]Uniswap V3简介

#本章节主要讲述了 Uniswap V3白皮书中的内容。同样,假设你没有理解本章的所有概念也没有关系,我们在后面章节直接看代码可能会更清晰。为了更好地理解 Uniswap V3 的创新之处在哪里,我们首先来看 Uniswap V2 的缺点有哪些。Uniswap V2 使用 AMM 机制实现了一个通用的交易市场。然而,并不是所有的交易对都是一样的,交易对可以根据价格的波动性分为以下两类:价格波动性中等或较高的代币对。大多数代币对都属于这一类,因为绝大多数代币并没有锚定(pegged to)到某些东西,因此其价格随着市场波动而波动。价格波动性低的代币对。这一类包含了有锚定的代币,主要为稳定币:USDT/USDC,USDC/DAI,USDT/DAI 等等。也包括 ETH/stETH,ETH/rETH(一些 wrapped ETH)等类型。这些不同的代币对,对于流动性池的配置有不同的要求。最主要的区别在于,锚定代币对需要非常高的流动性来降低大额交易对其价格的影响。USDC与USDT的价格必须保持在1附近,无论我要买卖多大数目的代币。由于 Uniswap V2 的通用 AMM 算法对于稳定币交易并没有很好的适配,所以在稳定币的交易中其他的 AMM(主要是Curve)更加流行。导致这个问题出现的原因是,Uniswap V2 池子的流动性是分布在无穷区域上的——池子允许在任何价格的交易发生,从0到正无穷:这听起来好像不是一个坏事,但事实上它导致了资产利用效率的不足。一个资产的历史价格通常是在某个区间内的,不管这个区间是大还是小。比如,ETH的历史价格大致在 $0.75

到 $4,800 这个区间(数据来源 CoinMarketCap)。在今天(2022年6月),1 个 ETH 的现货价格是 $1800,没有人会愿意用 $5000 购买一个 ETH,所以在这个价格上提供流动性是毫无用处的。因此,在远离当前价格区间的、永远不会达到的某个点上提供流动性是毫无意义的。当然,我们都相信ETH的价格某天会达到 $10000集中流动性

#Uniswap V3 引入了 集中流动性(concentrated liquidity) 的概念:LP 可以选择他们希望在哪个价格区间提供流动性。这个机制通过将更多的流动性提供在一个相对狭窄的价格区间,来大大提高资产利用效率;这也使 Uniswap 的使用场景更加多样化:它现在可以对于不同价格波动性的池子进行不同的配置。这就是 V3 相对于 V2 的主要提升点。简单地来说,一个 Uniswap V3 的交易对由许多个 Uniswap V2 的交易对构成。V2 与 V3 的区别是,在 V3 中,一个交易对有许多的价格区间,而每个价格区间内都有一定数量的资产。从零到正无穷的整个价格区间被划分成了许多个小的价格区间,每一个区间中都有一定数量的流动性。而更关键的点在于,在每个小的价格区间中,工作机制与 Uniswap V2 完全一样。这也是为什么我们说一个 Uniswap V3 的池子就是许多个 V2 的池子。下面,我们来对这种机制进行可视化。我们并不是重新选择一个有限的曲线,而是我们把它在价格 $a$ 与价格 $b$ 之间的部分截取出来,把它们当作是是曲线的边界。更进一步,我们把曲线进行平移使得边界点落在坐标轴上,于是得到了下图:它看起来或许有点单调, 因此 Uniswap V3 有许多的价格区间——这样它们就不会感到孤单了 正如我们在前一章中讲到的那样,交易 token 使得价格在曲线上移动,而价格区间限制了价格点的移动。当价格移动到曲线的一端时,我们说这个池子被耗尽了:其中一种代币的资产变成了 0,无法再购买这种代币(当然,仅仅指在这个价格区间内)。假设起始价格在上图中曲线的中间一点。为了到达点 $a$,我们需要购买池子里所有的 $y$ 来使得池子里的 $x$ 最大化;为了到达点 $b$,我们需要买光池子里的 $x$ 从而使 $y$ 最大化。在这两个点,池子里都只剩一种 token。一个有趣的事实:根据这个原理,可以利用V3的价格区间来挂限价单。如果当前价格区间池子被耗尽将会发生什么?价格点会滑动到下一个价格区间。如果下一个价格区间不存在,这笔交易就会以部分成交而结束——我们将在本书后面的部分看到其如何实现。下面一图展示了 USDC/ETH 池子的流动性分布:可以看到,大量流动性集中在现价的附近,而较远的价格区间中的流动性较少——这是因为 LP 更希望提高它们的资产利用效率。当然,整个区间也不是无穷的,在图片右侧也显示了其上界。Uniswap V3 的数学原理

#在数学原理上,V3 是基于 V2 的:它们使用了相同的底层公式,但实际上 V3 使用的是增强版。为了处理价格区间之间的转换,简化流动性管理,以及避免取整出现问题,V3 使用了下面这些新的标识:$$L = \sqrt{xy}$$$$\sqrt{P} = \sqrt{\frac{y}{x}}$$$L$ 被称作 流动性数量。池子中的流动性是两种 token 资产数量的组合。我们知道,按照公式,两种代币数量乘积为 $k$,因此我们可以用 $\sqrt{xy}$ 来衡量池子流动性。$L$ 实际上是 $x$ 和 $y$ 的几何平均数。$y/x$ 是 token0 相对于 token1 的价格。由于池子里两种代币的价格互为倒数,我们在计算中仅使用其中一个( Uniswap V3使用的是 $y/x$)。token1 相对于 token0 的价格即为 $\frac{1}{y/x}=\frac{x}{y}$。类似地, $\frac{1}{\sqrt{P}} = \frac{1}{\sqrt{y/x}} = \sqrt{\frac{x}{y}}$.我们使用 $\sqrt{P}$ 而不是 $P$ 有两个原因:平方根计算并不精确并且会引入取整的问题。因此,更简单的方法是我们干脆就在合约中存平方根的结果,而不是在合约中计算它。(合约中并不存储 $x$ 和 $y$ )$\sqrt{P}$ 与 $L$ 之间有一个有趣的关系:$L$ 也表示了输出数量的变化与 $\sqrt{P}$ 的变化之间的关系:$$L = \frac{\Delta y}{\Delta\sqrt{P}}$$证明:

$$L = \frac{\Delta y}{\Delta\sqrt{P}}$$$$\sqrt{xy} = \frac{y_1 - y_0}{\sqrt{P_1} - \sqrt{P_0}}$$$$\sqrt{xy} (\sqrt{P_1} - \sqrt{P_0}) = y_1 - y_0$$$$\sqrt{xy} (\sqrt{\frac{y_1}{x_1}} - \sqrt{\frac{y_0}{x_0}}) = y_1 - y_0$$$$\sqrt{y_1^2} - \sqrt{y_0^2} = y_1 - y_0$$$$y_1 - y_0 = y_1 - y_0$$(译者注:第四步到第五步,$\sqrt{xy} = \sqrt{x_0y_0} = \sqrt{x_1y_1}$ )价格

#同样,我们并不需要计算准确的价格——我们可以直接计算获得的token数量。并且,由于我们在合约中并不存储 $x$ 和 $y$,我们将仅通过 $L$ 和 $\sqrt{P}$ 进行计算。根据上文中的公式,我们能得到 $\Delta y$:$$\Delta y = \Delta \sqrt{P} L$$见上述证明中的第三步。正如上面所说,双方的价格互为倒数。因此,$\Delta x$ 的公式为:$$\Delta x = \Delta \frac{1}{\sqrt{P}} L$$$L$ 和 $\sqrt{P}$ 让我们不再需要存储和更新池子资产数量。并且,我们也并不需要每次都重新计算 $\sqrt{P}$ 因为我们从上述公式可以得到 $\Delta \sqrt{P}$。Ticks

#正如我们前面说到的,V2 中的无穷价格区间在 V3 中被分成了更小的价格区间,每个区间都由上下界端点进行限制。为了进行这些边界的协调,V3引入了 ticks。在 V3,整个价格区间由离散的、均匀分布的 ticks 进行标定。每个 tick 有一个 index 和对应的价格:$$p(i) = 1.0001^i$$$p(i)$ 即为 tick $i$ 的价格. 使用 1.0001 的幂次作为标定有一个很好的性质:两个相邻 tick 之间的差距为 0.01% 或者一个基点。基点 (1% 的百分之一,或者 0.01%,或者 0.0001)是在金融中用来衡量百分比的一个单位。你可能在央行宣布对于利率的调整中听过基点这个名词。正如我们之前讨论的,Uniswap V3 存储的是 $\sqrt{P}$ 而不是 $P$。所以这个公式实际上是:$$\sqrt{p(i)} = \sqrt{1.0001}^i = 1.0001 ^{\frac{i}{2}}$$我们得到的值大概是这样:$\sqrt{p(0)} = 1$, $\sqrt{p(1)} = \sqrt{1.0001} \approx 1.00005$, $\sqrt{p(-1)} \approx 0.99995$.Ticks 可以为正也可以为负,并且显然它不是无穷的。V3 把$\sqrt{P}$ 存储为一个 Q64.96 类型的定点数,使用 64 位作为整数部分,使用 96 位作为小数部分。因此,价格的取值范围是 $[2^{-128}, 2^{128}]$,ticks 的取值范围是:$$[log_{1.0001}2^{-128}, log_{1.0001}{2^{128}}] = [-887272, 887272]$$如果希望对于 Uniswap V3 的数学原理有更深的理解,推荐这篇技术文章,作者为 Atis ElstsUniswap V3简介集中流动性Uniswap V3 的数学原理价格Ti

部署合约 | Uniswap V3 Book 中文版

| Uniswap V3 Book 中文版

Uniswap V3 Book 中文版Milestone 0. 简介交易市场简介恒定函数做市商(CFMM)Uniswap V3开发环境Milestone 1. 第一笔交易简介计算流动性提供流动性第一笔交易管理合约部署合约用户界面Milestone 2. 第二笔交易简介输出金额计算Solidity中的数学运算Tick Bitmap Index通用mint通用swap报价合约用户界面Milestone 3. 跨tick交易简介不同价格区间跨tick交易滑点保护流动性计算关于定点数的拓展闪电贷用户界面Milestone 4. 多池子交易简介工厂合约交易路径多池子交易用户界面Tick 舍入Milestone 5. 费率和价格预言机简介交易费率闪电贷费率协议费率价格预言机用户界面Milestone 6: NFT positions简介ERC721 概述NFT 管理员合约NFT 渲染器补充资料中英名词对照

部署合约

部署选择本地网络运行本地区块链第一次部署与合约交互,ABIToken余额现在的 tick 和价格ABI

\[ \]部署

#我们的第一版合约已经完成了。现在,让我们来看看如何把它部署在一个本地以太坊网络上,方便我们之后用前端 app 交互。选择本地网络

#智能合约的开发需要运行一个本地的网络来在开发过程中进行部署和测试。这样的网络需要具有以下特点:真实的区块链。它必须是一个真实的区块链网络而不是一个模拟器,我们希望我们的合约如果能够在这样的网络上正常工作,那也一定能在主网上正常工作;速度。我们希望我们的交易能够快速被执行,这样我们能快速迭代;以太币。为了支付gas费,我们需要一些eth,因此我们希望这个网络能够允许我们生成任意数量的eth;cheat code。除了提供标准的 API,我们还希望这个网络能让我们做更多的事,例如:在任何地址上部署合约,以任何地址执行交易,直接修改合约状态等等。今天,有许多的工具能够提供这样的功能:Truffle套件中的GanacheHardhat,一套智能合约开发环境,除了包含本地网络节点以外还有很多有用的工具Foundry中的Anvil所有这些解决方案都能够满足我们的需求。尽管如此,项目现在都逐渐从 Ganache(最早的解决方案)迁移到 Hardhat(目前使用最广的方案),而 Foundry 也成为开发者的新宠。Foundry 也是上述三个方案中唯一使用 Solidity 来编写测试的框架(其他框架都使用 JavaScript)。除此以外,Foundry 还允许使用 Solidity 来编写部署脚本。因此,由于我们想一直使用 Solidity,我们会使用 Anvil 来运行一个本地区块链,并且使用 Solidity 编写部署脚本。运行本地区块链

#Anvil 不需要进行配置,我们可以直接在命令行运行:$ anvil

_ _

(_) | |

__ _ _ __ __ __ _ | |

/ _` | | '_ \ \ \ / / | | | |

| (_| | | | | | \ V / | | | |

\__,_| |_| |_| \_/ |_| |_|

0.1.0 (d89f6af 2022-06-24T00:15:17.897682Z)

https://github.com/foundry-rs/foundry

...

Listening on 127.0.0.1:8545

Anvil运行一个以太坊节点,所以它实际上并不是个网络,但也没什么问题。默认配置下它会创建 10 个账户,每个有 10000 ETH。它会把这些账户和对应私钥打印在命令行,我们会使用其中一个来部署合约和与其交互。Anvil在 127.0.0.1:8545 开放了 JSON-RPC API 接口——这个接口是与以太坊节点交互的主要方式。你可以在这里找到完整的 API 文档。在这里,你可以用 curl 与其交互:$ curl -X POST -H 'Content-Type: application/json' \

--data '{"id":1,"jsonrpc":"2.0","method":"eth_chainId"}' \

http://127.0.0.1:8545

{"jsonrpc":"2.0","id":1,"result":"0x7a69"}

$ curl -X POST -H 'Content-Type: application/json' \

--data '{"id":1,"jsonrpc":"2.0","method":"eth_getBalance","params":["0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","latest"]}' \

http://127.0.0.1:8545

{"jsonrpc":"2.0","id":1,"result":"0x21e19e0c9bab2400000"}

你也可以使用 cast(foundry 中的另一个组件)来访问:$ cast chain-id

31337

$ cast balance 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266

10000000000000000000000

现在,我们来将池子合约和管理合约都部署在本地网络上。第一次部署

#根本上来讲,部署一个合约意味着:将源代码编译成 EVM 字节码发送一个包含这些字节码的交易新建一个地址,执行字节码中构造函数的部分,将初始化的字节码存放在该地址。这一步是由以太坊节点自动完成的,在这笔交易被打包上链时。部署通常包含很多个步骤:准备参数,部署辅助合约,部署主合约,初始化合约等等。脚本能帮助我们自动化完成这些步骤,并且我们现在能用 Solidity 来编写脚本!创建 scripts/DeployDevelopment.sol 文件,写入以下内容:// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.14;

import "forge-std/Script.sol";

contract DeployDevelopment is Script {

function run() public {

...

}

}

它看起来与测试合约十分相似,唯一的差别在于它继承自 Script 合约而不是 Test。并且按照惯例,我们需要定义一个 run 函数作为部署脚本的主体。在 run 函数中,我们首先定义部署需要的参数:uint256 wethBalance = 1 ether;

uint256 usdcBalance = 5042 ether;

int24 currentTick = 85176;

uint160 currentSqrtP = 5602277097478614198912276234240;

这些正是我们之前用过的值。这里我们需要铸造 5042 个 USDC——其中 5000 个用来提供流动性,42 个用来交易。接下来,我们定义一系列在部署过程中需要执行的交易(每一步都是独立的交易)。我们使用startBroadcast/endBroadcast这个 cheat code:vm.startBroadcast();

...

vm.stopBroadcast();

这些 cheat code 可以在 forge的文档中找到,我们是从继承的 forge-std/Script.sol 里面得到这些功能的。在 broadcast() cheat code后面,或者 startBroadcast()/stopBroadcast() 之间的所有语句都会被转化成交易,这些交易会被发送到执行这个脚本的节点。在这两个 cheat code 之间,我们开始真正的部署步骤。首先需要部署两种 token:ERC20Mintable token0 = new ERC20Mintable("Wrapped Ether", "WETH", 18);

ERC20Mintable token1 = new ERC20Mintable("USD Coin", "USDC", 18);

没有 token 我们就无法部署池子,因此需要先部署 token 合约。

(译者注:由于原生代币 ETH 没有 approve 功能,因此在这里使用的是 WETH。在各种金融协议中,原生 ETH 通常都被单独拿出来处理)由于我们是在本地网络上进行部署,我们需要自行部署对应的 token。在主网上和公开测试网上(Ropsten, Goerli, Sepolia),这些 token 已经被部署。因此,如果想要在这些网络上进行部署,我们需要写网络特定的部署脚本。接下来就是部署池子合约:UniswapV3Pool pool = new UniswapV3Pool(

address(token0),

address(token1),

currentSqrtP,

currentTick

);

然后部署管理合约:UniswapV3Manager manager = new UniswapV3Manager();

最后,我们给我们自己的地址铸造一些token用来之后交易:token0.mint(msg.sender, wethBalance);

token1.mint(msg.sender, usdcBalance);

在Foundry脚本中,msg.sender 是在 broadcast 块中发送交易的地址。我们可以在运行脚本的时候对其进行设置。在脚本的最后,使用 console.log 打印出对应的地址信息:console.log("WETH address", address(token0));

console.log("USDC address", address(token1));

console.log("Pool address", address(pool));

console.log("Manager address", address(manager));

现在我们来运行这个脚本(确保 Anvil 在另一个窗口中正在运行):$ forge script scripts/DeployDevelopment.s.sol --broadcast --fork-url http://localhost:8545 --private-key $PRIVATE_KEY

--broadcast 启动交易的广播。它并不是默认开启的因为并不是每一个脚本都需要发送交易。--fork-url 设置我们要发送交易的节点地址。--private-key 设置调用者的钱包:需要私钥来签名交易。我们可以选择之前 Anvil 启动时在命令行打印出来的任何一个私钥。作者选择了第一个地址和私钥。部署需要消耗几秒钟。最后,你会看到它发送了一系列的交易。它同时也将交易收据存在了 broadcast 文件夹。在 Anvil 运行的窗口里,你也能看到很多行例如 eth_sendRawTransaction, eth_getTransactionByHash,

和 eth_getTransactionReceipt 这样的信息——在你向 Anvil 发送交易后,Forge 使用 JSON-RPC API 来检查它们的状态并且获得交易执行的结果(收据)。恭喜!你刚刚成功部署了一个智能合约!与合约交互,ABI

#现在,让我们来看看我们如何与已经部署的合约交互。每个合约都由一系列的public函数开放。以池子合约为例,包含 mint(...) 和 swap(...)。除此之外,Solidity 为每一个 public 的变量创建了 getter,所以我们也可以调用 token0(),token1(),positions() 等等,来访问对应变量的值。然而,由于合约都被编译成字节码,函数名在编译过程中丢失并且不存储在区块链上。在链上,每个函数都用一个函数选择器(selector)来表示,即函数签名哈希的前 4 字节。伪代码为:hash("transfer(address,address,uint256)")[0:4]

EVM 使用的是 Keccak 哈希算法,标准化名字为 SHA-3。特别地,Solidity 中的哈希函数名字为keccak256。根据以上信息,我们展示两种对于部署的合约进行调用的方法:一种使用 curl 来进行底层的调用,一种使用 cast。Token余额

#我们来检查一下部署者地址种的WETH余额。这个函数的签名是 balanceOf(address)(在 ERC-20 标准中定义),为了计算这个函数的 ID(即选择器),我们计算哈希并取前 4 字节:$ cast keccak "balanceOf(address)"| cut -b 1-10

0x70a08231

要把地址作为参数传递进去,我们把它附在函数选择器的后面(在左边 padding 到 32 个字节,因为地址在函数调用中占 32 字节):0x70a08231000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 是我们要查看余额的地址。这是本书选择的部署者的地址,也是 Anvil 创建时的第一个地址。接下来,我们会使用 eth_call JSON-RPC 方法来进行这个调用。注意到,这一步不需要发送一个交易——我们仅仅是从合约中读取数据。$ params='{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","to":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","data":"0x70a08231000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266"}'

$ curl -X POST -H 'Content-Type: application/json' \

--data '{"id":1,"jsonrpc":"2.0","method":"eth_call","params":['"$params"',"latest"]}' \

http://127.0.0.1:8545

{"jsonrpc":"2.0","id":1,"result":"0x00000000000000000000000000000000000000000000011153ce5e56cf880000"}

“to” 地址是 USDC token 的地址,它是在上一步部署脚本运行时打印出的日志里面的地址。以太坊节点返回的结果是字节流,为了理解结果我们需要知道返回值的类型。在 balanceOf 函数中,返回值的类型是 uint256。用 cast 可以把结果转换成十进制然后转换成 ethers 单位:$ cast --to-dec 0x00000000000000000000000000000000000000000000011153ce5e56cf880000| cast --from-wei

5042.000000000000000000

余额是正确的,我们在自己的地址中有 5042 USDC。现在的 tick 和价格

#上述例子展示了底层的合约调用。通常来说,你永远不会使用 curl 来发起调用,而是使用某个更友好的工具或库。cast 在这里也能够帮助我们简化这一过程。我们来使用 cast 获得当前合约的 tick 和 price:$ cast call POOL_ADDRESS "slot0()"| xargs cast --abi-decode "a()(uint160,int24)"

5602277097478614198912276234240

85176

如此容易!第一个值就是我们的 $\sqrt{P}$,第二个值就是现在的 tick。由于 --abi-decode 需要完整的函数签名,我们必须声明一个函数名 “a()",尽管我们只是为了解码函数的输出。ABI

#为了简化与合约的交易,Solidity 编译器可以输出 ABI,Application Binary Interface(应用二进制接口)。ABI 是一个包含了合约中所有 public 方法和事件的 JSON 文件。文件的目的在于使得编码函数参数和解码函数输出都更加容易。我们可以通过 Forge 来获取 ABI:$ forge inspect UniswapV3Pool abi

可以看一看生成的文件,来更好地理解 ABI 意味着什么。部署选择本地网络运行本地区块链第一次部署与合约交互,ABIToken余额现在的 tick 和价格

4-部署完整版UniswapV3

完整版UniswapV3

Software QA RevisitedRevisit Software QA skills and Testing AutomationHomeArchivesSearchLinks暗色模式目录前言完善部署脚本修改deploy文件部署合约结语Solidity

SmartContract4-部署完整版UniswapV3Aug 16, 2023阅读时长: 5 分钟前言文接上回,我们已经部署了Uniswap的核心合约,接下来我们将部署完整版的UniswapV3。完整版的UniswapV3包含了以下合约:UniswapV3Factory (Pool生成合约)UniswapV3SwapRouter (包装类交易合约)NonfungiblePositionManager (NFT管理合约)NonfungibleTokenPositionDescriptor (NFT仓位描述合约)NFTDescriptor (NFT描述合约)WETH9 (WrapperETH)我们上一章节已经部署完成了前两个合约,那么我们这一章节就需要开始部署后续合约。其实部署方法都是一样的。只不过有一点点需要注意的地方是,NonfungibleTokenPositionDescriptor需要进行Library链接,将NFTDescriptor部署后作为Library链接到NonfungibleTokenPositionDescriptor中。接下来我们会继续完善我们的部署脚本,将这些合约都部署出来。完善部署脚本我们继续完善我们的部署脚本,将上一章节中部署的合约和这一章节中需要部署的合约都部署出来。因为部署方式和上一章节中的部署方式一样,所以我们只需要在00_deploy_univ3.ts中添加一些代码即可。

不过我们还需要添加一个WETH9的合约。我们上一章节中,在填写WETH9的位置直接使用了0地址代替,现在可不行了。所以我们先打开网址https://github.com/gnosis/canonical-weth/blob/master/contracts/WETH9.sol,复制里面的代码,然后在contracts文件夹下新建一个WETH9.sol文件,将代码粘贴进去。然后我们运行一下yarn hardhat compile,将合约编译一下。可以不出所料的出现一个错误。

这是因为我们的编译器版本不对,因为WETH9的合约是用>=0.4.22 <0.6的版本进行编译,而我们默认的是^0.8.0的版本,所以我们需要修改编译器的版本。不过得益于Hardhat的强大功能,我们可以设定多个版本的编译器,这样我们就能在多个版本的编译器下编译我们的合约了。

我们打开hardhat.config.ts,在solidity的配置项中添加一个compilers的配置项,将其设置为一个数组,数组中包含我们需要的编译器版本。 1

2

3

4

5

6

7

8

9

10

11

12

const config: HardhatUserConfig = {

solidity: {

compilers: [

{

version: '0.8.0',

},

{

version: '0.4.22',

},

],

},

};

修改完成后,我们再次编译。

轻而易举的就编译成功了。修改deploy文件我们打开00_deploy_univ3.ts,在main函数中添加一些代码。 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

import { utils } from 'ethers'

import { DeployFunction } from "hardhat-deploy/types";

import {

abi as FACTORY_ABI,

bytecode as FACTORY_BYTECODE,

} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'

import {

abi as SWAP_ROUTER_ABI,

bytecode as SWAP_ROUTER_BYTECODE,

} from '@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json'

import { HardhatRuntimeEnvironment } from "hardhat/types";

import {

abi as NFTDescriptor_ABI, bytecode as NFTDescriptor_BYTECODE

} from '@uniswap/v3-periphery/artifacts/contracts/libraries/NFTDescriptor.sol/NFTDescriptor.json'

import {

abi as NFTPositionManager_ABI, bytecode as NFTPositionManager_BYTECODE

} from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json'

import {

abi as NFTPositionDescriptor_ABI, bytecode as NFTPositionDescriptor_BYTECODE

} from '@uniswap/v3-periphery/artifacts/contracts/NonfungibleTokenPositionDescriptor.sol/NonfungibleTokenPositionDescriptor.json'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const { deployments, ethers } = hre

const [deployer] = await ethers.getSigners()

const factory = await deployments.deploy("UniV3Factory", {

from: deployer.address,

contract: {

bytecode: FACTORY_BYTECODE,

abi: FACTORY_ABI

},

})

const WETH9 = await deployments.deploy("WETH9", {

from: deployer.address

})

await deployments.deploy("UniV3SwapRouter", {

from: deployer.address,

contract: {

abi: SWAP_ROUTER_ABI,

bytecode: SWAP_ROUTER_BYTECODE

},

args: [factory.address, WETH9.address]

})

const NFTDescriptorlibrary = await deployments.deploy('NFTDescriptorLibrary', {

from: deployer.address,

contract: {

abi: NFTDescriptor_ABI,

bytecode: NFTDescriptor_BYTECODE

}

})

const linkedBytecode = linkLibrary(NFTPositionDescriptor_BYTECODE,

{

['contracts/libraries/NFTDescriptor.sol:NFTDescriptor']: NFTDescriptorlibrary.address

}

)

const positionDescriptor = await deployments.deploy('NFTPositionDescriptor', {

from: deployer.address,

contract: {

abi: NFTPositionDescriptor_ABI,

bytecode: linkedBytecode

},

args: [

WETH9.address,

// 'ETH' as a bytes32 string

'0x4554480000000000000000000000000000000000000000000000000000000000'

]

})

await deployments.deploy('NFTPositionManager', {

from: deployer.address,

contract: {

abi: NFTPositionManager_ABI,

bytecode: NFTPositionManager_BYTECODE

},

args: [factory.address, WETH9.address, positionDescriptor.address]

})

}

function linkLibrary(bytecode: string, libraries: {

[name: string]: string

} = {}): string {

let linkedBytecode = bytecode

for (const [name, address] of Object.entries(libraries)) {

const placeholder = `__\$${utils.solidityKeccak256(['string'], [name]).slice(2, 36)}\$__`

const formattedAddress = utils.getAddress(address).toLowerCase().replace('0x', '')

if (linkedBytecode.indexOf(placeholder) === -1) {

throw new Error(`Unable to find placeholder for library ${name}`)

}

while (linkedBytecode.indexOf(placeholder) !== -1) {

linkedBytecode = linkedBytecode.replace(placeholder, formattedAddress)

}

}

return linkedBytecode

}

export default func;

其实上面很多都是些重复的代码,我们需要关注两段内容。第一段是这个linkLibrary函数。 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

function linkLibrary(bytecode: string, libraries: {

[name: string]: string

} = {}): string {

let linkedBytecode = bytecode

for (const [name, address] of Object.entries(libraries)) {

const placeholder = `__\$${utils.solidityKeccak256(['string'], [name]).slice(2, 36)}\$__`

const formattedAddress = utils.getAddress(address).toLowerCase().replace('0x', '')

if (linkedBytecode.indexOf(placeholder) === -1) {

throw new Error(`Unable to find placeholder for library ${name}`)

}

while (linkedBytecode.indexOf(placeholder) !== -1) {

linkedBytecode = linkedBytecode.replace(placeholder, formattedAddress)

}

}

return linkedBytecode

}

他的作用是将文件中library的链接到Bytecode里面去,但是一般情况下,我们不会采用这种方式。因为从源码部署的时候,我们可以借助工具来简化这个过程。而library是一种极为有效的减少合约字节码的方式,在后续的文章中,我们会专门讲解这个问题。第二段是这个NFTDescriptorlibrary的部署。 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

const linkedBytecode = linkLibrary(NFTTokenPositionDescriptor_BYTECODE,

{

['contracts/libraries/NFTDescriptor.sol:NFTDescriptor']: NFTDescriptorlibrary.address

}

)

const positionDescriptor = await deployments.deploy('NFTPositionDescriptor', {

from: deployer.address,

contract: {

abi: NFTPositionDescriptor_ABI,

bytecode: linkedBytecode

},

args: [

WETH9.address,

// 'ETH' as a bytes32 string

'0x4554480000000000000000000000000000000000000000000000000000000000'

]

})

其实这里就是借助linkLibrary函数,将NFTDescriptor的地址链接到NFTTokenPositionDescriptor的Bytecode中。部署合约到此,我们可以验证一下我们的部署脚本是否有问题。我们运行yarn hardhat deploy,如果一切顺利,我们可以看到如下的输出。1

2

3

Nothing to compile

No need to generate any newer typings.

✨ Done in 1.45s.

简单来说就是没有什么特别的输出,如果这里出现了报错,那么就证明我们的部署脚本出现了问题。有人可能会有疑问,我这里什么参数都没有填,我这合约究竟部署到了什么地方去了?其实,如果我们直接执行deploy脚本,那么他会默认部署到一个本地的网络中。我们也可以通过yarn hardhat node来启动一个本地的网络。但是,因为我们没有启动一个本地网络,所以在deploy时会自动启动一个本地网络用于部署,当部署完成后又会自动的关闭这个网络。所以我们基本看不到任何反馈输入,不过,没有反馈其实就是最好的反馈了。结语这一个章节我们把UniswapV3进行了完整部署,有了这个部署,我们就可以在后续的章节中进行一些测试了。当然,有能力的朋友也可以在这上面进行一些初步的合约开发工作。不过我并不是很推荐使用这种方式,因为用这种方式,当合约报错时,你是无法进行精确到行的Debug的。不过这个问题我们将在后面的章节进行解决。在下一章,我们将会部署一个Uniswap的前端进行测试。Solidity

SmartContractLicensed under My License相关文章1-Solidity 前期准备2-Solidity环境3-部署一个UniswapV3©

2023 Software QA RevisitedSoftware QA RevisitedBuilt with Hugo主题 Stack 由 Jimmy 设计

Uniswap Wallet on iOS and Android

Uniswap Wallet on iOS and Android

Uniswap in your pocket.A wallet built for swappingLearn moreJoin the waitlist for the Uniswap ExtensionJoin the waitlist for the Uniswap ExtensionJoin the waitlist for the Uniswap ExtensionClaim your uni.eth username in the Uniswap mobile app to join the waitlist for the Uniswap Extension.Claim your uni.eth username in the Uniswap mobile app to join the waitlist for the Uniswap Extension.Claim your uni.eth username in the Uniswap mobile app to join the waitlist for the Uniswap Extension.Learn MoreSwap on multiple chains.Supports Ethereum, Optimism, Polygon, Arbitrum, Base, and BNBOne simple wallet.All your NFTs, tokens, and wallets in one placeSafe and secure by design.Built by the most trusted team in DeFi.Swap on multiple chains.Supports Ethereum, Optimism, Polygon, Arbitrum, Base, and BNBOne simple wallet.All your NFTs, tokens, and wallets in one placeSafe and secure by design.Built by the most trusted team in DeFi.Swap on multiple chains.Supports Ethereum, Optimism, Polygon, Arbitrum, Base, and BNBOne simple wallet.All your NFTs, tokens, and wallets in one placeSafe and secure.Built by the most trusted team in DeFi.ResourcesDownload SupportOther ProductsSwap TokensExplore NFTsLearn moreBlogDiscordTwitter© 2024 – Uniswap Privacy PolicyTrademark PolicyResourcesDownload SupportOther ProductsSwap TokensExplore NFTsLearn moreBlogDiscordTwitter© 2024 – Uniswap Privacy PolicyTrademark PolicyResourcesDownload SupportOther ProductsSwap TokensExplore NFTsLearn moreBlogDiscordTwitter© 2024 – Uniswap Privacy PolicyTrademark Policy

Introducing Uniswap v3

oducing Uniswap v3 Uniswap Labs BlogLaunch AppBackIntroducing Uniswap v3 March 23, 2021# ProtocolsUniswap v1 was launched in November 2018 as a proof of concept for automated market makers (AMMs), a type of exchange where anyone can pool assets into shared market making strategies.

In May 2020, Uniswap v2 introduced new features and optimizations, setting the stage for exponential growth in AMM adoption. Less than one year since its launch, v2 has facilitated over $135bn in trading volume, ranking as one of the largest cryptocurrency spot exchanges in the world.

Uniswap now serves as critical infrastructure for decentralized finance, empowering developers, traders, and liquidity providers to participate in a secure and robust financial marketplace.

Today, we are excited to present an overview of Uniswap v3. We are targeting an L1 Ethereum mainnet launch on May 5, with an L2 deployment on Optimism set to follow shortly after.

Uniswap v3 introduces:

Concentrated liquidity, giving individual LPs granular control over what price ranges their capital is allocated to. Individual positions are aggregated together into a single pool, forming one combined curve for users to trade against

Multiple fee tiers, allowing LPs to be appropriately compensated for taking on varying degrees of risk

These features make Uniswap v3 the most flexible and efficient AMM ever designed:

LPs can provide liquidity with up to 4000x capital efficiency relative to Uniswap v2, earning higher returns on their capital

Capital efficiency paves the way for low-slippage trade execution that can surpass both centralized exchanges and stablecoin-focused AMMs

LPs can significantly increase their exposure to preferred assets and reduce their downside risk

LPs can sell one asset for another by adding liquidity to a price range entirely above or below the market price, approximating a fee-earning limit order that executes along a smooth curve

Uniswap's oracles are now far easier and cheaper to integrate. V3 oracles are capable of providing time-weighted average prices (TWAPs) on demand for any period within the last ~9 days. This removes the need for integrators to checkpoint historical values.

Even with these groundbreaking design improvements, the gas cost of v3 swaps on Ethereum mainnet is slightly cheaper than v2. Transactions made on the Optimism deployment will likely be significantly cheaper!

Read on for more details on Uniswap v3. For a deeper technical overview check out the Uniswap v3 Core whitepaper, the Uniswap v3 Core smart contracts.

Concentrated Liquidity

In Uniswap v2, liquidity is distributed evenly along an x*y=k price curve, with assets reserved for all prices between 0 and infinity. For most pools, a majority of this liquidity is never put to use. As an example, the v2 DAI/USDC pair reserves just ~0.50% of capital for trading between $0.99 and $1.01 , the price range in which LPs would expect to see the most volume and consequently earn the most fees.

V2 LPs only earn fees on a small portion of their capital, which can fail to appropriately compensate for the price risk ("impermanent loss") they take by holding large inventories in both tokens. Additionally, traders are often subject to high degrees of slippage as liquidity is spread thin across all price ranges.

In Uniswap v3, LP's can concentrate their capital within custom price ranges, providing greater amounts of liquidity at desired prices. In doing so, LPs construct individualized price curves that reflect their own preferences.

LPs can combine any number of distinct concentrated positions within a single pool. For example, an LP in the ETH/DAI pool may choose to allocate $100 to the price ranges $1,000-$2,000 and an additional $50 to the ranges $1,500-$1,750.

By doing so, an LP can approximate the shape of any automated market maker or active order book.

Users trade against the combined liquidity of all individual curves with no gas cost increase per liquidity provider. Trading fees collected at a given price range are split pro-rata by LPs proportional to the amount of liquidity they contributed to that range.

Capital Efficiency

By concentrating their liquidity, LPs can provide the same liquidity depth as v2 within specified price ranges while putting far less capital at risk. The capital saved can be held externally, invested in different assets, deposited elsewhere in DeFi, or used to increase exposure within the specified price range to earn more trading fees.

Let's illustrate with an example:

Alice and Bob both want to provide liquidity in an ETH/DAI pool on Uniswap v3. They each have $1m. The current price of ETH is 1,500 DAI.

Alice decides to deploy her capital across the entire price range (as she would have in Uniswap v2). She deposits 500,000 DAI and 333.33 ETH (worth a total of $1m).

Bob instead creates a concentrated position, depositing only within the price range from 1,000 to 2,250. He deposits 91,751 DAI and 61.17 ETH, worth a total of about $183,500. He keeps the other $816,500 himself, investing it however he prefers.

While Alice has put down 5.44x as much capital as Bob, they earn the same amount of fees, as long as the ETH/DAI price stays within the 1,000 to 2,250 range.

Bob's custom position also acts as a kind of stop-loss for his liquidity. Both Alice and Bob's liquidity will be entirely denominated in ETH if the price of ETH falls to $0. However, Bob will have lost just $159,000, versus Alice's $1m. Bob can use his additional $816,500 to hedge against downside exposure or to invest in any other conceivable strategy.

Instead of providing equivalent liquidity depth as a v2 LPs with less capital, v3 LPs can choose to provide greater depth with the same amount of capital as their v2 counterparts. This requires taking on more price risk ("impermanent loss") while supporting greater amounts of trading and earning higher fees.

LPs in more stable pools will likely provide liquidity in particularly narrow ranges. If the ~$25m currently held in the Uniswap v2 DAI/USDC pair was instead concentrated between 0.99 — 1.01 in v3, it would provide the same depth as $5bn in Uniswap v2 as long as the price stayed within that range. If the ~$25m was concentrated into the 0.999 - 1.001 range it would provide the same depth as $50b in Uniswap v2.

The tool below calculates the capital efficiency gains of a concentrated liquidity position (centered around the current price) relative to allocating capital across the entire price curve.

Liquidity Deposit ValueValue of paired tokens$Select ETH price rangeCurrent Price: $1,820V3 Range PositionCapital Required$150,000Fees per $ vs. V25.24xV2 PositionCapital Required$785,779These two positions will earn equal fees and perform idenitcally while the price remains between $1200 and $2800.

At launch, capital efficiency gains will max out at 4000x for LPs providing liquidity within a single 0.10% price range. The v3 pool factory is technically capable of supporting ranges as granular as 0.02%, translating to a maximum 20,000x capital efficiency gains relative to v2. However, more granular pools can increase swap gas costs and might be more useful on Layer 2.

Active Liquidity

If market prices move outside an LP's specified price range, their liquidity is effectively removed from the pool and is no longer earning fees. In this state, an LP's liquidity is composed entirely of the less valuable of the two assets, until the market price moves back into their specified price range or they decide to update their range to account for current prices.

In v3, it is theoretically possible for no liquidity to exist in a given price range. However, we expect rational LPs to continuously update their price ranges to cover the current market price.

Range Orders

v3's LP customizability opens up a novel order feature to complement market orders, which we are calling "range orders".

LPs can deposit a single token in a custom price range above or below the current price: if the market price enters into their specified range, they sell one asset for another along a smooth curve while earning swap fees in the process.

Depositing to a narrow range feels similar to a traditional limit order. For example, if the current price of DAI is below 1.001 USDC, Alice could add $10m worth of DAI to the range of 1.001 — 1.002 DAI/USDC.

Once DAI trades above 1.002 DAI/USDC, Alice's liquidity will have fully converted into USDC. Alice must withdraw her liquidity (or use a third-party service to withdraw on her behalf) to avoid automatically converting back into DAI if DAI/USDC starts trading below 1.002.

The average execution price of a fully executed range order is the geometric average of the minimum and maximum price: in Alice's case, the execution price equals 1.001499 DAI/USDC for a total of $1,001,499. This execution price does not account for additional swap fees earned during the period in which prices trade within the 1.001 — 1.002 DAI/USDC range.

Range orders within wider ranges may prove particularly useful for profit-taking, buying the dip, and primary issuance events: in the later use case, issuers are now able to deposit liquidity in a single asset and specify the exact range of prices across which they wish to sell their tokens.

Non-Fungible Liquidity

As a byproduct of per-LP custom price curves, liquidity positions are no longer fungible and are not represented as ERC20 tokens in the core protocol.

Instead, LP positions will be represented by non-fungible tokens (NFTs). However, common shared positions can be made fungible (ERC20) via peripheral contracts or through other partner protocols. Additionally, trading fees are no longer automatically reinvested back into the pool on LPs' behalf.

Over time we expect increasingly sophisticated strategies to be tokenized, making it possible for LPs to participate while maintaining a passive user experience. This could include multi-positions, auto-rebalancing to concentrate around the market price, fee reinvestment, lending, and more.

Flexible Fees

Uniswap v3 offers LPs three separate fee tiers per pair — 0.05%, 0.30%, and 1.00%. This array of options ensures that LPs tailor their margins according to expected pair volatility: LPs take on more risk in non-correlated pairs like ETH/DAI and, conversely, take on minimal risk in correlated pairs like USDC/DAI.

Although distinct fee tiers may lead to some degree of liquidity fragmentation, we believe that most pairs will calibrate to an obvious fee tier, which then serves as the canonical market. We expect like-kind asset pairs to congregate around the 0.05% fee tier and pairs like ETH/DAI to use 0.30%, while exotic assets might find 1.00% swap fees more appropriate. governance can add additional fee tiers as needed.

Uniswap v2 introduced a protocol fee switch, which allowed a flat 5 basis point (16.66% of LP fees) fee to be turned on by governance. Uniswap v3 protocol fees are far more flexible. Fees will be off by default, but can be turned on by governance on a per-pool basis and set between 10% and 25% of LP fees.

Advanced Oracles

Uniswap v2 introduced time weighted average price (TWAP) oracles. These oracles serve as a critical piece of DeFi infrastructure, and have been integrated into dozens of projects, including Compound and Reflexer.

V2 oracles work by storing cumulative sums of Uniswap pair prices on a per-second basis. These price sums can be checked once at the beginning of a period and once at the end to calculate an accurate TWAP over that period.

Uniswap v3 offers significant improvements to the TWAP oracle, making it possible to calculate any recent TWAP within the past ~9 days in a single on-chain call. This is achieved by storing an array of cumulative sums instead of just one.

This array of historical price accumulators makes it far easier and cheaper to create more advanced oracles that include simple-moving averages (SMA), exponential moving averages (EMA), outlier filtering, and more.

Despite this major improvement, the gas cost to Uniswap traders for keeping oracles up to date has been reduced by ~50% relative to v2. The costs for calculating TWAPs in external smart contracts is significantly cheaper as well.

License

We strongly believe decentralized financial infrastructure should ultimately be free, open-source software. At the same time, we think the Uniswap community should be the first to build an ecosystem around the Uniswap v3 Core codebase.

With this in mind, Uniswap v3 Core will launch under the Business Source License 1.1—effectively a time-delayed GPL-2.0-or-later license. The license limits use of the v3 source code in a commercial or production setting for up to two years, at which point it will convert to a GPL license into perpetuity.

Uniswap governance can accelerate the change to GPL or grant exemptions to the license at any time by updating the files at _ v3-core-license-date.uniswap.eth _ and _ v3-core-license-grants.uniswap.eth _.

Note that the BUSL 1.1 license does not affect integrations. All code that may be needed for external integrations has been licensed under GPL or MIT , including math libraries, peripheral contracts, interfaces, and the developer sdk. Any wallet, interface, mobile app, protocol, or other project will be able to integrate with v3 as expected.

For more information on this license, see this FAQ.

Audits and Bug Bounty

Our team believes security is of the utmost importance — it took hundreds of hours of testing for us to feel comfortable with launching Uniswap v3.

Our security process for v3 included:

A full-length audit from Trail of Bits

A full-length audit from ABDK

A full audit from samczsun (no report)

An auditing and review process from our engineering team

A comprehensive test suite, including the automated tools Echidna and Manticore

Major bugs discovered as part of the testing and auditing process were fixed. However, we would like to note that Uniswap v3 is an extremely complex protocol and we cannot guarantee all bugs have already been discovered and resolved.

To help find any open vulnerabilities, a public bug bounty will run over the next 30 days, with up to $500,000 offered for critical bugs. More detail on the public bug bounty can be found here.

Launch Details

The Uniswap v3 smart contracts will be deployed to the Ropsten, Rinkeby, Kovan, and Görli testnets in the coming days, giving developers time to begin experimenting with the protocol before the official launch.

The Uniswap v3 Core repository contains the essential, low-level smart contracts that power the protocol.

The Uniswap v3 Periphery repository contains a collection of smart contracts designed to ease user interaction with core contracts.

A liquidity provider migration portal will be available at launch, allowing v2 LPs to seamlessly transfer their liquidity to the new protocol.

In the meantime, there are few outstanding items to complete:

Partners and integrations can begin building on Uniswap v3 immediately, in preparation for mainnet launch!

The interface, analytics site, API, and developer SDK are being redesigned to work with Uniswap v3.

The initial Uniswap v3 router and position manager contracts are almost complete. While still subject to change, they are available here.

Documentation, guides, and further examples are in progress.

Additional infrastructure to support fungibile positions, liquidity mining, more complex strategies, and various other use cases will be built by Uniswap Labs together with the Uniswap community after mainnet launch

Reach out

On Friday, March 26 at 2pm ET we will host an AMA on the official Uniswap Discord, where we hope to answer any outstanding questions you may have around Uniswap v3. Questions can be submitted ahead of time here.

We will be releasing further updates, additional information, and initial documentation over the coming days and welcome all feedback and involvement from our community.

If you are integrating and wish to get in touch, please fill out this form and we will try to respond as soon as possible. Alternatively, reach out in the #v3-integrations channel in the community Discord

To get involved and stay up to date:

Join the Uniswap community discord

Follow Uniswap on Twitter

Subscribe to the Uniswap blog

Register as a delegate Sybil

Participate in Uniswap governance

Uniswap Team

Concentrated LiquidityCapital EfficiencyActive LiquidityRange OrdersNon-Fungible LiquidityFlexible FeesAdvanced OraclesLicenseAudits and Bug BountyLaunch DetailsReach outRelated posts May 05, 2021Uniswap v3 Mainnet launch March 23, 2020Uniswap v2 Overview June 01, 2023Uniswap 101: What is Uniswap? | Uniswap L

Uniswap Interface

wap InterfaceYou need to enable JavaScript to run this ap

Uniswap v3 Mainnet launch

wap v3 Mainnet launch Uniswap Labs BlogLaunch AppBackUniswap v3 Mainnet launch May 05, 2021# ProtocolsWe're thrilled to announce that Uniswap v3 has been deployed to the Ethereum mainnet! All relevant contract addresses can be found here.

Uniswap v3 is the most powerful version of the protocol yet, with Concentrated Liquidity offering unprecedented capital efficiency for liquidity providers, better execution for traders, and superior infrastructure at the heart of decentralized finance.

For a full description of v3's features, please refer to our announcement blog post. Audit reports for the core and periphery contracts can be found here and here. After 6 weeks, the Uniswap v3 bug bounty has returned no major findings. However, we would like to note that v3 is a complex new protocol and we cannot guarantee all bugs have been found and resolved.

Traders

The swap interface now routes trades through Uniswap v3 and will alert you when a better exchange rate is available on Uniswap v2.

The Uniswap analytics platform — info.uniswap.org — now tracks v3 performance. You can continue to review v2 stats here.

Liquidity providers

The pool interface now supports the creation of Uniswap v3 positions with multiple fee tiers and concentrated liquidity ranges. Each position is represented as an NFT and comes with a unique piece of on-chain generative art. Look out for rare sparkles!

We have also released a migration portal for Uniswap v2 and Sushiswap LPs to seamlessly migrate their assets over to v3. Due to the introduction of concentrated liquidity, the migration portal requires LPs to specify a fee tier and price range for their allocated liquidity. A migration walkthrough guide can be found here.

Developers

Developers can begin building on Uniswap v3 immediately!

Initial documentation and example projects can be found here. Additionally, the Uniswap Labs team will be available to answer integration-related questions in our Discord's #integrations channel.

Contact

The Uniswap Labs team will be available to answer questions in the Uniswap community Discord.

Follow the Uniswap Labs Twitter account for more updates!

FAQ:

1. What happens to the Uniswap v2 protocol?

The Uniswap v2 Protocol will remain functional and available for use as long as the Ethereum network continues to exist. However, we expect that over time the advantages of Uniswap v3 will draw a majority of liquidity and trading volume away from v2.

2. Do I have to migrate my liquidity?

You are not required to migrate your v2 liquidity if you so choose. The Uniswap v2 protocol will remain active and functional in perpetuity. However, it may be advantageous to migrate liquidity as we expect a majority of trading volume — and, consequently, LP fee generation — to take place on v3.

3. Will the updated Uniswap interface only execute trades through v3?

The updated interface will default to executing on v3 but will always alert you if a better trade is available on v2.

4. Is there a v3 liquidity mining program?

There is no v3 liquidity mining program scheduled at launch. Uniswap governance may introduce a liquidity mining program at any time through the standard Uniswap governance process.

To get involved and stay up to date:

Join the Uniswap community discord

Follow Uniswap on Twitter

Subscribe to the Uniswap blog

Register as a delegate Sybil

Participate in Uniswap governance

Uniswap Team

TradersLiquidity providersDevelopersContactFAQ:Related posts May 18, 2020Uniswap v2 Mainnet Launch March 23, 2021Introducing Uniswap v3 June 01, 2023Uniswap 101: What is Uniswap? | Uniswap L

Uniswap v3 Mainnet launch

wap v3 Mainnet launch Uniswap Labs BlogLaunch AppBackUniswap v3 Mainnet launch May 05, 2021# ProtocolsWe're thrilled to announce that Uniswap v3 has been deployed to the Ethereum mainnet! All relevant contract addresses can be found here.

Uniswap v3 is the most powerful version of the protocol yet, with Concentrated Liquidity offering unprecedented capital efficiency for liquidity providers, better execution for traders, and superior infrastructure at the heart of decentralized finance.

For a full description of v3's features, please refer to our announcement blog post. Audit reports for the core and periphery contracts can be found here and here. After 6 weeks, the Uniswap v3 bug bounty has returned no major findings. However, we would like to note that v3 is a complex new protocol and we cannot guarantee all bugs have been found and resolved.

Traders

The swap interface now routes trades through Uniswap v3 and will alert you when a better exchange rate is available on Uniswap v2.

The Uniswap analytics platform — info.uniswap.org — now tracks v3 performance. You can continue to review v2 stats here.

Liquidity providers

The pool interface now supports the creation of Uniswap v3 positions with multiple fee tiers and concentrated liquidity ranges. Each position is represented as an NFT and comes with a unique piece of on-chain generative art. Look out for rare sparkles!

We have also released a migration portal for Uniswap v2 and Sushiswap LPs to seamlessly migrate their assets over to v3. Due to the introduction of concentrated liquidity, the migration portal requires LPs to specify a fee tier and price range for their allocated liquidity. A migration walkthrough guide can be found here.

Developers

Developers can begin building on Uniswap v3 immediately!

Initial documentation and example projects can be found here. Additionally, the Uniswap Labs team will be available to answer integration-related questions in our Discord's #integrations channel.

Contact

The Uniswap Labs team will be available to answer questions in the Uniswap community Discord.

Follow the Uniswap Labs Twitter account for more updates!

FAQ:

1. What happens to the Uniswap v2 protocol?

The Uniswap v2 Protocol will remain functional and available for use as long as the Ethereum network continues to exist. However, we expect that over time the advantages of Uniswap v3 will draw a majority of liquidity and trading volume away from v2.

2. Do I have to migrate my liquidity?

You are not required to migrate your v2 liquidity if you so choose. The Uniswap v2 protocol will remain active and functional in perpetuity. However, it may be advantageous to migrate liquidity as we expect a majority of trading volume — and, consequently, LP fee generation — to take place on v3.

3. Will the updated Uniswap interface only execute trades through v3?

The updated interface will default to executing on v3 but will always alert you if a better trade is available on v2.

4. Is there a v3 liquidity mining program?

There is no v3 liquidity mining program scheduled at launch. Uniswap governance may introduce a liquidity mining program at any time through the standard Uniswap governance process.

To get involved and stay up to date:

Join the Uniswap community discord

Follow Uniswap on Twitter

Subscribe to the Uniswap blog

Register as a delegate Sybil

Participate in Uniswap governance

Uniswap Team

TradersLiquidity providersDevelopersContactFAQ:Related posts May 18, 2020Uniswap v2 Mainnet Launch March 23, 2021Introducing Uniswap v3 June 01, 2023Uniswap 101: What is Uniswap? | Uniswap L

版权声明:本文由bitpie比特派钱包官网发布,如需转载请注明出处。

本文链接:https://www.siyuewuyu.com/article/526.html