diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index e6e33340adaf6adb9a5358071ddc767c28ee9029..5ccc921fe58f00fc492e5e9283df393adea28456 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -145,6 +145,17 @@ let migrate_stake_distribution_for_o ctxt = let distr = List.map (fun (pkh, stake) -> (pkh, convert stake)) distr in Storage.Stake.Selected_distribution_for_cycle.update ctxt cycle distr) +(** Initializes the total supply at the beginning of O + Uses an estimation of the total supply at the activation of O. + This value can be refined at the beginning of P to have a + perfectly accurate ammount. + + Remove me in P. *) +let initialize_total_supply_for_o ctxt = + Storage.Contract.Total_supply.add + ctxt + (Tez_repr.of_mutez_exn 940_000_000_000_000L) + let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp ~predecessor = Raw_context.prepare_first_block ~level ~timestamp ctxt @@ -161,6 +172,7 @@ let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp ~predecessor Raw_level_repr.of_int32 level >>?= fun level -> Storage.Tenderbake.First_level_of_protocol.init ctxt level >>=? fun ctxt -> + Storage.Contract.Total_supply.add ctxt Tez_repr.zero >>= fun ctxt -> Storage.Block_round.init ctxt Round_repr.zero >>=? fun ctxt -> let init_commitment (ctxt, balance_updates) Commitment_repr.{blinded_public_key_hash; amount} = @@ -212,7 +224,8 @@ let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp ~predecessor Raw_level_repr.of_int32 level >>?= fun level -> Storage.Tenderbake.First_level_of_protocol.update ctxt level >>=? fun ctxt -> - migrate_stake_distribution_for_o ctxt >>=? fun ctxt -> return (ctxt, [])) + migrate_stake_distribution_for_o ctxt >>=? fun ctxt -> + initialize_total_supply_for_o ctxt >>= fun ctxt -> return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> List.fold_left_es patch_script ctxt Legacy_script_patches.addresses_to_patch >>=? fun ctxt -> diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 86e52b2cf4076d971e8d47305c9c8c0365f415d4..2a2850b7f2ce336d827709472e943900b780649d 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -407,6 +407,13 @@ module Contract = struct let name = ["total_frozen_bonds"] end) (Tez_repr) + + module Total_supply = + Make_single_data_storage (Registered) (Raw_context) + (struct + let name = ["total_supply"] + end) + (Tez_repr) end module type NEXT = sig diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index a82d10ee85a5042ff486251e965114c77bf70b48..b1280cff1f984ab5abe2a312d8823a8257597271 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -229,6 +229,10 @@ module Contract : sig with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t + + (** Stores the amount of tokens currently present on chain *) + module Total_supply : + Single_data_storage with type value = Tez_repr.t and type t := Raw_context.t end module Big_map : sig