Bonding Curve Formula

A simple constant product x * y = virtual_base_reserve * virtual_curve_reserve can be presented as x * y = liquidity * liquidity, while liquidity = sqrt(virtual_base_reserve * virtual_curve_reserve).

With a constraint on migration_quote_threshold, it can be presented as a function of liquidity, min_price, max_price.

We denote liquidity = l, min_price = pa, max_price = pb.

So we have:

bonding_curve_constant_product = function(l, pa, pb)

On our dynamic bonding curve protocol:

bonding_curve = function([l_i, pa_i, pb_i])

That means partner can configure a bonding curve with any liquidity distribution up on their strategy.

For example, if the pool has this configuration:

  • sqrt_start_price = 1

  • curve = [sqrt_price = 2, liquidity = 100), (sqrt_price = 4, liquidity = 500)]

Then the bonding curve will function of 2 price ranges: (l = 100, pa = 1, pb = 2) and (l = 500, pa = 2, pb = 4).

Example math to build a simple curve (constant-product) from your parameters

  • initial base reserve: x tokens (a decimals)

  • initial quote reserve: y tokens (b decimals) (SOL)

  • migration threshold: z tokens (SOL)

  1. Calculate price = y * (10^(b-a)) / x (pls keep floating point)

  2. Calculate sqrtStartPrice = floor(sqrt(price) * 2^64) (cut all floating point)

  3. Set maxSqrtPrice = 79226673521066979257578248091

  4. Calculate liquidity:

liquidity = z * 10^b * 2^128 / (maxSqrtPrice - sqrtStartPrice)

  1. Set curve:

curve = [{sqrtPrice: maxSqrtPrice, liquidity=liquidity}]

Dynamic Bonding Curve Integration

Please visit this section of the docs.

Last updated