123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 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. *)(* *)(*****************************************************************************)(** Abstraction of the staking parameters for tests *)typestaking_parameters={limit_of_staking_over_baking:Q.t;edge_of_baking_over_staking:Q.t;}letdefault_params=letProtocol.Staking_parameters_repr.{limit_of_staking_over_baking_millionth;edge_of_baking_over_staking_billionth;}=Protocol.Staking_parameters_repr.defaultin{limit_of_staking_over_baking=Q.(Int32.to_intlimit_of_staking_over_baking_millionth//1_000_000);edge_of_baking_over_staking=Q.(Int32.to_intedge_of_baking_over_staking_billionth//1_000_000_000);}letget_launch_cycle~locblk=letopenLwt_result_syntaxinlet*launch_cycle_opt=Context.get_adaptive_issuance_launch_cycle(Bblk)inAssert.get_some~loclaunch_cycle_opt(** AI operations *)letstakectxtcontractamount=Op.transactionctxt~entrypoint:Protocol.Alpha_context.Entrypoint.stake~fee:Tez_helpers.zerocontractcontractamountletset_delegate_parametersctxtdelegate~parameters:{limit_of_staking_over_baking;edge_of_baking_over_staking}=letentrypoint=Protocol.Alpha_context.Entrypoint.set_delegate_parametersinletlimit_of_staking_over_baking_millionth=Q.mullimit_of_staking_over_baking(Q.of_int1_000_000)|>Q.to_intinletedge_of_baking_over_staking_billionth=Q.muledge_of_baking_over_staking(Q.of_int1_000_000_000)|>Q.to_intinletparameters=Protocol.Alpha_context.Script.lazy_expr(Expr.from_string(Printf.sprintf"Pair %d (Pair %d Unit)"limit_of_staking_over_baking_millionthedge_of_baking_over_staking_billionth))inOp.transactionctxt~entrypoint~parameters~fee:Tez_helpers.zerodelegatedelegateTez_helpers.zeroletunstakectxtcontractamount=Op.transactionctxt~entrypoint:Protocol.Alpha_context.Entrypoint.unstake~fee:Tez_helpers.zerocontractcontractamountletfinalize_unstakectxt?(amount=Tez_helpers.zero)contract=Op.transactionctxt~entrypoint:Protocol.Alpha_context.Entrypoint.finalize_unstake~fee:Tez_helpers.zerocontractcontractamountletportion_of_rewards_to_liquid_for_cycle?policyctxtcyclepkhrewards=letopenLwt_result_syntaxinlet*{frozen;weighted_delegated}=Context.Delegate.stake_for_cycle?policyctxtcyclepkhinletportion=Tez_helpers.(ratioweighted_delegated(frozen+!weighted_delegated))inletto_liquid=Tez_helpers.mul_qrewardsportioninreturn(Tez_helpers.of_q~round:`Downto_liquid)