# Introduction

{% hint style="info" %}
LemmaSwap is a new type of decentralized exchange (DEX) protocol that allows traders to execute spot swaps using an underlying perpetual futures exchange's liquidity.&#x20;
{% endhint %}

## Why use LemmaSwap?

* For traders:
  * Deeper liquidity when executing spot swaps
* For liquidity providers:
  * Highly composable ERC20 assets
  * No impermanent loss
  * Yield generation via spot trading fees and funding rate PnL

## How does it work at a high level?

LemmaSwap holds assets such as ETH, BTC, USDC etc. on its balance sheet and acts as a counterparty to every trade while simultaneously hedging to keep its portfolio delta equal to one.

Liquidity providers can contribute to the assets on the LemmaSwap balance sheet in two ways:&#x20;

<figure><img src="/files/Y1V7t7O0alNeqTPB2Rh3" alt=""><figcaption><p>USDL backed by hETH, hBTC and USDC</p></figcaption></figure>

* By minting USDL  —  the LemmaSwap stablecoin, which is backed by pools of hedged assets (eg. hETH below is ETH + a short ETH position)<br>
* By minting synthetic tokens, which are backed by a mix of spot assets and 1x long perpetual futures positions (eg. ETH\*, a LemmaSwap synthetic asset can be backed by spot ETH and/or a long ETH perp)

<figure><img src="/files/PQ0GSntb9MPPjoFAEwCl" alt=""><figcaption><p>ETH* backed by spot ETH and/or a 1x ETH long</p></figcaption></figure>

Now let’s say a user wants to swap ETH for BTC, and LemmaSwap has USDL and synthetic BTC (BTC\*) as liquidity on its balance sheet. This liquidity is used to execute swaps in two simple steps:

* The user deposits ETH and LemmaSwap hedges it by increasing its short ETH position by the same amount deposited
* LemmaSwap increases its long BTC position by the same USD amount of ETH deposited and sends back to the user the freed up BTC collateral

<figure><img src="/files/wnSkLm4TYo7IjXu31NFQ" alt=""><figcaption><p>Swapping ETH for BTC</p></figcaption></figure>

At all times, USDL is backed 1:1 with USDC or a ETH delta neutral position, and BTC\* is backed 1:1 with a BTC spot or a 1x long BTC position.


# FAQ

## Does LemmaSwap have a token?

Besides USDL & synthetic tokens - LemmaSwap does NOT currently have a token.

## What are the fees?

For traders:

* LemmaSwap currently charges a 0.3% swap fee.

For liquidity providers:

* If you mint USDL or synthetic tokens, you may be charged a 0.3% fee if minted with different assets. For example:
  * Minting USDL with USDC will not incur any fees, but minting it with ETH, wBTC or other assets will.
  * Minting synthetic ETH (ETH\*) with spot ETH will not incur any fees, but minting it with USDL or USDC will.&#x20;
* These fees will show up as your earnings being slightly negative initially.

LemmaSwap does NOT charge any "management" fees either. The protocol allocates a portion (30%) of the liquidity provider profits to its insurance fund & treasury. To learn more about why this is necessary please read our [risk](/concepts-overview/additional-risks) section.

## What are some of the risks involved?

As with any financial tool, there are always risks to be aware of. Here are a few of the main ones for this specific protocol:&#x20;

* Perpetual futures markets are only functional as long as liquidations of traders are executed fast enough. This means that if a perpetual futures DEX LemmaSwap has integrated with does a forced settlement of their markets, LemmaSwap liquidity providers may incur a loss.
* While the max losses caused by funding rates are capped, if they are superior to the spot trading fees generated, LemmaSwap liquidity providers will incur a loss.
* LemmaSwap is audited but the risk of an exploit happening is never 0%.

As always, please do your own research and decide for yourself. To learn more about the risks involved read our [risk](/concepts-overview/additional-risks) and [smart contracts](/smart-contracts/security) sections.

## Does LemmaSwap have investors?

Yes! We're lucky to have been able to raise from:

* Dragonfly and Standard Crypto with participation from Nascent, Multicoin, Coinbase Ventures, Robot Ventures (Tarun Chitra & Robert Leshner), Folius, Wintermute, Kronos, GSR, MCDEX and Perpetual Protocol
* Our angels include Matteo Leibowitz, Max Bronstein, Jonathan Wu, Nick Chong, Mika Honkasalo, Julian Koh, Greg Tusar, Vijay Chetty, Eric Chen, Yenwen Feng, Nick Tong, Francesco Agosti, Craig Lemens, Ivangbi, Nick Pappageorge, Sam Bobley and Vikas Dua
* Additionally, we were incubated by EI Ventures

## Legal

LemmaSwap is not available to residents of Belarus, the Central African Republic, the Democratic Republic of Congo, the Democratic People’s Republic of Korea, the Crimea region of Ukraine, Cuba, Iran, Libya, Somalia, Sudan, South Sudan, Syria, the USA, Yemen, and Zimbabwe.

## Where can I ask further questions about LemmaSwap?

If you have any questions about hiring, support etc. please send a Discord admin a message or reach us at <hello@lemma.finance> and we'll be in touch very soon.


# How do I deposit?

* If your assets are on Ethereum L1, make sure to bridge them over to Optimism (an Ethereum L2)
  * We recommend checking out the [Optimism bridges page](https://www.optimism.io/apps/bridges) for options
  * Make sure the asset you want to deposit is supported by LemmaSwap before bridging
* Click on any of the "Connect Wallet" buttons on the LemmaSwap website
* After connecting to your wallet, click on "Change Network" and confirm the switch
* Enter an amount of the asset you would like to deposit
* If you are not a resident of a ["Prohibited Jurisdiction"](/resources/faq#what-should-i-know-before-depositing) then you will be see "View terms & enable deposits"
* Click on the "View terms & enable deposits" button & read the ToS and the Risk page
* Click on "Deposit", confirm the transaction on your wallet and you'll be good to go!


# USDL

USDL is a stablecoin backed by a long spot and short futures position. The price fluctuations of the underlying spot assets are “canceled out” by a corresponding short futures positions. As a result, the portfolio backing USDL is stable in USD terms.

This sort of portfolio is called “delta neutral” or “market neutral” as the price movement of underlying spot assets has very little to no impact on it. This means USDL can be backed by any spot cryptocurrency asset, as long as LemmaSwap can short the asset’s futures on a decentralized exchange.

<figure><img src="https://lh3.googleusercontent.com/Q6cwCNs3rlknKLb-ljiPsTkHcDlCP-ETimS9YwQvqTd85YsDo5utOMo4fsQCK5J53xe5ivKdYadEXjkH3ktpzoiuF0DFMq2KSRY6nhd3wplm6ktG-ltCVuwxgW8JLsy8-haTZwDu6oD1kWk6tqY110h3SAWl_BldQFNAN141bmuX8lG5NdtIAfZD" alt=""><figcaption><p>USDL backed by a delta neutral position</p></figcaption></figure>

## Perpetual Futures

The futures instrument LemmaSwap uses to hedge deposited spot assets is called a perpetual future. Perpetuals are futures with no expiration date. Their prices are pegged to the underlying spot asset via funding rates - a fee traders on the “popular” side of the trade pay to the ones on the “unpopular” side of the trade. ie. If long traders are taking liquidity more aggressively than short traders, then long traders will pay a small fee every hour to short traders (and vice versa).

## Minting USDL

There are three ways of minting USDL:&#x20;

* Deposit USDC.&#x20;
* Deposit an asset supported as collateral on an integrated perpetual futures DEX. In this case, the deposited assets are used as collateral to open a short of equivalent size.&#x20;
* Deposit assets that are not supported as collateral on integrated perpetual futures DEXs. When users deposit such assets, the following steps are executed:
  * If USDL has USDC (or other USD stablecoins) on its balance sheet:
    * The USDC on the USDL balance sheet is used to open a short with the same size as the USD value of the tokens deposited
  * If USDL doesn’t have USDC (or other USD stablecoins) on its balance sheet:
    * Half of the assets deposited are sold on an aggregator for USDC
    * The USDC is used as collateral to open a short equivalent to 50% of the USD value of the deposited assets

## USDL Price Stability

Let’s imagine the USDL price in the ETH/USDL spot market goes down to 0.9 USD. A rational trader then would:

* Buy USDL with ETH
* Redeem each USDL for 1 USD worth of ETH on Lemma
* Repeat the process with the newly acquired ETH until USDL is worth 1 USD again

This arbitrage yields an instant \~10% return on capital with each completed loop, without taking into account gas fees and the price increase from 0.9 USD to 1 USD. This arbitrage also works the opposite way (to decrease USDL price) and with other forms of collateral to mint or redeem USDL for (eg. a mix of USDC and wBTC).

## Rebalancing

As we saw above, USDL can be backed by a position that consists of 50% spot assets and 50% of a USDC backed short. eg. 100 USDL can be backed by $50 worth of spot ETH and 50 USDC shorting ETH with no leverage.

If no action is taken and the price of the token increases by more than \~88.24%, LemmaSwap could get liquidated on this short. However, by rebalancing & selling some of its spot ETH for USDC and adding that USDC to the margin, LemmaSwap can avoid liquidation. LemmaSwap can do so by setting up range orders on the spot DEXs it uses, thereby avoiding unnecessary slippage and paying "taker" fees.

There is however a risk factor: perpetual futures DEXs often use oracles to determine whether or not to liquidate a position. Oracles get their price data from various exchanges, and if the price is not arbitraged properly between those exchanges and the spot DEXs LemmaSwap uses, there could be a disparity in price that could cause the rebalance to be more expensive than necessary & potentially even cause liquidations. This problem can be mitigated by running arbitrage bots between the spot DEXs LemmaSwap uses and the ones used by oracles.


# Synthetic Tokens

LemmaSwap synthetic tokens are yield bearing ERC20s backed by spot assets and/or long perpetual positions with no leverage. For example, a synthetic ETH (ETH\*) can be backed by a long ETH/USD perpetual futures position and/or spot ETH.

There are two ways of minting synthetic tokens:&#x20;

* Deposit a spot asset. LemmaSwap will keep the asset in a collateral pool and mint a corresponding synthetic token.&#x20;
* Deposit USDC. LemmaSwap will use the USDC to go long with no leverage on a user chosen asset’s perpetual market and mint a corresponding synthetic token.


# Swaps

## Execution

LemmaSwap utilizes the USDL and synthetic token collateral pools to execute swaps. For example, let’s say a user wants to swap ETH for BTC, and LemmaSwap has spot BTC on its synthetic BTC (BTC\*) balance sheet. The following steps would be executed atomically:

* The user’s ETH would be sent to a perpetual futures DEX
* LemmaSwap would increase the ETH short perpetual position backing USDL by the exact amount of ETH deposited
* LemmaSwap would increase the BTC long perpetual position backing BTC\* by the exact USD amount by which it increased the ETH short
* The freed up spot BTC collateral would be sent back to the user

The USD value of the collateral backing USDL and the synthetic tokens stays constant, but the distribution of the spot assets changes. In the chart below, we illustrate a user swapping ETH for BTC. hETH stands for “hedged ETH” and represents a long spot ETH + short ETH futures position.

<figure><img src="https://lh6.googleusercontent.com/H8mLGynwmE5h3XPDh39JanoU2v11FjnK_eFgN_OhZ4x7CwLP7oL05eHzTN8moxIXMks7fVYDs0m1WIOHQ2mWcvUDwzlWbbgRKSvx4dP79fo9OZ528eI4_kaiBH6LkTC3fXjGh4L_Ih1xRkyQgJYXV5D7sFKIlz_tm-PKDvC1_MQxZrX7Dor_W_7s2w" alt=""><figcaption><p>Swapping ETH for BTC</p></figcaption></figure>

## Rerouting

If a user wants to buy more assets than USDL has on its balance sheet, LemmaSwap will reroute the unfilled part of the order to an aggregator.

Eg. If a user wants to buy 50 million USD worth of BTC but USDL only has 30 million USD worth of hedged BTC on its balance sheet, then the first 30 million USD worth of the order will be filled and the remaining 20 million USD will be rerouted to a spot DEX aggregator.

## Fees

LemmaSwap will initially charge a 0.3% “fee” on every trade.


# Liquidity Provisioning

{% hint style="info" %}
Liquidity provider deposit assets and get back highly composable ERC20s that can generate yield. The yield comes from a combination of spot trading fees and funding rate PnL.
{% endhint %}

## Spot Trading Fees

LemmaSwap will initially charge a 0.3% “fee” on each trade. There are two different types of trades that affect what profits liquidity providers can expect. The first type is a trade that involve swapping a cryptocurrency for another cryptocurrency (such as ETH for BTC), and the second type is one that involves swapping a cryptocurrency for a stablecoin or vice versa (such as ETH for USDL or USDL for ETH).

For the first type of trade, LemmaSwap has to execute two transactions on the underlying perpetual futures market in order to hedge itself properly. As such, if the spread on the underlying perpetual futures DEX is 0.1%, then the total transaction cost excluding slippage will be 0.2%. The remaining 0.1% will be divided between the liquidity providers whose assets were used to facilitate the transaction.

For the second type of trade, LemmaSwap only has to execute one transaction on the underlying perpetual futures market. As such, if the spread on the underlying perpetual futures DEX is 0.1%, then the total transaction cost excluding slippage will be 0.1%. The remaining 0.2% will be divided between the liquidity providers whose assets were used to facilitate the transaction.

Staked USDL and synthetic token holders receive a pro rata percentage of spot trading fees generated by LemmaSwap on their corresponding markets.

For example, for a ETH/USDC swap, if there is $1000 worth of ETH\* minted, $500 worth of staked USDL minted with ETH, and $1500 worth of staked USDL minted with USDC then a third of the 0.2% fee would go to ETH\* holders and two thirds would go to staked USDL holders.

## Funding Rate PnL

### How funding rates work for LemmaSwap

Every time a user sells a given spot asset for stablecoins on LemmaSwap, Lemma’s short position on that market increases. Every time a user buys a given spot asset with stablecoins, Lemma’s long position on that market increases. However, since longs and shorts “cancel” each other out, LemmaSwap can only ever be net long, net short or 0 on any given market. As a result, the funding rate LemmaSwap will pay or receive on that net position will tend to be quite small relative to the overall amount of liquidity provided to the protocol.

Ideally, the net funding rate payments generated by LemmaSwap would be positive or near 0. These payments can be calculated as below:

`F=A*(TWAP_vAMM-TWAP_index)/24`

Where:

* A: LemmaSwap’s net position, A > 0 if more longs and A < 0 if more shorts
* TWAP\_vAMM : Time-Weighted Average Price for the vAMM (a type of perpetual futures DEX)
* TWAP\_index : Time-Weighted Average Price returned by the oracle

Therefore:

* If A < 0 and TWAP\_vAMM > TWAP\_index then F < 0 and the net funding rate payment will be negative, ie. LemmaSwap makes money
* If A > 0 and TWAP\_vAMM > TWAP\_index then F > 0 and the net funding rate payment will be positive, ie. LemmaSwap loses money

and so on.

### Improving funding rate PnL

When Lemma’s net position is long on a given market, the respective synthetic token holders for that market will receive or pay the funding rate. When Lemma’s net position is short on a given market, staked USDL holders will receive or pay the funding rate.

If the contract price of the perpetual is consistently under the spot price, it means two things:

* Funding rates are negative and therefore short traders are paying a fee to long traders
* The price LemmaSwap quotes for spot swaps is better than the current oracle spot price, and is therefore "incentivizing" more longs

The opposite also holds. As a result, LemmaSwap continuously seeks to be on the right side of funding rates and to improve the net exposure of its liquidity providers.

### Capping funding rate loss

If the contract price drops below the spot price by more than a given threshold, LemmaSwap can perform an automatic arbitrage to improve its funding rate position. It does so by selling some of its spot position and increasing its long position, thereby staying delta neutral. The threshold is the sum of the fees charged by the spot DEX used to sell the spot position and the fees charged by the perpetual futures DEX used to increase the long position. Once again, the opposite also holds true.

For example, for a spot market with a 0.3% fee and perpetual futures market with a 0.1% fee, the threshold would be 0.4%. If the entire LemmaSwap notional was short, the max loss due to negative funding rate payments would be capped at about \~77% over the course of a year.


# DAO

## LemmaSwap token & governance

LemmaSwap will (in the future) issue LEMMA tokens to manage governance for the stablecoin. Holders will be able to set risk parameters, prioritize the roadmap and propose new features, amongst other things. A few example include:

* Deciding which derivative DEXs’ perpetual contracts should be used for LemmaSwap and set risk parameters for each one
* Deciding what percentage of the yield should be allocated towards the user vs. the insurance fund vs. the treasury
* Deciding how much to charge for spot swaps

## Treasury & insurance fund

Routing yield towards the treasury / insurance fund will help mitigate risks for liquidity providers. As such, a percentage (initially 30%) of the profits generated by the basis trading vault will be allocated to the treasury / insurance fund.


# Additional Risks

{% hint style="info" %}
LemmaSwap is still in Beta and there are many different ways that the protocol could fail and result in a total loss of assets. Some of these risks are outlined below.
{% endhint %}

## Derivative DEX Risk

LemmaSwap is built on top of various decentralized derivatives exchanges and as such, it is potentially vulnerable to an exploit of their smart contracts as well as a forced settlement of perpetuals.

In order to mitigate these risks, the [Lemma DAO ](/concepts-overview/dao)will need to decide what derivative DEXs the protocol should integrate with, and assign them risk scores and debt ceilings (to cap the amount of collateral that can be lost on any given DEX). Additionally, the insurance fund will be used to mitigate losses for liquidity providers in case these types of events occur.

## Smart contract risks

While Lemma has been audited by Peckshield, no product can be guaranteed to be always safe from exploits. Please do your own research and use at your own risk.


# Security

Information about Lemma's security

## :detective: Audits

The audits are available here: <https://github.com/lemma-finance/audits>

## :bug: Bug Bounty

Find bugs in Lemma and get paid $50,000 🤑 . \
\
Visit [https://immunefi.com/bounty/lemmafinance/ ](https://immunefi.com/bounty/lemmafinance/)for full details.


# Contract Addresses

Lemma's core contract addresses

USDLemma: [0x96F2539d3684dbde8B3242A51A73B66360a5B541](https://optimistic.etherscan.io/address/0x96F2539d3684dbde8B3242A51A73B66360a5B541)

xUSDL: [0x252Ea7E68a27390Ce0D53851192839A39Ab8B38C](https://optimistic.etherscan.io/address/0x252ea7e68a27390ce0d53851192839a39ab8b38c)

LemmaSwap: [0x6B283Cbcd24fdF67E1C4E23d28815C2607eEfE29](https://optimistic.etherscan.io/address/0x6B283Cbcd24fdF67E1C4E23d28815C2607eEfE29)

PerpLemmaETH: [0x29b159aE784Accfa7Fb9c7ba1De272bad75f5674](https://optimistic.etherscan.io/address/0x29b159aE784Accfa7Fb9c7ba1De272bad75f5674)

PerpLemmaWBTC: [0xe161C6c9F2fC74AC97300e6f00648284d83cBd19](https://optimistic.etherscan.io/address/0xe161C6c9F2fC74AC97300e6f00648284d83cBd19)

LemmaETH: [0x3BC414FA971189783ACee4dEe281067C322E3412](https://optimistic.etherscan.io/address/0x3BC414FA971189783ACee4dEe281067C322E3412)

LemmaBTC: [0x8A641696Caf0f59bB7a53CF8D2dc943ED95229A6](https://optimistic.etherscan.io/address/0x8A641696Caf0f59bB7a53CF8D2dc943ED95229A6)

xLemmaETH: [0x89c4e9a23Db43641e1B3C5E0691b100E64b50E32](https://optimistic.etherscan.io/address/0x89c4e9a23Db43641e1B3C5E0691b100E64b50E32)

xLemmaBTC: [0x7D39583e262CBe75a1D698A6D79cd5a2958cb61d](https://optimistic.etherscan.io/address/0x7D39583e262CBe75a1D698A6D79cd5a2958cb61d)


# Terms of Service

Lemma is a decentralized spot exchange protocol built on third party decentralized derivatives exchanges. There is currently only a single version of the Lemma Protocol; it is made of free, public, open-source or source-available software including a set of smart contracts that are deployed on the Ethereum blockchain. Use of the Lemma Protocol involves [various risks](/concepts-overview/additional-risks), including, but not limited to, losses due to the forced settlement of the underlying perpetual markets and losses due to funding rate payments, slippage and other fees (eg. gas, exchange...). Before using the Lemma Protocol, users should review all relevant documentation to make sure they understand how the Lemma Protocol works. Users are responsible for doing their own diligence and understanding the fees and risks of the protocol.

LEMMA PROTOCOL IS PROVIDED ”AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND. The Lemma team developed much of the initial code for the Lemma protocol, it does not provide, own, or control the Lemma protocol, which is run by smart contracts deployed on the Ethereum blockchain. Upgrades and modifications to the protocol will increasingly be managed in a community-driven way. In using the Lemma Protocol, you agree that no developer or entity involved in creating the Lemma protocol will be liable for any claims or damages whatsoever associated with use, inability to use, or interaction with other users of the Lemma protocol, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.


