Revolutionizing DeFi: A deep dive into AMM and the AMM landscape on Starknet

Everything you need to know about AMM

Introduction

Automated Market Makers (AMMs) have emerged as a revolutionary concept within the decentralized finance (DeFi) landscape, reshaping the way users exchange tokens in a decentralized manner. Instead of relying on traditional order books, AMMs operate through liquidity pools, enabling users to directly swap assets within a decentralized and permissionless environment.

In this article, we will delve deeper into the essence of AMMs, looking at their fundamental mechanisms and how they have evolved through various versions. We will also explore the evolving AMM landscape on Starknet, highlighting notable projects and the exciting innovations they bring.

Table of Contents:

  1. I/ What is an AMM ?

  2. II/ Different versions of Uniswap-style AMM: version 1 - 2 - 3 - 4

  3. III/ AMMs landscape on Starknet

I/ What is an AMM ?

An AMM is a decentralized exchange (DEX) that allows users to exchange two tokens with each other through liquidity pools, rather than an order book. Orders are executed automatically by a smart contract that calculates exchange prices based on the liquidity present in each pool.

Liquidity pools typically consist of two assets (although there are also pools with more than two assets, such as those found on Curve Finance). The price of each asset in the pool is calculated using formulas directly implemented in the AMM's smart contracts, which vary the price based on supply (liquidity in the pool) and demand (swaps).

The most commonly used formula (especially in the context of UniV1-V2 style AMMs) is: x*y=k where:

  • x = value of asset A

  • y = value of asset B

  • k = constant

If x increases, the value of y will decrease to maintain the constant value of k. This creates a range of different prices for two assets based on the supply and demand of those two assets.

For example 👇️ 

Let's consider an ETH - USDC pool with the following quantities: 10 ETH (x) and 1000 USDC (y).

  • x*y = k

  • 10 * 1000 = k

  • k = 10,000

When a user buys ETH in exchange for USDC, if he wants to buy 1 ETH, the price of ETH will not be 100 USDC but 👇️ 

  • 9 * y = 10,000 (9 because he is removing one ETH from the pool and adding USDC)

  • y = 10,000/9

  • y = $1,111.11

This result is because the constant K must always be equal to 10,000 based on the liquidity present: 9 * 1,111.11 ~ 10,000

After this purchase, the new quantity in the pool will be 👇️ 

  • 9 ETH (x)

  • 1,111.11 USDC (y)

Thus, the user will have bought its ETH for 111.11 USDC, not 100 USDC.

This mechanism ensures that the market balances itself based on supply and demand, without the need for an intermediary. Therefore, an AMM can be defined as: "A mathematical function to algorithmically price assets based on liquidity pools".

Since prices are only influenced by demand and liquidity in each pool, imbalances between the prices of one AMM pool and those of others AMM are often present.

This is why it is preferable for swappers to use aggregators that gather this fragmented liquidity in one place rather than on AMMs directly. Arbitrageurs intervene to rebalance the pools by taking advantage of imbalances to make profits—for example, buying ETH at $1200 on AMM B and selling it at $1220 on AMM A. Since this activity is often automated by bots and algorithms, it is rare - if not impossible - to find an arbitrage opportunity. When there are no more profitable opportunities, the pools are balanced.

All AMM users can become liquidity providers (LP) by providing liquidity in the AMM pools in exchange for the fees generated by these pools. For example, liquidity providers in the ETH-USDC pool receive all the fees generated by that pool. These fees come from all trades made on this pair (in UniV2 style AMM, this corresponds to 0.3% of each swap).

LP are rewarded for two reasons:

  • The liquidity they provide allows AMM to function; without fees or token incentives, there would be no interest in providing liquidity.

  • They take two risks: the risk related to the smart contract (hacking, backdoor...) and the risk of Impermanent Loss.

What is Impermanent Loss (IL) ?

When a LP participates in a pool, the liquidity is divided between the two assets. For example, if an LP provides liquidity to the ETH-USDC pool, the LP will deposit 50% in ETH and 50% in USDC.

IL is a phenomenon in which the LP would have a higher value if he had simply held its assets rather than providing them to the pool. For example 👇

Digger deposits 10 ETH and 10,000 USDC in an ETH/USDC pool, where the price of one ETH is 1,000 USDC. The value of the initial deposit is therefore 20,000 USDC.

The pool in which Digger deposited contains 50 ETH and 50,000 USDC, which means that Digger holds 20% of the pool.

  • 50 (x) * 50,000 (y) = 2,500,000 (k)

The price of ETH is multiplied by 4 and is now worth 4,000 USDC. After the arbitrageurs' transactions, the price of ETH and USDC in the pool balances according to this new price. The pool now consists of:

  • x () * 200,000 (y) = 2,500,000 (k)

  • x = 2,500,000/200,000

  • x = 12.5

That is 12.5 ETH and 200,000 USDC.

If Digger, who holds 20% of the pool, decides to withdraw, he will end up with:

  • 2.5 ETH and 20,000 USDC, or a value of $30,000.

If Digger had simply held onto its assets, its value would have been $50,000 (10 ETH + 10,000 USDC). Instead, he gained $10,000, but missed out on a potential gain of $30,000 if he had held onto its assets. This represents an IL of $20,000.

Despite the IL risk, LPs provide liquidity in the hopes of earning much more through fees.

So, an AMM enables users to:

  • Exchange assets directly from a non-custodial wallet in a decentralized and permissionless environment.

  • Create their own pools and provide liquidity for new tokens.

  • Trade without the need for a counterparty, unlike order book DEXs.

  • Become a market maker by providing liquidity to pools.

II/ Different versions of UniSwap style AMMs: version 1 - 2 - 3 - 4

Although there are other types of AMMs, such as hybrid formula AMMs, three-asset pools, and Curve stable pools, the most commonly used AMMs to date are constant formula AMMs (the one we explained above: x*y=k).

The pioneer of this type of AMM is Uniswap, which launched the first version of AMM (V1) in November 2018. Since then, we are already at version 4, with the recent launch of Ekubo on the Starknet Mainnet.

Let's look at each version one by one.

1. UniV1 style AMM 👇

As mentioned above, Uniswap V1 was released in November 2018, offering a revolutionary new type of DEX: AMM. For the first time, users were able to provide liquidity, become market makers, and trade without the need for counterparties, whether through intermediaries on CEXs or the opposite party on an order-book DEX. Uniswap also allowed anyone to create their own trading pairs and list their own tokens without permission.

The characteristics of Uniswap V1 are:

  • ETH/ERC20 exchange pair: All exchanges use ETH, so in order to exchange token A for token B, you first need to exchange token A for ETH, and then ETH for token B.

  • Uniswap factory: It allows anyone to create an exchange contract for any ERC20 token without permission, and thus create their own liquidity pools by providing an equal value in ETH and ERC20 tokens for the pool.

  • Opening the Market Making market for anyone: Now, anyone can provide liquidity on any ERC20 pool of their choice.

2. UniV2 style AMM 👇

UniSwap V2 was launched in May 2020, providing significant improvements to the user experience, diversity, and flexibility for traders and LPs. The main addition is the ability to directly trade ERC20/ERC20 pairs without having to go through ETH each time, which greatly reduces slippage and gas fees that traders pay for ERC20/ERC20 exchanges.

Compared to V1, Uniswap V2 has the following characteristics:

  • Direct pairs between ERC20 tokens, no need to go through ETH: any ERC20 token can be paired directly with any other ERC20 token.

  • Optimization of price oracle: the introduction of a time-weighted average price (TWAP) over a 24-hour period, which helps to reduce the risk of price manipulation.

3. UniV3 style AMM 👇

Uniswap V3 was introduced to the market in May 2021, with its main innovation being concentrated liquidity. This innovation provides LP with greater control and profitability over their positions. It also enables traders to obtain better rates for their transactions.

Prior to V3, LPs provided liquidity on a single price range, from 0 to infinity. However, with V3, LPs can choose the price range in which they want to provide liquidity, allowing them to manage their risk and obtain better returns than before. The smaller the range, the more fees the LP will receive when the price is within that range. This enables liquidity to be concentrated where traders need it the most.

For instance, in a USDC/USDT pool, the price ranges between $0.995 and $1.005 99% of the time. Thus, it is unnecessary to offer liquidity for a price range from 0 to infinity.

In summary, Uniswap V3 provides LPs with more options and revenue optimization while also improving traders' efficiency when compared to Uniswap V2.

Furthermore, Uniswap V3 introduces new exclusive features:

  • Three fee options for LPs: LPs now have more flexibility in choosing fees compared to V2, which only offers a 0.3% rate. LPs can now select from three fee levels (0.05%, 0.3%, and 1%) based on the risk level and volatility of the pools.

  • Fee optimization and capital efficiency: Liquidity concentration allows for up to 4000 times improvement in capital efficiency, while optimizations in the oracle mechanism reduce transaction fees for simple transactions by 30% compared to the V2.

  • NFT implementation: NFTs now represent LP positions and the unique choice of price range and fee level per position.

  • Order types: The range choice corresponds to limit orders on the market.

For example, suppose an LP provides $1000 in ETH/USDC in the price range of $900 to $1100 for ETH. If the price drops below $900, the position is converted to USDC ($1000). If the price rises above $1100, the position is converted to ETH. If the price then returns to the range, the assets are converted back in equal parts, and the strategy resumes.

The drawback of this new version is that liquidity providers must monitor their position much more actively.

Also, in Uniswap V3, the formula x*y=k is slightly modified: there is no longer a single constant K, but a multitude depending on each customized price interval defined by the liquidity providers. Now, each liquidity provider chooses their own value of K.

4. UniV4 style AMM 👇

Uniswap V4 is not yet available, but its plan was made public in June 2023. The main improvements of V4 are the fee optimization for pool creators and swappers.

Here are the main features:

  • Singleton: All Uniswap pools are grouped into a single smart contract, unlike before where one pool equaled one smart contract. This drastically reduces costs: pool creation costs by 99% and swap costs by 50%. The architecture provided by the singleton contract contains part of the code required for pool creation, so it is no longer necessary to deploy it every time, reducing the number of calls in contracts. All of this takes less time and costs less!

  • Hooks: modules that are attached to pool smart contracts to allow developers to customize pools. In V3, it was only possible to customize LP and fees (choose from 3: 0.05%; 0.3%; 1%). Here, LPs can adapt pools to their needs and preferences. For example, an LP can choose to set up dynamic fees that adapt based on market volatility and a hook that allows lending liquidity outside the range on a lending protocol to generate yield even when it goes out of range. But also a hook that automatically reinvests LP fees into LP positions or setting up MEV in the pool and distributing profits to LPs. The possibilities are endless and only limited by the imagination of devs.

Aggregators will greatly benefit from UniV4 style AMM thanks to the improved capital efficiency and the huge liquidity that will be grouped into the singleton.

What is exciting is that the creation of these versions (V2 - V3 - V4) complements each other and meets all needs:

  • V2 offers simple and passive LP

  • V3 enables capital efficiency and profit maximization for active LP

  • V4 is more complex but drastically reduces gas fees and allows for much more flexible pools for LP

III/ AMMs landscape on Starknet

Now that you have an overview of each type of AMM and what they offer to the market, let's map out the AMM present on Starknet.

A. Jediswap 👇️

JediSwap is the top DeFi protocol on Starknet in terms of TVL, thanks to its innovative approach that enables anyone in the community to participate in building the protocol. In fact, the JediSwap protocol is entirely built and owned by its community.

At present, JediSwap is a simple UniV2 style AMM. However, the team has been working on upgrading it to v3 for months, and it is set to be released soon according to the JediSwap roadmap.

B. mySwap 👇️

mySwap is the first AMM to be launched on the Starknet Mainnet. It is built by the same team as the Braavos wallet and is integrated into it, allowing users to trade directly from the wallet interface.

Currently, mySwap is an UniV2 style AMM. While there is no official information about the development of a v3, it is likely that the team is working on it.

C. 10kSwap 👇️

10kSwap is the third protocol in terms of TVL to be deployed on Starknet. However, there is limited information available about it, such as the absence of a roadmap, partnerships, or a doxed team (unlike JediSwap and mySwap).

10kSwap is also an UniV2 style AMM.

D. SithSwap 👇️

SithSwap is a hybrid AMM that offers both volatile pools (similar to UniV2 style AMM) and stable pools (similar to Curve). Volatile pools are suitable for negatively correlated assets (where y decreases when x increases and vice versa), while stable pools are suitable for uncorrelated assets, such as stablecoins, whose value remains stable during trades.

Therefore, stable pools are specifically designed for tokens with little or no volatility during trades; the formula is optimized to offer minimal slippage, even for large transaction volumes.

While v2-type pools follow the formula x * y = k, SithSwap's stable pools follow the formula xℨy + yℨx ≥ k.

E. Ekubo 👇️

Ekubo is the first UniV4 style AMM in the entire crypto ecosystem and has recently launched on the Starknet Mainnet (in private alpha).

The project is currently awaiting integrations from Starknet aggregators to publicly launch the protocol.

As the only UniV4 style AMM on Starknet (where there are currently only UniV2 style AMM), it is likely that Ekubo will attract TVL from other AMMs in the coming weeks.

F. Coming AMMs 👇️

Four new AMMs will soon be available on Starknet:

In addition, there are also two other (very small) UniV2 style AMM on Starknet: StarkEx and Protoss.

Conclusion

In the rapidly evolving realm of DeFi, AMM stand as a testament to the transformative power of blockchain technology. These ingenious protocols have disrupted traditional exchange mechanisms, offering users unprecedented autonomy and efficiency in token swapping. From the foundational x*y=k formula to the latest iterations like v4, AMMs have continuously evolved to provide enhanced functionalities and liquidity management. The landscape on Starknet presents a dynamic array of AMMs, each contributing to the growth and diversity of the DeFi ecosystem. With each advancement, AMMs redefine not only how tokens are exchanged but also how financial systems can be redesigned for greater inclusivity and innovation.

To take advantage of these AMM and make swaps on Starknet, I recommend using AVNU, the DEX aggregator of Starknet. This aggregator unifies all the fragmented liquidity of Starknet into a single interface. This means that, thanks to its routing algorithm, you will automatically get the best available rates across all of these AMMs, saving you time and money. If you want to learn more about AVNU, check out this thread that explains the project in detail.

Additionally, if you wish to benefit from the growth of these AMMs as a LP, I suggest exploring Morphine. Morphine is a yield optimizer that aggregates all the necessary data on its interface to help you take advantage of the best APR on Starknet (there are some excellent opportunities on some Starknet AMM for those who search carefully!).

And, if you want to learn more about Starknet's AMMs, follow me on Twitter. I will be posting two deep-dive threads about SithSwap and Ekubo very soon!

If you enjoyed this article, feel free to share it and follow me on Twitter, that’s the best way you can support me and push me to continue! Also, feel free to subscribe to this newsletter and to join my Starknet community Discord, it’s totally free!

Join the conversation

or to participate.