> For the complete documentation index, see [llms.txt](https://docs.contango.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.contango.xyz/basics/how-does-it-work.md).

# How does it work?

Contango builds positions by automating [looping](/basics/what-is-looping.md) strategies, through [flash loans](/resources/glossary.md#flash-loan).

When a trader opens a long ETH/DAI position with DAI as margin, the protocol gets the remaining DAI from a flash loan, swaps all DAI for ETH on the spot market, and lends ETH on a money market, to borrow DAI and repay the flash loan.

<div align="center" data-full-width="false"><figure><img src="/files/JURBOei43p4NI8MX4JhE" alt=""><figcaption><p>High level explanation of how Contango synthetizes a long ETH/DAI position</p></figcaption></figure></div>

When closing a position, Contango simply undoes the above steps.

Please note that currently Contango has integrated with [*variable-rate* markets](/resources/glossary.md#money-market) (which does not necessarily close the door to integrations with *fixed-rate* markets too).

Below is a detailed explanation how Contango builds long and short positions.

The following sub-section examines in detail a [real transaction](/basics/how-does-it-work/detailed-tx-analysis.md).

### Long position

#### Quote currency as margin

If a trader wants to long ETH with some DAI as margin, Contango will first obtain the remaining DAI with a flash loan, swap all DAI for ETH, lend that ETH on a variable rate market, and borrow DAI against it to reimburses the initial flash loan.

The diagram below recaps these steps and provides a numerical example when a trader longs 1 ETH with 200 DAI as margin, and spot ETH = 1000 DAI.

<figure><img src="/files/5qY5Oq6XVXl7kPcwXudN" alt=""><figcaption><p>Steps carried out to open a long ETH/DAI position, with DAI as margin</p></figcaption></figure>

#### Base currency as margin

If a trader wants to long ETH with some ETH as margin, Contango will first obtain DAI with a flash loan, swap DAI for ETH, lend that ETH + the ETH posted as margin, and borrow DAI against it to reimburses the initial flash loan.

The diagram below recaps these steps and provides a numerical example when a trader longs 1 ETH with 0.2 ETH as margin, and spot ETH = 1000 DAI.

<figure><img src="/files/54WbxuWV1eYHWLzehHGY" alt=""><figcaption><p>Steps carried out to open a long ETH/DAI position, with ETH as margin</p></figcaption></figure>

### Short position

Short are built slightly different from the above flow.

* Effectively, shorts are longs on the inverse contract with a +1 on the leverage. For instance, a 2x ETH/DAI short is like a 3x long on the inverse DAI/ETH contract. This is because you need the full notional exposure on the asset you're shorting for your PnL to be coherent.
* A consequence of this is that you always have a liquidation price on Contango, even at 1x leverage.

#### Quote currency as margin

If a trader wants to short ETH with some DAI as margin, Contango will first obtain the full ETH exposure with a flash loan, swap all ETH for DAI, lend that DAI on a variable rate market, and borrow ETH against it to reimburses the initial flash loan.

The diagram below recaps these steps and provides a numerical example when a trader shorts 1 ETH with 200 DAI as margin, and spot ETH = 1000 DAI.

<figure><img src="/files/NKGvKcHzFmr2q0UeKpVs" alt=""><figcaption><p>Steps carried out to open a short ETH/DAI position, with DAI as margin</p></figcaption></figure>

#### Base currency as margin

If a trader wants to short ETH with some ETH as margin, Contango will first obtain the full ETH exposure with a flash loan, swap all ETH for DAI, lend that DAI on a variable rate market, and borrow ETH against it to reimburses the initial flash loan.

The diagram below recaps these steps and provides a numerical example when a trader shorts 1 ETH with 0.2 ETH as margin, and spot ETH = 1000 DAI.

<figure><img src="/files/pHeCGfd72yAsXDLTQOMG" alt=""><figcaption><p>Steps carried out to open a short ETH/DAI position, with ETH as margin</p></figcaption></figure>
