123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contextopenEnvironmentincludeTezlet(+?)t1t2=t1+?t2|>wrap_tzresultlet(-?)t1t2=t1-?t2|>wrap_tzresultlet(*?)t1t2=t1*?t2|>wrap_tzresultlet(/?)t1t2=t1/?t2|>wrap_tzresultlet(+!)t1t2=matcht1+?t2withOkr->r|Error_->Pervasives.failwith"adding tez"let(-!)t1t2=matcht1-?t2with|Okr->r|Error_->Pervasives.failwith"subtracting tez"let(*!)t1t2=matcht1*?t2with|Okr->r|Error_->Pervasives.failwith"multiplying tez"let(/!)t1t2=matcht1/?t2with|Okr->r|Error_->Pervasives.failwith"dividing tez"letof_intx=matchTez.of_mutez(Int64.mul(Int64.of_intx)1_000_000L)with|None->invalid_arg"tez_of_int"|Somex->xletof_mutezx=matchTez.of_mutezxwithNone->invalid_arg"tez_of_mutez"|Somex->xletto_mutez=Tez.to_mutez(* Should be the same as Tez.max_mutez *)letmax_tez=matchTez.of_mutezInt64.max_intwithNone->assertfalse|Somep->pletof_za=Z.to_int64a|>Tez.of_mutez_exnletof_q~roundQ.{num;den}=(matchroundwith`Up->Z.cdivnumden|`Down->Z.divnumden)|>of_zletto_za=to_muteza|>Z.of_int64letrationumden=Q.make(Z.of_int64(to_muteznum))(Z.of_int64(to_mutezden))letmul_qtezportion=lettez_z=to_muteztez|>Z.of_int64inQ.(mulportion~$$tez_z)moduleCompare=TezmoduleEz_tez=struct(** Aliases for tez values *)typetez_quantity=|Half|All|All_but_one|Nothing|Max_tez|Amountoftlettez_quantity_ppfmtvalue=lets=matchvaluewith|Nothing->"Zero"|All->"All"|All_but_one->"All but 1µꜩ"|Half->"Half"|Max_tez->"Maximum"|Amounta->Format.asprintf"%aꜩ"ppainFormat.fprintffmt"%s"s(* [all] is the amount returned when [qty = All]. If [qty = Half], returns half of that. *)letquantity_to_tezallqty=matchqtywith|Nothing->zero|All->all|All_but_one->ifequalallzerothenzeroelseall-!one_mutez|Half->all/!2L|Max_tez->max_tez|Amount a->aend