DeFi Mini Course: Part 2, Currency Exchange
Before You Get Started on Part 2.
In this part, you'll learn how to swap one crypto for another on Uniswap so you can lend it out on the COMPOUND or AAVE platform in Part 3 of this course.
You'll need a MetaMask wallet with $100 worth of Ether. Skip back to Part 1 for guidance on this.
Disclaimer: Crypto is still in its infancy and very high risk. I recommend setting the expectation that you will lose all of the money you invest as you're learning and treat it as an education. Throughout the mini-course, I will indicate the cryptos I hold myself, so at least - if you do copy me - I'll lose money if you do! This course is not investing advice, it is intended to teach you how DeFi works! You are reading these materials and taking any guided steps at your own risk. Crypto is technical and funds are easily lost if you are not careful with passwords as well as sending and receiving money to/from the right wallet addresses - not to mind bugs in nascent software platforms or bad actors. Learn with small amounts to minimise your risk.
Update June 2021: Disclaimer and Workaround for High Gas Costs.
Given the high transaction costs on Ethereum, it may be wise to learn instead on Binance Smart Chain or Celo - two blockchains I have used. The exchanges on those platforms are pancakeswap.finance and ubeswap.org (instead of uniswap.org).
Part 2, Currency Exchange
DeFi is like a bank, but you can participate in being the bank :)
In the same way that banks make money by offering currency exchange and lending services, you can participate in DeFi and earn money just as a bank does.
This part of the mini-course will walk you through a currency change platform (UniSwap) where you can either exchange currency OR earn crypto by supporting the currency exchange mechanism.
Exchanging Currency on UniSwap
You will exchange some of your Ether for USDC (US Dollar Coin), so that you can later lend it out on Compound or Aave in Part 3 of this course.
US Dollar Coin (USDC) is what's known as a stable coin. Each USDC has it's value backed by a real US dollar that is held in reserve. Stable coins make it easier to transact with crypto because - unlike with Bitcoin - their value is fixed relative to a real/fiat currency and does not fluctuate. USDC is one of the more popular stable coins (others include Tether or Celo USD) and it is one that is supported for lending on Compound, as well as earning a good interest rate, which is why we will choose it for now.
*Swap $10 worth of Ether for USDC
*Navigate to app.uniswap.org and connect in using your Metamask wallet.
*Select Ether and USDC and adjust the amount of Ether you'll swap until it gives you an output of about $10 of USDC. It should look a bit like this:
There are a few costs to keep in mind before you press Swap:
Transaction costs (gas) - which will depend on how busy the network is. Probably will cost you a between $3-$15. Yes, expensive! We'll discover a partial solution to that in Part 4 of the course!
Liquidity Provider Fee of 0.3% - paid to those facilitating this exchange (learn how to earn that in the next section!).
Price impact - the larger your trade, the bigger the difference between the exchange rate you get and the current exchange rate. For trades as small as we are doing here, this will be small.
*Click Swap and you'll be directed to choose your transaction speed, which affects your gas price. There'll be a link to Etherscan where you can see your transaction status.
You now have USDC that you'll be able to lend out on Compound or Aave in Part 3 of this course.
How can you be the bank with UniSwap?
Alright, so you've seen how to use UniSwap to exchange crypto. You can alternately make money by facilitating this exchange. As a concrete example, let's think about how you could facilitate (as the bank) the Ether-USDC trade that you just did - known as "being a liquidity provider".
At the time I did the transaction above, the price of USDC was 0.0008 Ether. The way Uniswap works for liquidity providers is that you contribute both Ether and USDC to a pool of funds (known as a liquidity pool) in the same ratio as the current exchange rate between the two cryptos. For example, you could contribute 0.0008 Ether and 1 USDC to a an Ether-USDC pair liquidity pool. [We won't actually do this because we'll waste too much gas for these small amounts invested, but you can do so using your Metamask wall here: https://app.uniswap.org/#/pool].
The reward the liquidity pool gets for providing that liquidity is 0.3% of each transaction submitted to that pair's liquidity pool, distributed among pool providers according to the value they provide. That's how you make money as the bank!
A few further notes on that 0.3%. This is 0.3% of each transaction submitted to the pool - not 0.3% of the pool. To figure out what your return is on lending to the pool you have to divide the daily transaction fees received by the pool by the total amount of funds in the pool - and then annualize that ratio to get an annual rate. UniSwap does that for you, and you can see the instantaneous interest rates being earned on different pair pools here: https://info.uniswap.org/pairs .
Which leaves us with one more key question - how is the exchange rate determined and updated on Uniswap? The answer is market forces... read on.
Calculating Exchange Rates on UniSwap
During a transaction on a UniSwap liquidity pool, the ratio between the two cryptos must obey the relationship x * y = constant, where x is one crypto and y is the second.
For example, in an ETH-USDC pool, the product of the number of Ether times the number of USDC must be constant during a transaction. What does that mean?
Well, lets say there are 8 units of Ether and 10,000 units of USDC in a liquidity pool. Now, I - as someone who wants to exchange Ether for USDC come along with 11 Ether. The formula the exchange must follow is:
8 * 10,000 = (8 + 1) * (10,000 - z), where z is the amount of USDC I get for my 1 Ether.
Solving for z, I get back $1,111 USDC.
There's a subtle but beautiful point here, the more of a currency I need to exchange, the worse of an exchange rate that I get from the pool. This is by design because it makes it expensive to manipulate/attack the price of the pool by doing sudden exchanges. I realise I'm not giving a precise explanation of an attack here, but hopefully you can grasp the high level point that the system is designed to make attacks expensive.
How exchange rates are maintained on UniSwap
The question you should now be asking yourself is how - if someone can swap one currency for another using a pool - the pool doesn't get imbalanced and move away from the exchange rate in the broader crypto market. For example, could someone buy up all of the Ether using USDC?
In fact, the exchange rate does move! But, market forces move it back to equilibrium. For example, if the pool moves to 1,100 USDC per Ether on Uniswap but you can find an exchange rate of 1,200 USDC per Ether on another exchange platform (e.g. Sushiswap), then an arbitrage opportunity opens up and participants will buy Ether on Uniswap and then sell it on Sushiswap. Yes, the platform names are hilarious.
The bad news - and yes there is bad news for liquidity providers - is that this process of arbitrage is a cost to the liquidity pool. According to the x*y=constant formula, the larger the value of the constant (i.e. the size of the liquidity pool), the less the effect on exchange rate of a transaction of fixed size. This loss to the pool is called impermanent loss, and is a risk of providing liquidity to pools. Generally, the larger the pool and the less volatile the cryptos being exchange in the pool, ,the lower the impermanent loss. As a concrete example, exchange pools involving stable coins like USDC will generally have less impermanent loss than exchange pools involving Bitcoin or Ether (not stable coins).
My perspective on Uniswap
I don't own any Uniswap governance token. I'm not an expert on Uniswap but my initial sense is that I like the platform and the incentives are community driven. There is the option for 0.05% out of the 0.3% liquidity provider fee to be redirected to the protocol at some point in the future, so potentially the UniSwap token might accrue value from that in the future. For now, the token seems focused on governance and I think Uniswap is providing a useful exchange service to the crypto community.
Further Technical Notes - for the Quiz Bonus Section!
Uniswap Pool Formula - Actually, it's not x * y = constant. The constant increases slightly on each transaction because there is a transaction fee of 0.3% of the transaction amount.
GOVERNANCE - Many DeFi platforms, such as UniSwap and Compound, have what's called a governance token - often named after the platform (e.g. UNI and COMP). This governance token often has a form of voting associated with it that allows the platform to propose, accept and reject changes to itself. Sometimes the token purely serves as governance. Sometimes the token also earns a share of transaction fees on the platform and/or is issued to participants in the platform to incentivise certain behaviours (e.g. providing liquidity to a certain pool). We won't delve too much into this until Part 4 of this course where I'll cover Harvest.Finance and the FARM governance token.
A note on fees - What we are doing here buying small amounts of crypto (e.g. $10) doesn't make financial sense because any return that might be earned lending out this small amount is easily be dwarfed by the cost of gas. With improvements to the Ethereum protocol, gas prices should go down over the next years. For now - it's necessary to invest larger sums of money in DeFi to get a return beyond gas fees. There is a partial solution to that - pooling resources with other market participants - and we'll get to that in Part 4 of this course.
Almost done with Part 2!
You now understand how exchanges work on DeFi...and you have some USDC ready in your wallet. Take the quiz below! If you pass, you're ready to move to Part 3 and lend out your USDC on Aave or COMPOUND!
[googleapps domain="docs" dir="forms/d/e/1FAIpQLScgY6txx1F6vmfhjmt5jS0lu9JZtV9lAjOh8DVkel2azXMOFA/viewform" query="embedded=true" width="700" height="520" /]
Once you've clicked Submit on the quiz, scroll up to see your answers!