Introducing CompliFi AMM

Dmitri S
CompliFi Protocol
Published in
7 min readFeb 3, 2021

--

This post is for general information purposes only. It does not constitute investment advice or a recommendation or solicitation to buy or sell any investment, or to issue or trade derivatives, and should not be used in the evaluation of the merits of making any financial or investment decision.

TL; DR

  • We started off with a derivatives issuance protocol – a “synthetic risk factory” that can mint a wide variety of ERC20 derivatives.
  • We are now combining it with a novel AMM focused on handling extremely volatile assets. Derivative issuance goes under the hood, users get the familiar AMM interface.
  • Market making in derivatives is hard. We spent a lot of time figuring out how to protect LPs without stifling trading volumes.
  • End users of risk can now purchase a range of x5 leveraged tokens. More instruments are on the way.
  • All CompliFi derivatives currently have a finite maturity. Our next priority is to structure them into perpetual instruments.

Why Derivatives Need a Different AMM

A few months ago, we launched CompliFi as a pure derivative issuance protocol – one that can create instruments which redistribute value between users based on any oracle-measured change in the world. We like to think of it as a synthetic risk factory. It takes value (pretty much in any on-chain form) as raw material and returns the same value structured into a derivative – one that would never get liquidated and would always pay what’s promised.

The process is simple: you pick a derivative from a variety of available specs, send collateral to a vault and receive equal amounts of two ERC20 tokens, akin to the long and the short positions in your chosen derivative. No market risk is incurred – when the long and the short tokens are held in equal amounts, they cancel each other out and can always be swapped back for the underlying collateral.

At this point, you have derivatives, but no risk. There are two ways you can go from here. Either you sell one side of the trade and keep the exposure you want, or, if you are an LP or market maker, you could sell both at a premium. Sounds easy enough – the derivatives are ERC20s like any other, so why not just go to Uniswap or Balancer, create a market and let the AMM magic happen? That’s what we thought, until we ran some simulations.

The reality is that the current AMMs are simply not designed to handle the swings in value that derivatives can often experience. Arbitrage traders would take huge bites out of LP portfolios and impermeant losses can get out of control. What’s more, finite maturity of the derivatives means that the impermanent losses crystallise and become permanent at settlement – LPs cannot just wait them out. On a side note, existing perpetual derivative designs do not solve this problem, but simply reshape it into counterparty risk, as we discuss in more depth in our earlier posts.

We came to the conclusion that the only way to both give traders the much-loved AMM experience and protect LPs is to build a new kind of AMM.

How It Works

Our approach to building a derivatives-focused AMM starts with Uniswap, the most popular and well-understood design. Then, we simply introduced the necessary changes in response to any problems we encountered. It took us on a much longer journey than we expected.

1. Disconnecting Slippage and Prices from Pool Balances

To begin with, we focused on two issues. First, we wanted to be able to control slippage without the need to add or remove assets. Slippage plays a big role in protecting LPs from market fluctuations, and we wanted to be able to tailor it to a given derivative’s volatility. Second, we found it inconvenient that AMM prices are rigidly connected to the quantities of assets in the pools. Setting the correct price often means LPs have to add more of some asset than they want to, which is a waste of capital and dilutive to returns.

Our solution – add leverage to the Uniswap invariant. Using individual leverage coefficients for each of the pool assets, we allow LPs to ”trick” the invariant into thinking there is more, or less, of each asset than in reality – you get the effect of committing the ideal amount of capital to the pools without having to actually do it. More formally, we have found a way to decouple terms of trade from LP portfolios. A detailed discussion of the design can be found here.

2. Getting Arbitrage under Control

Our next hurdle was excessive arbitrage. While slippage does provide LPs with some protection, it does so at the expense of trading volumes. For volatile instruments, you had to crank it up so high that you might as well not bother creating a market.

The solution came from the realisation that the AMM actually has access to much of the information that allows traders to arbitrage it. CompliFi derivatives already rely on a decentralised oracle for settlement, so why not use the same oracle to reprice them in every block prior to the first trade? We went on to build a flexible mechanism that can do just that for a range of instruments. Among its components is an on-chain implementation of the Black-Scholes formula for valuing options.

It is important to keep in mind that derivative pricing is complicated and often subjective, and our mechanism is but an early attempt that leaves many questions for future research. Nonetheless, we see it as a big step forward.

Complexities of pricing aside, the goal of this feature is to contain arbitrage to within the 13 seconds of the ETH block time and the accuracy margin of the oracle (e.g. +/- 0.5% for Chainlink’s ETH/USD feed). Within those bounds, traders have the information that the AMM does not, and could profit from it. For context, Uniswap is entirely “blind” to the external market.

3. Addressing LP Exposure

Having cut arbitrage to a manageable level, we saw a new problem arise. Almost inevitably and in the normal course of trading, our simulations showed LP portfolios getting drawn away from the riskless state where the amounts of long and short tokens are equal. Once that happens, LPs effectively hold a naked derivative position. They may get lucky and make a lot of money from it, but there would also come a time when the opposite happens and their portfolios go up in flames. In order to make liquidity provision a steady, market-agnostic, fee-generating business, we needed to address LP portfolio risk.

We dealt with the problem in two ways. First, we set limits on the possible magnitude of the naked derivative exposure – AMM will refuse to perform a trade that pushes LPs out of their predetermined risk bounds.

Second, we introduced the idea of dynamic fees. In simple terms, if a proposed trade lowers LPs’ exposure, the AMM charges a very low fee for it. In the opposite direction, the fee increases rapidly with the additional exposure that it causes (quadratically under the current design). As a result, LPs get ample financial compensation for taking on market risk. Traders get economically discouraged from performing certain transactions, but on the flipside, they enjoy lower fees in most other situations than would be possible under the flat transaction fee model.

4. Current AMMs Are Not Designed to Sell Assets in Bulk

Our final hurdle stemmed from the original design philosophy of AMMs. They are much more a portfolio rebalancing tool than a shopping mall, in that they don’t allow traders to efficiently acquire large portions of an asset in the pool. This is great if LPs want to have their portfolio maintain fixed proportions by asset value. It makes much less sense if LPs have minted an inventory of derivatives and want to sell them on to end users.

Suppose we have a pool with three assets: two derivative tokens representing the long and the short positions, and USDC. A pattern where traders alternately acquire small amounts of the long and the short tokens for USDC would result in a steady flow of fees to LPs without exposing them to excessive risk – basically the ideal scenario. However, under the classic Uniswap invariant, the increasing amount of USDC in the pool would soon suppress its value to the point of making this trading pattern uneconomic.

To solve this problem, we made use of a property, shared by all CompliFi derivatives, that a portfolio containing equal amounts of long and short tokens has a fixed value in terms of underlying collateral. For USDC-backed ETHx5 leveraged token for instance, 1 long token + 1 short token = 2 USDC. This property is how CompliFi derivatives are minted in the first place— you exchange collateral for both sides of a trade.

We integrated this relationship into the AMM simply by using our issuance protocol as another pool, on par with the one that enables derivative vs. derivative trading. Combining these two orthogonal markets creates a new type of invariant with the properties we were looking for. For a visual analogy, imagine skateboarding in a swimming pool shaped like a half-sphere. Wherever you go, you will eventually go up an increasingly steep wall – that’s what happens to price when you buy more and more of an asset from a Uniswap pool. Our modification effectively turns the half-sphere into a half-pipe. It still gets steep when you trade derivative vs. derivative, but it’s flat in the direction of the symmetric derivative portfolio vs. collateral. This means the desirable trading pattern described earlier is now possible.

These four modifications on top of Uniswap comprise the CompliFi AMM. Much of what we have described happens behind the scenes, and the UX remains largely the same for both traders and LPs. However, this does not mean our AMM has made derivatives “easy” or “safe”. They remain extremely complex and volatile instruments that require deep expertise, and the AMM is an early-stage, experimental product — a good rule of thumb would be to assume you will lose all of the capital you put in.

What Comes Next

Our next objective is to create perpetual instruments on top of the finite-maturity CompliFi derivatives. These instruments would have very similar financial characteristics and retain the crucial “no liquidation, no default” property. Should they wish, holders would still have recourse to the constituent finite-maturity derivatives and, consequently, to the underlying collateral.

Eliminating friction caused by the need for settlement would not only improve and simplify user experience, but also pave the way for CompliFi instruments to play a greater role in the decentralised asset management space.

--

--