dAMM, an L2-Powered AMM

A DeFi-friendly L2 AMM

StarkWare
StarkWare
Apr 4 · 5 min read

TL;DR

  • Capital efficiency is a major source of concern when considering L2 solutions for DeFi.

Background

AMMs are an important DeFi tool. Its core qualities — autonomy, composability & liquidity bootstrapping — make AMMs the first building block of the DeFi lego. Since its start with Bancor and Uniswap, the AMM design space has been developed in many directions: from specialized markets (e.g. Curve), through generalized markets (e.g. Balancer) to impermanent-loss-aware markets (e.g. Dodo or Bancor V2).

How do AMMs fit in with the fast-growing L2 scaling landscape?

Up till now, L2 AMM designs entailed moving the AMM in its entirety to L2, including liquidity, resulting in undesirable fragmentation of L1 liquidity.

We propose an L2-powered AMM design that allows liquidity to remain on L1, and users to trade on L2.

Beyond allowing L1-based Liquidity Providers (LPs) to participate in the AMM, this design also allows:

  • Liquidity to be deposited in other L1 DeFi protocols (work initiated by BentoBox and Balancer V2).

What is dAMM?

High-Level Concept

dAMM is an L2-powered AMM. It allows liquidity to be bridged on L2 while remaining unfragmented, on L1.

dAMM has an off-chain Operator, which processes batches of L2 trades. The Operator is the sole entity trading against an L2 powered AMM contract on L1. It mimics the contract’s logic, and offers trade quotes based on the state of the AMM at the beginning of the batch, and the subsequent L2 trades included in the batch.

At the end of the batch, the Operator settles all trades by executing the net difference against the L2 powered AMM contract. The Operator must mimic the contract’s logic, and apply it to the correct state of accounts, in order to ensure that the L1 contract will be able to serve as a counterparty to the L2 trades.

Participants

Off-chain

  • Operator: a risk-less market maker existing on L1 and L2s.
    The Operator functions as a coordinator. Its sole purpose is to match traders within each batch with one another and match the net difference against the L1 contract. It settles batches of trades using STARK proofs.
    Note the Operator is only trusted to fairly order all trades. To remove this point of centralization, the Operator itself could be decentralized.

On-chain

L2 Powered AMM Smart Contract
This contract presents a standard AMM interface with two major modifications:

  • Only the Operator can trade against this contract on L1.

StarkEx: The smart contract connecting the AMM’s logic with the off-chain StarkEx scalability engine.

What’s New? Batch-Long Flash Loans

As we said previously, StarkEx will soon add two new features: L1 Limit Orders and Batch-Long Flash Loans. We already described L1 Limit Order in our DeFi Pooling post. Let us introduce Batch-Long Flash Loans.

Batch-Long Flash Loan is a flash loan that is not limited to a single transaction; instead, it extends for the duration of a batch. It offers the Operator the ability to mint tokens on L2, as long as these tokens are burned by the end of the batch.

This improves the Operator’s efficiency to serve as a middle man, simplifying the merger of multiple Limit Orders into a single one, or routing trades within the L2.

Basic Operations

L2 Trading

  1. Alice/Bob requests/approves a quote from the Operator

Because the Operator abides by the AMM formula, they can:

  1. Generate an L1 Limit Order from the AMM

L1 LP-ing

For LPs, there is no difference whatsoever between L1 and L2. They interface with the AMM via its L1 smart contract, without having to know anything about its inner workings off-chain. Let’s look at the two basic operations for an LP - deposit and withdraw:

Deposit

Deposit is an atomic operation: Carol deposits her funds on L1 and receives her LP token. The Operator monitors the chain to include new deposits to their quote.

Withdraw

Withdraw is a three-step operation

  1. Carol locks her LP tokens, thus triggering the AMM Cooldown Period (ACP)

Conclusion

To bring back DeFi’s primary goal of financial inclusion, we need to reduce transaction costs and avoid liquidity fragmentation at all costs.
dAMM, an L2-powered AMM, is a step in this direction. It minimizes the L2 logic while providing better capital efficiency, enabling L2 liquidity to be used as superfluid collateral, i.e. to both serve as collateral and produce returns. We continue to actively explore and research the design space around dAMM.

Louis Guthmann

StarkWare

Developing the Full Proof Stack for STARK