Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ChainValue

A Value Object to facilitate calculations for token and coin values (QNT/NQT).

For efficiency reasons, the monetary values/quantities are stored as integers with a prefined set of decimals, e.g. Signa has 8 decimals and stores the values as Planck that is 1 Signa = 100_000_000 Planck (NQT) and tokens have configurable decimals (0 to 8), so that a custom FooCoin can hav 2 decimals only where 1 FOO = 100 FOOQNT

In this context integer quantities are denominates as _atomic values and fractional values considering the decimals are denominated as compound values.

Note: This class uses a big number representation (ES5 compatible) under the hood, so number limits and numeric calculations are much more precise than JS number type

Hierarchy

  • ChainValue

Index

Constructors

constructor

  • Constructs a value object instance for calculations. The initial value is 0;

    Parameters

    • decimals: number

      The number of decimals of the amount. Must be between 0 and 8

    Returns ChainValue

Methods

add

clone

divide

equals

getAtomic

  • getAtomic(): string

getCompound

  • getCompound(): string
  • Gets the 'compound' representation

    Returns string

    value in decimal related representation, i.e. 100 QNT with 3 decimals results in '0.3'

getDecimals

  • getDecimals(): number

getRaw

  • getRaw(): BigNumber

greater

greaterOrEqual

less

lessOrEqual

multiply

  • Multiplies this value object with a numeric value (not ChainValue!)

    Parameters

    • value: number | string

      A numeric value to be multiplied with

    Returns ChainValue

    the mutated value object

setAtomic

  • Sets value as atomic value, i.e. overwrites current hold value

    Parameters

    • a: number | string

      The atomic value. Float numbers are floored to first lower integer, i.e. 1.23 -> 1

    Returns ChainValue

    the updated value object

setCompound

subtract

toFormat

Static create

  • Constructs a value object instance for calculations. The initial value is 0;

    Parameters

    • decimals: number

      The number of decimals of the amount. Must be between 0 and 8

    Returns ChainValue