Curve Finance- An efficient automated market maker with better leverage & minimal slippage - Steemit Crypto Academy- S5W7- Homework Post for @sapwood
Introduction
Automatic Market Makers function on decentralized exchanges to set the prices of assets through a given formula. These AMMs give users the ability to swap assets in a decentralized exchange without the need of a third party. In a bid to eliminate the limitations of other AMM models when it comes to trading stablecoins, Curve Finance was developed with a clear and clever solution.
The lesson by professor @sapwood is very informative as it brings entirely new concepts to the students. After properly going through the lesson and making my own research, I will now present my answers to the task according to my understanding.
(1) Discuss the various features of Curve Finance? What are the different types of pools available in Curve Finance? What are the major DeFi protocols Curve is integrated with? How does Curve Finance improves the second layer utility of a token of a different protocol?
Curve Finance is a decentralized exchange on the Ethereum blockchain known for its effective AMM protocol for swapping stablecoins at low risk and with low slippage.
To access the platform, we need to visit Curve.fi and connect a wallet. I connected MetaMask below;
Various Features of Curve Finance
Home Tab
Under the Home tab, we can directly perform a swap and view different liquidity pools. We can also view ou veCRV stats and the liquidity pool stats.
Pools
Under the Pools tab, we have view the different liquidity pools and their stats.
Factory
Under Factory, we can create pools and deploy gauges to them.
DAO
Clicking on DAO we will be taken to the window in the screenshot above. We can see the statistics of the Guage Relative Weight of different Liquidity Pools. The data can be expanded and downloaded by clicking the three lines at the top right corner next to the pie chart. We can also see other Stats of the Curve DAO. The protocol requires users to have a minimum of 2500 veCRV to create a DAO proposal.
Use CRV
Under this tab, we can see various statistics of CRV staking. We are also provided a link to Stake CRV and one for guidelines towards the process.
Trade
Under Trade, there is a price chart of DAI-USDC and a depth book of the Bid and Ask prices. Further below, we can swap tokens.
Stats
Clicking on the Stats tab, we can see extensive statistics of the different liquidity pools.
Risks
This tab simply provides the Risks of using Curve Finance.
Different Types of Pools on Curve Finance
The different types of pools on Curve Finance are;
- Plain pools/Tripools
Assets Pegged to the U.S. Dollar.
- BTC Pools
Bitcoin based assets.
- ETH Pools
Ether based assets.
- Crypto Pools
Assets based on cryptos and tokens like WBTC, WETH, AAVE, etc.
- Others
Assets here are pegged to EUR and then LINK.
- Factory Pools
These are pools that can be launched by anybody which are not listed on the homepage unless certain criteria are met.
Major DeFi Protocols Curve is integrated with
The major DeFi protocols are;
- Compound
- Yearn Finance
- Synthetix
- Aave
How Curve improves the second layer utility of a token of a different protocol
Curve offers users various options across the different DeFi protocols it is integrated with right on its ecosystem. This is thanks to the DeFi Composability of the Ethereum Blockchain. This feature improves the second layer utility of a token.
For example, using the Compound protocol users can lend out DAI to receive an LP token called cDAI which earns them interest for the liquidity provided. This cDAI can also be be staked in its liquidity pools on Curve Finance for additional income.
Another example is with Aave which gives aDAI when DAI is lent out by a user. This aDAI can be staked in its liquidity pools on Curve Finance
(2) What is impermanent loss? Explain with examples? How does Curve Finance mitigate this loss?
Impermanent Loss
When providing liquidity to a pool we deposit two different assets with the same value despite the amount. That means if we were providing AAVE and BNB, they would have to of the same value. Let's say AAVE and BNB have the same value of $500 and we deposit one each. Therefore, we will have $1000 in total that was deposited. If by any chance the prices of any of these assets changes, arbitrage traders would have to come in and balance the supply. This, however, would cause an impermanent loss to the Liquidity providers.
Impermanent loss is a phenomenon that occurs in DeFi when providing liquidity. It occurs when the prices of assets change compared to when they were deposited in a liquidity pool. It is called impermanent loss because the losses are not realized until the assets are withdrawn from the liquidity pool.
An impermanent loss can be a downright decrease in the value of the assets or it could be the negative difference, in the case of a price increase, between the value of the assets compared to what they would have been worth if they were held in a wallet.
Example;
Using our example of AAVE and BNB, let's say we deposit 1 AAVE and 1 BNB both worth $500 to an AAVE-BNB liquidity pool pair on UniSwap.
AAVE(x) = BNB(y) = $500
The total would be $1000.
Using uniswap's model, xy =k
This implies that, 1 x 1 = 1. Therefore 1 is the constant.
Now, assuming the price of BNB was the same when we wanted to withdraw our coins but the price of AAVE had gone up to $600, we would no longer have 1 BNB and 1 AAVE. Instead, thanks to the balancing carried out by arbitrage traders, we would have 0.91 AAVE and 1.10 BNB to maintain the constant.
0.91 x 1.10 = 1
The total value of this would now be $1,095.45. I was able to calculate this with this software.
On the other hand, if we held the coins in a wallet we would still have 1 AAVE and 1 BNB at a new sum price of $1100. That means there was a loss for the liquidity providers.
How Curve Finance mitigates the impermanent loss
Curve Finance mitigates the impermanent loss phenomenon by pooling similar assets together. For a stablecoin pool only stable coins would be pooled together. Even for a BTC or ETH pool we would have different tokenized versions of the coins in their respective pools. These tokenized versions track the price of the asset and so behave like it.
So, for the BTC pools, we have tokenized versions like wibBTC, renBTC, oBTC, HBTC and so on. We can observe this in the image below;
Also, for ETH pools, we have tokenized versions like rETH, ankrETH and so on. We can observe this below;
(3) What is the difference between constant product invariant and constant sum invariant? How does Curve Finance accommodate these two to offer a wider zone of INPUT/OUTPUT balance? How does it lower the slippage?
Difference between constant product invariant and constant sum invariant
Constant product invariant
Constant Product invariant is a function that determines the total reserves of assets provided in a liquidity pool by taking the product of the assets. This function satisfies the formula;
where x and y are the reserves of the assets in the pool while k is the constant.
Since k is a constant, in order to maintain its value when the value of an asset changes, the supply of the assets would be changed. For example, if the liquidity pool was A-B and A starts to increase in price, the supply of A would decrease while the supply of B increase so that the constant is maintained. If we plot this function on a graph, we would have a hyperbola.
From the image, we can see that both quantities stretch out to infinity meaning there will always be liquidity using this model. This is great for a decentralized system. However, there is a confined input and output zone and wider slippage areas. This model is used by UniSwap.
Constant Sum invariant
Constant Sum invariant is a function that determines the total reserves of assets provided in a liquidity pool by taking the sum of the assets. This function satisfies the formula;
where x and y are the reserves of the assets in the pool while k is the constant.
This function is represented on a graph as a straight line as shown below.
This function is very simple but it is not very feasible in decentralized systems. As we can see from the graph above, the quantity of the assets are finite. If arbitrage traders increase the supply of A to reduce B, B would eventually get to 0 and there would be no liquidity.
How Curve Finance accomodates the two
Curve Finance has been able to create an efficient function by combining the Constant Product and Constant Sum variables. The function Curve Finance uses reduces slippage if the assets always maintain a small price range. Curve Finance has also made it possible that more than two assets can be in a pool. The formula for the function is given below;
Where;
n is the number of assets
x is the reserves for each asset
D is the value of the reserve
A is a coefficient known as the Amplification Coefficient.
This formula is represented in the graph below;
From the image above, we can see that the curve looks like what Curve Finance describes as a “zoomed in” hyperbola. The zone of Input/Output balance is much wider than that of the constant product and so the slippage areas are smaller. Also, the line is not finite which means there is always liquidity.
(4) What is veCRV? What are the benefits of holding veCRV token?
veCRV is a token that is given to users on Curve Finance who stake CRV tokens. CRV is locked within a period of 1 week and 4 years to receive veCRV. veCRV stands for vote-escrowed CRV and it is non-transferable. It is a governance token that diminishes linearly as the lock periods draws nearer.
Benefits of holding veCRV
1. Holders receive a boost of up to 2.5% on the liquidity they provide.
2. Holders receive 50% of trading fees.
3. Holders can vote on DAO proposals.
4. Holders can earn Governance fees.
5. Holders can vote on Gauge weights.
(5) Perform a stablecoin swap using Curve Finance using a suitable network of your choice? Include the transaction hash? Indicate the total fees incurred during the entire process? State your observation?Screenshot/Transaction Hash required?(Hint- You may use Polygon Network, I have provided the RPC details to add Polygon Network in your Metamask wallet, should you need this.)
I will use the Polygon network to swap USDT for DAI. First thing to do is to add the Polygon network to MetaMask.
I already have some MATIC deposited for fees.
To perform a swap, follow the steps below;
Step 1: On Curve Finance, choose the network. In this case I chose Polygon.
Step 2: Confirm the change on MetaMask.
Step 3: Select the input and output. My input is USDT while my output is DAI. Then click Sell.
Step 4: Confirm the transaction on MetaMask.
The Swap is complete. The transaction hash is 0x44dcb381ed1f14c70e7d6ee51e2d53aacac18801f37464b85d8f35ee4eda9ff6.
We can view the transaction on the Polygonscan.
Observations
- I noticed that the transaction was routed through eurtusd. Checking the swap details, we can see that a number of transactions took place before I received the DAI.
- I exchanged 1 USDT for 0.9996 DAI. This is efficient because there were minimal fees and minimal slippage.
- The transaction fee is 0.06201445 MATIC or approximately $0.16.
Conclusion
Curve Finance has clearly developed an ingenious model for its AMM. The combination of a finite and infinite concept to produce a Function with real life applications is a Thumbs-Up in my opinion. Tackling slippage makes Curve Finance a force to be reckoned with and it's clear that if more developments are made on the ecosystem, it will become very revolutionary in DeFi.