Caspian, an L2-Powered AMM

A DeFi-friendly L2 AMM

StarkWare
StarkWare
Apr 4 · 5 min read

TL;DR

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:

What is Caspian?

High-Level Concept

Caspian is an L2-powered AMM. Just like the Caspian Sea — the world’s largest lake — the Caspian AMM allows liquidity to be bridged on L2 while remaining unfragmented, on L1.

Caspian 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

On-chain

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

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

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

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

Conclusion

To bring back DeFi’s primary goal of financial inclusion, we need to reduce transaction costs and avoid liquidity fragmentation at all costs.
Caspian, 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 Caspian.

Louis Guthmann

StarkWare

Developing the Full Proof Stack for STARK

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store