package tezos-protocol-011-PtHangz2
Tezos protocol 011-PtHangz2 package
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/src/tezos_raw_protocol_011_PtHangz2/liquidity_baking_migration.ml.html
Source file liquidity_baking_migration.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Tocqueville Group, 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. *) (* *) (*****************************************************************************) (** This module is used to originate contracts for liquidity baking during protocol stitching: a CPMM (constant product market making) contract and a liquidity token FA1.2 contract, with the storage of each containing the other's address. The CPMM's storage contains a token address, which corresponds to tzBTC when originated on mainnet and a reference FA1.2 contract when originated for testing. The test FA1.2 contract uses the same script as the liquidity token. Its manager is initialized to the first bootstrap account. Before originating it, we make sure we are not on mainnet by both checking for the existence of the tzBTC contract and that the level is sufficiently low. The Michelson and Ligo code, as well as Coq proofs, for the CPMM and liquidity token contracts are available here: https://gitlab.com/dexter2tz/dexter2tz/-/tree/liquidity_baking All contracts were generated from Ligo at revision 4d10d07ca05abe0f8a5fb97d15267bf5d339d9f4 and converted to OCaml using `tezos-client convert`. *) open Michelson_v1_primitives open Micheline let null_address = Bytes.of_string "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" let mainnet_tzBTC_address = "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn" (** If token_pool, xtz_pool, or lqt_total are ever zero the CPMM will be permanently broken. Therefore, we initialize it with the null address registered as a liquidity provider with 1 satoshi tzBTC and 100 mutez (roughly the current exchange rate). *) let cpmm_init_storage ~token_address ~lqt_address = Script_repr.lazy_expr (Micheline.strip_locations (Prim ( 0, D_Pair, [ Int (1, Z.one); Int (2, Z.of_int 100); Int (3, Z.of_int 100); String (4, token_address); String (5, lqt_address); ], [] ))) let lqt_init_storage cpmm_address = Script_repr.lazy_expr (Micheline.strip_locations (Prim ( 0, D_Pair, [ Seq ( 1, [ Prim ( 2, D_Elt, [Bytes (3, null_address); Int (4, Z.of_int 100)], [] ); ] ); Seq (5, []); String (6, cpmm_address); Int (7, Z.of_int 100); ], [] ))) let test_fa12_init_storage manager = Script_repr.lazy_expr (Micheline.strip_locations (Prim ( 0, D_Pair, [ Seq (1, []); Seq (2, []); String (3, manager); Int (4, Z.of_int 10_000); ], [] ))) let originate ctxt address ~balance script = Contract_storage.raw_originate ctxt address ~balance ~script ~delegate:None >>=? fun ctxt -> Fees_storage.record_paid_storage_space_subsidy ctxt address >>=? fun (ctxt, size, paid_storage_size_diff) -> let result : Migration_repr.origination_result = { balance_updates = Receipt_repr.[(Contract address, Credited balance, Protocol_migration)]; originated_contracts = [address]; storage_size = size; paid_storage_size_diff; } in return (ctxt, result) let originate_test_fa12 ~typecheck ctxt admin = Contract_storage.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, fa12_address) -> let script = Script_repr. { code = Script_repr.lazy_expr Liquidity_baking_lqt.script; storage = test_fa12_init_storage (Signature.Public_key_hash.to_b58check admin); } in typecheck ctxt script >>=? fun (script, ctxt) -> originate ctxt fa12_address ~balance:(Tez_repr.of_mutez_exn 1_000_000L) script >|=? fun (ctxt, origination_result) -> (ctxt, fa12_address, [origination_result]) (* hardcoded from lib_parameters *) let first_bootstrap_account = Signature.Public_key.hash (Signature.Public_key.of_b58check_exn "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav") let check_tzBTC ~typecheck current_level ctxt f = Contract_repr.of_b58check mainnet_tzBTC_address >>?= fun tzBTC -> Contract_storage.exists ctxt tzBTC >>=? function | true -> (* If tzBTC exists, we're on mainnet and we use it as the token address in the CPMM. *) f ctxt tzBTC [] | false -> (* If the tzBTC contract does not exist, we originate a test FA1.2 contract using the same script as the LQT. This is so that we can test the contracts after performing the same protocol migration that will be done on mainnet. First, we check current level is below mainnet level roughly around 010 injection so we do not accidentally originate the test token contract on mainnet. *) if Compare.Int32.(current_level < 1_437_862l) then originate_test_fa12 ~typecheck ctxt first_bootstrap_account (* Token contract admin *) >>=? fun (ctxt, token_address, token_result) -> f ctxt token_address token_result else (* If we accidentally entered the tzBTC address incorrectly, but current level indicates this could be mainnet, we do not originate any contracts *) return (ctxt, []) let init ctxt ~typecheck = (* We use a custom origination nonce because it is unset when stitching from 009 *) let nonce = Operation_hash.hash_string ["Drip, drip, drip."] in let ctxt = Raw_context.init_origination_nonce ctxt nonce in Storage.Liquidity_baking.Escape_ema.init ctxt 0l >>=? fun ctxt -> let current_level = Raw_level_repr.to_int32 (Level_storage.current ctxt).level in Contract_storage.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, cpmm_address) -> Contract_storage.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, lqt_address) -> Storage.Liquidity_baking.Cpmm_address.init ctxt cpmm_address >>=? fun ctxt -> check_tzBTC ~typecheck current_level ctxt (fun ctxt token_address token_result -> let cpmm_script = Script_repr. { code = Script_repr.lazy_expr Liquidity_baking_cpmm.script; storage = cpmm_init_storage ~token_address:(Contract_repr.to_b58check token_address) ~lqt_address:(Contract_repr.to_b58check lqt_address); } in typecheck ctxt cpmm_script >>=? fun (cpmm_script, ctxt) -> let lqt_script = Script_repr. { code = Script_repr.lazy_expr Liquidity_baking_lqt.script; storage = lqt_init_storage (Contract_repr.to_b58check cpmm_address); } in typecheck ctxt lqt_script >>=? fun (lqt_script, ctxt) -> originate ctxt cpmm_address ~balance:(Tez_repr.of_mutez_exn 100L) cpmm_script >>=? fun (ctxt, cpmm_result) -> originate ctxt lqt_address ~balance:Tez_repr.zero lqt_script >|=? fun (ctxt, lqt_result) -> (* Unsets the origination nonce, which is okay because this is called after other originations in stitching. *) let ctxt = Raw_context.unset_origination_nonce ctxt in (ctxt, [cpmm_result; lqt_result] @ token_result))
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>