Overview of DEX and AMM technology
1. AMMs Automated Market Makers
1.1 AMMs types
Automated Market Makers (AMMs) are part of the decentralized finance (DeFi) ecosystem, and they allow digital assets to be traded in a permissionless and automated manner using liquidity pools. AMMs users contribute crypto tokens to liquidity pools, the price of which is determined by a constant mathematical formula.
AMMs are mathematical functions that algorithmically price assets based on liquidity pools. Currently, several AMM formulas are utilized to cater to different asset pricing strategies. Some of the more popular AMM formulas are as follows:
• Constant product market maker formula:
When the constant product market maker formula is drawn, it is a convex curve where x and y represent the number of two tokens in the liquidity pool and k represents the product. This formula helps to create a price range for both tokens based on the amount available for each token. To keep k constant, when the supply of x increases, the supply of y must decrease, and vice versa. Therefore, the resulting price is inherently volatile, as the size of the transaction may affect the price in relation to the size of the pool. Higher slippage caused by large trades may result in impermanent losses.
• Constant and market maker formulas:
The constant and market maker formulas form a straight line when drawn. It is an ideal model for zero-slippage trading, but unfortunately, it does not provide unlimited liquidity. This model is flawed because it presents arbitrage opportunities when quotes differ from market prices for assets traded elsewhere. Arbitrageurs can drain the entire reserves in the liquidity pool, leaving no more available liquidity for other traders. This mode is not suitable for most AMM use cases.
• Constant Average Market Maker Formula:
The constant average market maker formula, or also known as the "value function", was created and made popular by Balancer. It allows for more than two tokens in a liquidity pool and allows pools to add different tokens beyond the standard 50/50 distribution. This allows for variable exposure to different assets in the pool and enables exchanges between any asset in the liquidity pool.
• Stable exchange formula:
The formula is a mixture of constant product and constant sum formula. It is popularized by Curve Finance. When the portfolio is relatively balanced, trading occurs on the constant sum curve, and when it is unbalanced it switches to the constant product curve. This allows for lower slippage and impermanent losses, but only works for assets of similar value since the price of the desired trading range is always close to 1. For example, this would be useful for transactions between stablecoins (DAI and USDC) and wrapped assets (wBTC and sBTC). Most automated market makers (AMMs) face three main challenges: high fees, high slippage, and impermanent losses.
1.2 Liquidity Pool
Liquidity pools are cryptocurrencies locked in smart contracts that facilitate transactions between assets on decentralized exchanges (DEXs).
A liquidity pool is a mechanism by which users can pool their assets into smart contracts on DEXs, providing traders with liquidity for their assets to exchange between currencies. Liquidity pools provide much-needed liquidity, speed, and convenience to the DeFi ecosystem. AMM solves the problem of limited liquidity by creating liquidity pools and providing liquidity providers with incentives to provide assets to these pools. The more assets in the pool, the stronger the liquidity in the pool. The easier it is to trade.
1.3 Liquidity Provider (LP, Liquidity Provider)
In the crypto ecosystem, liquidity providers (LPs) are users who deposit tokens into liquidity pools. In return for providing liquidity, users typically receive liquidity tokens that represent a user-owned share of the liquidity pool. These users are often incentivized to hold liquidity tokens for a percentage of transaction fees and other crypto rewards.
1.4 Liquidity Token (LP Token, Liquidity Provider Token)
Liquidity tokens are tokens created and given to users who deposit assets into liquidity pools. Liquidity tokens represent the share of liquidity pools owned by liquidity providers, and LPs usually receive a percentage of liquidity pool transaction fees as financial incentives. Liquid tokens can often be transferred, exchanged and pledged. Liquidity providers remain in full control of their staked tokens, which are only lent to the platform’s protocol. When liquidity providers want to withdraw liquidity, they must burn liquidity tokens to receive their original crypto assets, in addition to any accumulated commissions on transaction fees or loan interest. Liquidity tokens also allow automated market makers (AMMs) to be non-custodial, meaning you still control your assets and can redeem them at any time.
Uniswap: Uniswap liquidity providers will be rewarded with a homogenized ERC-20 liquidity token, which allows the token to be used in the wider Ethereum DeFi ecosystem. Therefore, even though there is usually no direct market to buy and trade the liquidity token itself, a liquidity token like Uniswap can be used as collateral for lending protocols like MakerDAO. Notably, Uniswap liquidity is different from UNI governance tokens, which are used to vote on new proposals and other forms of decentralized decision-making.
Curve: Liquidity providers utilizing the AMM curve will receive liquidity tokens for the corresponding tokens, not liquidity tokens tied to trading pairs. For example, if a user lends ETH to the Compound DeFi platform, it is exchanged for a liquidity token called cETH, which automatically accumulates interest for the holder. In addition to allowing Curve's crypto liquidity providers the right to withdraw their ETH and interest from Compound, Curve users are also able to stake their cETH into other liquidity pools to generate passive yields and CRV (Curve's governance token). As such, these liquidity tokens allow users to gain additional utility and potential profits from their initial investment.
Balancer: Balancer is an AMM protocol that enables liquidity pools consisting of multiple unevenly weighted assets. Like many of the examples above, the Balancer liquidity token is called the Balanced Pool Token (BPT), which is an ERC-20 token that can be used in the wider Ethereum DeFi ecosystem. However, given Balancer's unique multi-asset pool configuration, the BPT token is backed by a basket of cryptoassets. Some projects built on Balancer pools require users to stake BPT tokens for rewards.
1.5 Slippage
Slippage is the difference between the expected price of a trade and the actual price at which the trade was executed. Slippage typically occurs when investors buy or sell assets on platforms with illiquid and low trading volumes. If there is a large gap between the buy and sell prices on the exchange’s order book, asset buyers may end up paying more for the asset, or receiving less than expected after the trade is executed.
1.6 Impermanent Loss (IL, Impermanent Loss)
The temporary loss of funds that occurs at the same time as liquidity is provided is called impermanent loss, which is a common phenomenon in decentralized finance.
For example, Uniswap uses the formula x * y = k to manage transactions in the pool.
Here's an easy way to understand how liquidity provider impermanent losses occur:
• Token A: 1 ETH
• Token B: 100 DAI
• In the pool after providing tokens: 10 ETH and 1000 DAI, the assets I own account for 10%
• After a period of time, 1 ETH can trade 200 DAI, so how is impermanent loss calculated?
• First, we first calculate the constant k in the initial fund pool. 10 * 1000 = 10000, which gives k = 10000
• Calculate the status of 1 ETH transaction 200 DAI, the amount of Token A, the amount of Token B
• x * y = 10000 (1)
• 200 * x = y (2)
• Simultaneously (1) (2) can be solved that x is approximately equal to 7.07 and y is approximately equal to 1414
• The existing asset will be $300 (worth $200 in ETH, and $100 in DAI), but not worth that much due to impermanent losses, as follows (calculated in USD)
• 200 * 7.07 + 1414 = 2828
• 200 * 10 + 1000 = 3000
• So lost 3000 - 2828 = 172
• Slippage: 172 / 3000 = 5.73%
To mitigate impermanent losses in the decentralized finance ecosystem and incentivize users to contribute tokens to liquidity pools, AMM platforms pay transaction fees to liquidity pools and providers, and frequently distribute platform tokens to users. With sufficient trading volume on the platform, liquidity providers can accumulate fees to compensate for impermanent losses and even make profits.
2. Uniswap
Uniswap is a decentralized protocol that executes without an order book or centralized intermediary. Uniswap achieves this through a liquidity pool model that uses automated smart contracts to enable potential traders to access a reserve of tokens funded by competing users as the primary source of market liquidity. Anyone can exchange tokens, contribute tokens to the pool and earn fees, or list tokens on Uniswap. Since Uniswap is built on Ethereum, almost any ERC-20 token can be exchanged using Uniswap. Additionally, there are no listing fees for tokens traded on Uniswap - a marked difference from most centralized crypto exchanges.
In traditional markets, an order book compiles an exchange's open buy and sell orders for any asset. If there is a large gap between what buyers are willing to pay and what sellers are willing to accept, the resulting lack of trading activity can lead to a drop in liquidity. This means that if you hold the affected asset, it will be more difficult to sell. Uniswap pools minimize this misalignment between buy-side and sell-side market orders by creating a pool of traded assets, which in turn helps alleviate potential market liquidity issues. Additionally, Uniswap's automated market maker technology algorithmically analyzes liquidity pools to provide the most appropriate price for a particular trade.
The platform currently charges a 0.3% transaction fee when users trade using the Uniswap liquidity pool. This 0.3% is the transaction fee in Uniswap V2 (1/6 of the fee is for the Uniswap protocol, and 5/6 is for the liquidity provider). In Uniswap V3, the fee level method (0.05%, 0.3%, 1% ) to optimize charging fees for different tokens. Any user who contributes to the Uniswap liquidity pool will receive a fraction of these fees proportional to their stake in the overall pool.
Uniswap uses a constant product formula (x * y = k), where both x and y are variables that represent the total value of a token in a market pair. For example, x is the total value of ETH and y is the total value of DAI in the protocol's ETH/DAI liquidity pool. Uniswap multiplies these two numbers to determine k, which represents the pool liquidity for the trading pair.
The core requirement of Uniswap trading is that the liquidity of the pool remains the same even if the value of x or y changes. So while each transaction affects the price of x and y, the liquidity remains the same. For example, if a trader buys 1 ETH in exchange for 330 DAI, the ratio of ETH in the liquidity pool decreases, while the DAI ratio increases to accommodate one less ETH and 330 DAI tokens in the pool. As a result, the price of ETH will rise while the price of DAI will fall. This formula ensures the maintenance of fair market value, while maintaining liquidity at all times.
Uniswap launches a native governance token, UNI, that facilitates greater community participation and oversight. UNI holders can vote on Uniswap project development, which determines the evolutionary trajectory of the platform. UNI holders can also use the token to fund liquidity pools, grants, partnerships and other growth-driven initiatives to expand Uniswap’s availability and reach. As the Uniswap community grows and UNI Holdings further diversifies, the founding team will play a smaller and smaller role in designing the governance of the platform. This proves that the unifying concepts of decentralization and incentives, both of which are at the heart of the DeFi revolution, are being put into practice by Uniswap.
At present, Uniswap has added many optimization mechanisms from V1, V2 to V3. The differences between the versions of Uniswap series are as follows:
• Fluidity
V1: Only ETH can be exchanged for other ERC20 tokens. If you want to exchange USDT for other ERC20 tokens, first exchange USDT for ETH, and then exchange ETH for other tokens. This pays gas twice and suffers two slippages.
V2: On the basis of the ERC20/ETH pool existing in V1, an ERC20/ERC20 liquidity pool has been added, and any ERC20 tokens can be withdrawn and traded without the need for multiple exchanges, reducing gas and slippage risks.
V3: On the basis of v2, the liquidity token adopts ERC721 non-fungible token.
• Cost
V1: The fee is 0.3%, and then the fee is reinvested into the liquidity pool.
V2: The fee is 0.3%, of which 0.05% is the fee of the Uniswap protocol, and the remaining 0.25% is given to the liquidity provider. The reinvestment of the obtained fee is to enter the liquidity pool, and the fee can only be obtained when the liquidity is removed.
V3: The fee adopts the fee level (0.05%, 0.3%, 1%). Other fees can be opened through UNI governance. The fees in different intervals can be directly accumulated, and there is no need to continue to put them into the liquidity pool and take them out manually.
• Oracle
V1: There is no oracle mechanism, because the price of V1 is closely related to the real world, and the price fluctuates too much in a short period of time, so it cannot be safely used as an oracle.
V2: Adopt TWAP time-weighted average price oracle, improve this oracle function by measuring and recording the price before the first transaction of each block, which is more difficult to manipulate than the block price. Only the latest cumulative price value is provided, and developers need to record and capture historical prices by themselves.
V3: The same trading pair has different trading pools at different rates. Therefore, the improved oracle not only records price information, but also records the cumulative value of liquidity time. V3 uses the geometric mean, which is more stable than the arithmetic mean of V2. The most recent accumulated time value is stored by default, and can be expanded as needed. It supports up to 65535 historical price information (plus the currently unwritten price information, a total of 65536, the storage is stored in a ring array, and after the last position is stored, it is stored in the first position, the loop is stored sequentially).
3.Curve
Curve is a protocol for AMMs that shares many similarities with Uniswap and Balancer, but differs by only accommodating liquidity pools consisting of similarly behavioral assets (like stablecoins) or wrapped versions of similar assets (like wBTC and tBTC). This approach allows Curve to use a more efficient algorithm with the lowest fees, slippage and impermanent losses of any decentralized exchange (DEX) on Ethereum.
Launched in 2020, Curve aims to create a low-fee AMM exchange for traders while providing liquidity providers with an efficient fiat savings account. By focusing on stablecoins, Curve allows investors to avoid volatile crypto assets while still earning high interest rates from loan agreements. Compared to other AMMs platforms, the Curve model is particularly conservative as it avoids volatility and speculation in favor of stability.
On AMMs like Curve, liquidity pools are constantly trying to “buy low” and “sell high.” Here’s a look back at how the rebalancing worked, this time with the dollar-pegged stablecoins USDC and DAI. If you sell DAI on Curve, the following sequence of events is triggered:
• · More DAI has been added to the pool
• · Pool becomes unbalanced as there is now more DAI than USDC
• · The pool sells DAI at a small discount compared to USDC to incentivize balances
• · Pool rebalances its DAI to USDC ratio
By selling DAI at a discount, the pool attempts to restore the pool to its original state. Because the assets in Curve pools are price-stabilized against each other, transactions between them cause minimal volatility compared to other AMMs liquidity pools. On AMMs like Uniswap or Balancer, liquidity pools can consist of any token with high volatility. By limiting pools and the types of assets in each pool, Curve minimizes impermanent losses, an AMM phenomenon in which liquidity providers suffer from liquidity pool fluctuations relative to the token's market value. loss of currency value.
Impermanent losses are not always negative, however. Volatility and slippage present opportunities for users who are trying to profitably enter and exit liquidity pools at the right time. By weighing the high-risk (and sometimes high-reward) aspects of volatility, Curve instead uses so-called DeFi composability to attract liquidity providers. This means you can use your investment on the Curve platform to earn rewards elsewhere in the DeFi ecosystem.
Unlike Uniswap or Balancer, Curve does not try to keep the values held in different assets always equal or proportional to each other (i.e. balanced). This allows Curve to concentrate liquidity around the ideal price of similarly priced assets (in a 1:1 ratio) so that it has liquidity where it is most needed. Therefore, Curve can achieve higher liquidity utilization than these assets.
The asset-like approach of AMMs is not limited to stablecoins. Tokenized versions of Bitcoin (BTC), such as wBTC and renBTC, also make up Curve’s liquidity pools. Bitcoin is highly volatile compared to stablecoins, but the Curve method still works because tokens in a Curve pool do not need to be stable, they only need to be stable relative to other tokens in the same pool. In other words, wBTC and renBTC can be in the same Curve liquidity pool, while wBTC and USDC are not a functional combination.
On AMMs exchanges like Uniswap, you can earn fees when you make trades. On Curve, transaction fees are lower than on Uniswap, but you can also earn rewards from outside of Curve using interoperable tokens.
For example: when DAI is lent on Compound, it is exchanged for a liquidity token called cDAI, which automatically accrues interest for the holder. Holding cDAI means you have the right to withdraw DAI (principal plus interest) from Compound. Curve users are able to use cDAI in their liquidity pools to potentially gain from the same investment.
The ability to use Compound's cTokens on Curve exemplifies the composability advantage in the DeFi ecosystem. Compound is just one example of an external DeFi protocol that Curve integrates with. The protocol also integrates with Yearn Finance and Synthetix to maximize incentives for liquidity providers.
4.Balancer
Balancer is an automated market maker (AMM) that allows users to create liquidity pools of up to eight different tokens at any ratio. Balancer pools can be thought of as self-rebalancing portfolios, where anyone can create an index fund, and the fees go to liquidity providers rather than intermediary fund managers. The Balancer protocol is managed by Balancer (BAL) Token, which can earn interest by depositing cryptocurrency into Balancer's liquidity pool for liquidity mining.
Instead of manually rebalancing liquidity pools like traditional index funds, Balancer uses its constant average market maker equation to algorithmically automatically rebalance the pool's assets every time a trade is made, probably thousands of times a day. In fact, this ongoing state of rebalancing helps ensure that markets are active and trading opportunities are plentiful, benefiting both liquidity providers and traders. Transaction fees on the Balancer crypto exchange are not paid to fund managers like an index, but are paid directly to liquidity providers. These tokens effectively represent ownership stakes in the platform and voting rights in community governance decisions.
By realigning incentives and eliminating intermediaries from top to bottom, the Balancer protocol has taken over traditional finance's index funds and automates, democratizes and decentralizes the concept into an entirely new device that creates a of extraordinary value. In this way, Balancer is a great example of DeFi both in theory and in practice.
The most essential feature of the Balancer cryptographic protocol is its set of algorithms that govern and incentivize interactions between liquidity providers, liquidity pools, and traders: rebalancing pools and finding the best price in pools.
Here is an example of how rebalancing on Balancer works: Suppose the Balancer crypto pool is set to keep 80% of its value (in wETH) and 20% of its value (in wBTC). If slippage occurs, the protocol will adjust the token price to maintain the 80/20 ratio. On the Balancer DEX, when a trader wants to buy wBTC with wETH, the protocol will algorithmically scan its liquidity pool for the best price. By design, the pool with the best price per wETH to wBTC will also be the one most in need of rebalancing.
Like any investor, liquidity providers want the best return on their assets when depositing with AMM. Balancer not only allows tightly controlled trading pairs, but also allows liquidity providers to execute their own strategies.
For example, if you think the ratio of 80% ether (ETH) to 20% bitcoin (BTC) is optimal, Balancer allows you to access liquidity pools using your preferred strategy. If you are a liquidity provider looking to participate in an existing 80/20 ETH/BTC pool on Balancer and have 10 BTC available, the steps are roughly as follows:
• You contribute 10 BTC to the pool
• 2 BTC is deposited into the pool
• 8 BTC converted to the equivalent in ETH
• The protocol looks at all pools containing ETH and BTC to get the best price to execute this exchange
• 8 BTC worth of ETH deposited into the pool
• You will receive a Balancer Pool Token representing your share in the pool
• These Balancer Tokens will always be redeemable for 80% ETH and 20% BTC
• Balancer now has more BTC than ETH than before you entered the pool
• In order to maintain the 80/20 value ratio, the price of BTC has decreased relative to ETH
By only supplying BTC to the pool containing BTC and ETH, you increase the amount of BTC relative to ETH. By increasing the relative quantity of BTC, the relative price of BTC must decrease to maintain a constant value ratio for Balancer's liquidity pool.
There are two main types of Balancer pools: native pools and smart pools.
However, the native pool itself comes in two forms:
Private form, which means that the pool owner is the only participant who can manage the pool parameters and add or remove liquidity. Centralized private pools are dynamic, where weights, ratios, fees and even the tokens themselves can be changed by the pool creator. Private pools are like actively managed index funds, and you have to trust the creators to continue making the right decisions.
Public form, which means its parameters are immutable, but anyone can add liquidity and trade. The finalized Balancer core pool with 80% ETH, 20% BTC and 0.1% fees will always remain that way, guaranteed by smart contract code that is immutable on the Ethereum network. Public pools are more suitable as passive investment strategies, you can set and forget, anyone can join the strategy at any time.
Smart pools are private pools controlled by automated smart contracts that act as a gateway for anyone to provide liquidity. Therefore, smart pools can be viewed as a hybrid of private and shared pools, a combination of the best of both worlds. Smart pools have features such as dynamic fees, liquidity caps, LP whitelisting, trading suspension, and more.
The Balancer crypto platform has two sides: an exchange for traders and an investment fund for liquidity providers. Liquidity providers want to own a share of the Balancer crypto pool because they believe that holding the weighted balance and fees of the assets in the pool will be more profitable than holding their assets outside the Balancer. Traders are just looking for the best price to exchange tokens.
Balancer Check out all the different liquidity pools on the platform to get the best price per ETH to BTC. Compared to other liquidity pools on Balancer, the liquidity pools with the largest differences in price and token distribution are where transactions happen first. When a trader wants to buy BTC and sell ETH on Balancer, the protocol will automatically choose the pool with the best price for that transaction. Since the pricing of AMMs like Balancer is determined by a constant transaction formula, the pool of BTC with the lowest price will also be the pool with the most BTC relative to ETH.
Like many DeFi projects, Balancer Protocol has integrated governance mechanisms into its native Balancer Token. The Balancer community is responsible for governing the protocol and for proposing updates or changes. Holders of Balancer Tokens can then approve or reject proposals by voting with their Balancer Tokens. Since decisions are made by BAL holders, Balancer Token basically represents the ownership of Balancer. A potential future outcome of the governance process is that BAL holders vote to implement protocol-level transaction fees on Balancer, which may accumulate value back into the Balancer Token.
5. Compared with CEX, what are the advantages of DEX
The Central Exchange (CEX) is based on individual and central infrastructure, which enables fast transactions in near real-time. The algorithms of leading exchanges can process thousands of orders per second, and exchanges can react to changing market conditions without waiting. CEXs are highly liquid due to their high trading volume.
But CEX's wallet is integrated and not within the user's control. The ownership of the private key is in the hands of the exchange. If the exchange is leaked or attacked, the user's private key and digital assets are at risk of being completely lost.
The core links of the exchange are order cancellation, order placement, matching, fund settlement, and cash withdrawal. CEX is matched by the trading platform itself in all links, while the decentralized exchange (DEX) puts all the above links in the chain, and the smart contract performs all operations, and the user's transaction process does not require any trusted third party. Smart contract-driven DEX can save users from responsible KYC audits, and can also help users eliminate the risks brought by centralized exchanges "disconnected", secretly manipulating prices, falsifying transaction volumes, and running away. All transaction records can be found on-chain.
Therefore, DEX has the following advantages over CEX:
• Security: All transaction processes of DEX are completed by smart contracts. The ownership of coins is completely in the hands of the users. There is no transaction escape. Users can place transaction pairs in the transaction pool without any restrictions.
• Anonymity: No KYC and no personal files uploaded to the server. You only need to register a cryptocurrency wallet to trade, and there is no personal data exchange between exchanges and authorities;
• AMM model: suitable for DeFi to start from small-scale tokens, it can be any user of encrypted assets, no matter how much the asset is, it can be used as a market maker, and it can earn fees from other users. In CEX, CEX only participates in transactions ;
• Liquidity cost: DEX minimizes the cost of liquidity conversion. Compared with traditional liquidity, the generation of traditional liquidity requires many intermediaries. The intervention of regulatory agencies increases the cost of time and price to a certain extent;
6. What problems have DEXs exposed in a bear market?
Some time ago, the prices of Bitcoin and Ethereum continued to fall, hitting new lows in price over the past year. At the same time, it also affects DeFi. First, observe the image below:
This graph comes from the Token Terminal cryptographic analysis platform, and comes from the 365-day change analysis graph of the trading volume of several top exchanges. We can see from this graph that over the past year, DEX trading volume has peaked several times due to trading activity and price appreciation, and then briefly decreased in height due to market weakness. In the most recent period, the height has been basically at the low level for the whole year.
This graph is the monthly exchange volume. We can see that in November 2021, the DEX's trading volume reached its maximum value, and since then, the DEX's total trading volume has continued to decline.
At the same time, the liquidity problem of DEX has attracted much attention. Uniswap, the largest DEX, still faces the problem of insufficient liquidity. As MakerDAO liquidated a large number of ETH positions, a large amount of ETH was sold into the market, causing the price to crash below $1,000 at one point, when the fair price was $1,350, and the slippage was as high as 25%. However, the price of ETH on Uniswap quickly recovered and returned to the fair price.
As the market goes down, the impermanent losses in the DEX also expand, which leads to the fact that the fees earned by LPs may not be able to make up for the losses, thus reducing liquidity. Therefore, low liquidity brings the following problems:
• Low liquidity can lead to a large price gap, making it impossible for orders to be executed at the originally specified price, resulting in large slippage;
• Users bear the brunt of greater financial risks and cause serious economic losses;
• Small pools with low liquidity can be hacked using techniques such as flash loans to flood the market with excess orders and drain funds from smart contracts;
No comments:
Post a Comment