Marginly essentials: leveraged trading and derivatives on top of AMM liquidity

6 min readJun 2, 2023


Uniswap forks are dead, long live Uniswap forks!

Everyone loves the simplicity of Uniswap — it’s just a couple of clicks to flip one cryptocurrency for another. But things get way more complicated when you decide to get the maximum out of your funds and earn a little more on price movements or build up a more intelligent market strategy.

This is where leveraged trading and derivative products kick in. Uniswap and its forks cannot help much here, and you end up juggling multiple DeFi protocols broadcasting expensive transactions or trading perps. The former option gives you relatively low maximum leverage (up to 5X, probably not something you desired), while the latter offers a minimal set of trading pairs. In both cases, you get exposed to oracle attacks, harsh interest rates, and severe liquidation risks.

Marginly is a novel leverage protocol introducing a new angle on decentralized spot margin trading (enabling up to 20X leverage) and derivatives that can run on top of existing DEXs. With the simplicity of Uniswap in its top-notch mobile-first interface, Marginly addresses major DeFi challenges on the backend: no oracles, no liquidations, risk-based interest rates, long-tail assets trading, and aggregated liquidity at user disposal. This article breaks down how the protocol works and what amazing things you can do with it.

A powerful combo of side pools and an order router

In a nutshell, Marginly works as a non-custodial pluggable side pool that holds users’ margin and their trade proceeds. All mechanics related to trade management (mark-to-market, margin calls, ongoing position management) are implemented on the Marginly side. Trade orders are routed to linked AMMs through a smart router, and actual trades happen on existing DEXs. Here is an illustration of opening a leveraged long position on Marginly:

Fig. 1 How to open a long position on Marginly

As you can see, a user provides their margin in a target asset they long, and then, Marginly pulls out leverage in an opposite asset to swap for the target one. After the trade is finalized, the user’s margin and trade proceeds remain locked within the pool altogether until the user closes their position or a margin call occurs.

Smart order routing definitely puts a special spark to the overall setup. It lets users trade with the best slippage and lowest fees. If Uniswap offers you 0.3% slippage on 100K notional and Balancer offers only 0.2% slippage, the router automatically picks for you the best option. Also, it helps aggregate AMM liquidity and execute trades of almost any size for different assets. The latter creates an interesting opportunity for long-tail pools.

5 amazing things you can do with Marginly

The power of leverage lets users trade crypto assets and get larger returns as opposed to just trading on spot. But a combination of leverage liquidity and connections to AMM pools enables other use cases as well. Let’s see what Marginly brings to the table.

Trade spot with up to 20x leverage

Of course, margin trading is a core feature of the protocol. Marginly users can go up to 20x long and short on multiple assets (even long-tail, as said before). Simple: bring 1 ETH margin and borrow enough funds to go long up to 20 ETH combined. Works in other direction too: deposit 1000 USDC and short sell ETH for up to 20K USDC proceeds.

Provide liquidity and earn a passive yield

If you are an active hodler and don’t expect to trade, you can provide funds to Marginly pools and expect passive returns coming primarily from interest on leveraged trades. In fact, traders also earn like liquidity providers as the proceeds of their trades are available for borrowing by the opposite side (we call it ‘Infinity loop’ of liquidity and will talk more about it below).

Hedge your portfolio

Thanks to this feature, our users can keep their positions delta-neutral to the market. This is very similar in nature to Curve’s crvUSD handling. Unlike Curve, we don’t reinvent the wheel and use time and battle-tested option pricing approaches to hedging. Note: this functionality will be available in V2 of the protocol

Utilize non-trivial option strategies

In V2, we will exploit Uniswap V3 and its option-lie payoff to mimic different option strategies. Here are some examples:

Short Straddle: Deploy 2 x ETH liquidity to the single tick as close to the current market price as possible, then sell 1 x ETH on the market.

Short Strangle: Deploy USDC liquidity in a range below the current market price and deploy ETH liquidity in a range above the current market price, then sell the same amount of ETH elsewhere in a separate transaction.

Earn in range or when price doesn’t move

As you can recall, the option strategies above allow you to earn dough while the price is in the range or doesn’t move. Something that sophisticated DeFi users crave a lot. Also available on Marginly starting V2.

Why Marginly is better than other leveraged markets

We’ve covered almost all aspects of Marginly’s client-facing facade. But what’s going on under the hood? Does Marginly have any tricks up its sleeves? This chapter looks more closely at special features on the protocol backend and highlights how they differentiate Marginly from others.

Deleverage & insurance pool vs. liquidations

In Marginly, we can cover insolvent users against users with offsetting positions if things start to look scary on the market. This process is called deleveraging, and it’s a reduction of the total leverage of the pool (collateral and debt) when there is a liquidity shortage. Deleveraging perfectly hedges the risks of thin liquidity in connected AMMs. The protocol also runs an Insurance pool that absorbs collected commission fees and handles liquidations of the last resort. The diagram below shows how the process works.

Fig. 2 Deleveraging in Marginly

Isolated pools

Each Marginly’s pool is isolated and mimics a specific trading pair. For example, Marginly runs a separate ETH & USDC pool used for leveraged trading in ETH/USDC pairs across all connected DEXs. This design allows us to measure pool risk precisely using advanced statistical techniques on-chain and implement dynamic interest rates. As such, Marginly segregates risks of volatile assets, significantly reducing potential risks for liquidity providers.

More fair funding costs

As said above, the protocol implements a risk-based approach to loan pricing that accounts for leverage, underlying margin volatility, and liquidity risk based on the liquidity depth of the respective AMM pools. Thanks to this, users can expect more transparent interest rates relying on fairly objective factors and even affect paid costs by setting the leverage level in their positions.

Infinity loop™ of liquidity for effective capital utilization

This novelty makes Marginly extremely effective as it needs less TVL to serve more leveraged trades. This became possible thanks to an option to borrow proceeds from the opposite trade side (the process is presented in the diagram below). Of course, we are not a central bank with zero reserve requirement type retards and have a clever system of checks and balances in place to ensure this infinity loop doesn’t spiral out of control.

Fig. 3 Infinity loop™ in Marginly

Ok, you got my attention. What’s next?

This article hasn’t covered exciting opportunities that Marginly prepared for partner DEXs. Respectively, our profitable on-chain revenue-sharing program, priority order routing to partners designed to bring them more trading liquidity, access to aggregated liquidity, and other features. We will explore these details in a separate long read (soon™).

Very soon™, we are going to reveal our technical documentation. You will be able to read more about the tech aspects of Marginly. A separate analytical article with protocol modeling is also on its way. Keep an eye on our announcements.

Also, don’t miss our further plans for the launch and be among the first to get your hands on our exceptional mobile-first margin trading application. We are cooking something really exciting to celebrate it.

Hurry up to follow us on Twitter and join our Discord to stay updated!




Go up to 20X long or short on Uniswap and other DEXs