A whirlwind tour of Ethereum finance

As a hacker and cryptocurrency liker, I have been hearing for a while about “DeFi” stuff going on in Ethereum without really knowing what it was. I own a bunch of ETH, so I finally decided that enough was enough and spent a few evenings figuring out what was going on. To my pleasant surprise, a lot of it was fascinating, and I thought I would share it with LW in the hopes that other people will be interested too and share their thoughts.

Throughout this post I will assume that the reader has a basic mental model of how Ethereum works. If you don’t, you might find this intro & reference useful.

Why should I care about this?

For one thing, it’s the coolest, most cypherpunk thing going. Remember how back in 2012, everyone knew that Bitcoin existed, but it was a pain in the ass to use and it kind of felt weird and risky? It feels exactly like that using all this stuff. It’s loads of fun.

For another thing, the economic mechanism design stuff is really fun to think about, and in many cases nobody knows the right answer yet. It’s a chance for random bystanders to hang out with problems on the edge of human understanding, because nobody cared about these problems before there was so much money floating around in them.

For a third thing, you can maybe make some money. Specifically, if you have spare time, a fair bit of cash, appetite for risk, conscientiousness, some programming and finance knowledge, and you are capable of and interested in understanding how these systems work, I think it’s safe to say that you have a huge edge, and you should be able to find places to extract value.

General overview

In broad strokes, people are trying to reinvent all of the stuff from typical regulated finance in trustless, decentralized ways (thus “DeFi”.) That includes:

  • Making anything that has value into a transferable asset, typically on Ethereum, and typically an ERC-20 token. A token is an interoperable currency that keeps track of people’s balances and lets people transfer it.

  • Making liquid exchanges where you can swap all of those tokens at market prices.

  • Making schemes for moving those tokens over time, like borrowing, futures, etc.

  • Making elaborate scams and arbitrages to obtain other people’s tokens.

It’s not completely clear to me what the main value proposition of all of this is. It’s easy to generate things about it that seem somewhat valuable, but hard to say how each stacks up. Some possible value includes:

  • Evading regulation, like securities laws, money laundering laws, sanctions, capital controls, laws against online gambling, etc. etc.

  • Allocation of capital among projects that can raise money using cryptocurrency tokens (because somehow they have a scheme to tie the success of their project to the value of the token, making it a kind of virtual equity.)

  • Having less middlemen than existing financial systems, making it more trustworthy and cheaper. (It is not currently more trustworthy or cheaper than mainstream American institutions, but it plausibly could be in a few years.)

Tokenization

The first step is to make everything into an ERC-20 token. This will let all the other products work with everything, because they will interoperate with ERC-20 tokens.

Stablecoins and pegs

It’s common for someone to want to own an Ethereum version of some other asset that is not Ethereum, so that they can use it on Ethereum. The most typical example of this is US dollars. A token whose price is designed to be pegged to an external thing like this is called a stablecoin.

There are a few techniques people use to accomplish this. The most popular one is to have a giant pile of US dollars somewhere under someone’s control, and have that person act as a counterparty for anyone who wants to buy or sell 1 US dollar for 1 token. This is what Tether and USDC do.

A more complicated version is to have a giant pile of something that is not US dollars, but is worth something, and then be willing to trade 1 US dollar worth of whatever, for 1 token. This seems like what Reserve does. In a way it’s also what MakerDAO does; I’ll discuss this later when I get around to talking about loans.

Another asset people really like to own on Ethereum is bitcoin. This is accomplished by WBTC (“wrapped bitcoin”) using a giant-pile-of-bitcoin technique, with a few useful twists; firstly, there’s a cryptographic scheme by which you can trustlessly mint the WBTC tokens on Ethereum and send the BTC to the custodian on Bitcoin atomically. (This is a general mechanism for cross-blockchain transfers.) Secondly, you can go look at the Bitcoin balance of the custodian, so you know they actually have some collateral somewhere.

There are some other schemes for doing this that are trying to get around the requirement of having a giant pile of assets, by making it so that more of the coin is minted when the value of the coin goes above the peg, and the coin is burnt somehow when the value goes below the peg. Basis kind of tried to do this. It seems like nobody quite knows yet whether or not this is possible.

Governance tokens, i.e. tokenized equity

It’s extremely common for new cryptocurrency projects to want to essentially give out equity in their project as a way to make money. In particular, a very common way to do it seems to be to mint “governance” tokens representing equity, give some of them to investors, and also give a bunch to early users, as a way of establishing a big userbase and attaining some network effects.

Frequently these tokens have a profit sharing component. Almost always, they let the owners of the tokens make some kinds of decisions relevant to the project—parameter values, future redistribution of profits, development direction, project mergers, and so on, under the assumption that they will do so in a self-interested way as the stakeholders in the project.

I’ve found that governance tokens seem surprisingly valuable on the market, even when there is no explicit profit sharing component. For example, the Uniswap governance token has a market cap of $6B. Like companies that don’t issue dividends or buy back shares, it’s slightly puzzling at first glance where so much value is coming from. Expectation of future profit sharing mechanisms? The ability to control the future direction of the project in other ways? Maybe people just like the stock. A lot of how people are making money right now on these platforms is by taking advantage of aggressive governance token rewards for using new and speculative projects.

Exchanges

Once everything is a token, you want to be able to trade the tokens. The old cryptocurrency model of having centralized, NYSE-style exchanges hasn’t gone away; you can still trade lots of tokens on Coinbase and so on. However, a totally new variety of trustless, decentralized exchanges have popped up in the past few years. I will explain Uniswap, which is just about the simplest possible one, and then talk about some variations on a theme.

Automated market making

Uniswap is a constant function market maker. More specifically, it’s a constant product market maker. This means it is an Ethereum contract that manages a giant pool of two tokens, and anyone can trade one token for the other against the pool as long as their trade preserves the product of the two token quantities in the pool.

The main reason you would do this is if you wanted one instead of the other. But even if you didn’t, you would do it anyway, if the current rate being offered (i.e. the ratio of the two token quantities in the pool, times the constant) is different than the rate you can get on another liquid market. If it’s better, you trade one way on the pool and the other on the market. If it’s worse, vice versa. As a result of this arbitrage, Uniswap’s rate will always magically be at the prevailing market rate.

Well, not quite. It will always magically be somewhere inside the prevailing market spread, plus or minus transaction fees, for the first epsilon quantity you’re trading. After that, it will slip to a worse rate. The slippage will depend on how giant the pool of tokens is compared to your trade.

There are a number of appealing properties about this compared to a centralized exchange with an order book:

  • All the machinery for making new pools is all automated and anyone can do it. My understanding is that you can invent two new ERC-20 tokens right now, mint a bunch of them, and make your very own Uniswap pool, without asking anyone’s permission.

  • The trade I described is way less computationally expensive than keeping track of an order book, so it costs way less gas. This is a huge concern right now in Ethereum land.

  • The software is quite simple. That means there probably aren’t many bugs.

  • You only need to trust the software; you don’t have to put your money into a questionable cryptocurrency exchange platform.

As a result of these properties, a lot of people are making similar kinds of automated market makers for different purposes. For example, Curve is a CFMM which uses a function that has less slippage when the two tokens have very similar value; it’s used for trading stablecoins and tokens that are pegged against each other. Balancer is a CPMM that works with a set of more than two tokens and maintains the constant product invariant for all of them, so you can trade any of them for the rest of them.

Yield farming

All of these automated market makers operate on the same model of incentivizing people with money (“liquidity providers”) to make a really giant pool of tokens for them, so that they can support lots of trade volume with minimal slippage. There are typically two incentives: one is that you get transaction fees on the trades proportional to your portion of the pool, the other is that you get governance tokens for the exchange platform.

These frequently add up to what looks like a really good APR on your money. The shallower the pool and the more the trading volume, the more of the transaction fees you are making. So a lot of people spend their time looking for AMM pools with attractive yields, buying whatever tokens that pool supports, and depositing them in the pool. Then later you can take your tokens back out plus whatever profits you made in the meantime. This is called “yield farming”.

At a glance this sounds like a relatively safe way to make money, but there are a few non-obvious risks. One is your exposure to the tokens you bought and put in the pool. If the pool is so shallow, it’s probably because one or the other of those tokens is new or has questionable value, so you might not be thrilled to own them. Another is systemic risk based on smart contract hacks, malicious governance, and so on. Another is impermanent loss; it turns out that for many AMMs, liquidity providers will not be indifferent to price movements of the tokens. So it’s a way to make money, but not necessarily a very safe way to make money.

Loans

There seems to be a lot of demand for loans of cryptocurrency. Like a lot of this technology, it’s not totally clear to me where the demand is coming from. Some possibilities:

  • Borrowing for the purposes of shorting this or that token.

  • Borrowing as a way to invest on margin.

Because it’s supposed to be trustless and decentralized, all loans are necessarily at least fully collateralized (except for flash loans, which I describe later.) I’ll explain two prominent lending systems.

MakerDAO & the DAI stablecoin

MakerDAO is one of the oldest Ethereum projects. It has a mechanism that not only results in a way to borrow with collateral, but also results in a stablecoin just sort of popping out as a consequence, which is cool.

The way it works is, you can send some stuff to a Maker “vault” contract. The stuff can be any token that has value according to a big list that Maker manages collectively. The USD value (per some governance-approved oracle) of the stuff acts as your collateral. Once you have some stuff in there, you can mint a token called DAI proportional to the amount of your collateral (everything is somewhat overcollateralized, because most of the stuff has a lot of price variance) and do whatever you like with the DAI. Later, you can pay back the DAI to get your collateral back.

What if a loan becomes insufficiently collateralized, because the market value of the collateral went down? Maker solves this problem by making it profitable for other people to liquidate you in this case; other people can bid DAI in an auction to pay off your loan and take your collateral. Naturally, this should happen basically instantaneously.

There are some other mechanisms in play; as usual, there’s a governance token MKR that shares profits from a fee you pay on your loans. There’s also a kind of emergency shutdown lever that MKR holders can pull to liquidate everyone and redistribute the collateral to everyone who owns DAI, presumably in case Maker becomes self-aware.

Why is DAI stable? Well, if DAI got much more expensive than $1, you can make more DAI, sell the DAI on the market, and then default. If DAI got much less expensive than $1, people with outstanding loans could buy DAI off the market and pay off their loans with it. If DAI really tanked, DAI holders could invoke the emergency shutdown and reclaim the collateral. And when DAI starts drifting a bit, Maker governance tries to nudge it using a familiar central bank tool—the interest rate on Maker loans. All of these things help peg DAI to the dollar and they seem to mostly work.

Compound

Whereas Maker is basically a way to “lend to yourself”, or take out leverage, Compound is an interpersonal lending system.

You start by putting a bunch of stuff into Compound, which will serve as collateral. Hopefully, other people have also put some stuff into Compound that you would like to borrow. If so, you can borrow it—like Maker, you can borrow $1 of stuff for every $1.50 of collateral. Interest will accrue at some rate, and you can repay the loan and get your collateral back any time you choose. Meanwhile, the other people who put the stuff you borrowed there get the interest you paid.

What’s the interest rate? Each token you can lend or borrow (e.g.) has an “interest rate model”, chosen by platform governance (I don’t know how they decide what it ought to be) which defines the interest rate as some function of the supply and demand for loans of that token. So if the demand for loans is high, but there isn’t much of that token sitting around, lenders will get a high rate when they put that token into the pool.

Compound has a different approach to liquidating positions that have dipped below their collateral requirements due to market movements. If a loan is not sufficiently collateralized, any random person can call a function on the contract to steal some of the collateral and pay back some of the loan, at a better than market rate; so they will. It’s a kind of “whoever notices it first” situation rather than Maker’s slow auction. To me this seems simpler and effective—I wonder why Maker didn’t do it.

Malarkey

It turns out if you create a bunch of interoperable software that lets you transfer utility around, the software sometimes has unanticipated problems. It’s very common for people to notice some way to Dutch book some combination of these services and pump money out until someone figures out how to do something about it.

Recently, someone created an amazing new invention which is like the Low Orbit Ion Cannon of arbitrage, called a flash loan. A micro loan is a very small loan; a flash loan is a very fast loan. You can borrow the money—with zero collateral required, and with a very small fee—if and only if you can repay it at the end of the same Ethereum transaction. I find this quite remarkable.

Aave (how do you pronounce this?) is the leading flash loan service. To use it, you have to deploy a contract that calls the loan contract, does whatever you wanted the money for, and calls the loan contract again to repay it. I guess there are also some other use cases for flash loans. For example, if you have a collateralized loan on Compound, and you don’t want to repay the loan, but you wish the collateral were something else, you could (as I understand it) take a flash loan of the other thing, deposit it, withdraw your old collateral, and sell the old collateral to repay your flash loan.

But the really sweet use case is incinerating slightly imperfect systems made of Ethereum contracts and taking out all the money. Check out some of these autopsies.

Burninating the peasants at bZx, a kind of margin trading platform:

The origin account of the transaction starts with nothing, then borrows and moves a pile of cash, causes two huge Uniswap orders (in both directions) in the course of the same transaction, and ends up with 65 ETH. That definitely looks fishy.

Burninating the countryside at Harvest, a decentralized hedge fund:

The attacker repeatedly exploited the effects of impermanent loss of USDC and USDT inside the Y pool on Curve.fi. They used the manipulated asset value to deposit funds into the Harvest’s vaults and obtain vault shares for a beneficial price, and later exit the vault at a regular share price generating a profit...The value lost is about $33.8 million, which corresponded to approximately 3.2% of the total value locked in the protocol at the time before the attack.

Burninating the thatched-roof houses of something called Value DeFi after they tweeted about their new “flash loan attack protection”:

The attacker returned $2 million to the protocol and pocketed $6 million — and with it left one audacious message stating, “do you really know flashloan?”

Value Defi said it suffered a “complex attack that resulted in a net loss of $6 million.”

You get the idea.

Should I really send my money to this computer program?

Good question. After a few evenings of looking at this I haven’t been able to easily quantify the risk involved in using any of these tools to actually attempt to make money. If you go look at being a liquidity provider for stablecoin pairs on Curve—which “should” be a very low risk investment when everything works—you’re getting a rate of a few dozen percent APR. But the potential, hard-to-quantify costs and risks abound:

  • Is there a bug in Curve’s contracts? Maybe. Maybe not, if nobody has found it yet? But who knows?

  • Will you screw up in the process of moving your money onto the platform, or get owned by malware that nabs your keys?

  • Will the underlying tokens, like DAI or USDC, lose their value for a hard-to-understand reason, even though they are not supposed to?

  • What will the APR be like three months from now? You’re getting rewarded in CRV governance tokens, and it’s expensive in gas to sell them instantly—are those going to hold their value? Who exactly is on the other side of this trade?

  • Speaking of gas, given current prices, if you don’t put a lot of money in, you’re probably not looking at an attractive proposition.

  • Doing US taxes on this is ridiculous. There’s software that is supposed to help build your return, but it’s hard to keep the tax implications in your head and take them into account.

So… a few dozen percent APR is a lot. And it’s not designed to be a scam. To paraphrase Eliezer, “The contract does not hate you, nor does it love you, but you have deposited ERC-20 tokens which it can use for something else.”

I advise the emptor to caveat. But I also advise you to check this stuff out, if you independently value exploring an exciting new land of nonsense.