Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 4.14 KB

rmm-sdk.floating.md

File metadata and controls

58 lines (43 loc) · 4.14 KB

Home > @primitivefi/rmm-sdk > Floating

Floating class

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Floating point Decimal numbers are used to calculate values for RMM pools.

Signature:

export declare class Floating 

Remarks

However, sometimes the result of these math operations can return a value that has more decimal places than the token which the amount represents the value of.

Higher decimal values on lower decimal tokens will truncate the amount once it reaches on-chain. This is because truncation is used in computing when division is done with integers (e.g. in the EVM) and the answer must be an integer.

This class is aware of this and will truncate after any math operation.

Properties

Property Modifiers Type Description
_raw number (BETA)
decimals number (BETA) Decimal places to truncate this raw value at.
HALF static Floating (BETA) Floating class with raw value of 0.5.
INFINITY static BigNumber (BETA) 2^256 as a BigNumber.
isInfinity boolean (BETA) True if this scaled value is gte 2^256.
isZero boolean (BETA) True if this scaled value is zero.
normalized number (BETA) Raw value truncated to this decimal places.
ONE static Floating (BETA) Floating class with raw value of 1.0.
raw number (BETA) Value which this entity was instantiated with.
scaled number (BETA) Raw value scaled by scale factor and floored.
scaleFactor number (BETA) Scalar value to multiply numbers before math operations.
ZERO static Floating (BETA) Floating class with raw value of 0.0.

Methods

Method Modifiers Description
add(adder) (BETA) Scales up, adds scaled values, downscales back.
div(divider) (BETA) Divides this scaled by scaled divider.
divCeil(divider) (BETA)
downscaleInteger(value) (BETA) Divides value by this scale factor and truncates it to this decimals.
from(value, decimals) static (BETA) Instantiates a Floating value from a value with default decimals of 18.
mul(multiplier) (BETA) Multiplies scaled multiplier and this value, downscales back.
mulDiv(multiplier, divider) (BETA) Multiplies scaled multiplier and this value, divides by scaled divider, downscales back.
sub(subtractor) (BETA) Scales up, subtracts scaled values, downscales back.
toFixed(decimals) (BETA) Normalized value fixed to decimals. This will be rounded up.
toString() (BETA) Raw value as a string.
upscaleInteger(value) (BETA) Multiplies value by this scale factor and floors it.