Introduction to Decentralised Finance

Image for post
Image for post

In this article we present an overview of the different decentralised finance (DeFi) products, with a particular focus on loans which are arguably the most popular application. By the end of the article the reader should have an idea of what is meant by DeFi and the different strategies for profit that people are using to make money with decentralised lending platforms, as well as the risks associated.

What is Decentralised Finance (DeFi)

The concept of decentralised finance, is of creating composable basic finance primitives, that are implemented as smart contracts, with some degree of decentralization.

DeFi is an approach that is primarily focused on decentralising the power dynamic over money, helping people have better relationships with their money and avoiding being exploited as well as increasing access to financial services by disintermediating all the gatekeepers (banks).

On Ethereum, you can write smart contracts that interact with money and can represent products such as loans, collateralised debt, etc. In other words, smart contracts become the intermediaries on the Ethereum platform instead of banks in the centralized world.

DeFi involves taking existing financial products and porting them over to the blockchain. Similar to Lego, individual parts of DeFi can be pieced together to make something new. For example, ETH is used as collateral into the MakerDAO protocol to mint DAI tokens (a stablecoin pegged to USD), DAI can then be supplied to Compound (a lending platform) to earn interest in a token called cDAI, cDAI tokens can be used in other DApps.

DeFi products can be categorised as follows:

  • Loans
  • decentralised Exchanges (DEXes)
  • Derivatives
  • Payments
  • Assets


Arguably, the most popular and fastest growing sector of DeFi is borrowing and lending platforms.

Maker and Compound are examples of collateralised lending platforms. MakerDAO is one of the most popular lending DApps, it allows you to lock in ETH for DAI, a stablecoin pegged to the USD. DAI provides a way for token holders to access liquidity at the cost of an annual interest rate. Often the collateral position is higher than the loan amount.

There are a few websites which help users look for the best interest rates across all major lending platforms and for different cryptocurrencies or stablecsoins available. Two such platforms are loanscan.io and defipulse.com.

Image for post
Image for post
Image for post
Image for post

A major attraction of decentralised finance is that it allows investors to earn competitive interest rates, much more competitive than traditional finance without the need for KYC or to be an accredited investor, and this fact by itself could drive the adoption of blockchain. DeFi loans allows investors to get passive income from cryptocurrency markets without speculating on cryptocurrency prices.

Image for post
Image for post

Compound is currently the most popular lending platform due to its usability, although other competitors such as Aave and dYdX are making their way to the top quickly as they are becoming popular flashloan liquidity providers.


Flash loans are an innovtive financial product made possible by the atomic nature of transactions on the Ethereum blockchain. They allow users to borrow large amounts of cryptocurrency from liquidity pools without collateral as long as the loan is repaid in the same transaction. They are similar to leverage trades and margin accounts in traditional finance, but without the need to be approved and provide collateral. Unlike margin trading, it is not possible to lose your capital when you trade using flashloans, if the financial transaction enabled by the loan is unsuccessful you will only lose a small fee ranging between $1 and $6 that is paid to the liquidity provider.

Decentralised Exchanges

Decentralised Exchanges (DEXes) are cryptocurrency exchanges that use smart contracts to enforce the trading rules, execute trades, and securely handle funds when necessary.

DEXes allow you to quickly exchange different cryptocurrencies and stablecoins, and may be used as part of flash loan strategies in order to acquire the assets needed. The website dex.ag allows users to find the best exchange rates across all decentralised exchanges, as seen below.

Image for post
Image for post


A derivative is a contract, the value of which is determined by the performance of an underlying asset. Derivative markets in DeFi trade a wide range of assets on the blockchain using synthetic pricing. For example, there are derivative tokens for equities, futures, and popular cryptocurrencies.

Image for post
Image for post


The payments category is largely dominated by layer 2 payment channel networks. These networks are built on top of existing blockchains, a prime example being the Lightning network.

Image for post
Image for post


Tokenized assets and asset management is a quickly growing sector of DeFi. Existing financial assets deployed to the blockchain as tokens fit nicely into DeFi protocols which extend their utility. Asset management protocols allow investors to put their money in the hands of smart contracts or fund managers which manage their portfolio. Other asset management protocols, such as Set Protocol, employ automated strategies such as periodic rebalancing or following technical indicators.

Image for post
Image for post

Set Protocol (tokensets.com) in particular is gaining a lot of popularity over the past months.

Image for post
Image for post

Tokensets allows you to use automate asset management strategies that calculate when to buy and sell crypto in order to rebalance your portfolio. You can also follow professional traders by following their strategies at the click of a button.

Image for post
Image for post


In this section we will be talking about the main strategies for profiting with lending platforms, namely flashloans and yield farming.

Arbitrage using flashloans

Arbitrage is arguably the main use case for flashloans, which means buying cryptocurrency (or an asset) for a price and selling it for a higher price on a different exchange. The term arbitrage also exists in the centralized finance worl, although flashloans offer arbitrage opportunities that are not possible in traditional finance. The main challenge with arbitrage is that by the time you sell an asset the price of it might have changed, but with flashloans you don’t have that problem. Additionally, with flashloans you don’t have to have the crypto asset, you can just borrow it, therefore the earning coming from the price difference (spread) will be proportional to the amount traded. Arbitrage actually brings efficiency to the market because you are reducing the spread, which is the difference between the lowest price someone is prepared to sell a currency and the highest price someone is prepared to buy it for. DeFi needs arbitrage because it makes markets more efficient by bringing prices closer together.

You don’t need to hold any cryptocurrency in order to trade it. The trades can’t fail and if they fail you don’t lose any money (you don’t make any either though).

Arbitrage Strategies

There are two main strategies for arbitrage, which are called horizontal and vertical scale. Vertical scale means making lots of money in one single transaction, that happens when you find larger arbitrage opportunities. Horizontal scale means making a lot of transactions over and over again, it is more likely that you’re going find horizontal opportunities than vertical ones.

Arbitrage Sequence

In general, arbitrage works as follows: start with token A, convert it to token B, and then go back to token A with more of it than you started with. This works best when the spreads are bigger, which happens when the markets are more volatile, that is when you see spikes (on line charts) which means the markets are moving faster than usual. For example, a 1% change in price over an hour is a significant volatile market even for Ethereum or Bitcoin.

For example, in a flashloan you could get a loan in order to borrow Dai, sell it for Ether on the Kyber network decentralised exchange, then sell Ether for Dai on Uniswap, the goal being to have more Dai then you started with.

Basic Requirements and considerations

  • The arbitrage opportunity has to actually be there, for the flash loan arbitrage to be profitable.
  • Gas fees, which depend on the complexity of the flash loan contract, the number of contract calls, etc.
  • Flash loan fees which are decided by the flash loan provider
  • You will need to transact with multiple decentralized exchanges for exchange arbitrage
  • There could also be opportunities for arbitrage across multiple trading pairs

If there are abitrage opportunities involving a currency pair that is not offered by one exchange, say ZRX/OMG. In this case you can still borrow DAI and swap it for ZRX, then swap ZRX for OMG, and finally go back to DAI by doing this process in reverse. This process is called triangular arbitrage. Triangular arbitrage is a specific strategy, where you draw your layout currencies on a triangle, they don’t have a common currency, and then you trade currencies from an angle of the triangle to the next until you get back to where you started.

Image for post
Image for post

Yield Farming

Yield farming is the act of maximizing the yield one makes via decentralised finance applications. With a good understanding of yield farming and Ethereum it is possible for investors to capitalize on this rapidly growing income and capital growth strategy while minimizing their exposure to risk.

What is the return on investment?

The return on investment falls into three categories

  • Transaction fee income
  • Token rewards
  • Capital growth

Transaction fee income

Transaction fees vary between protocols and pools. In the case of Balancer, the fee is set by the user at the pool creation stage and can vary between 0.001% and 10%. Other pools such as Uniswap charge a flat fee (0.03%). Currently, all fees are passed onto liquidity providers, however in the future it is likely that governance token holders will receive a portion of the proceeds.

Token rewards

Token rewards are used as an incentive to provide liquidity but are not always available. These rewards are typically distributed over a set period of time which can range from weeks to years. The tokens rewarded are often used for governing the system, either at the time of issuance or at some point in the future. These tokens can then be traded on exchanges like Coinbase if popular enough.

Capital growth

Capital growth (or the lack thereof) makes calculating the profitability of any given yield farming opportunity challenging. In some cases, the rewards, fees and assets supplied may be in the form of stablecoins. In this instance, there is no capital growth and calculating income is a lot more straightforward. However, in the majority of cases, speculative assets join the mix and their appreciation or depreciation can decide the yield. Taking an example of BTCe, this yield farming strategy provides exposure to BTC, REN, SNX and CRV. These assets are volatile and can move without correlation. It is wise, therefore, to adopt yield farming strategies that align with a positive future outlook for the tokens involved. Alternatively, those looking to avoid token volatility entirely can opt for yield farming strategies that are exposed only to stablecoins.

What to Consider Before Yield Farming

Misleading APY

Annual percentage yield can be extremely misleading in the short term. In some instances, APYs may be advertised in the hundreds of percent. These yields take into account the value of the fees and tokens rewarded. In instances where the token rewards experience a short and sharp bubble (as was seen with COMP quickly moving from $60 to $330), the quoted yield can be misleading.

Liquidity provision can be fickle; users are able to move their liquidity from one place to another, hunting out the best possible return at the time. This means that the APY of a certain strategy can shift dramatically day to day.

Price volatility

When determining a strategy, price volatility of the underlying assets should be considered. If an asset is providing a high APY but is considered to be one that may see massive capital losses, the strategy is likely to be unfavorable. Equally, this can work in the other direction. In the case of the COMP distribution, yield farmers were most excited by their ability to access a token which, they expected, would see significant price appreciation.

DeFi Risks

Returns in DeFi farming are never risk free. The high yields are a reflection of the significant risks taken on by the liquidity provider. These risks include but are not limited to:

  • Smart contract risks
  • Oracle risks
  • Exchange rate risks
  • Black swan events

DeFi is an immature area, being only about one year old and yet over the past few months we have seen its various components being exploited multiple times, a non comprehensive list of exploits is:

  • Jun 2019: Synthetix sETH $37m
  • Feb 2020: bZx $900k
  • Mar 2020: iEarn $280k
  • Mar 2020: MakerDAO Black Thursday $9M
  • Apr 2020: LendfMe $25m
  • Apr 2020: imBTC Uniswap Pool $300k
  • Jun 2020: Balancer $500k ETH
  • Jul 2020: Liquid $16m BTC (avoided)

One likely reason for this recent explosion in the number of hacks is due to the rise of flashloans; most of these exploits would not have been possible without flashloans as they require large amounts of capital which attackers need in advance, for example, in order to manipulate price oracles of pump and dump the value of a cryptocurrency.

Smart contract risks

With the expansion of the DeFi space and the enormous volume of liquidity being poured into applications thanks to yield farming, the incentive for bad actors to exploit smart contracts is ever-increasing.

Oracle risk

Oracles provide data to smart contracts that is then used in the execution of functions. Price feeds are one of the critical pieces of infrastructure in decentralised finance and their failure or exploitation can lead to negative outcomes for users and platforms. DeFi project, bZx, famously suffered from an oracle attack with the hackers stealing some 630,000 ETH. Chainlink and other decentralised oracle networks are helping to mitigate this risk.

Synthetix Hack

In this case, a Synthetix oracle, responsible for providing external data to Synthetix’s smart contracts, transmitted false data on June 25th 2019, which a bot took advantage of. This particular bot was able to take advantage of the mispricing issue immediately, and exploit it repeatedly. The company contacted the owner of the arbitrage bot that unintentionally hacked the oracle and agreed on a bounty deal with him in order to return the funds

bZx second hack

This is an example of an exploit relying on oracle manipulation, made possible by the large amount of ETH available to the attacker as she takes advantage of the bZx flashloan feature to borrow 7,500 ETH. See this article for an in depth explaination.

With the flashloan, the exploit swaps 900 ETH in two batches for sUSD through Kyber. The sell-off of these two batches effectively drives the price of sUSD to around 2.5x higher when compared to the average ETH/sUSD market price.

The attacker this time takes the approach of first collateralizing the collected sUSD back into bZx and then borrowing from it 6,796 ETH. As bZx relies on Kyber for the price feed, with the spiked sUSD/ETH price, the collection of sUSD allows for the borrow of 6796 ETH, which indicates that this loan is now underwater with insufficient collateralization.

With the borrowed 6,796 ETH (3,082 ETH leftover), the attacker is able to repay the 7,500 ETH flashloan back to bZx with the profit of 2,378 ETH.

Exchange rate and liquidation risk

The assets used for yield farming are often highly volatile. This volatility can lead to large capital losses over the period that someone wishes to farm yield. While assets are never “locked” and can always be withdrawn by the user, it does add friction to the process if an asset needs to be sold quickly and there is difficulty finding liquidity.

Exchange rates can also impact the viability of a position in DeFi. For instance, in the borrowing and lending platform, Compound, a user farming COMP may find that their position is liquidated as the value of their collateral falls below the required amount due to an unfavourable exchange rate movement.

Black swan events

A recent episode that affected the collateralised loans market, was a problem for the DAI stable coin when it faced the collapse of Ether exchange rate by more than 55% in a single day, this episode became known as black Thursday, and was partly in response to the COVID-19 pandemic and the concurrent crash of the stock market as well. DAI depends on overcollateralization, where you must maintain 150% of collateral in order to back your DAI as an absolute minimum, htus even contracts that were in theory 300% collateralised ended up undercollateralised because of the fall in value of the collateral.

In normal circumstances the response would be that through automated systems as well as manual intervention, users would add DAI back into the system in order to re-collateralize their loans, or put ETH as additional collateral in order to refund or re-collateralize their loans. However, during the time when the value of ETH dropped 55%, the gas price increased and it became difficult to get transactions accepted. The situation was compounded by a bug in the auction system that allowed some users to buy some of these loans for close to zero and liquidate them. In the end the damage was only about 5 million dollars, and most accounts affected were reimbursed.

Although this was a black swan event, it shows how a cascade failure of multiple problems all occurring at the same time can happen and therefore is a risk that should be taken into account.


This article has looked at the main ways that DeFi is being used at the moment. A simple use case is loans, funded by depositing cryptocurrencies (that you have been HODLing since 2017) into a liquidity provider such as Compound in order to gain passive income from holding the asset. In contrast with traditional banks, no approval is needed for the loan. A more complex use-case is the one used by traders and programmers, flash loans. These can be used in order to perform leverage trades with a minimal downside (other than a transaction fee of a few dollars). Finally, yield farming, which means searching for the best interest rates available and lending a selection of cryptocurrencies across multiple exchanges. A few tools are already available which allow beginners to automatically follow successful strategies without minimal effort, in exchange for a share of the gains.

This article is the first of a series, in the next articles we will cover flash loans in depth and yield farming individually, including strategies, flash loans code examples and trading bots that are ready for testing on the Ethereum Mainnet.

Written by

Oxford-based blockchain and zero knowledge consultancy and auditing firm

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store