jordan-public / cfd-dex

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This project won the following prizes at the Scaling Ethereum 2023 hackathon:

πŸ’‘ Polygon β€” Best dApp Deployed on Polygon zkEVM

πŸ”΄ Optimism β€” Just Deploy!

πŸ₯‡ Mantle β€” Best Use

πŸ₯ˆ Taiko β€” Best Dapp

πŸ“œ Scroll β€” Just Deploy!

πŸ† Scaling Ethereum Finalist

Ccontracts for Difference Decetralized Exchange and

Flash Collaterals - more powerful than Flash Loans

How to run and install

Demo video and demo deployments

Abstract

We created a novel way of implementation of Flash borrowing called Flash Collaterals in order to stabilize blockchain DeFi protocols and liquidations. It allows us to borrow funds for this purpose, even in extremely illiquid markets where no such funds are available. To achieve this, the protocol has to use cash settlements, but instead of enforcing cash balances, it should create a "collateral" based on deposit of assets. Then, for the duration of a single transaction, such collateral can be fictitiously generated, as long as at the end it is returned in full.

This allows for improved efficiency of liquidations. Such nimble and inexpensive liquidations which can be executed by anyone without any funds (other than gas), makes the protocols more stable and resilient to sudden price movements that could otherwise render the protocol insolvent.

This technique can be used in any "cash settled" derivative protocols, such as Decentralized Exchanges (DEX) for Contracts for Difference (CFD), cash settled Options and Futures and much more.

This repo implements a CFD DEX using the above technique.

CFD DEX

Contracts for Difference are cash settled instruments. For example, the user deposits some collateral and can then trade EUR/USD (foreign exchange) and settle in USDC. Buying such EUR/USD CFD does not result in holding of any asset. Neither EUR nor USD is touched. When the user exits this long position, the difference in the recorded entry and exit prices is used to calculate the profit (or loss), which is then added (subtracted) to the collateral which can be withdrawn.

The user has to deposit sufficient collateral to meet the Entry Margin (typically 10%) and maintain collateralization above the Liquidation Margin (typically 5%) in order to avoid being liquidated.

Anyone can liquidate a position which is undecollateralized below the Liquidation Margin. The liquidator has to have sufficient collateral to take over the liquidated position and meet the Entry Margin collateralization. The liquidator receives additional penalty from the liquidated position, typically 2% of the market value at the time of liquidation.

Flash Collaterals

If the liquidator does not have sufficient collateral to take over the liquidated position, the liquidation transaction reverts. However, the liquidator can borrow any desired amount of collateral, even amounts that do not exist anywhere, as long as he can return the borrowed collateral within the same blockchain transaction. In the meantime, after borrowing the collateral, the user is free to go back at the CFD DEX and perform multiple liquidations and take multiple bids and offers to offset the positions resulting from the liquidations. If such exercise is profitable, the user can return the borrowed "flash collateral" and exit the transaction with profit.

About

License:Other


Languages

Language:Solidity 54.2%Language:TypeScript 32.2%Language:CSS 7.2%Language:Shell 6.0%Language:JavaScript 0.3%