Carbon DeFi Dev
  • Carbon DeFi
    • Introducing Carbon DeFi
      • What Makes Carbon DeFi Unique?
      • Fees & Payments
      • Resources
    • Security & Audits
  • Contracts & Functions
    • Contracts
      • CarbonController
      • CarbonVortex
      • CarbonVortexBridge
      • Deployments
        • Mainnet Contracts
        • Testnet Contracts
    • CarbonController Functions
      • Write Functions
        • Transaction Prerequisites
          • approve() / allowance()
        • Trade
          • tradeBySourceAmount()
          • tradeByTargetAmount()
        • Strategy Management
          • createStrategy()
          • updateStrategy
          • deleteStrategy()
      • Read Functions
        • controllerType()
        • tradingFeePPM()
        • pairTradingFeePPM()
        • pair()
        • pairs()
        • strategy()
        • strategiesByPair()
        • strategiesByPairCount()
        • calculateTradeSourceAmount()
        • calculateTradeTargetAmount()
      • Data & Events
        • TradingFeePPMUpdated()
        • PairCreated()
        • StrategyCreated()
        • StrategyDeleted()
        • StrategyUpdated()
        • TokensTraded()
        • FeesWithdrawn()
    • CarbonVortex Functions
      • Write Functions
        • trade()
        • execute()
      • Read Functions
        • amountAvailableForTrading()
        • availableTokens()
        • expectedTradeInput()
        • expectedTradeReturn()
        • finalTargetToken()
        • minTargetTokenSaleAmount()
        • minTokenSaleAmount()
        • pairDisabled()
        • priceDecayHalfLife()
        • rewardsPPM()
        • targetToken()
        • targetTokenPriceDecayHalfLife()
        • targetTokenSaleAmount()
        • tokenPrice()
        • totalCollected()
        • tradingEnabled()
    • CarbonVortexBridge Functions
      • Write Functions
        • Bridge()
  • Rest API
    • Carbon DeFi Public REST API
  • Developer Guides
    • Carbon DeFi SDK
      • Getting started
      • Interacting with the SDK
        • Managing Strategies
        • Performing Trades
        • Getting User and Pair Data
        • Collecting Liquidity Data
      • SDK Functions
        • constructor
        • startDataSync
        • getCachedPairs
        • hasLiquidityByPair
        • getLiquidityByPair
        • getUserStrategies
        • getTradeData
        • composeTradeByTargetTransaction
        • composeTradeBySourceTransaction
        • createBuySellStrategy
        • updateStrategy
        • deleteStrategy
        • getMinRateByPair
        • getMaxRateByPair
        • getRateLiquidityDepthByPair
    • The Carbon DeFi versus Uniswap V3 Invariant Functions
    • Carbon DeFi Subgraph
      • Accessing the Subgraph
      • Creating Subgraph Queries
      • Subgraph Query in Python
      • Sample Subgraph Queries
    • Using CarbonVortex
      • CarbonVortex Dynamics
Powered by GitBook
On this page
  • Naming Conventions and Nomenclature
  • The Carbon DeFi versus Uniswap V3 Invariant Functions
  1. Developer Guides

The Carbon DeFi versus Uniswap V3 Invariant Functions

PreviousgetRateLiquidityDepthByPairNextCarbon DeFi Subgraph

Last updated 6 days ago

Carbon DeFi makes use of the same geometric price sequences that have governed AMM behavior since its first realization in 2017. While Carbon DeFi is not an AMM, the majority of the underlying theory is indistinguishable from that of conventional β€œconcentrated liquidity” AMM designs. However, rather than let the price curves be determined by one and the same invariant curve (which, traditionally described two different token balances), instead, each token balance is given its own implicit curve (i.e. one β€œbonding curve” per token). This allows for arbitrary separation of bidding and asking prices characterized by irreversible token swaps, from which emerges a trading β€œstrategy” – the core object of Carbon DeFi.

Naming Conventions and Nomenclature

The implicit curves of the invariant function used by Carbon Defi adhere to the following conventions:

  • Assume the implicit curves are drawn on a Cartesian plane.

  • The available token balance is always depicted on the y axis, whereas the x axis does not refer to a token balance.

  • Therefore, during a token swap, the tokens sent from the swapper to the contract is always Ξ”x, and the tokens sent from the contract to the swapper is always Ξ”y.

  • The marginal price quote, -βˆ‚y/βˆ‚x, refers to the rate of y tokens purchased during a swap relative to the x tokens sold by the swapper; therefore large -βˆ‚y/βˆ‚x values represent a higher valuation of the x token relative to the y token and small -βˆ‚y/βˆ‚x values represent a lower valuation of the x token relative to the y token.

  • Carbon DeFi’s β€œliquidity providers” choose two separate price quotes or price quote ranges: one supports trades of TKN1 β†’ TKN2, and the other supports trades TKN2 β†’ TKN1. Since both tokens are featured independently on their own y axis, and owing to the swap conventions described above, both price quotes are expressed in the form - βˆ‚y/βˆ‚x.

  • Each token’s implicit real curve is parametrized by three (3) terms:

    1. 𝒂

      β–ͺ Defined as the difference between the square roots of the marginal exchange rates at the 𝑦-intercept, and the π‘₯-intercept.

      β–ͺ π‘Ž=𝑃highβˆ’π‘ƒlow=(βˆ’πœ•π‘¦πœ•π‘₯∣π‘₯=0)12βˆ’(βˆ’πœ•π‘¦πœ•π‘₯βˆ£π‘¦=0)12\normalsize π‘Ž = \sqrt{𝑃_{high}} βˆ’ \sqrt{𝑃_{low}} = \left( -\frac{πœ•π‘¦}{πœ•π‘₯}|_{π‘₯=0}\right)^\frac{1}{2} βˆ’ \left(βˆ’ \frac{πœ•π‘¦}{πœ•π‘₯}|_{𝑦=0}\right)^\frac{1}{2}a=Phighβ€‹β€‹βˆ’Plow​​=(βˆ’πœ•xπœ•yβ€‹βˆ£x=0​)21β€‹βˆ’(βˆ’πœ•xπœ•yβ€‹βˆ£y=0​)21​

    2. 𝒃

      β–ͺ Defined as the square root of the marginal exchange rate at the π‘₯- intercept, only.

      β–ͺ b=𝑃low=(βˆ’πœ•π‘¦πœ•π‘₯∣y=0)12\normalsize b = \sqrt{𝑃_{low}} = \left( -\frac{πœ•π‘¦}{πœ•π‘₯}|_{y=0}\right)^\frac{1}{2} b=Plow​​=(βˆ’πœ•xπœ•yβ€‹βˆ£y=0​)21​

    3. 𝒛

      β–ͺ Defined as the value of the 𝑦-intercept.

      β–ͺ 𝑧=y∣x=0\normalsize 𝑧 = y|_{x=0}z=y∣x=0​

The Carbon DeFi versus Uniswap V3 Invariant Functions

The Carbon DeFi invariant function can be written as:

Which has the same structure as the familiar Uniswap V3 invariant function, as written in its whitepaper:

Both Carbon DeFi’s and Uniswap V3’s invariant functions refer to the same underlying mathematical and geometric objects, and the terms highlighted above are equivalent to each other.

(x+zaβ‹…(a+b))β‹…(y+zβ‹…ba)=z2a2\Large \left(x + \textcolor{#ffa2a1}{ \frac{z}{a \cdot (a+b)}}\right) \cdot \left( y + \textcolor{#dc70fa}{ \frac{z \cdot b}{a}}\right) = \textcolor{#90f597}{\frac{z^2}{a^2}}​x+aβ‹…(a+b)z​​⋅(y+azβ‹…b​)=a2z2​
(x+LPhigh)β‹…(y+Lβ‹…Plow)=L2\Large \left( x + \textcolor{#ffa2a1}{\frac{L}{\sqrt{P_{high}}}}\right) \cdot \left( y + \textcolor{#dc70fa}{L \cdot \sqrt{P_{low}}}\right) = \textcolor{#90f597}{L^2}​x+Phigh​​L​​⋅(y+Lβ‹…Plow​​)=L2
zaβ‹…(a+b)=LPhigh\Large \textcolor{#ffa2a1}{\frac{z}{a \cdot (a+b)}} = \textcolor{#ffa2a1}{\frac{L}{\sqrt{P_{high}}}}aβ‹…(a+b)z​=Phigh​​L​
zβ‹…ba=Lβ‹…Plow\Large \textcolor{#dc70fa}{\frac{z \cdot b}{a}} = \textcolor{#dc70fa}{L \cdot \sqrt{P_{low}}}azβ‹…b​=Lβ‹…Plow​​
z2a2=L2\Large \textcolor{#90f597}{\frac{z^2}{a^2}} = \textcolor{#90f597}{L^2}a2z2​=L2

For further assistance, please join the group

Bancor Developer telegram