Documentation ¶
Index ¶
- func Divide(adjustByPrice uint64, adjustByExponent types.Exponent, price uint64, ...) (adjustedPrice uint64)
- func Invert(price uint64, exponent types.Exponent) uint64
- func Multiply(price uint64, exponent int32, adjustByPrice uint64, adjustByExponent int32) (adjustedPrice uint64)
- func PriceToFloat32ForLogging(price uint64, exponent types.Exponent) float32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Divide ¶
func Divide( adjustByPrice uint64, adjustByExponent types.Exponent, price uint64, exponent types.Exponent, ) (adjustedPrice uint64)
Divide divides two prices, returning the resulting price as a uint64 multiplied by the divisor price's exponent.
Formula: rawPrice = price * 10 ^ exponent
rawAdjustByPrice = adjustByPrice * 10 ^ adjustByExponent rawAdjustedPrice = rawAdjustByPrice / rawPrice adjustedPrice = rawAdjustedPrice * 10 ^ -exponent
This price conversion method is typically used in practice to derive stablecoin prices by dividing crypto asset prices in two different stablecoin quote currencies: for example, USDT-USD = BTC-USD / BTC-USDT.
func Invert ¶
Invert inverts a price, returning the inverted price multiplied by 10^-exponent. This method is meant to be used for inverting stablecoin ticker prices. For the sake of precision, price inversion is only intended to be used for pricing markets that are close to 1:1 price-wise, e.g. USD-USDT. Inverting a price that is <<>> 1 could result in a loss of precision.
func Multiply ¶
func Multiply(price uint64, exponent int32, adjustByPrice uint64, adjustByExponent int32) (adjustedPrice uint64)
Multiply multiplies two prices, returning the resulting price as a uint64 multiplied by the first exponent.
Formula: rawPrice = price * 10 ^ exponent
rawAdjustByPrice = adjustByPrice * 10 ^ adjustByExponent rawAdjustedPrice = rawPrice * rawAdjustByPrice adjustedPrice = rawAdjustedPrice * 10 ^ -exponent
The most common use case of multiply will be to convert a market price from one stablecoin to another. For example, 1INCH-USD = 1INCH_USDT * USDT-USD.
func PriceToFloat32ForLogging ¶
PriceToFloat32ForLogging converts a price, exponent to a float32 for logging purposes. This is not meant to be used for price calucations within the protocol, as it could result in an arbitrary loss of precision.
Types ¶
This section is empty.