flash loans conceptual design

in #bitcoin5 years ago

In this article we are going to dive more inside flash loans as a Defi product/service and why it differs from any service/product banking system offers , flash loans qualities over real world banking sector services/products, Defi world actors and their cross interactions during a flash loan exectution, , flash loans real world use cases.
Introduction:
the most interesting thing about flash loans as product/service is that there is no real world example for it in the banking business side like other defi products (e.g. lending, borrowing, exchanging,…) its more defined as an inherited property of the atomicity of the blockchain itself and that’s brings us to the qualities of flash loans and how it differs completely from any other banking services/products
Qualities of flash loans over real world financial services
No debt default risk:
What if it were possible to offer credit, without managing the risk that the borrower does not pay back the debt? Such a concept appears impossible and impractical in the traditional banking system. No matter how small the debt, and how short the loan term is, the risk remains but in case of flash loans its bossible as A lender offering a flash loan bears no risk that the borrower defaults on its debt because the transaction is transacted atomically on the the blockchain
No need for collateral:
As a consequence Because the lender is guaranteed to be paid back, the lender can issue credit without upfront collateral from the borrower: a flash loan is non-collateralized because in reality the transaction is excuted atomically and that’s why there is no need for collateral
Loan size:
Flash loans are taken from a public smart contract-governed liquidity pool. Any borrower can borrow the entire pool at any point in time, two of the biggest pools exceeding 20M each are Aave and dydx

DeFi Actors interacting with flash loans
In the following, we define the on-chain actors that we consider within this article and focus on a single blockchain.
DEFI:
Decentralized Finance (DeFi) Decentralized Finance is a combination of financial cryptocurrency-related protocols build by open-source smart contracts. These protocols for instance allow to lend and borrow assets MakerDao and Compound, exchange Uniswap, dydx margin trade dydx, Bzx short and long Bzx, and allow to create derivative assets Compound At the time of writing the article, the DeFi space accounts for over 1bn USD in smart contract locked capital among different providers. The majority of the DeFi platforms operate on the Ethereum blockchain, governed by the Ethereum Virtual Machine (EVM)
Trader:
A trader controls a private/public key pair and is responsible for signing and sending transactions towards other accounts and smart contracts.
Flash loan Provider:
A trader with capital may chose to offer this capital to other traders, e.g. as collateral within a lending platform or within a DEX.
Flash loan Taker:
A trader which is taking advantage of liquidity provider with fees in exchange to accessing the available capital
DeFi Platforms
Here in this article we briefly provide an overview of some of DeFi platforms where flash loans plays a huge role, such as exchanges Kyber and Uniswap, margin trading platforms DyDx and Bzx, credit/lending platforms Maker Dao and Compound.
Exchanges
Limit order book (LOB) DEX: An order book is a collection of bid and ask orders. Traders post buy/bid or sell/ask orders for an asset of the market to a LOB Several blockchain exchanges operate a LOB within a smart contract like MakerDao , Aurora and Kyber
Automated market maker (AMM) DEX: An alternative exchange design is to collect funds within a liquidity pool like MakerDao, Uniswap
Margin trading
Trading on margin helps traders to borrow assets from the trading platform and trade with these borrowed assets e.g. Bzx and DyDx
Credit and lending
With over 900M USD locked capital, credit represents one of the most significant recent usecases for blockchain based DeFi systems e.g. Compound
Flash loans use cases
We provide a comprehensive overview of how and where the technique of flash loans can and is utilized

Arbitrage
In case of flash loans, trader can operate arbitrage on different DEXs, without the need to hold sufficient funds or being exposed to volatility risks as the trade held in one block. The trader can simply open a flash loan, perform an arbitrage trade and pay back the loan plus the fees
Arbitrage example: On 18th Jan 2020,
• a flash loan borrowed 3, 137.41 DAI from Aave to make an arbitrage trade on the AMM DEX Uniswap (transaction address: https://etherscan.io/tx/0x4555a69b40fa465b60406c4d23e2eb98d8aee51def21faa28bb7d2b4a73ab1a9) . To prepare the arbitrage,
• DAI is converted to 3137.41 SAI using MakerDAO’s migration contract (transaction address : https://etherscan.io/address/0xc73e0383F3Aff3215E6f04B0331D58CeCf0Ab849) .
• The arbitrage converts SAI for 18.16 ETH using SAI/ETH Uniswap,
• immediately converts 18.16 ETH back to 3, 148.39 DAI using DAI/ETH Uniswap.
• After the arbitrage, 3, 148.38 DAI is transferred back to Aave to pay the loan plus fee. This transaction costs 0.02 ETH of gas (about 5.63 USD at the time of writing). Note that even though the transaction sender gains 3.29 DAI from the arbitrage, this particular transaction is not profitable. rbitrage example
Wash Trading
Trading volume of a coin indicates the popularity of that asset the most traded asset is the most popular Malicious exchanges or traders can mislead other traders by artificially inflating the trading volume of an asset to attract interests In centralized exchanges operators can easily and freely create fake trades in the backend, while decentralized exchanges settle trades onchain. Wash trading on DEX thus requires wash traders to hold and use real assets. Flash loans can remove this “obstacle” and wash trading comes at a cost of the loan interest, trading fees, and (blockchain) transaction fees
Wash trading example: On March 2nd, 2020, a flash loan of 0.01 ETH borrowed from dYdX performed two back-and-forth trades (first converted 0.01 ETH to 122.1898 LOOM and then converted 122.1898 LOOM back to 0.0099 ETH) on Uniswap ETH/LOOM market (transaction id: https://etherscan.io/tx/0xf65b384ebe2b7bf1e7bd06adf0daac0413defeed42fd2cc72a75385a200e1544) . The 24-hour trading volume of the ETH/LOOM market increased by 25.8% (from 17.71 USD to 22.28 USD) as a result of the two trades
Collateral Swapping
There are two types of defi platforms as follows: (i) a DeFi system where a new asset is minted and backed-up with userprovided collateral (e.g. MakerDAO’s Aave DyDx) and (ii) a DeFi system where long-term loans are offered and assets are aggregated within liquidity pools (e.g. margin trading Bzx or long term loans Aave). Once a collateral position is opened, DeFi platforms store the collateral assets in a vault until the new/borrowed asset are destroyed/returned. Because cryptocurrency prices fluctuate, this asset lock-in bears a currency risk. With flash loans, it is possible to replace the collateral asset with another asset, even if a user does not possess sufficient funds to destroy/return the new/borrowed asset. A user can close an existing collateral position with borrowed funds, and then immediately open a new collateral position using a different asset
Collateral swapping example:
On February 20th, 2020, a flash loan borrowed 20.00 DAI (from Aave) to perform a collateral swap (on MakerDAO) (transaction id: https://etherscan.io/tx/0x5d5bbfe0b666631916adb8a56821b204d97e75e2a852945ac7396a82e207e0ca) . Before this transaction, the transaction sender used 0.18 WETH as collateral for instantiating 20.00 DAI (on MakerDAO). The transaction sender first withdraws all WETH using the 20.00 DAI flash loan, then converts 0.18 WETH for 178.08 BAT (using Uniswap). Finally the user creates 20.03 DAI using BAT as collateral, and pays back 20.02 DAI (with fee to Aave). This transaction converts the collateral from WETH to BAT and the user gained 0.01 DAI, with an estimated gas fee of 0.86 USD
Flash Minting
Cryptocurrency assets are commonly known as either inflationary (further units of an asset can be mined) or deflationary (the total number of units of an asset are finite). Flash minting is an idea to allow an instantaneous minting of an arbitrary amount of an asset — the newlymined units exist only during one transaction. It is yet unclear where this idea might be applicable to, the minted assets could momentarily increase liquidity. Flash minting example: A flash mint function can be integrated into an ERC20 token, to mint an arbitrary number of coins within a transaction only. Before the transaction terminates, the minted coins will be burned. If the available amount of coins to be burned by the end of the transaction is less than those that were minted, the transaction is reverted (i.e. not executed). An example ERC20 flash minting code could take the following form

image.png