Steemit Crypto Academy Season 5 [Advanced Course] Week 7 - Curve Finance- An efficient automated market maker with better leverage & minimal slippage

in SteemitCryptoAcademy3 years ago (edited)

s5w7.png

sap204.png

image.png

AMM-based Uniswap has solved the long-standing liquidity issues of traditional DEXs; AMM replaces the order book with liquidity pools and creates an opportunity for the users to stake and cater to the use case of decentralized exchange. In return, the users who contribute to the liquidity pools share exchange fees generated through the trades(0.3%).

image.png

The Bonding curve in the Automated Market Making algorithm is xy=k

The worth of both the sides, x, and y has to be equal, and the resulting product plots a hyperbola.


AMM-based Uniswap may have solved the liquidity issues of DEX, but it has its limitations as well:-

(1) Slippage is contained in a particular zone
Slippage depends on the size of the Liquidity Pool. It may not offer a competitive exchange rate for large trades because the xy=k curve is balanced only in a specific zone; beyond that zone, the output diminishes and becomes too expensive for a trader. In other words, for a trade to become feasible and cost-effective, the liquidity size has to be 100 times more than the exchange value. For example, if you want to trade 1 million USD worth of exchange in AMM-based DEX, the liquidity pool must be 100 times bigger, which means 100 million USD.

(2) Liquidity Pool stems from the use-case "Decentralized Exchange"

In AMM-based DEX, the primary use case is exchanging a pair in a decentralized way without relying on an order book. Since the use-case is "exchange," you need a liquidity pool to cater to that use-case. You invite users to contribute to that pool and then distribute the exchange fees generated from trades among the liquidity providers.

So a purely AMM-based DEX does not leverage on the liquidity pools of another category, such as staking, lending, etc. Put, it lacks the depth and extent of its pool size/network.

(3) The exchange rate and slippage in traditional AMM-DEX may not work best for stablecoin swap

For speculative coins(other than stable coins), the AMM-based market-making algorithm, xy=k, does not assume the price; the only criterion is an evenly balanced liquidity pool, i.e. x has to be evenly balanced with y.

x is a composition of supply(nos of tokens) and price. So as y.

If the same concept applies in a stable coin swap, it becomes too much expensive and not very appealing for a liquidity provider. Remember, in speculative coin segments, the liquidity providers ride on the "store of value" and contribute to the pool to generate passive money.

In the case of Stablecoin, it is non-speculative; it presumably remains pegged to the designated currency; for example, 1 USDT will remain pegged to 1 USD, so as USDC and other stable coins.

So imagine, if the liquidity providers are uninterested in a stable coin swap liquidity pool, then the AMM-based DEX also becomes inefficient(large slippage, big size trades not feasible). After all, a robust liquidity pool is an underlying base for AMM-based DEX.

To address the aforesaid problem interface of AMM-based DEX like Uniswap and to further optimize the AMM-based algorithm to cater to a cost-effective stable coin swap with low fees, low slippage, and much better liquidity(cross-network liquidity), etc., Curve Finance introduces a stable coin swap facility that acts as AMM DEX leveraging on cross-network liquidity pools and acts as a fiat saving account for the liquidity providers; as a result, the exchange fee drastically reduces, large size trades become feasible with low/minimal slippage.

sap204.png

Curve Finance: How does it work?

The AMM-based Uniswap is a constant product market maker, where xy=k

Both x and y are a composition of supply and price, with x being evenly balanced to y.

The algorithm does not know what the price of the asset is, that is determined by the trader.

If x decreases, y increases the price becomes derivative of dy/dx. If y decreases and x increases, the price becomes a derivative of dx/dy. Any larger deviation is counter-traded by arbitrageurs, and brings the price back to the equilibrium point.

xy=k was initially introduced with Uniswap as a two-dimensional liquidity pool with two tokens evenly balanced in the pool.

The further optimization with Balancer protocol has already established that xy=k can also be made n-dimensional AMM with n different tokens.

The market-making algorithm in Stabelcoin swap of Curve Finance is a constant price market maker, where x+y= k

The algorithm knows what the price of the asset is. But the Stableswap invariant is somewhere between xy=k and x+y=k, because we have not taken the supply or the liquidity into account yet. The price may be known to the algorithm, but for an exchange to happen, it still requires a pool.

xy=k is a hyperbola, x+y=k is a straight line.

The constant sum will produce a hyper surface for more than two coins in a pool.

The first optimization that Curve finance made is by making it n-dimensional, which means more than two coins for the pool.

The constant-sum (straight line) depicts an exchange price with zero slippage and infinite leverage(or infinite liquidity). The constant product(hyperbola) represents limited leverage(or limited liquidity) and approaches zero leverage. That is why in xy=k, the slippage is contained within a particular zone(a very narrow zone), if you move left or right from that zone, it results in excessive slippage, and the output diminishes.

But in a finite world, the liquidity can not be infinite. Therefore, realistically the property of Stableswap of Curve finance finds a way in between constant product and constant sum.

The first approach for the Cruve finance stableswap feature is to make it n-dimensional to access the liquidity of different pools, even to the extent of different networks. Therefore the curve is not linear. The second objective is to achieve the output with low slippage, and any slight variation must restore to the balance. For that, an amplification coefficient, A is used. When the value of A=100 is used, it becomes equivalent to 100x leverage of 2-dimensional Uniswap. Recall, the slippage can be countered with better leverage.

screenshot (53).png

Source: Curve Finance White Paper

Even if it is stablecoin swap, in a market-making algorithm, every time, there will be either a slight increase or decrease in either X(+/- dx) or Y(+/- dy). If the variation is negative, it is a loss because a stablecoin is meant to be stable at 1. But as long the variation is minimal with a specific, close range, and counter-balanced with better profitability for the liquidity providers, it can have better coverage and 100 times better than the equivalent constant product invariant of Uniswap. That is where the amplification coefficient comes to the rescue.

image-7.png

Source: Curve Finance White Paper

Much lower slippage in Stableswap than Uniswap constant product invariant, thanks to n-dimensional pool, constant price invariant, and amplification co-efficient.

curve-9.png
Source: Curve Finance White Paper

sap204.png

Mitigating the impermanent loss

Let's first understand what impermanent loss is. As we know, in constant product market-making algorithm xy=k, x has to be evenly balanced by y all the time, as that is equilibrium position. If it does not, it creates an arbitrage trading opportunity, and the arbitrageurs trade it to bring it to the equilibrium value. In that process, the Liquidity provider loses value of their asset in time.

Example,

Let's say you stake 1 ETH and 1 ETH equivalent USDT in Uniswap for ETH-USDT exchange pair.

Let's say ETH price now is 4000 USDT, so if x side is 1 ETH, the y side has to be 4000 USDT.

So you have contributed= 4000+4000= 8000 USDT

If ETH appreciates in value and trades at 5000 after 15 days.

Your asset worth= 5000+1000= 9000

But xy=k with x has to be evenly balanced with y.

Therefore such a scenario will attract arbitrageurs to trade and make it 1 ETH=5000 USDT. They will trade it until the pool becomes 0.889 ETH : 4445 USDT

Notwithstanding you get a share from the exchange fees every time a trade happens, if you hold these tokens outside the liquidity pool, then the asset's worth would be 5000+4000= 9000 USDT

But the same holding inside the liquidity pool now is 4445+4445= 8890 USDT.

So despite the rise in the value of ETH, your impermanent loss now become 9000-8890= 110 USDT

This generally happens if assets in a pool behave differently. To mitigate this risk, Curve employs a mechanism where the pooling of the tokens are made keeping in mind the asset's behaviors; precisely, the assets are pooled together only if they behave similarly in their price dynamics.

For example, stablecoins will always remain close to 1 USDT, as they are meant to be stable and pegged to 1 USD.

It's not like that Curve only features Stablecoins pool and their swap functions. NO. It does support the tokenized version of speculative coins as well. For example, renBTC, sBTC, wBTC, etc. All are tokenized versions of the coin BTC. They may be different tokenized versions, but their prices track the value of BTC. Therefore they behave similarly. Pooling together such assets minimizes the impermanent loss, negligible.

Note- The V2 Pool contains non-pegged assets and differently behaving assets; in such a pool, the liquidity providers are still exposed to the perceived impermanent loss.

sap204.png

Second layer utility in Curve Finance

Curve's integration with other major external DeFi protocols and cross-chain interoperability make Curve the single point DeFi home for the users. That also enhances the second layer utility of a coin.

For instance, you can use the lending platform in Compound, and in that process, you will be issued with cDAI token. Apart from what primary benefits you get in the Compound platform, you can further utilize your cDAI token to optimize your earning potential in Curve finance because Curve offers a cDAI liquidity pool where you can stake cDAI earn additional benefits: variable APY+ token based APR.

Furthermore, Curve integrates with a variety of major networks like Etherum, Polygon, Arbitrum, Avalanche, Fantom, Harmony, etc. That makes the Cruve DeFi segment more liquid. Against the backdrop of robust algorithm together with cross-chain compatibility make Curve equivalent to Uniswap with better leverage, with much lower fees and low slippage.

sap204.png

CRV and veCRV

CRV is the native token of Curve Finance. It is also the Governance token of Curve DAO. However, to maximize the influence and earn better rewards from CRV inflation, CRV needs to be staked to get veCRV which is vote escrowed CRV. The locking period is from one week to four years. The longer the locking period, the greater the influence and benefits.

1 CRV locked for 4 years = 1veCRV
1 CRV locked for 3 years = 0.75veCRV
1 CRV locked for 2 years = 0.50veCRV
1 CRV locked for 1 year = 0.25veCRV

The veCRV holders can propose, vote, and implement changes in the liquidity pools, reward shares, create new pools, amendment of yield farming, etc.

The veCRV voting weight gradually becomes ineffective as it approaches the expiry. To know more about the depletion of effectiveness, please visit link: https://dao.curve.fi/locker

The veCRV holder also can boost their mining speed up to a max of 2.5x in the liquidity pool they have invested/staked/contributed.

sap204.png

Perform a swap using the Stableswap feature of Curve Finance

Curve Finance is compatible with networks like Etherum, Matic(Polygon), Fantom, etc, and many others. I will not use the Etherum network owing to higher gas fees. Instead, I chose Polygon network.

I will use Metamask wallet to interact with Curve Finance. Therefore I first need to switch to Polygon Network. If you have not added Polygon Network in your Metamask wallet, please find the RPC details of Polygon Network and accordingly Add Polygon Network first.

matic1.png

  • Go to Curve Finance-- curve.fi
  • Select the Network, I have to perform the swap in Polygon Network.
  • Select the desired INPUT and OUTPUT, make sure you have sufficient balance for the INPUT. Hint- Blue color signifies sufficient balance whereas Red color, insufficient balance.
  • Click on Sell
  • Grant permission access to the protocol, click on Confirm, another pop-up will appear, Confirm again.

You are good to go now. I have successfully exchanged my USDT for USDC.

screenshot (54).png

screenshot (55).png

screenshot (56).png

screenshot (57).png

Observation:-

  • The swap from USDT to USDC costs $0.0767 (transaction cost), that too onchain using Polygon network. Indeed cost-effective.
  • The swap was executed routing through EURTUSD pool. That further testifies that Curve Finance relies on an n-dimensional liquidity pool to bring your cost-effective stableswap.
  • Both USDT and USDC are stable coins; the exchange rate(including fee) was 1 USDT= 0.9998 USDC. Indeed minimal fees & minimal slippage.

Now let's enter the input as 1 million USDT for USDC. Interestingly, the output is still with the same exchange rate; the slippage does not exceed even for a much higher input, which further validates the thesis that the INPUT and OUTPUT are contained in a much wider zone than any other DeFi facility.

curve-5.png

sap204.png

Conclusion

Not withstanding volatility and speculation which creates opportunity(equally a risk) in the crypto segment, DeFi space; stability and combosibility, together with cross chain compatibility and integration with other major DeFi protocol is another important dimension of DeFi segment, perhaps the more important one which can challenge the centralized exchanges to a larger extent, particularly with cost-effectiveness in Curve Finance and with absolute control. Curve Finance arguably spearheads this space, with much lower slippage & unlimited leverage.

curve-7.png
Source: https://defipulse.com/curve-finance

Since its inception, the ever rising TVL(14.882 Billion USD as it stands) further reaffirms the growing confidence in this DeFi niche among the lager spectrum of DeFi space. To conclude with Curve Finance, I can say-- this is just the beginning!

Thank you.

sap204.png

Homework Task (Season 5/Week-7)

(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?

(2) What is impermanent loss? Explain with examples? How does Curve Finance mitigate this loss?

(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?

(4) What is veCRV? What are the benefits of holding veCRV token?

(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.)

Guidelines

  • Your article should be at least 500 words.
  • It is always better to gain user experience before submitting your article.
  • Refrain from spam/plagiarism. This task requires screenshot(s) of your own experience. Use images from copyright-free sources and showcase the source, if any.
  • This homework task will run until 1st Jan'2021, Time- 11:59 PM UTC.
  • Users with a reputation of 65 or above and a minimum SP of 900(excluding any delegated-in SP, delegating to vote-buying services is viewed negatively) are eligible to partake in this Task. (Must not be powering it down).
  • #club5050 status (last one month) is a prerequisite to participating in this homework task. The minimum threshold for Club5050 is 150 SP power up in the last one month regardless of the payout and earning. This is applicable for both active and inactive users.
  • Add tag #sapwood-s5week7 #cryptoacademy in your post and should be among the first five tags. You can also use other relevant tags like #curve #defi #crv or any other relevant tag. And also make sure you post in the Steemit Crypto Academy community.
  • Those who include the real examples/screenshots will score better.
  • Specify the Adddress you have used for real transaction/swap so that we can verify it.
  • Your homework title should be Curve Finance- An efficient automated market maker with better leverage & minimal slippage - Steemit Crypto Academy- S5W7- Homework Post for @sapwood

Important Note:-

"If you have not had any earnings in the last one month, you will need to make a power-up of at least 150 STEEM to take part in the Academy(to validate your Club5050 status, inactive users).

This can either be from any liquid STEEM or SBDs you have, or you can buy STEEM from an exchange".

"Alternatively, you can make posts outside of the Academy and wait until you have earnings from those posts to power up."

(Please feel free to join the comment section if you have any doubt on Homework-Task)

sap204.png

Unless otherwise stated, all the images, infographics, charts, tables, etc(if any) are my original works. The screenshots are from the official website of Curve Finance.

sap204.png

Sort:  

Congratulations @sapwood

This is the most positive post amongst top 100 hot posts on steemit at this moment.
image.png

 3 years ago 

Outstanding lecture on Curve Finance Professor.

Professor kindly check, Am I eligible to participate in Beginner Course?

Eligible.

Please prof just want to find out if i can beginners courses and i want to know how many steem i need to power up o meet up.

Min 150 SP powered up during last one month. You have powered up only 24 STEEM, therefore I would suggest you power up another 126 STEEM.

Thank you.

Thank you so much prof for the quick response, i am grateful.

Hello, prof @sapwood.

I'm not quite sure I get the first question as I don't see a definite answer from the course. Any help?

 3 years ago (edited)

Different pools

Lending pool, Tri-pools, liquidity pools being integrated with lending protocols, etc and many others

Different features

Stablecoin swap, integrated pools, multichain existence of CRV, lending pools and non-lending pools, etc

What are the major DeFi protocols Curve is integrated with?

Hint- Compound. Do a bit more research, you will get to know others.

How does Curve Finance improve the second layer utility of a token of a different protocol?

Do a bit more research again. You can lend in Compound, and issued with cToken, that token can be utilized in Curve Finance to earn extra rewards (specific pool), indicate those pools.

I hope it clarifies.

Thank you.

Yeah. Now I get the question. Thanks for elaborating.

 3 years ago 

Amazing post @sapwood

Thank you.

 3 years ago 

I'm not eligible for Advance homework yet but I often enjoy reading your post. unlike other professors, You are the kind of teacher who taught first and then ask valid questions out of it. @sapwood

Thank you so much for being so kind to me. I feel deeply motivated when I learn to know that the silent readers are also getting benefited from such posts.

I wish you reach 65 reputation sooner so that you can partake in Advanced Tier.

Have a great day.

And wishing you a happy and fulfilling New year, and you deserve it.

Steem on.

 3 years ago 

Thanks @sapwood