Understanding the Development Logic and Defects of the Automated Market Maker Balancer
This article was published on May 2, 2020, by ChainNews, and the author, Pan Zhixiong, is the Research Director at ChainNews.
Now is the best time to focus on the "Automated Market Maker" track in the DeFi space. In this track, the previous brightest star was the decentralized trading platform Uniswap. According to the latest DeFi data report released by Alethio, Uniswap is eating up an increasing amount of trading volume on the Ethereum chain. As a protocol that implements trading through automated algorithms, Uniswap surprisingly attracted 40% of the daily active users among Ethereum trading platforms during the "Black Thursday" on March 12.
Another star worth noting is Balancer, which just launched in early April. This newly launched DeFi platform injects more imagination into AMM tools like Uniswap: Balancer can not only serve as a trading tool but can also expand into a popular "index fund investment tool," with investment returns expected to exceed those of professional investors.
If Uniswap achieved a breakthrough from 0 to 1, then Balancer may drive growth from 1 to 10.
Balancer is a significant enhancement to on-chain liquidity tools. Compared to its predecessor Uniswap, it offers more settings and features, so you can think of it as a "premium version of Uniswap."
Before Balancer, Uniswap and Curve were the two most typical products in the same category: Uniswap provided a simple general solution, while Curve was deeply optimized for the stablecoin scenario. However, both Uniswap and Curve were limited to the "trading" scenario and could not expand to more applications. Moreover, in their trading functionalities, the level of customization was not high. For example, in Uniswap, liquidity providers cannot customize fees, each pool cannot allocate funds in specific ratios, and each pool only supports two tokens.
But Balancer broke through this issue. To provide market makers with a more comprehensive and customizable solution, Balancer addressed the aforementioned problems. In Balancer's design, market makers and liquidity providers can create a highly customizable trading pool to achieve:
- Customizable fees: Pools (trading pairs) with lower or higher trading fees, while Uniswap is fixed at 0.3%;
- Customizable asset ratios: Assets in the pool can be added in any ratio, while Uniswap requires a 1:1 ratio;
- Supports up to 8 assets: In fact, a pool can include up to 8 assets, while Uniswap pools only contain 2 assets;
- Index funds: A multi-asset pool can function as an index fund, allowing users to engage in passive investment.
From a certain perspective, Uniswap can be seen as a subset of Balancer. Users can create a pool that is almost identical to Uniswap through Balancer, but liquidity depends on the pool's capital volume, so there is a competitive relationship between the two.
Broadly speaking, Balancer is also competing with other asset management DeFi protocols. As liquidity providers for Balancer, the main purpose of investing capital is to earn trading fees, so if there are higher yield and lower risk investment opportunities, it may ultimately affect Balancer's liquidity performance.
Since Balancer launched on the Ethereum mainnet on April 1, it has seen good overall growth. Currently, 29 independent pools have been created, with a cumulative trading volume of $360,000 and total liquidity reaching $1.37 million.
The pool with the best liquidity is composed of WETH and MKR, gathering assets of about $760,000. This is similar to Uniswap, where the pools with advantageous liquidity are also composed of Ethereum and the governance token MKR of MakerDAO.
Overall, the development of Balancer is worth looking forward to.
A Brief Introduction: What are Market Makers, AMM, and Liquidity Pools?
Before delving deeper into Balancer, it is necessary to provide a brief introduction to "Automated Market Makers (AMM)."
Both Uniswap and Balancer belong to the category of Automated Market Makers (AMM). These types of DeFi products have become the infrastructure of DeFi. An increasing number of on-chain trading platforms or decentralized exchanges (DEX) have integrated AMM as a foundational liquidity guarantee.
Market makers are liquidity providers in trading markets, helping to enhance market trading efficiency.
Automated Market Makers (AMM) operate based on specific algorithms or models. For example, Uniswap uses the constant product market maker model, and there are more complex AMM models that can be customized based on trading categories or market fluctuations.
Each AMM protocol will include multiple liquidity pools, which can be understood as the trading pairs of an exchange, but they contain some assets used to execute the AMM's market-making model. Users interact with the AMM's liquidity pools mainly in three ways: injecting liquidity, withdrawing liquidity, and trading. Users injecting liquidity effectively become market makers, while users withdrawing liquidity are taking back their previous funds from the pool.
To encourage more ordinary users to inject idle funds into liquidity pools and become market makers, AMM protocols generally include a "dividend" mechanism that distributes collected trading fees to all liquidity providers based on their share of the pool.
What are the Differences Between Balancer and Uniswap?
As mentioned earlier, Balancer can be understood as a "premium version of Uniswap," while Uniswap can be seen as a subset of Balancer.
The term "premium" does not refer to performance, as both are based on Ethereum Layer 1, making it difficult to differentiate in terms of performance or transaction throughput; rather, the differences lie in customizability and scalability.
As the infrastructure for Ethereum DEX, Uniswap's advantages include a simple market-making algorithm and product logic, and because it lacks admin special privileges (admin key), it is considered by the community to be a highly decentralized protocol. Other common decentralized trading protocols like Kyber and 0x API also delegate some trading orders to Uniswap for matching.
To maintain the simplicity of product logic, some parameters in Uniswap are fixed within the protocol and are not open for user settings; it is uncertain whether they will be opened in the future. However, based on the current improvements in Uniswap V2, these aspects are still not the focus of Uniswap at this stage.
This precisely creates a breakthrough point for Balancer, allowing it to engage in differentiated competition with Uniswap. Compared to Uniswap, Balancer mainly increases the customizability of three components:
- Customizable pool fees: This parameter determines the additional trading cost that traders need to pay for each transaction, which is the income proportion that liquidity providers can earn;
- Supports up to 8 assets: This means ordinary users can achieve trading of up to 8 assets within a single pool, while in Uniswap, users often need to use multiple pools to trade two tokens;
- Configurable asset ratios: When creating a pool, assets do not need to be added in equal value (as in Uniswap) but can be added in any ratio.
The first point is a relatively clear feature, but the second and third points require more specific examples for understanding.
In addition, the core module of AMM tools, the "market-making algorithm," needs to be adjusted accordingly. The previously used "constant product market maker" algorithm model in Uniswap is no longer applicable and needs to be upgraded to a more general model, which we might call the "enhanced constant product market maker," adding weight and multi-token attributes to better support the aforementioned second and third features.
We hope to understand the differences between the two through an example. For ease of calculation, the following examples exclude the impact of trading fees and simplify the calculation scale.
Uniswap's Constant Product Market Maker Model
Assuming that Uniswap's ETH/DAI pool has 10 ETH and 1000 DAI, the constant product model for that pool is:
This model stipulates that regardless of how subsequent users trade, the product of the number of ETH and DAI retained in the pool remains constant at 10,000. If a user trades through this pool, submitting 10 ETH can exchange for 500 DAI:
Balancer's "Enhanced" Constant Product Market Maker Model
In Uniswap, a single pool only contains two tokens, so the above formula is valid. However, Balancer's market-making model supports multiple tokens, meaning a pool can contain 8 tokens (this is the current limit) that can be exchanged with each other, thus involving up to 8 variables at most.
It is also important to note that this model can support more tokens, and perhaps in the future, this limit will be lifted.
Assuming a Balancer pool contains ETH, DAI, and SNT, with the initial state of the pool containing 10 ETH, 500 DAI, and 100,000 SNT, and the creator of this pool sets the asset ratios to 30%, 30%, and 40%, respectively, the constant product for this pool model would be:
This formula takes into account the influence of multiple assets and their weights, allowing for the calculation of the ratios during each transaction. If the number of assets increases, more products are added, and so on.
Through the "enhanced" constant product market maker model, the pool can support up to 8 types of assets.
Advantages: Why Support Multiple Tokens?
Uniswap can facilitate the exchange of any two ERC-20 tokens, but this is actually achieved through two liquidity pools. Each ERC-20 asset can create a pool with ETH, and then ordinary users can provide liquidity for that specific pool.
For example, when a user exchanges SNT for BAT, it is actually done through the SNT/ETH pool and the BAT/ETH pool, with ETH serving as a trading medium to facilitate the simultaneous execution of both trading pairs, but this incurs two trading fees.
However, in Balancer, since a single pool can contain multiple tokens, the trading between ERC-20 tokens can be executed within the same pool, potentially reducing trading fees and on-chain gas costs.
Moreover, to reduce trading costs (slippage), Balancer can also help users find and aggregate the optimal trading path from multiple pools.
Advantages: Customizable Fees Promote Marketization
One major improvement of Balancer is that pool creators can set the trading fees for the pools, and customizable fees can promote the marketization of liquidity supply.
In Uniswap, each pool's fee is fixed at 0.3%, while Curve's fee is only 0.04%. Therefore, in stablecoin trading scenarios, users are likely to prefer Curve, as its market-making model is more suitable for stablecoins, resulting in lower slippage.
Balancer provides pool creators with the ability to customize fees, and different pools may compete for trading volume based on fees as a core parameter. This is expected to lower the overall trading fees of DEX.
For liquidity providers with large amounts of capital or those providing pools for certain special assets, they can set a higher trading fee because they provide more liquidity and special resources to the market.
Why Should Ordinary Users Provide Liquidity for AMM? It Can Be Profitable, But There Are Risks
Liquidity providers can view AMM as a form of asset management tool.
To incentivize more users to inject idle funds into liquidity pools, AMM needs to distribute the earnings from the pools to all liquidity providers.
Earnings depend on the pool's trading fee rate and the total trading volume of the pool. For example, Curve's pool has a low trading fee of only 0.04%, but due to high trading volume, it can yield returns of up to 20% annually for liquidity providers. However, recently, the returns from Curve's pools have significantly declined, dropping as low as 4%.
With the marketization of liquidity supply, returns will eventually revert to a balance point. If a certain pool's annual yield is significantly higher than others, more users will invest in that higher-yielding pool, and as the total amount in the pool increases, the unit cost of returns will decrease.
However, some risks are unavoidable.
From the perspective of protocol security risks, open-source AMMs that have undergone security audits carry relatively low risks, as all transactions are executed through smart contracts. But a clear drawback is that user earnings need to be valued in a basket of currencies. When users provide liquidity, they need to inject all supported tokens into the pool; when they withdraw liquidity, they also receive all supported tokens from the pool.
From the above " yield " formula, to simplify calculations, an important variable is actually omitted: the change in the value of the assets themselves. Thus, the above formula is suitable for pools where asset values do not fluctuate significantly (such as Curve's stablecoin pools). If the variable of asset value change is added, the pool's yield would need to subtract the depreciation of the asset's price or add extra gains, making calculations quite complex.
After all, prices between assets can fluctuate significantly based on market changes.
Taking Uniswap's balanced pools as an example, if a user initially provided liquidity of 1 ETH and 100 DAI (when the market price is 1 ETH = 100 DAI), but by the time they withdraw, the price of ETH has surged compared to DAI (the market price rises to 1 ETH = 133.34 DAI), they can only withdraw 0.9 ETH and 120 DAI.
If valued entirely in ETH, the user's initial investment of 2 ETH has dropped to 1.8 ETH (a loss), while if valued entirely in DAI, the user's initial investment of 200 DAI has risen to 240 DAI (a profit). In comparison, if the user had not participated in the pool and instead held 2 ETH, their asset value in DAI would be 266.67 DAI (still a loss).
Crypto Español channel blogger AlfaBlok once wrote specifically about this risk in more detail. When fixing certain parameters, in a more realistic case, under the premise of 1 ETH = 100 DAI, a trading fee of 0.3%, a pool size of 30K ETH, a monthly trading volume of 200,000 ETH, and a holding period of 1 year for Uniswap's ETH/DAI pool, when the ETH/DAI price fluctuates within the range of -80% to 120%, investing in the pool yields higher returns; otherwise, it is better to hold ETH.
In the entire yield calculation, variables include pool size, pool trading volume, trading fee rate, price fluctuations between the two assets, and the asset in which the valuation is made, etc., so this is not a simple asset management investment tool, which may become a barrier for many novice liquidity providers.
Disadvantages: Balancer Pools May Increase Trading Slippage
From the perspective of trading slippage, Uniswap's AMM model is superior. In Uniswap, each pool is set up with a 50% and 50% ratio, so its curve (X*Y=K) is a standard inverse function (only in the first quadrant).
In Balancer, however, since the proportion of each asset in the pool can be set, for example, if token A and token B are combined in a pool with a ratio of 85% and 15%, the constant product curve for that pool is as follows.
Blue curve
As previously introduced, the specific formulas for Uniswap and Balancer can be used to deduce that Uniswap's 1:1 model has lower overall slippage. Alternatively, you can refer to the above image, where the green point is a clear watershed; to the left of the green point, token B (Y-axis) requires a significant cost to exchange for a small amount of token A (X-axis).
If this situation is extended to Balancer's multi-token pools, the scenario is similar. However, to reduce slippage, Balancer's pools can also set asset ratios to 1:1 or 1:1:1, making them similar to Uniswap.
Reimagining Balancer's Potential: Index Fund Generator
Balancer has the opportunity to complement Uniswap well or become an important provider of on-chain asset liquidity. But that’s not all: another essence of Balancer is to serve as a tool for creating index funds.
Index fund investing is a fundamental investment strategy in traditional finance. For example, the S&P 500 or CSI 300 are two major indices, and fund companies can create corresponding index funds based on these indices to track market trends.
Due to the low fees associated with such passive investment funds, and often yielding returns that rival actively managed funds, they are a mainstream and popular form of passive investment in the market.
The father of index funds, Vanguard founder John Bogle, once said: "Regardless of market conditions, index funds provide you with reasonable market returns." Warren Buffett has stated: "By regularly investing in index funds, an amateur investor who knows nothing can outperform most professional investors."
Specifically, index funds are composed of various asset targets in corresponding proportions to track certain specific market indicators or asset prices. Coincidentally, this is exactly how Balancer's liquidity pools are set up.
Each Balancer pool supports up to 8 assets, so users can create an index fund composed of up to 8 assets through Balancer, such as:
- Tracking the cryptocurrency market, which can consist of Bitcoin (which can be realized through cross-chain to Ethereum's WBTC or HBTC), Ethereum, and DAI;
- Tracking the DeFi ecosystem, which can consist of native tokens of DeFi protocols, such as MKR, ZRX, KNC, BNT, etc.;
- Tracking the Oracle ecosystem, which can consist of native tokens of oracle products, such as LINK, TRB, NEST, etc.
There are many such examples. If the functionality allows, Balancer can also be used to issue composite funds or fund of funds (FoF), simply by supporting the aggregation of liquidity tokens from various index funds back into a Balancer pool.
Why Can the Index Fund Generator Solve Liquidity Issues?
Because index funds have a demand for rebalancing, while traders have a demand for finding optimal exchange rates or arbitrage. Matching these two demands provides liquidity to the market, and we can understand the entire process through an example.
Assuming the current market price is 1 BTC = 10,000 USDC, we create a fund on Balancer composed of 50% Bitcoin and 50% USDC, attempting to track the prices of the dollar and Bitcoin.
If after 5 days, the market fair price of BTC rises by 20% to 12,000 USDC, the value proportions of the two assets in the pool will adjust accordingly based on the latest market prices, becoming 55% and 45%.
However, the exchange ratio of this pool remains at 1 BTC = 10,000 USDC on the constant product curve. For external traders, the price within the pool deviates from the market price, creating an opportunity for external traders to profit.
According to the constant product model, arbitrageurs can invest 500 US dollars into the pool to obtain 0.0476 Bitcoin (equivalent to 1 BTC = 10,504 USDC), which is significantly lower than the market price (1 BTC = 12,000 USDC). Users can sell the 0.0476 Bitcoin on the open market, earning 571.2 USDC.
With a cost of 500 US dollars, they earn 71.2 dollars, yielding a single transaction return of 14%, which will certainly attract many arbitrageurs to enter and exploit the arbitrage space, increasing market liquidity.
Ultimately, the market price should be very close to the exchange ratio within the pool, and this is a dynamically ongoing process, so the asset distribution of the pool should continue to maintain the initial ratio set.
If we consider the above pool as an index fund, the market self-adjustment mechanism described above is equivalent to performing " rebalancing " of the index fund, restoring it to the initial index allocation ratio set. Conventional index funds typically rebalance at daily, weekly, monthly, or yearly frequencies, but in Balancer, rebalancing occurs at any time.
Issuing Liquidity Tokens Using Bonding Surfaces
How does the Balancer protocol record the amount of funds contributed by each liquidity provider? By issuing "liquidity tokens" as a form of accounting certificate. To better describe the process of "issuing liquidity tokens," Balancer also introduces the concept of "bonding surface."
The term "bonding surface" comes from "bonding curve," with the former being a more general version of the latter. You might also think of "bonding surface" as an upgraded version of "bonding curve."
First, let’s understand the well-known " bonding curve " in the DeFi space, which is a method of issuing tokens through smart contracts. Many people might think that "bonding curve" refers to a specific curve, but it is actually just a concept used to describe the relationship between "token issuance" and "token price." Therefore, regardless of whether the functional relationship between the two is plotted as a curve or a straight line in a Cartesian coordinate system, they can all be referred to as "bonding curves."
Why do "token prices" and "token issuance" have a functional relationship? Why is there no correlation between the issuance of Bitcoin or Ethereum and their prices?
Because issuing tokens using "bonding curves" is similar to the primary market, not the secondary market. Moreover, this primary market is different from the primary market for project financing; the process of issuing tokens via bonding curves is implemented through smart contracts.
What is the Relationship Between Bonding Curves and Balancer?
There is one main function: issuing "liquidity tokens" as a form of accounting certificate for the liquidity contributed. When users provide liquidity for a certain pool in Balancer, Balancer calculates the user's contribution based on the amount of assets contributed, using the corresponding formula, and issues the corresponding "liquidity tokens" as a form of proof.
If, after a period of time, the pool has not undergone any changes, the user can exchange the previously issued liquidity tokens back for the same assets. However, if during this period the pool has collected more trading fees, the user can exchange the previously issued liquidity tokens back for the same assets plus the trading earnings they have accrued.
It is called a bonding surface because the bonding curve only involves two tokens: the contributed token A and the received token B. However, in Balancer's dual-asset pools, it actually involves three tokens: token A and token B in the pool, as well as the corresponding "liquidity tokens."
X and Y axes represent token A and B, while the Z axis represents liquidity tokens.
The bonding surface describes the relationship between token A, token B, and liquidity tokens in the pool. However, if Balancer's pool contains more than two tokens, the bonding surface will also upgrade to a higher-dimensional surface. Although it is challenging to plot higher-dimensional bonding surfaces on a computer, all formulas and definitions remain valid.
Balancer Has Opened the Door to AMM Application Scenarios
The AMM concept initiated by Uniswap and Bancor has always been confined to the scenario of spot trading. Balancer is the first tool to broaden the application scenarios of AMM, demonstrating that AMM can not only facilitate ordinary spot trading but can also serve as an index fund management platform to manage large-scale passive investment funds in a decentralized manner.
Now, more and more DeFi projects are exploring various limits of AMM, such as Curve and Shell Protocol optimizing stablecoin AMM algorithms, while MCDEX and Futureswap are exploring the field of derivatives trading, such as 20x leveraged perpetual swap contracts.
At the current stage, Ethereum's performance is limited, and the DeFi ecosystem may need automated tools like AMM to reduce on-chain submission frequency to save network performance. However, if one day Ethereum 2.0 significantly increases transaction throughput by hundreds or thousands of times, it may present a different scenario, where market making is almost dominated by professional institutions like centralized exchanges. At that time, the scenario for general-purpose AMM is a question that the DeFi ecosystem can consider now.