math

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2025 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustAmount

func AdjustAmount(amount sdkmath.Int, factor float64) sdkmath.Int

AdjustAmount adjusts the given amount based on the provided adjustment factor.

func AdjustSlippageFloat64

func AdjustSlippageFloat64(price float64, slippage float64, isBuy bool) float64

func BpsToDecimal

func BpsToDecimal(bps int64) float64

func CalculatePriceFromCoins

func CalculatePriceFromCoins(base, baseDenom string, baseDecimals int, quote, quoteDenom string, quoteDecimals int) (*big.Float, error)

CalculatePriceFromCoins computes base/quote as a big.Float

func ComparePercentageChange

func ComparePercentageChange(oldValue, newValue float64, threshold int64) (float64, bool)

ComparePercentageChange calculates the percentage change and checks if it is significant.

func ConvertDecimalsBigInt

func ConvertDecimalsBigInt(value *big.Int, fromDecimals, toDecimals int) *big.Int

ConvertDecimalsBigInt truncates a fixed-point decimal from `fromDecimals` to `toDecimals`

func ConvertDecimalsSDK

func ConvertDecimalsSDK(value sdkmath.Int, fromDecimals, toDecimals int) sdkmath.Int

ConvertDecimalsSDK truncates sdkmath.Int from `fromDecimals` to `toDecimals`

func DivideWithDecimals added in v0.0.6

func DivideWithDecimals(f float64, b *big.Int, decimals int) *big.Int

DivideWithDecimals divides a big.Int by a float64 considering the decimals and returns the result as a fixed-point big.Int with the specified decimals.

func FloatToFixedInt added in v0.0.6

func FloatToFixedInt(price float64, decimals int64) sdkmath.Int

FloatToQuantumPrice converts a floating point price to a quantum-adjusted fixed-point integer Example: floatToQuantumPrice(1.234567899, -9) returns sdkmath.NewInt(1234567899)

func FloatToLegacyDec

func FloatToLegacyDec(value float64) sdkmath.LegacyDec

Convert float64 to sdkmath.LegacyDec

func FloatToQuantumPrice

func FloatToQuantumPrice(price float64, quantumConversionExponent int64) sdkmath.Int

FloatToQuantumPrice converts a floating point price to a quantum-adjusted fixed-point integer Example: floatToQuantumPrice(1.234567899, -9) returns sdkmath.NewInt(1234567899)

func GenerateDeviation

func GenerateDeviation(baseValue float64, rng *rand.Rand) int64

func Interpolate added in v0.0.6

func Interpolate(
	x, x1, y1, x2, y2 sdkmath.LegacyDec,
) sdkmath.LegacyDec

interpolate linearly interpolates between two points (x1,y1) and (x2,y2) to find the y-value corresponding to the provided x-value

func MultiplyWithDecimals

func MultiplyWithDecimals(f float64, b *big.Int) *big.Int

MultiplyWithDecimals multiplies a float64 and a big.Int considering the decimals and returns the result as a fixed-point big.Int with the specified decimals.

func ParseCoinString

func ParseCoinString(token string, denom string, decimals int) (*big.Float, error)

ParseCoinString converts a coin string to a big.Float value based on decimals

func RoundFixedPointInt

func RoundFixedPointInt(value sdkmath.Int, roundTo uint64) sdkmath.Int

func RoundToNearestTickSpacing

func RoundToNearestTickSpacing(value, r int64) (int64, error)

RoundToNearestTickSpacing rounds a value to the nearest multiple of r.

func SaturatingSub

func SaturatingSub(minuend, subtrahend sdkmath.Int) sdkmath.Int

SaturatingSub subtracts `subtrahend` from `minuend`, but ensures the result is never negative.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL