123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 Tocqueville Group, Inc. <contact@tezos.com> *)(* Copyright (c) 2022-2023 Nomadic Labs <contact@nomadic-labs.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. *)(* *)(*****************************************************************************)(** Options available for per-block votes *)typeper_block_vote=|Per_block_vote_on|Per_block_vote_off|Per_block_vote_passtypeper_block_votes={liquidity_baking_vote:per_block_vote;adaptive_issuance_vote:per_block_vote;}letper_block_vote_compact_encoding=letopenData_encodinginletopenCompactinunion~union_tag_bits:2~cases_tag_bits:0[case~title:"per_block_vote_on"(payload(constant"on"))(functionPer_block_vote_on->Some()|_->None)(fun()->Per_block_vote_on);case~title:"per_block_vote_off"(payload(constant"off"))(functionPer_block_vote_off->Some()|_->None)(fun()->Per_block_vote_off);case~title:"per_block_vote_pass"(payload(constant"pass"))(functionPer_block_vote_pass->Some()|_->None)(fun()->Per_block_vote_pass);]letliquidity_baking_vote_encoding=letopenData_encodingindef"liquidity_baking_vote"(Compact.make~tag_size:`Uint8per_block_vote_compact_encoding)letadaptive_issuance_vote_encoding=letopenData_encodingindef"adaptive_issuance_vote"(Compact.make~tag_size:`Uint8per_block_vote_compact_encoding)letper_block_votes_compact_encoding=letopenData_encodinginletopenCompactinconv(fun{liquidity_baking_vote;adaptive_issuance_vote}->(liquidity_baking_vote,adaptive_issuance_vote))(fun(liquidity_baking_vote,adaptive_issuance_vote)->{liquidity_baking_vote;adaptive_issuance_vote})(obj2(req"liquidity_baking_vote"per_block_vote_compact_encoding)(req"adaptive_issuance_vote"per_block_vote_compact_encoding))letper_block_votes_encoding=letopenData_encodingindef"per_block_votes"(Compact.make~tag_size:`Uint8per_block_votes_compact_encoding)moduleLiquidity_baking_toggle_EMA=Votes_EMA_repr.Make(structletbaker_contribution=Z.of_int500_000letema_max=2_000_000_000lend)moduleAdaptive_issuance_launch_EMA=Votes_EMA_repr.Make(struct(* The baker_contribution parameter of the adaptive issuance
activation vote was chosen so that 2 weeks are needed to move
the EMA from 0% to 50% when all bakers vote On.
This was computed using the following formula:
baker_contrib = (1/2) * ema_max * (1 - 2^(-1/k))
where k is the number of blocks in 2 weeks (which is 80640).
Because of a small accumulation of rounding errors, two more
blocks are actually needed. *)letbaker_contribution=Z.of_int8595letema_max=2_000_000_000lend)letcompute_new_liquidity_baking_ema~per_block_voteema=matchper_block_votewith|Per_block_vote_pass->ema|Per_block_vote_off->Liquidity_baking_toggle_EMA.update_ema_upema|Per_block_vote_on->Liquidity_baking_toggle_EMA.update_ema_downemaletcompute_new_adaptive_issuance_ema~per_block_voteema=matchper_block_votewith|Per_block_vote_pass->ema|Per_block_vote_off->Adaptive_issuance_launch_EMA.update_ema_downema|Per_block_vote_on->Adaptive_issuance_launch_EMA.update_ema_upema