In this essay I’ll try to explain how much of DeFi (decentralized finance) works. According to DeFiPulse.com, there is currently over $75 billion in funds in this ecosystem. It’s a growing part of the overall crypto market, and one I find pretty fascinating. I’m going to briefly define the basics, but won’t dwell on them and will focus on the economic analysis here, skipping over a lot of details - you can find explanations of the basics in many places. If you already understand the basics, you can skip down to the “Yield Farming” section. At the end, I include a case study of Polyquity and a description of an arbitrage that was (and may still be) available. For future posts, I’ll jump right into the analysis.
Introduction
First, blockchains, smart contracts, stablecoins. A “blockchain” is just a series of transactions, grouped into “blocks” and saved. Once a transaction has been added, it’s permanent; nobody can reverse the transaction1. There’s a special programming language in which “smart contracts” are written, and once a particular contract is on the blockchain, you can only interact with it via specific methods in the code. For example, one of the most basic contracts is for a token. This keeps tracks of everyone’s balances, it has a way to send tokens from one address to a different address, and starts with a fixed supply of tokens allocated to a specific address, with no new tokens allowed to be created. You would then have, say, a million units of this token, and people could send them back and forth, but the supply could never go up. Alternatively, you could have the ability to “mint” new tokens, either available to anyone or restricted to particular addresses. A “stablecoin” is a token that’s meant to be worth some amount of fiat money, typically $1. USDC is one example: if you wire their operators (Coinbase and Circle) money, they will “mint” an equivalent amount in USDC, using their privileged status as the only address allowed to mint USDC, and send it to you. And if you send them USDC you can cash it out for $1.
The last piece of the puzzle you need to understand is a more complicated smart contracts called a decentralized exchange (“DEX”). This is a way for people to trade cryptocurrency for other cryptocurrencies, entirely on the blockchain. It works by depositing two tokens, say USDC and ETH, and allowing anyone to trade USDC for ETH or vice versa. As people buy more of one, the person who deposited this liquidity gets more of the other token according to some formula, and can withdraw at any time. Some popular DEXes are Uniswap, Curve, and Sushiswap, with hundreds of millions of dollars in liquidity for some token pairs. For example, this USDC/ETH pool on Uniswap v3 has 249M USDC and 35K ETH in it for a total of 361M liquidity. In the last 24 hours, there were 330M in transactions to this pool, generating 999k in fees to those providing liquidity, who are acting as market makers.
The more liquidity a pair has, the more people can trade with minimal price impact. You can trade millions on this pool without moving the price much.
Yield farming
Imagine you just launched a new crypto project. Don’t worry too much about what this project does at this point; most of the people buying in won’t care either. The first thing you do is launch a token, let’s call it CAT. It initially starts out as worthless, and hard to buy. So you add some liquidity to a DEX, and start marketing. But what you really need is a reason to buy CAT, and a reason to provide liquidity so it’s easy for others to buy and sell - if it’s hard to sell, people won’t want to buy large amounts. The solution is very standard: projects will issue rewards using their token for people interacting with the project. The details vary depending on the project, but one near-universal is that liquidity for that token is incentivized. Typically, you’d have an incentivized Uniswap pool for the USDC-CAT pair, with the rewards paid in CAT, along with CAT rewards for people interacting with the protocol. This creates an artificial demand for CAT in the short run, as people must buy it in order to provide liquidity, but creates selling pressure over the medium term, as usually people will sell the tokens they get in rewards fairly quickly, plus anyone exiting the system will have to sell their tokens as well. Usually what happens is the token jumps a lot initially, then slowly declines as rewards get sold off, until eventually the token isn’t worth enough for people to think it’s worth continuing to “farm” it, and they exit. This is ultimately a zero sum game; all money being made by anyone here comes at the expense of others who played it wrong. If there’s no reason for the token to be worth anything long term, that is - but people are betting on a project perhaps lasting longer than usual. A handful of projects launched this way have survived and thrived for the long term, for example Curve (stablecoin swapping) and Aave (lending and borrowing cryptos).
When I look at a project I try to map out all the moving parts and figure out where it’s going. Often there are arbitrages or low-risk opportunities to make some yield.
Case Study - Polyquity
A few weeks ago, a new project called Polyquity launched. It copied its code from an existing protocol called Liquity, but instead of being based on Ethereum, it was based on Polygon, which is a sidechain with cheaper transaction costs than Ethereum. Polyquity consists of two tokens: PYQ, the project token, and PUSD, a stablecoin. In theory, 1 PUSD is worth $1. In practice, it’s different. First, we need to understand how PUSD gets created. The way to make PUSD is by depositing Matic (native token of Polygon) and creating PUSD using the smart contract, up to a limit: you need Matic valued at least 110% of the minted PUSD. So for example if you deposited at least $110k worth of Matic, you could create 100k PUSD. There was a .5% minting fee, so you’d only actually get 99.5k PUSD, but you would have “debt” of 100k PUSD. If you want to get back that Matic, you need to deposit 100k PUSD, and then the contract lets you withdraw your Matic.
As typical, they have an incentivized pool of PUSD/USDC, along with a pool for PYQ/USDC. Because of this, PUSD consistently trades at a premium to $1; people will buy it in order to stake in the PUSD/USDC pool and are willing to pay over $1. Looking at https://polygon.poocoin.app/tokens/0x9af3b7dc29d3c4b1a5731408b6a9656fa7ac3b72, it has ranged from $1.05 to $1.08 in the last week. The day it launched, it was higher, and I realized there was an opportunity to short it and cover later when the price would drop. The way to do this is by minting PUSD against Matic, selling it, then when the price drops buy back the PUSD, repay the loan, and get your Matic back. Since I didn’t want to buy Matic and risk that exposure, I added another step and borrowed Matic against my USDC from AAVE (the lending protocol). Here is the entire process, step by step:
Deposit USDC at AAVE
Borrow Matic from AAVE
Deposit Matic at Polyquity
Mint PUSD from Polyquity (using your Matic as collateral)
Sell PUSD (I used 1inch to get best price)
Wait for price to drop (it took around a week for price to go down to around $1.02-3 and I started closing the position)
Buy PUSD
Repay PUSD to Polyquity
Withdraw Matic from Polyquity
Repay Matic to AAVE
Withdraw USDC from AAVE
Additionally, while waiting I needed to monitor the price of Matic; if it went up a lot I would need to deposit more collateral at AAVE to prevent my USDC from getting liquidated, while if it went down a lot I would need to deposit more at Polyquity. It was an easy rebalance, if it moved one way I’d borrow more Matic from AAVE and deposit to Polyquity, if it moved the other way I’d withdraw Matic from Polyquity and partially repay the Matic loan at AAVE, just had to set alerts for 15-20% price moves to avoid issues.
After about a week I had made around 2-3% on the capital I devoted to the trade and was fully closed out.
There may be an opportunity now, as you can short for a 6-8% premium as mentioned above. The problem is that it’s hard to know how long this will last, and since you need to tie up capital in two places it’s pretty capital intensive. Eventually, PYQ price will decline because more and more gets emitted as rewards, and then people will exit the various pools and repay/sell their PUSD and it’ll head back to $1, but over an unknown timeline.
If you need to hold the position a month and monitor to make 3% on your overall capital committed, it’s a pretty marginal trade. It may be more interesting to swing trade; short at 8%, buy back if it drops to 6%, and repeat, without closing out the trade. Note that closing out by repaying the minted PUSD costs you .5% if you want to open again, while if you swing trade you only pay the trading fee each time, which is negligible for IronSwap.
In future posts I hope to analyze similar protocols in this way and identify profitable opportunities.
Except for reorgs, but you don’t need to worry about those in practice
Golden article. Thanks for the inspiration. You also explain liquidity and yield farming from high level really well. Looking forward to future posts. I also would like to start researching similar opportunities in low risk arbing.
nice post, what was the scale of this strategy? i can't imagine there is a huge amount of liquidity on the PUSD pairs. at a certain point, the market impact of entering and exiting the trade becomes material