Curve

Breakdown of Curve Finance v2

Overview

  • Curve specialises in allowing the most efficient exchanges between assets with the same value. It’s often used for trading between dollar-pegged stablecoins and token pairs like ETH/stETH.

  • The V2 of the protocol will allow users to swap between unpegged assets.

    • With a first pool dedicated to ETH, BTC, and USDT, the project could be a challenger to the likes of Uniswap and Sushiswap in DeFi's AMM space.

    • Made possible thanks to the integration of Synthetix - how? TBD

Problem with DEXes

  • Both traders and liquidity providers suffer when there is volatility, lack of liquidity, or both

  • Low liquidity can be especially harmful to traders who are exchanging assets that are pegged to the same external value—like different stablecoins that are both pegged to USD, for example—because it creates slippage.

  • Slippage, which is the difference between the expected price on an order and the actual price once the order executes, can result in losses for crypto traders.

Solution

  • Curve pools solve this by refining the AMM formula to allow for concentrated liquidity.

  • Concentrated liquidity reduces loss by adjusting the internal price of the assets in the pool.

  • Not only does this decrease the trade slippage, but it also minimizes the divergence in the internal prices of the assets in order to reduce losses for liquidity providers

  • Curve V2 introduces new features like internal price oracles and dynamic swap fees to make the AMM protocol even more efficient.

Concentrated liquidity

To maximize capital efficiency, the DEX will automatically concentrate liquidity around the current price to offer better prices and low slippage.

  • Integrated an automated version of Uniswap V3’s concentrated liquidity feature.

  • Concentrated liquidity allows users to choose which price range they’d like to provide liquidity for

  • For example, instead of providing liquidity to every possible price of Ethereum on the ETH/USDT pool, liquidity providers (LPs) can target the 2,000-3,000USDT/ETH range to maximise the effectiveness of the liquidity as long as the ETH price stays in range.

  • Uniswap boasted 4,000x greater capital efficiency at launch, but the feature was also criticized for requiring too much active management on the part of the user.

  • Through a complicated mathematical formula, Curve will automatically concentrate all liquidity from its LPs around the current price to reduce slippage and allow users to exchange large sums without majorly affecting the price of the asset.

  • Curve has consistently been the most favorable option for DeFi users to swap stablecoins, even after Uniswap’s V3 concentrated liquidity feature threatened to surpass it. If its V2 update can maintain the protocol’s high standard of capital efficiency, other AMMs like Uniswap and Sushiswap could face another challenger in the DEX space.

Curve StableSwap Exchange: LP Tokens

  • In exchange for depositing coins into a Curve pool (see Curve Pools), liquidity providers receive pool LP tokens.

  • A Curve pool LP token is an ERC20 contract specific to the Curve pool. Hence, LP tokens are transferrable. Holders of pool LP tokens may stake the token into a pool’s liquidity gauge in order to receive CRV token rewards.

  • Alternatively, if the LP token is supported by a metapool, the token may be deposited into the respective metapool in exchange for the metapool’s LP token (see here).

CRV Inflation

  • The initial inflation rate which supports the above inflation schedule is r=22.0% (279.6 millions per year).

  • All of the inflation is distributed to Curve liquidity providers, according to measurements taken by the gauges

Liquidity Gauges

  • Inflation is directed to users who provide liquidity within the protocol.

  • This usage is measured via “Liquidity Gauge” contracts. Each pool has an individual liquidity gauge.

  • The Gauge Controller maintains a list of gauges and their types, with the weights of each gauge and type.

  • To measure liquidity over time, the user deposits their LP tokens into the liquidity gauge.

  • Coin rates which the gauge is getting depends on current inflation rate, gauge weight, and gauge type weights. Each user receives a share of newly minted CRV proportional to the amount of LP tokens locked.

  • Additionally, rewards may be boosted by up to factor of 2.5 if the user vote-locks tokens for Curve governance in the Voting Escrow contract.

Curve v2 Pools

Curve v2 pools consist of three core components: the bonding curve, the price scaling mechanism, and the fee mechanism.

1. Bonding Curve

  • Like most AMMs, Curve v2 uses a bonding curve to price assets based on the pool’s supply of each asset

  • To concentrate liquidity near the center of the bonding curve, Curve v2 uses an invariant that is intermediate between the StableSwap (Curve v1) and constant-product (Uniswap, Balancer, etc.) invariants.

  • Curve focuses most of the liquidity near the price of 1. Near the price of 1 its line aligns with the constant price formula. Unlike Uniswap it does not spread liquidity across infinite prices

💡 Comparison of AMM invariants: Curve v2 (orange), StableSwap (blue), and two constant product invariants (dashed). The line labelled “constant product” corresponds to the typical “xy=k” bonding curve. The line labelled “adj. constant product” is an adjusted constant product invariant that determines the asymptotic behavior at the “tails” of the v2 bonding curve. Modified from the whitepaper.

  • Notably, in contrast to other AMMs, the “center” (equilibrium point) of the Curve v2 bonding curve is dynamically shifted in accordance with price changes.

Parameters

The shape of the bonding Curve is governed by 2 parameters:

  • A (amplification coefficient): As in the StableSwap invariant (Curve v1), the A parameter adjusts how flat the center portion of the bonding curve is. Therefore, it controls the concentration of liquidity near the expected exchange rate (i.e. the “price scale”; see below)

  • Gamma: The gamma parameter adjusts the distance between the two constant product curves shown in the above figure (dashed lines). Increasing the gamma parameter “stretches” the “adjusted constant product” curve towards the lower-left corner of the graph, shifting the curve’s asymptotes closer to the axes and making the curve more broad overall

In general, the A parameter primarily adjusts the center portion of the curve, while the gamma parameter can be used to further fine-tune the overall shape. In particular, the gamma parameter can give more control over pricing as the pool becomes more imbalanced (i.e., towards the “tails” of the curve). However, these two parameters can have partially overlapping effects, especially when taken to the extreme. Generally, gamma should be kept very low (near zero).

2. Price Scaling

  • Curve v2 pools dynamically shift liquidity to maximize depth (i.e., minimize slippage) near current market prices.

  • This is accomplished by taking a running EMA (exponential moving average) of the pool’s recent exchange rates (an “internal oracle”), and re-centering liquidity at the EMA only when it is financially reasonable for LPs to do so - when/how do they know when it is financially reasonable?

  • This process can be thought of as “re-pegging” the bonding curve so that the point of maximum liquidity concentration (i.e., the center of the curve) is matched to the EMA.

  • The price where liquidity is maximally concentrated is referred to as the “price scale”, whereas the current EMA is referred to as the “price oracle.

Parameters

Three parameters govern price scaling in Curve v2.

  1. MA half time parameter adjusts the half-time of the EMA price oracle. This controls how temporally smoothed the price oracle is, with greater values increasing smoothing.

  2. The allowed extra profit and adjustment step parameters govern when re-pegging (i.e., updating “price scale” to equal “price oracle”) is allowed to occur. In particular, re-pegging only occurs if:

  • Current profits are greater than half of feasible profits (i.e., profits ignoring losses due to re-pegging) plus the allowed extra profit parameter

  • The price scale adjustment is larger than the adjustment step parameter (in units of log Euclidean distance between current and updated prices)

  • Changing the price scale would retain at least half the pool’s profits

3. Dynamic Fee mechanism

  • Curve v2 pools charge dynamic fees depending on pool balance/imbalance.

  • Instead of a competitively low 0.04% flat fee on all crypto swaps, the fees on V2 can range from 0.04% to 0.40%.

  • Fees are minimal when the pool is in a balanced state, and increase with increasing imbalance.

  • Curve V2 trading fees depend on the difference between the internal price oracle and the actual price of the assets, although the Curve V2 whitepaper and additional documentation don't go into detail on how exactly the internal oracle impacts trading fees.

Dynamic fees are defined using three parameters:

  • Fee Mid: The fee charged when the pool is completely balanced. This is the minimum fee.

  • Fee Out: The fee charged when the pool is completely imbalanced. This is the maximum fee.

  • Fee Gamma: Adjusts how quickly fees increase with greater imbalance. Lower values produce sharp fee increases with increased imbalance; higher values produce more gradual fee increases with increased imbalance.

Smart Contracts

Registry

The registry is comprised of the following contracts:

  • AddressProvider: Address provider for registry contracts. This contract is immutable and it’s address will never change. On-chain integrators should always use this contract to fetch the current address of other registry components.

  • Registry: The main registry contract. Used to locate pools and query information about them as well as registered coins.

  • PoolInfo: Aggregate getter methods for querying large data sets about a single pool. Designed for off-chain use.

  • Swaps: The registry exchange contract. Used to find pools and query exchange rates for token swaps. Also provides a unified exchange API that can be useful for on-chain integrators.

Types of liquidity pools:

  1. Plain pools: a pool where two or more stablecoins are paired against one another.

  2. Lending pools: a pool where two or more wrapped tokens (e.g., cDAI) are paired against one another, while the underlying is lent out on some other protocol.

  3. Metapools: a pool where a stablecoin is paired against the LP token from another pool.

  4. Factory pools

Plain Pool

  • simplest Curve pool is a plain pool, which is an implementation of the StableSwap invariant for two or more tokens.

  • The key characteristic of a plain pool is that the pool contract holds all deposited assets at all times.

  • An example of a Curve plain pool is 3Pool, which contains the tokens DAI, USDC and USDT.

Lending Pool

  • Curve pools may contain lending functionality, whereby the underlying tokens are lent out on other protocols (e.g., Compound or Yearn).

  • Hence, the main difference to a plain pool is that a lending pool does not hold the underlying token itself, but a wrapped representation of it.

  • An example of a Curve lending pool is Compound Pool, which contains the wrapped tokens cDAI and cUSDC, while the underlying tokens DAI and USDC are lent out on Compound.

  • Liquidity providers of the Compound Pool therefore receive interest generated on Compound in addition to fees from token swaps in the pool.

  • Currently supports: Aave, Compound, Cream, Yearn

Meta Pool

  • A metapool is a pool where a stablecoin is paired against the LP token from another pool, a so-called base pool.

  • For example, a liquidity provider may deposit into 3Pool and in exchange receive the pool’s LP token 3CRV. The 3CRV LP token may then be deposited into the GUSD metapool, which contains the coins GUSD and 3CRV, in exchange for the metapool’s LP token gusd3CRV. The obtained LP token may then be staked in the metapool’s liquidity gauge for CRV rewards.

  • Metapools are Curve liquidity pools where one asset is traded with assets in an underlying base pool. Metapools enable the creation of liquidity pools containing one tri-pool and another ERC-20 asset.

  • This allows for a less liquid crypto token to be traded with crypto assets in a larger LP without diluting the existing pool

  • Another way to look at metapools is that they allow for a small-cap token to be traded with stablecoins in the larger 3pool without impacting the prices of assets in the 3pool.

Curve v2 vs. Uniswap v3

Both propose a universal solution for aggregating liquidity across the price range.

Difference 1: How to decide where to aggregate liquidity

  • Market making in Curve V2 does not require LPs to actively choose the liquidity aggregation range.

  • The system will automatically pool the LP’s liquidity around the trading price based on the movement of the market price.

  • Uniswap V3, on the other hand, requires LPs to judge the price trend of the market and choose the price range for market making on their own.

Difference 2: Is the LP’s position homogeneous?

  • Since each LP’s market making amount and range are different, Uniswap uses NFTs to represent LP’s market making position in V3.

  • In Curve V2, this problem is completely eliminated, as each LP has the same liquidity distribution in the pool, with only quantitative differences between them, so it is still possible to use homogeneous ERC20 tokens to represent the LP positions.

  • This greatly reduces the difficulty of combining other protocols with Curve.

Difference 3: How to rebalance funds

  • After Uniswap upgraded to V3, the passive market making management solution is no longer effective, and LPs need to actively judge the price trend and adjust their positions.

  • With Curve, users no longer need to understand the basic principles of rebalancing, nor do they need to choose among many proxy solutions in the market. They only need to consider when to deposit and when to withdraw, and the rest is automatically executed by Curve’s protocol layer.

Difference 4: How to determine transaction fees

  • Uniswap does not offer a universal solution to the issue of fees. The system natively provides only three levels of fees for LPs to choose from, and each level corresponds to a separate pool of funds, which not only limits the range of options for users, but also increases the degree of fragmentation of liquidity.

  • In contrast, Curve V2 still uses an automated solution, with a built-in fee rate range of 0.04%-0.4% (this rate is derived from community discussions, and any errors are welcome).

  • Fees are lowest when the market price is close to the midpoint of liquidity aggregation, and gradually increase when it deviates. The whole process is fully automated and does not require LP management or intervention.

Last updated