partner_chains_cardano_offchain/reserve/init.rs
1//! Initialization of the reserve management is execution of two similar transaction to
2//! initialize two scripts: Reserve Management Validator and Reserve Management Policy
3//!
4//! Transaction for each of these scripts should have:
5//! * an output to Version Oracle Validator address that should:
6//! * * have script reference with the script being initialized attached, script should be applied with Version Oracle Policy Id
7//! * * contain 1 token of Version Oracle Policy with "Version oracle" asset name, minted in this transaction
8//! * * * mint redeemer should be Constr(1, [Int: SCRIPT_ID, Bytes: Applied Script Hash])
9//! * * have Plutus Data that is [Int: SCRIPT_ID, Bytes: Version Oracle Policy Id]
10//! * an output to the current governance (holder of governance token) that should:
11//! * * contain a new Governance Policy token, minted in this transaction,
12//! * * * mint redeemer should be empty constructor Plutus Data
13//! * a script reference input of the current Governance UTXO
14//! * signature of the current governance
15
16use crate::{
17 await_tx::AwaitTx,
18 cardano_keys::CardanoPaymentSigningKey,
19 multisig::MultiSigSmartContractResult,
20 versioning_system::{ScriptData, initialize_script},
21};
22use ogmios_client::{
23 query_ledger_state::{QueryLedgerState, QueryUtxoByUtxoId},
24 query_network::QueryNetwork,
25 transactions::Transactions,
26};
27use raw_scripts::{RESERVE_AUTH_POLICY, RESERVE_VALIDATOR, ScriptId};
28use sidechain_domain::UtxoId;
29
30/// Stores smart contracts used for reserve management in the versioning system.
31/// Scripts stored are:
32/// - Reserve Management Validator
33/// - Reserve Management Policy
34/// - Illiquid Circulation Supply Validator
35/// - Illiquid Circulation Auth Token Policy
36pub async fn init_reserve_management<
37 T: QueryLedgerState + Transactions + QueryNetwork + QueryUtxoByUtxoId,
38 A: AwaitTx,
39>(
40 genesis_utxo: UtxoId,
41 payment_key: &CardanoPaymentSigningKey,
42 client: &T,
43 await_tx: &A,
44) -> anyhow::Result<Vec<MultiSigSmartContractResult>> {
45 let reserve_validator = ScriptData::new(
46 "Reserve Management Validator",
47 RESERVE_VALIDATOR.0.to_vec(),
48 ScriptId::ReserveValidator,
49 );
50 let reserve_policy = ScriptData::new(
51 "Reserve Management Policy",
52 RESERVE_AUTH_POLICY.0.to_vec(),
53 ScriptId::ReserveAuthPolicy,
54 );
55
56 Ok(vec![
57 initialize_script(reserve_validator, genesis_utxo, payment_key, client, await_tx).await?,
58 initialize_script(reserve_policy, genesis_utxo, payment_key, client, await_tx).await?,
59 ]
60 .into_iter()
61 .flatten()
62 .collect())
63}