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	csl::TransactionContext,
20	multisig::MultiSigSmartContractResult,
21	plutus_script, scripts_data,
22	versioning_system::{ScriptData, initialize_script},
23};
24use ogmios_client::{
25	query_ledger_state::{QueryLedgerState, QueryUtxoByUtxoId},
26	query_network::QueryNetwork,
27	transactions::Transactions,
28};
29use raw_scripts::{RESERVE_AUTH_POLICY, RESERVE_VALIDATOR, ScriptId};
30use sidechain_domain::UtxoId;
31
32/// Stores smart contracts used for reserve management in the versioning system.
33/// Scripts stored are:
34///  - Reserve Management Validator
35///  - Reserve Management Policy
36///  - Illiquid Circulation Supply Validator
37///  - Illiquid Circulation Auth Token Policy
38pub async fn init_reserve_management<
39	T: QueryLedgerState + Transactions + QueryNetwork + QueryUtxoByUtxoId,
40	A: AwaitTx,
41>(
42	genesis_utxo: UtxoId,
43	payment_key: &CardanoPaymentSigningKey,
44	client: &T,
45	await_tx: &A,
46) -> anyhow::Result<Vec<MultiSigSmartContractResult>> {
47	let payment_ctx = TransactionContext::for_payment_key(payment_key, client).await?;
48	let version_oracle = scripts_data::version_oracle(genesis_utxo, payment_ctx.network)?;
49
50	let reserve_validator = ScriptData::new(
51		"Reserve Management Validator",
52		plutus_script![RESERVE_VALIDATOR, version_oracle.policy_id_as_plutus_data()]?
53			.bytes
54			.to_vec(),
55		ScriptId::ReserveValidator,
56	);
57	let reserve_policy = ScriptData::new(
58		"Reserve Management Policy",
59		plutus_script![RESERVE_AUTH_POLICY, version_oracle.policy_id_as_plutus_data()]?
60			.bytes
61			.to_vec(),
62		ScriptId::ReserveAuthPolicy,
63	);
64
65	Ok(vec![
66		initialize_script(reserve_validator, genesis_utxo, payment_key, client, await_tx).await?,
67		initialize_script(reserve_policy, genesis_utxo, payment_key, client, await_tx).await?,
68	]
69	.into_iter()
70	.flatten()
71	.collect())
72}