This class is used for doing amount conversions of different types. When dealing with circuit, there are three main encodings are used for representing amounts:

  • LittleEndian - Used by Substrate as part of the SCALE encoding. The amount is LittleEndian encoded
  • Float - Floats are the human-readable format of amounts. This is very user facing.
  • Integer - In combination with decimals, used to represent amounts. These are represented as TS number or BN object

This class enables the conversion between these different types. The gateway class heavily relies on this class, passing parameters like decimals and value types out of the box.

Hierarchy

  • AmountConverter

Constructors

  • Construct an AmountConverter, ensuring that only integers or LittleEndian values are passed.

    Parameters

    • args: {
          decimals?: number;
          value?: string | number | BN;
          valueTypeSize?: number;
      }

      The arguments to convert

      • Optional decimals?: number

        The decimals of the target. Default: 12

      • Optional value?: string | number | BN

        The arguments to convert. Two types are possible with different encodings:

        • Integer: BN, string or number
        • LittleEndian: hex string
      • Optional valueTypeSize?: number

        The value type size in bytes. Default: 16 (u128)

        new AmountConverter({
        100000,
        decimals: 12,
        valueTypeSize: 16
        })
        .toFloat()

    Returns AmountConverter

Properties

decimals: number
value: BN
valueTypeSize: number

Methods

  • Convert a float parameter into BN, using the set decimals

    Parameters

    • value: number

      The value to convert

    Returns BN

Generated using TypeDoc