Trait cw20_bonding::curves::Curve[][src]

pub trait Curve {
    fn spot_price(&self, supply: Uint128) -> StdDecimal;
fn reserve(&self, supply: Uint128) -> Uint128;
fn supply(&self, reserve: Uint128) -> Uint128; }

This defines the curves we are using.

I am struggling on what type to use for the math. Tokens are often stored as Uint128, but they may have 6 or 9 digits. When using constant or linear functions, this doesn’t matter much, but for non-linear functions a lot more. Also, supply and reserve most likely have different decimals… either we leave it for the callers to normalize and accept a Decimal input, or we pass in Uint128 as well as the decimal places for supply and reserve.

After working the first route and realizing that Decimal is not all that great to work with when you want to do more complex math than add and multiply Uint128, I decided to go the second route. That made the signatures quite complex and my final idea was to pass in supply_decimal and reserve_decimal in the curve constructors.

Required methods

fn spot_price(&self, supply: Uint128) -> StdDecimal[src]

Returns the spot price given the supply. f(x) from the README

fn reserve(&self, supply: Uint128) -> Uint128[src]

Returns the total price paid up to purchase supply tokens (integral) F(x) from the README

fn supply(&self, reserve: Uint128) -> Uint128[src]

Inverse of reserve. Returns how many tokens would be issued with a total paid amount of reserve. F^-1(x) from the README

Loading content...

Implementors

impl Curve for Constant[src]

fn reserve(&self, supply: Uint128) -> Uint128[src]

Returns total number of reserve tokens needed to purchase a given number of supply tokens. Note that both need to be normalized.

impl Curve for Linear[src]

impl Curve for SquareRoot[src]

Loading content...