Module Mavryk_raw_protocol_001_PtAtLas.Tez_repr

type repr

Internal representation of the Tez currency. Behaves mostly like a natural number where number 1 represents 1/1,000,000 Tez (1 micro-Tez or mumav). It's protected from ever becoming negative and overflowing by special arithmetic functions, which fail in case something undesired would happen. When divided, it's always rounded down to 1 mumav.

Internally encoded as int64, which may be relevant to guard against overflow errors.

type t =
  1. | Tez_tag of repr

t is made algebraic in order to distinguish it from the other type parameters of Script_typed_ir.ty.

type Mavryk_protocol_environment_001_PtAtLas.Error_monad.error +=
  1. | Addition_overflow of t * t
  2. | Subtraction_underflow of t * t
  3. | Multiplication_overflow of t * int64
  4. | Negative_multiplicator of t * int64
  5. | Invalid_divisor of t * int64
type mav = t
val zero : t
val one_mumav : t
val one_cent : t
val fifty_cents : t
val one : t
val max_mumav : t
val sub_opt : t -> t -> t option

Same as ( -? ) but returns None instead of an error.

val div2 : t -> t
val div2_sub : t -> t * t

div2_sub mav returns (⌊mav / 2⌋, mav - ⌊mav / 2⌋).

val mul_ratio : rounding:[ `Down | `Up ] -> t -> num:int64 -> den:int64 -> t Mavryk_protocol_environment_001_PtAtLas.Error_monad.tzresult

mul_ratio ~rounding mav ~num ~den returns mav * num / den without failing when mav * num overflows. rounding controls the rounding of the division.

val mul_percentage : rounding:[ `Down | `Up ] -> t -> Int_percentage.t -> t

mul_percentage mav percentage returns mav * percentage / 100. No errors can happen.

val to_mumav : t -> int64
val of_mumav : int64 -> t option

of_mumav n (micro mav) is None if n is negative

val of_mumav_exn : int64 -> t

of_mumav_exn n fails if n is negative. It should only be used at toplevel for constants.

val mul_exn : t -> int -> t

It should only be used at toplevel for constants.

val div_exn : t -> int -> t

It should only be used at toplevel for constants.

val balance_update_encoding : [ `Credited of t | `Debited of t ] Mavryk_protocol_environment_001_PtAtLas.Data_encoding.t
include Mavryk_protocol_environment_001_PtAtLas.Compare.S with type t := t
val (=) : t -> t -> bool
val (<>) : t -> t -> bool
val (<) : t -> t -> bool
val (<=) : t -> t -> bool
val (>=) : t -> t -> bool
val (>) : t -> t -> bool
val compare : t -> t -> int
val equal : t -> t -> bool
val max : t -> t -> t
val min : t -> t -> t
val of_string : string -> t option
val to_string : t -> string