AmountMath: {
    add: (<A>(leftAmount: A, rightAmount: A, brand??: Brand) => A);
    coerce: (<A>(brand: Brand, allegedAmount: A) => A);
    getValue: (<A>(brand: Brand, amount: A) => A["value"]);
    isEmpty: ((amount: Amount, brand??: Brand) => boolean);
    isEqual: (<A>(leftAmount: A, rightAmount: A, brand??: Brand) => boolean);
    isGTE: (<K>(leftAmount: Amount<K>, rightAmount: Amount<K>, brand??: Brand<K>) => boolean);
    make: (<B, V>(brand: B, allegedValue: V) => B extends Brand<"nat">
        ? NatAmount
        : V extends bigint
            ? NatAmount
            : V extends CopySet
                ? CopySetAmount<V<V>["payload"][0]>
                : V extends CopyBag
                    ? CopyBagAmount<V<(...)>["payload"][0][0]>
                    : V extends SetValue
                        ? SetAmount<V<V>[0]>
                        : never);
    makeEmpty: {
        (brand: Brand): NatAmount;
        <K>(brand: Brand<K>, assetKind: K): Amount<K>;
    };
    makeEmptyFromAmount: (<A>(amount: A) => A);
    max: (<A>(x: A, y: A, brand??: Brand) => A);
    min: (<A>(x: A, y: A, brand??: Brand) => A);
    subtract: (<L, R>(leftAmount: L, rightAmount: R, brand??: Brand) => L extends R
        ? L<L>
        : never);
} = ...

Logic for manipulating amounts.

Amounts are the canonical description of tradable goods. They are manipulated by issuers and mints, and represent the goods and currency carried by purses and payments. They can be used to represent things like currency, stock, and the abstract right to participate in a particular exchange.

Type declaration

  • add: (<A>(leftAmount: A, rightAmount: A, brand??: Brand) => A)

    Returns a new amount that is the union of both leftAmount and rightAmount.

    For fungible amount this means adding the values. For other kinds of amount, it usually means including all of the elements from both left and right.

      • <A>(leftAmount, rightAmount, brand?): A
      • Type Parameters

        Parameters

        • leftAmount: A
        • rightAmount: A
        • Optionalbrand: Brand = undefined

        Returns A

  • coerce: (<A>(brand: Brand, allegedAmount: A) => A)

    Make sure this amount is valid enough, and return a corresponding valid amount if so.

      • <A>(brand, allegedAmount): A
      • Type Parameters

        Parameters

        Returns A

  • getValue: (<A>(brand: Brand, amount: A) => A["value"])

    Extract and return the value.

      • <A>(brand, amount): A["value"]
      • Type Parameters

        Parameters

        Returns A["value"]

  • isEmpty: ((amount: Amount, brand??: Brand) => boolean)

    Return true if the Amount is empty. Otherwise false.

      • (amount, brand?): boolean
      • Parameters

        Returns boolean

  • isEqual: (<A>(leftAmount: A, rightAmount: A, brand??: Brand) => boolean)

    Returns true if the leftAmount equals the rightAmount. We assume that if isGTE is true in both directions, isEqual is also true

      • <A>(leftAmount, rightAmount, brand?): boolean
      • Type Parameters

        Parameters

        • leftAmount: A
        • rightAmount: A
        • Optionalbrand: Brand = undefined

        Returns boolean

  • isGTE: (<K>(leftAmount: Amount<K>, rightAmount: Amount<K>, brand??: Brand<K>) => boolean)
      • <K>(leftAmount, rightAmount, brand?): boolean
      • Returns true if the leftAmount is greater than or equal to the rightAmount. The notion of "greater than or equal to" depends on the kind of amount, as defined by the MathHelpers. For example, whether rectangle A is greater than rectangle B depends on whether rectangle A includes rectangle B as defined by the logic in MathHelpers.

        Type Parameters

        Parameters

        Returns boolean

  • make: (<B, V>(brand: B, allegedValue: V) => B extends Brand<"nat">
        ? NatAmount
        : V extends bigint
            ? NatAmount
            : V extends CopySet
                ? CopySetAmount<V<V>["payload"][0]>
                : V extends CopyBag
                    ? CopyBagAmount<V<(...)>["payload"][0][0]>
                    : V extends SetValue
                        ? SetAmount<V<V>[0]>
                        : never)

    Make an amount from a value by adding the brand.

    Does not verify that the Brand's AssetKind matches the value's.

      • <B, V>(brand, allegedValue): B extends Brand<"nat">
            ? NatAmount
            : V extends bigint
                ? NatAmount
                : V extends CopySet
                    ? CopySetAmount<V<V>["payload"][0]>
                    : V extends CopyBag
                        ? CopyBagAmount<V<(...)>["payload"][0][0]>
                        : V extends SetValue
                            ? SetAmount<V<V>[0]>
                            : never
      • Type Parameters

        • B extends Brand
        • V extends
              | bigint
              | CopySet
              | SetValue
              | CopyBag

        Parameters

        • brand: B
        • allegedValue: V

        Returns B extends Brand<"nat">
            ? NatAmount
            : V extends bigint
                ? NatAmount
                : V extends CopySet
                    ? CopySetAmount<V<V>["payload"][0]>
                    : V extends CopyBag
                        ? CopyBagAmount<V<(...)>["payload"][0][0]>
                        : V extends SetValue
                            ? SetAmount<V<V>[0]>
                            : never

  • makeEmpty: {
        (brand: Brand): NatAmount;
        <K>(brand: Brand<K>, assetKind: K): Amount<K>;
    }

    Return the amount representing an empty amount. This is the identity element for MathHelpers.add and MatHelpers.subtract.

  • makeEmptyFromAmount: (<A>(amount: A) => A)

    Return the amount representing an empty amount, using another amount as the template for the brand and assetKind.

      • <A>(amount): A
      • Type Parameters

        Parameters

        • amount: A

        Returns A

  • max: (<A>(x: A, y: A, brand??: Brand) => A)

    Returns the max value between x and y using isGTE

      • <A>(x, y, brand?): A
      • Type Parameters

        Parameters

        • x: A
        • y: A
        • Optionalbrand: Brand = undefined

        Returns A

  • min: (<A>(x: A, y: A, brand??: Brand) => A)

    Returns the min value between x and y using isGTE

      • <A>(x, y, brand?): A
      • Type Parameters

        Parameters

        • x: A
        • y: A
        • Optionalbrand: Brand = undefined

        Returns A

  • subtract: (<L, R>(leftAmount: L, rightAmount: R, brand??: Brand) => L extends R
        ? L<L>
        : never)

    Returns a new amount that is the leftAmount minus the rightAmount (i.e. everything in the leftAmount that is not in the rightAmount). If leftAmount doesn't include rightAmount (subtraction results in a negative), throw an error. Because the left amount must include the right amount, this is NOT equivalent to set subtraction.

      • <L, R>(leftAmount, rightAmount, brand?): L extends R
            ? L<L>
            : never
      • Type Parameters

        Parameters

        • leftAmount: L
        • rightAmount: R
        • Optionalbrand: Brand = undefined

        Returns L extends R
            ? L<L>
            : never