AMMs Made Easy — A Beginner Guide To Automated Market Makers

Beethoven X
Balancer Protocol
Published in
13 min readJul 25, 2024

Automated Market Makers have facilitated over $1.256 trillion in transactions over the last year.

In the past 24 hours alone, more than $5.5 billion in volume has been processed through AMMs.

Historically, over 62 million unique addresses have used an AMM to swap tokenized assets permissionlessly on the blockchain.

There is no doubt that AMMs are rapidly absorbing financial market share, but do you know what they actually are?

Automated Market Makers provide one pivotal DeFi function: allowing users to swap tokenized assets on an immutable, trust-minimized, smart contract-powered decentralized exchange. While this statement is factual, it’s also a bit of a mouthful, filled with crypto buzzwords and complicated terminology — much like the plethora of DeFi educational material spread across the internet today. Unlike other resources, this article aims to explain things simply: starting with the basics, sprinkling in some technical details, and finally looking towards the future.

DeFi

Ethereum allowed for the creation and execution of trustless agreements based on a predefined set of instructions, known as Smart Contracts. Just as the App Store offers a secure environment for apps on iPhones, Ethereum provides a decentralized and programmable blockchain environment for creating decentralized applications (dApps). This means that while Bitcoin created a finite and decentralized monetary unit, Ethereum has enabled the development of a new and powerful financial system.

Where previously intermediaries such as banks and lending agents were required to facilitate interactions in the financial system, smart contracts have enabled the creation of decentralized applications (dApps) that require no human intervention once deployed. For example, on-chain lending markets allow anyone with an internet connection to supply a tokenized asset and earn interest from those who wish to borrow it. There are no middlemen to solicit or block the transaction; instead, there is simply a piece of cryptographic code governed by a mathematical model that calculates interest rates based on supply and demand mechanics.

Stablecoins have been created to offer users a tokenized version of national currencies such as the USD and EUR — a $164 billion sector that has seen adoption from traditional financial giants like Visa and PayPal. Backed by transparent off-chain reserves (such as US Treasuries) or pegged to the dollar but backed by ETH, stablecoins provide anyone, anywhere with instant access to an online and tokenized currency of their choosing.

With the advent of smart contracts, finance has entered into a programmatic and decentralized frontier known as DeFi, or Decentralized Finance.

Decentralized Exchanges

At the very center of the smart contract-powered economy lie Decentralized Exchanges, a $72 billion sector at its peak, enabling the permissionless peer-to-peer trading of tokenized assets. Beyond the meteoric rise of stablecoins, crypto-native assets and tokenized Real World Assets (RWAs) have seen significant liquidity inflows into the blockchain. For anyone to swap these assets trustlessly, an application is required that allows for asset swapping without a middleman. These applications are known as Decentralized Exchanges or DEXs for short.

DEXs eliminate the need for a middleman by implementing a ‘liquidity pool’ that combines a collection of funds in a smart contract to facilitate trading. Liquidity providers are incentivized to supply assets to the contract, such as Ethereum (ETH) and a stablecoin like USDC, by earning fees each time an ETH <> USDC swap occurs.

With an ever-expanding array of tokenized assets, there is an increasing number of combinations in which these assets can trade. This leads to hundreds of different liquidity pools and constant iterations and evolutions in the logic of how these pools operate. For liquidity pools on a DEX, the trading of assets within the pool is governed by math and implemented through code. The method by which assets are traded, known as the logic and accounting of the pool, is defined by the specific Automated Market Maker (AMM) utilized by the liquidity pool.

In summary, a DEX is a Decentralized Exchange application that users leverage to trade tokenized assets. A liquidity pool enables these trades by pairing assets within a smart contract and incentivizing users to provide liquidity by offering them trading fees. The AMM determines how the assets within the liquidity pool are traded.

Automated Market Makers

Instead of relying on traditional buy and sell orders, Automated Market Makers (AMMs) enable users to trade directly with a pool of funds provided by other users, known as a liquidity pool. These pools are governed by algorithms that automatically adjust asset prices based on supply and demand.

If one asset’s price is plotted on the x-axis and the other on the y-axis, the way the assets trade can be represented on a graph. The resulting line, or curve, is governed by a mathematical formula that relates the two assets, known as the invariant.

To illustrate, if a liquidity pool uses an AMM with an invariant defined by the equation X + Y = K, the curve on the graph would be a straight, linear line (as shown on the graph above with the dashed line). The graph also displays two other AMM invariants commonly used in DeFi for different asset types. For stable assets, a stableswap invariant is typically employed, while for volatile assets, a constant-product invariant is used.

AMMs operate based on mathematical principles. Unlike the subjective nature of human agreements, their outcomes are deterministic and can be mathematically proven and solved.

To clarify, let’s delve into an example.

Constant Product AMM

The constant product invariant allows two assets that are unrelated and volatile to trade against one another in a pool of equal weights, for example, a 50/50 pool containing ETH and USDC. This invariant works by ensuring that the product of the quantities of two assets in a liquidity pool remains constant during trading by implementing a formula that states:

x⋅y = k

where:

  • x is the quantity of one asset in the liquidity pool.
  • y is the quantity of the other asset in the liquidity pool.
  • k is a constant that remains unchanged during trades.

Here’s how it works:

  1. Starting State: Suppose a liquidity pool starts with 10 units of asset x and 20 units of asset y. The constant k would be 10×20=200
  2. Trade Example: If a trader wants to swap asset x for asset y, the new quantities of x and y must still satisfy the equation x⋅y =200.
  3. For instance, if the trader swaps 5 units of x, the pool absorbs it, making it 15 units. The quantity of y must also be adjusted so that 15⋅y =200. Thus, y would become 200/15 ≈ 13.33

This invariant ensures that as one asset is added to or removed from the pool, the price of each asset adjusts automatically according to supply and demand, maintaining a balance within the pool.

Arbitrage Trade

When a swap occurs on a DEX, the asset flows through the most efficient route available. For example, if one swaps ETH for USDC, the transaction might pass through an ETH/USDC pool that uses a constant product AMM. In this case, the trader sells their ETH, and all liquidity providers (LPs) in the pool collectively absorb the sale, effectively becoming buyers of ETH at that specific price.

Each time a swap occurs via an AMM, the price of the assets in the pool adjusts based on the underlying logic (invariant) used. These price changes are isolated within the specific pool facilitating the swap. Consequently, the same assets may trade at slightly different prices across different pools, creating opportunities for arbitrage trading. Arbitrage traders are economically incentivized to find instances where the same asset is priced differently in separate markets. They buy the asset at a lower or “undervalued” price in one market and sell it at a higher price in another, thus profiting from the price discrepancy.

Liquidity Provision

Why would a user provide liquidity to a pool?

Liquidity providers (LPs) are economically incentivized to provide liquidity because they can earn swap fees, akin to interest, on the assets they supply. Instead of merely holding two assets, such as ETH and USDC, in a wallet, a user may choose to bet on the volatility and the resulting swap revenue these assets could generate by supplying them to an ETH/USDC liquidity pool. The bulk of liquidity provider swap fees are generated through the underlying arbitrage opportunities that AMMs create.

Swap fees work as follows:

Swap fees are set by the pool deployer (e.g., 0.5% on every trade) and are then shared among all users in the pool based on the share of liquidity they provide. For example, if the pool is worth $100,000 and a user supplies $1,000, that user would receive 1% of the total swap fee revenue. These fees are automatically compounded within the pool token that liquidity providers receive. An LP token can be thought of as a receipt token representing a user’s share of the pool; while the number of LP tokens won’t naturally increase, the value of the pool, and thus the LP token, increases as fees accumulate.

This relationship has two important features:

1. To generate organic yield, LPs require a large number of swaps flowing through the pool (volume).

2. To enable large volumes, the pool requires deep liquidity to ensure traders’ swaps do not occur slippage.

Slippage refers to the difference between the expected price of a trade and the actual price at which the trade is executed, caused by the trade’s impact on the liquidity pool’s balance. High slippage indicates that a trader is receiving a poor price for the assets they are swapping.

For example, a trade with 10% slippage would result in a $100 trade yielding only $90. Slippage is more significant with larger trades or in pools with low liquidity, as these factors have a greater impact on the pool’s token prices, leading to less favorable rates for traders. AMMs require deep liquidity to ensure swaps occur with minimal slippage.

On the other hand, as the liquidity within a pool increases, the share of the pool an individual liquidity provider (LP) owns relative to the whole pool decreases, which in turn reduces the swap fees that the liquidity provider earns. Traders desire deep liquidity for better pricing, while liquidity providers prefer a smaller pool to maximize their share of the swap fees. This dynamic creates an AMM principal-agent problem, where liquidity providers and traders have competing interests.

The solution? AMM innovation.

AMM innovation

Throughout history, systems have evolved to become as efficient as possible, and AMMs are no exception. The efficiency they seek in this regard, is known as capital efficiency.

Simply put, capital efficiency refers to optimizing liquidity provision so that less capital provides better prices for traders while simultaneously generating more volume and thus greater yield for LPs. Another way to consider it is to ask: how much of a liquidity provider’s capital is being utilized for swaps at any given time?

In traditional AMMs, often as little as 10% of the available liquidity is utilized at any given time. The goal of all AMM designers is to increase this number as close to 100% as possible. Various solutions have emerged from this design goal, which we will briefly explain below.

Concentrated Liquidity AMMs

Rather than spreading LP liquidity over the full range of the curve and potential token prices, concentrated liquidity confines the allocated liquidity within a smaller and more focalized range. This allows sophisticated DeFi users to allocate to price bounds where they believe the majority of swaps will be concentrated.

The result is that, if configured to the right range, less capital can be supplied which will see a higher return in swap yields and also provide more effective swap prices for traders as liquidity depth is increased. The drawback with this AMM model is that the position requires constant management to ensure the area in which liquidity is being supplied is the correct area. If the price falls outside of this range, the liquidity will not generate any swap yield for LPs, nor supply any liquidity for traders.

Balancer Boosted AMM

While concentrated liquidity has proven to be one mechanism for increasing capital efficiency, Balancer boosted pools provide a powerful alternative without the burden of continuous liquidity and tick management. Rather than confining liquidity within a predefined swap range, Boosted Pools deposits idle liquidity in a trusted third-party platform (like Aave or Yearn), providing passive LP exposure to an additional layer of sustainable yield.

For example, if a Liquidity Provider provides ETH and USDC to a boosted pool, 20% of a Liquidity Provider’s assets may be utilized for swaps in a given day. But rather than the remaining liquidity sitting idly, the other 80% will be directed to yield markets such as Aave and supplied as collateral to generate additional yield. This means that liquidity providers gain exposure to both AMMs and lending markets, unlocking both Swap Fees + Lending Market Interest Rates.

Balancer v3 will iterate on this dynamic further with 100% boosted pools that direct 100% of underlying LP liquidity at yield markets while implementing a unique “buffer” contract to allow gas-efficient unwraps to ensure liquidity is always available for swaps.

AMM Made Easy

As explained above, the goal of AMM developers is to make capital efficiency as optimal as possible. I.e allow liquidity providers to earn more, while providing less (while ensuring low slippage swaps for traders).

To date, the AMM design space has been tackled mostly by a small portion of established DeFi teams with a majority of swap volume flowing through a handful of AMMs.

The great question is: Will the AMM landscape look the same today in the next 5 years? As with everything, likely not.

If you were to map out the development and deployment of a new AMM built by a new team, the approach traditionally takes place as follows.

The team ideates around AMM innovation, program logic, runs simulations, develops the DEX’s front-end, back-end, and accounting contracts, bootstraps liquidity, reaches out to aggregator integrations, launches incentive mechanics, forges business partnerships, builds social network, initiates marketing strategy, and so on…

AMM developers must not only design new and innovative AMM logic but also build the whole decentralized exchange and social network.

AWS (AMM Web3 Service)

For over three years, Balancer Technology has been at the forefront of Automated Market Maker (AMM) innovation.

Yet, rather than isolating AMM innovation to the internal team, Balancer takes a different approach — It simplifies and streamlines the AMM development process for everyone. To use an analogy, just like AWS is a building block for websites, Balancer Technology can be considered a building block for AMM deployment (AMM Web3 Service).

Besides in-house developed weighted and boosted pools, Balancer powers a wide array of DeFi projects, including Gyroscope’s E-CLPs, Cron Finance’s TWAMMs, Fjord’s LBPs, and Xave’s FX markets.

Balancer Technology does this by taking a unique design approach that separates low-level tasks that are trivial across all AMMs, like token management, accounting, and front-end interface… and instead creates a streamlined launchpad for teams to plug in and innovate with different AMM strategies. The technology allows external teams to leverage a pre-built UI/UX, and instantly plug into an existing liquidity, incentive, and partnership network to streamline AMM deployment.

In simple terms, Balancer allows external teams to code less, build more, and bring AMM products to market. FAST.

Gyroscope

Gyroscope is a great example. The protocol designed a custom elliptical concentrated liquidity invariant that focalizes swap liquidity within an asymmetric curve to boost capital efficiency. This novel concentrated liquidity AMM does not require active management by Liquidity providers while still offering the benefits of optimal, concentrated liquidity allocation for swaps.

Rather than building this custom AMM from scratch, the Gyroscope team chose to leverage Balancer Technology to plug into a battle-tested liquidity layer and incentive system, gain instant connection to the Balancer social network, and streamline the ability to showcase PMF.

E-CLPs instantly showcased their unique capabilities, forged multiple partnerships within the Balancer network, onboarded millions of dollars in liquidity, and saw a vast uptick in capital-efficient volume which totals over $1,700,000,000 today.

The Future of AMMs

As DeFi continues to grow, the types of assets deployed on the blockchain, and how they trade will need to evolve and develop alongside it. One specific avenue currently proving to be a focus for AMM development is rebalancing the asymmetry of information arbitrage traders have vs LPs in an area known as MEV mitigation.

“On-chain interactions are moving towards being executed in a fair, MEV-minimizing manner. For LPs to become more profitable, our industry must seek solutions to capture the MEV that currently ends up in the hands of validators.”

— Fernando Martinelli (Balancer Co-Founder)

As a testament to the role Balancer Technology can play in streamlining AMM deployment, CoW DAO recently announced that they would leverage Balancer’s expertise, infrastructure, and integrated UI/UX to launch CoW AMM — the first MEV-capturing, LVR-resistant AMM design in DeFi.

“Loss versus rebalancing (LVR) is arguably the biggest (application layer) problem for DeFi on Ethereum. Traditional AMMs are inefficient, and for the next generation of AMMs, the alpha of AMM design is LVR.”

- A recent post by Blockworks Research

While the breadth of AMM products that will emerge remains to be seen, Balancer empowers developers to define them.

“In the face of uncertainty, be like the bamboo: strong yet bending. Prepare for change, but remain adaptable to whatever comes.”

--

--