Trait cw20_bonding::curves::Curve [−][src]
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
Implementors
impl Curve for Constant
[src]
fn spot_price(&self, _supply: Uint128) -> StdDecimal
[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.