AmountMath: {
    add: (<K>(leftAmount, rightAmount, brand?) => Amount<K>);
    coerce: (<K>(brand, allegedAmount) => Amount<K>);
    getValue: (<K>(brand, amount) => AssetValueForKind<K>);
    isEmpty: ((amount, brand?) => boolean);
    isEqual: (<K>(leftAmount, rightAmount, brand?) => boolean);
    isGTE: (<K>(leftAmount, rightAmount, brand?) => boolean);
    make: (<K>(brand, allegedValue) => Amount<K>);
    makeEmpty: {
        (brand): Amount<"nat">;
        <K>(brand, assetKind): Amount<K>;
    };
    makeEmptyFromAmount: (<K>(amount) => Amount<K>);
    max: (<K>(x, y, brand?) => Amount<K>);
    min: (<K>(x, y, brand?) => Amount<K>);
    subtract: (<K>(leftAmount, rightAmount, brand?) => Amount<K>);
} = ...

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: (<K>(leftAmount, rightAmount, brand?) => Amount<K>)
      • <K>(leftAmount, rightAmount, brand?): Amount<K>
      • 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.

        Type Parameters

        • K extends AssetKind

        Parameters

        • leftAmount: Amount<K>
        • rightAmount: Amount<K>
        • Optional brand: Brand<K> = undefined

        Returns Amount<K>

  • coerce: (<K>(brand, allegedAmount) => Amount<K>)
      • <K>(brand, allegedAmount): Amount<K>
      • Make sure this amount is valid enough, and return a corresponding valid amount if so.

        Type Parameters

        • K extends AssetKind

        Parameters

        • brand: Brand<K>
        • allegedAmount: Amount<K>

        Returns Amount<K>

  • getValue: (<K>(brand, amount) => AssetValueForKind<K>)
      • <K>(brand, amount): AssetValueForKind<K>
      • Extract and return the value.

        Type Parameters

        • K extends AssetKind

        Parameters

        • brand: Brand<K>
        • amount: Amount<K>

        Returns AssetValueForKind<K>

  • isEmpty: ((amount, brand?) => boolean)
      • (amount, brand?): boolean
      • Return true if the Amount is empty. Otherwise false.

        Parameters

        • amount: Amount<AssetKind>
        • Optional brand: Brand<AssetKind> = undefined

        Returns boolean

  • isEqual: (<K>(leftAmount, rightAmount, brand?) => boolean)
      • <K>(leftAmount, rightAmount, brand?): boolean
      • Returns true if the leftAmount equals the rightAmount. We assume that if isGTE is true in both directions, isEqual is also true

        Type Parameters

        • K extends AssetKind

        Parameters

        • leftAmount: Amount<K>
        • rightAmount: Amount<K>
        • Optional brand: Brand<K> = undefined

        Returns boolean

  • isGTE: (<K>(leftAmount, rightAmount, brand?) => 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

        • K extends AssetKind

        Parameters

        • leftAmount: Amount<K>
        • rightAmount: Amount<K>
        • Optional brand: Brand<K> = undefined

        Returns boolean

  • make: (<K>(brand, allegedValue) => Amount<K>)
      • <K>(brand, allegedValue): Amount<K>
      • Make an amount from a value by adding the brand.

        Type Parameters

        • K extends AssetKind

        Parameters

        • brand: Brand<K>
        • allegedValue: AssetValueForKind<K>

        Returns Amount<K>

  • makeEmpty: {
        (brand): Amount<"nat">;
        <K>(brand, assetKind): Amount<K>;
    }
      • (brand): Amount<"nat">
      • Return the amount representing an empty amount. This is the identity element for MathHelpers.add and MatHelpers.subtract.

        Parameters

        • brand: Brand<AssetKind>

        Returns Amount<"nat">

      • <K>(brand, assetKind): Amount<K>
      • Return the amount representing an empty amount. This is the identity element for MathHelpers.add and MatHelpers.subtract.

        Type Parameters

        • K extends AssetKind

        Parameters

        • brand: Brand<AssetKind>
        • assetKind: K

        Returns Amount<K>

  • makeEmptyFromAmount: (<K>(amount) => Amount<K>)
      • <K>(amount): Amount<K>
      • Return the amount representing an empty amount, using another amount as the template for the brand and assetKind.

        Type Parameters

        • K extends AssetKind

        Parameters

        • amount: Amount<K>

        Returns Amount<K>

  • max: (<K>(x, y, brand?) => Amount<K>)
      • <K>(x, y, brand?): Amount<K>
      • Returns the max value between x and y using isGTE

        Type Parameters

        • K extends AssetKind

        Parameters

        • x: Amount<K>
        • y: Amount<K>
        • Optional brand: Brand<K> = undefined

        Returns Amount<K>

  • min: (<K>(x, y, brand?) => Amount<K>)
      • <K>(x, y, brand?): Amount<K>
      • Returns the min value between x and y using isGTE

        Type Parameters

        • K extends AssetKind

        Parameters

        • x: Amount<K>
        • y: Amount<K>
        • Optional brand: Brand<K> = undefined

        Returns Amount<K>

  • subtract: (<K>(leftAmount, rightAmount, brand?) => Amount<K>)
      • <K>(leftAmount, rightAmount, brand?): Amount<K>
      • 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.

        Type Parameters

        • K extends AssetKind

        Parameters

        • leftAmount: Amount<K>
        • rightAmount: Amount<K>
        • Optional brand: Brand<K> = undefined

        Returns Amount<K>

Generated using TypeDoc