Category: DeFi

  • DeFi with oranges: Yield Trading

    It’s January 1st and you’re a farmer that is trying to plan your business for the rest of the year. With current estimates, you think your orange trees will produce 50 bushels, worth $5000. However, there was a late freeze last year which destroyed half of your crops. You’re concerned that this could happen again so you want to find a way to hedge your risk. You draw up a contract that represents rights to all of the oranges that your trees have grown by June 30th and look for a buyer. Someone might buy your contract for several reasons. First is that you might be willing to sell the contract for less than $5000 but more than $2500. This would protect you from the kind of downside you faced the year before, while if everything goes as predicted the buyer will make the difference between $5000 and the price of the contract. A second possibility is that the buyer of the contract believes the price of oranges will increase by the time of harvest, making the 50 bushels worth $6000 instead. Similarly, they could also expect the price to remain the same but the trees to produce more than 50 bushels. In all three situations, you hedge your risk by collecting your money up front, while the buyer takes on some risk over a longer time horizon for more benefit. The buyer of the contract can freely trade it afterwards as well, and many trading opportunities can occur as people have different opinions on how many oranges will be harvested and/or what the price of oranges will be in 6 months. 

    A month later, you decide that you want to get out of orange farming all together. You’ve already promised the oranges that will be grown are owed to the holder of the first contract, so you can’t sell your trees immediately. Instead, you draw up another contract, which entitles someone to all the trees in your orchard on July 1st. To make up for the time that they won’t be able to take possession of the trees, you sell the trees for less than they would be worth at current market value. In this situation, you free up capital early to reinvest into something else, while the buyer gets a discount on the trees they want, as long as they’re willing to be a little patient. In this situation too, the buyer can trade their contract as they see fit, and the final holder will be the one that takes possession of the trees on the date of expiration.

    When generalized, you can call the orange trees the principal, and the oranges themselves the yield. Any asset that passively accrues some value can have this framework applied to it, as people use their own assumptions and modeling to determine how much income an asset will generate and how to value both that income and the asset itself.

  • DeFi with apples: Automated Market Makers

    You’re at the market and want to buy some apples. In the middle of the market, there’s a big book that people can record things in. People that want to buy apples write down how many they want and at what price they’re willing to buy, and people that want to sell apples do the same in reverse. A trade happens when a buyer and seller agree on a price and quantity.

    This is the standard central limit order book (CLOB) system that most stock brokerages use. In big markets dealing with popular assets like apples, there are usually also businesses built around constantly filling both sides of the book to keep the market liquid. These businesses require significant capital, and generally only focus on the largest markets.

    So what happens if you actually want to buy oranges, and there isn’t a company willing to be a market maker that fills both sides of an order book? The issue isn’t a lack of buyers or sellers, or that the price isn’t determinable, it’s that trading gets tricky when there aren’t many offers on either side. An orange might truly be worth $2, but if the buy side only has an order for $1 and the sell side only has an order for $3, anyone that wants to buy or sell an orange is going to have to be out a dollar.

    One way to solve this is by creating a marketplace that doesn’t need an order book, and instead lets trade happen at any time by setting pricing according to an algorithm.

    Imagine in this same market, the book in the middle gets replaced with a magic scale. The scale has a spell on it such that the two sides must always be balanced, and that the number of objects must always multiply to a fixed number set when the scale was calibrated. Taking the same example of oranges, let’s say the scale gets set up when oranges are $2. Someone puts 5 oranges on one side, and 10 dollar bills on the other. People can buy and sell oranges at any time, as long as the number of oranges times the number of dollar bills is equal to 50, the scale stays balanced. When you generalize the concept, you can use a formula like x * y = k, where x and y are the units of each asset and k is a constant value. 

    Going back to our oranges, if I want to buy 3 oranges, I take 3 from that side, leaving 2. To know how much those oranges are going to cost, we can do the math of 50 (the constant target) divided by 2 (the number of oranges left). This means that there would need to be 25 dollar bills on the other side to keep things equal. There are already 10 dollars there, so I would need to pay 15 to rebalance the scale. You might notice that the price of the oranges here isn’t 2 dollars, but rather 5. This difference is called price impact. It happens when you try to make a large trade compared to the amount of liquidity available. Since there are only 5 oranges, buying 3 is taking up more than half the supply, which naturally moves the price much higher.

    On the flip side of that, let’s say I want to sell 5 oranges instead. We start with the 5 on the scale, add 5 more to get 10, and then divide 50 by that to get 5. Since there are 10 dollars on the other side of the scale, I need to take 5 to get back to a balance. The same principle of price impact applies here, just in the other direction.

    The effect of price impact is reduced when there are more people willing to add both oranges and dollars to each side of the scale. If the scale had 5000 oranges on it, removing 3 wouldn’t require much change on the other side. The people who add both oranges and dollars to the scale are called liquidity providers, and the assets they provide are collectively called a liquidity pool. When you make a trade through this pool, you pay a small fee, just like you would on a brokerage platform. In this case, the fee is split proportionally between the liquidity providers. This fee gives liquidity providers a way to earn money for keeping the system running smoothly.

    In both of these directions, people can continue to buy and sell oranges to an infinite amount. So, while traditional markets need buyers and sellers to line up their prices, an AMM system lets anyone trade anytime.