What is looping?

Mitch | Contango
Contango
Published in
6 min readOct 2, 2023
what is looping banner

Contango builds perps by automating a looping strategy, also known as recursive borrowing and lending.

This mechanism is similar to the popular levered strategies of Instadapp and Defisaver, but has a professional trading interface built on top. These strategies automate the looping that DeFi users performed manually back in the days.

By using a flash loan, leverage can be achieved in one transaction instead of creating multiple loops manually.

This article delves into the details of how this is achieved.

The origin of looping ➿

We don’t know exactly who’s been the first looper, but we know for sure that $COMP farming in mid 2020 made this strategy pretty popular (source). But some users apparently looped even before, as soon as MakerDAO went live in 2017, to long ETH natively on-chain (source).

So DeFi users have been looping for more than 6 years!

And nowadays pretty much everyone is levering up on Aave, Morpho, Spark. For instance, Morpho claims 64% of their volumes comes from users performing looping strategies (source). That’s why Contango chose to build futures (expirables first, and now perps) using money markets: it’s the DeFi native way of longing and shorting on-chain.

In a nutshell, looping involves lending or depositing some capital (e.g. ETH into a MakerDAO vault or on Aave), borrowing another currency (e.g. DAI) against it, swapping the borrowed amount for the original asset (ETH), and repeating the steps through several loops to gain more exposure to the initial asset — or simply to farm more rewards.

Money markets normally require you to be overcollateralized, meaning that you can only borrow less than the value of what you deposit. For instance, ETH on Aave has a maximum loan-to-value (LTV) ratio of 82.5% meaning that you can only borrow 82.5% of the $ value of the ETH you’ve deposited.

That’s why, after 12–15 loops normally you get diminishing returns on the effort you’re putting into looping: the exposure you get to the asset you’re lending increases by smaller and smaller amounts (kudos to Stephen from Defi Dojo for his brilliant explainer and calculator).

Let’s see an example on Aave, with spot ETH = 1000 DAI, and max LTV = 82.5%.

1st loop:

  • Deposit 1 ETH
  • Borrow 825 DAI
  • Swap 825 DAI for 0.825 ETH
  • Lend 0.825 ETH

2nd loop:

  • Borrow 681 DAI
  • Swap 681 DAI for 0.681 ETH
  • Lend 0.681 ETH

[…]

14th loop:

  • Borrow 56 DAI
  • Swap 56 DAI for 0.056 ETH
  • Lend 0.056 ETH

15th loop:

  • Borrow 46 DAI
  • Swap 46 DAI for 0.046 ETH
  • Lend 0.046 ETH

As you can see, at the 15th loop, the total net ETH exposure (which is already around 5.45 ETH) doesn’t increase by that much anymore (just 0.046 ETH, not even 1%). And gas fees might make the following loop not worth it.

Indeed, manual looping is pretty expensive, especially on L1.

That’s why automated strategies were developed.

Flashback to flash loans ⚡

With the introduction of flash loans, loops could be replaced by a single transaction.

A flash loan allows users to borrow any capital upfront without collateral, as long as it’s repaid within the same block.

This was enough for Instadapp and Defisaver to build automated leverage strategies, already in 2019 (source). Contango does the same and replaces manual looping by simply:

  1. Getting a flash loan, up to whatever the LTV ratios allows you to do, given your margin (see point 4).
  2. Swapping this loan for the desired asset you want exposure to.
  3. Lending this asset, together with your margin.
  4. Borrowing against it within the LTV limits.
  5. Reimburse the initial flash loan amount.

Below is a diagram depicting the previous steps:

Diagram showing the steps realized by Contango to open a long ETHDAI with ETH as margin
Steps realized by Contango to open a long ETHDAI with ETH as margin

Leverage is determined by the loan-to-value ratio (meaning: how much you can borrow against your collateral) on the underlying money market. Leverage is = 1/(1 — LTV ratio).

Note: Contango also allows traders to post collateral in the quote currency (e.g. post DAI when trading ETHDAI). The flow changes slightly: the margin is swapped for the base before lending it, as depicted in the diagram below.

Diagram showing the steps realized by Contango to open a long ETHDAI with ETH as margin
Steps realized by Contango to open a long ETHDAI with DAI as margin

By using flash loans users can gain access to leverage instantly and more efficiently, without having to loop up manually to increase their exposure with every loop.

Manual vs automated looping

Let’s compare manual looping with the automated strategy that uses a flash loan, on Aave:

A trader wants to get exposure for 1 ETH by posting 0.2 ETH as margin (so around 5x leverage), while the spot price is 1 ETH = 1000 DAI.

The manual route would require at least 9 loops (borrow → swap → lend), with the associated gas fees for each transaction.

The trader starts by supplying 0.2 ETH and borrows 165 DAI against it (within the 82.5% LTV limit).

He then swaps those DAI for 0.165 ETH, and supplies this new ETH on Aave, increasing his total exposure to 0.365 ETH (about 1.8x leverage).

With more loops, he keeps incrementing his exposure up to 1 ETH, which is equivalent to a 5x leveraged position.

This strategy is clearly time and gas intensive.

The following diagram recaps the architecture and the different steps:

Diagram showing a manual looping strategy to long 1 ETH with 5x leverage
Example of a manual looping strategy to long 1 ETH with 5x leverage

Conversely, an automated strategy would achieve the desired leverage and exposure in one single transaction:

  1. Obtain 800 DAI through a flash loan.
  2. Convert the 800 DAI from the flash loan to 0.8 ETH on the spot market, like Uniswap.
  3. Lend 1 ETH (0.2 ETH from trader’s margin + 0.8 ETH from step 2) on Aave.
  4. Borrow 800 DAI against it.
  5. Reimburse the initial flash loan with 800 DAI.
Diagram showing an automated looping strategy to long 1 ETH with 5x leverage
Example of a automated looping strategy to long 1 ETH with 5x leverage

Let’s call things by their names

These leveraged strategies synthesize the cash flow of future positions.

Leveraged positions on variable money markets can be interpreted as perpetual futures. The variable funding rate associated with these positions is not like the classic CeFi funding fee, but is determined by the difference between the cash flows you have on the borrowing and lending legs of each position. That’s why it’s called APY on Contango.

Similarly, looped positions on fixed-rate money markets can be interpreted as dated futures — and that’s how we built expirables (still accessible on Contango v1, but to be phased out soon). Here, the difference between the rates you have on the borrowing and lending legs of your position determines the fixed basis rate.

These strategies are not margin trading, either. Margin trading involves borrowing some capital to gain more purchasing power, i.e. leverage. There’s no lending involved with margin trading.

Still not convinced? Read more on our new perps here.

About Contango

Contango builds perps through looping on money markets. Deep liquidity is sourced on money markets, where interest rates produce less volatile funding rates. An intuitive trading interface welcomes advanced traders ready to trade with size, seasoned loopers looking for better monitoring tools, and degens eager to farm rewards on money markets.

Website | Twitter | Discord | Docs | Blog

--

--