How it works

Basic understanding about margin trade

In a margin trade, a trader borrows an asset and sells it immediately on the market for another asset, which is the asset that said trader would like to trade against.

Suppose a user would like to open a Long position on the trading pair of [ETH/USDC]. In this case:

  • ETH is called a base token.

  • USDC is called a quote token, which basically describes how much “USDC” it takes to be equal to 1 “ETH”.

Longing with margin on ETH/USDC simply means that a trader is borrowing more quote token (USDC) than he already has, to buy a certain amount of base token (ETH). If the price of ETH rises against USDC, he would be able to sell all his ETH for USDC and repay all his debt. The remaining USDC would be his profit. In the event that ETH’s value drops relatively to USDC, a trader would suffer a loss.

Now consider the case that a user would like to go Short on the same trading pair, ETH/USDC.

He would need to borrow some base token (ETH) and trade it for quote token (USDC). If the price of ETH drops relatively to USDC, he would only have to spend a smaller amount of USDC in order to buy back the amount of the ETH owned previously and thus effectively pockets a difference as profit.

Cost-wise, traders would have to pay some interest rates when borrowing funds from exchanges. However, the assets bought would only act as collaterals, sitting idly inside these exchanges without generating any income whatsoever, making margin trading rather expensive.

What is a Flash Swap

Flash Swap is an integral function of Uniswap V2 and V3. Since most current DEXes on the Ethereum blockchain as well as many other EVM-based-blockchains are forked from Uniswap, they all inherit the same function.

It is quite difficult to have an analogy of Flash Swap in real world examples. Instead, let’s take a look at how an ordinary swap is carried out inside of Uniswap.

Suppose John wants to buy some ETH with his USDC, the technical term suggests that John is swapping his USDC for ETH.

John then proceeds to interact with Uniswap Pool of ETH/USDC. This pool contains both assets (ETH and USDC) and the logic to decide the price of each asset relatively to the other. In an ordinary swap, the first thing John would do is to send his USDC to the Pool, after the Pool receives John’s USDC, it will conduct its preset logic and calculates how much ETH is to be worth and then sends out ETH to John.

However, in a Flash Swap, the Pool doesn’t necessarily need to check if it has received any USDC at the beginning of the swap. Instead, it optimistically transfers out the requested ETH to John. At this point in time, John owns that ETH and can do whatever he wants with it. At the end of the transaction, the Pool will enforce that enough USDC is returned to its reserve.

One might wonder that what if John doesn’t pay back his USDC in a Flash Swap?

Since Ethereum transactions are atomic, the entire transaction can be rolled back to its initial state and John’s ETH would actually never be transferred out.

It is also worth notice that everything must occur within a single block and John can decide to either return ETH or USDC to Uniswap Pool.

A normal on-chain margin trade

Having grasped the basic concept of Margin Trading and Flash Swap, let’s dive into how Flæx utilizes these features to power its own trading platform.

For margin trades, it is common that a trader has access to a pool of assets available for borrowing.

Roll back to the example in Basic understanding about margin trade, supposed John would like to go for a long position on ETH/USDC.

Since John is going on long on ETH, which is the base token, John has to already own some ETH and needs to borrow some USDC in order to buy more ETH.

John can go to any existing Lending Protocols such as AAVE, Compound… and deposit his ETH as collateral, he then is eligible to borrow any other allowed assets against his collateral. In this case, he can borrow some USDC, which is the quote token, to buy more ETH.

However, Lending Protocols limit his borrowing power due to their “over-collateralized” model, which means he cannot borrow more than what he has put in as collateral. In fact, he can only borrow at a maximum cap of around 80-85% depending on which kind of assets being supplied.

Let’s say John put in 0.5 ETH aka $1500 (at a value of $3000 per ETH), he decides to go for an 80% maximum cap of borrowable, which is equal to 1200 USDC and buys another 0.4 ETH.

At this point, John’s position would be:

  • Collateral: 0.5 ETH

  • A loan with Aave: 1200 USDC

  • Available asset: 0.4 ETH

This would mean that John has entered a Long position in ETH/USDC at 1.8x Leverage.

What John can do now is re-supply his 0.4 ETH to the Lending Protocol to “rinse and repeat”, effectively keeps increasing his leverage.

A normal 'rinse and repeat' margin increasing

However, one can clearly see that this approach poses a great deal of risks and requires many repetitive transactions. John can be instantly liquidated right after he hits his first borrow at 80% as the interest is accrued to his debt.

Leverage conflict

Assume ETH/USDC is $3,000. John wants to long 1 ETH but only has $1,500 USDC, aiming for 2x leverage. Following the previous examples, the goal is to borrow an additional 1500 USDC so that, combined with the 1500 USDC (or 0.5 ETH) he already has, he can purchase 1 ETH

Let’s check out the flows:

  • Step 1: John somehow could borrow 1,500 USDC from Aave

  • Step 2: John uses 1,500 USDC he borrowed, plus the 1,500 USDC he has, to buys 1 ETH on Uniswap

-> This is simply impossible from step 1 because John could not borrow $1,500 USDC from Aave if he haven't deposit 1 ETH as collateral yet!

This is where Flæx comes into play and provide an extremely clever solution.

Flaex's solution

In order to increase leverage, the most crucial task is to be able to keep on borrowing, buying assets and re-supplying those assets back as collateral.

After the first borrow, John is left with 0.5 ETH which he would definitely continue to re-supply into the Lending Protocol as collateral. What if John has access this 0.5 ETH even before he has to supply the first 0.5 ETH? If John can achieve this, he can actually supply 1 ETH and thus has effectively increased his borrowable amount.

It turns out that this is entirely possible thanks to the power of Flash Swap. After first Flash Swap 01 ETH, he can now supply 01 ETH into the Aave as collateral and proceed to borrow the same $1,500 USDC as previously explained plus his initial $1,500 USDC to repay the Flash Swap amount.

In this case, John only has to borrow a much less amount of USDC which is reflected in terms of loan-to-value because:

  • Collateral: 1 ETH

  • Borrow: 1,500 USDC

  • Loan to Value: {1500 / (3000 USDC per ETH)} / 1 = 50%

John can easily increase his leverage by increasing the Flash Swap amount, as long as his loan-to-value doesn’t exceed the maximum cap, he will not be liquidated.

At 80% maximum cap, John can effectively go as high as 4x!

Flaex's role

From the above example, one might wonder what the role of flæx is supposed John can carry out this entire maneuver on his own.

Firstly, it is worth noticing that a Flash Swap is only available via smart contract interactions and requires deep understanding of not only defi but also program development expertise.

Secondly, when an individual user attempts to carry out this entire transaction on his own, he is subject to maximum 4X leverage. At the same time, he would be liquidated if asset’s price moves to the unfavorable direction much sooner than he expects. This is because, at any given point in time, if the loan-to-value reaches the maximum cap, which is only at about 80%, he would be instantly liquidated. This can be simplified by the below example:

A trader entered a long position of 2X in ETH/USDC, the entered price of 1 ETH is equal to 2000 USDC. The initial capital is 10 ETH.

His position would be:

  • Collateral: 10 ETH

  • Borrow: 10,000 USDC

  • Loan to Value at entered point in time: 50%

If the price of ETH drops to a point where his loan-to-value increases to 80%, he would be liquidated. The implied price could be calculated to be at 1250 USDC per ETH.

This is rather unfavorable for traders because, commonly speaking, when a trader goes for a 2X leverage position, he wouldn’t be liquidated if assets price won’t drop by nearly half!

Flæx, with its robust and well-designed architectural implementation, can allow other users to act as collateral provider, effectively decreases the whole protocol’s loan-to-value and thus increases trader’s leverage level.

The suggested ideal leverage would be somewhere around 10X.

This model attracts investors who are willing to become "collateral providers" to earn real yield generated from both interest rate from AAVE and sharable profit from other trader’s commission fees.

To see how a transparent liquidation works, see

Last updated