Skip to main content

ogmios_client/schema/
protocol.rs

1//! Protocol parameter types for Cardano.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use super::primitives::*;
6use super::transaction::ExUnits;
7
8/// Protocol parameters for Cardano.
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct ProtocolParameters {
12    /// Minimum fee coefficient (per byte).
13    pub min_fee_coefficient: u64,
14    /// Minimum fee constant.
15    pub min_fee_constant: AdaValue,
16    /// Minimum fee for reference scripts.
17    #[serde(default)]
18    pub min_fee_reference_scripts: Option<MinFeeReferenceScripts>,
19    /// Maximum block body size in bytes.
20    pub max_block_body_size: BlockSize,
21    /// Maximum block header size in bytes.
22    pub max_block_header_size: BlockSize,
23    /// Maximum transaction size in bytes.
24    pub max_transaction_size: BlockSize,
25    /// Stake key deposit.
26    pub stake_credential_deposit: AdaValue,
27    /// Pool registration deposit.
28    pub stake_pool_deposit: AdaValue,
29    /// Pool retirement epoch bound.
30    pub stake_pool_retirement_epoch_bound: u64,
31    /// Desired number of stake pools.
32    pub desired_number_of_stake_pools: u64,
33    /// Stake pool pledge influence (a0).
34    pub stake_pool_pledge_influence: Ratio,
35    /// Monetary expansion (rho).
36    pub monetary_expansion: Ratio,
37    /// Treasury expansion (tau).
38    pub treasury_expansion: Ratio,
39    /// Protocol version.
40    pub version: ProtocolVersion,
41    /// Minimum stake pool cost.
42    pub min_stake_pool_cost: AdaValue,
43    /// Extra entropy (deprecated, always neutral).
44    #[serde(default)]
45    pub extra_entropy: Option<Nonce>,
46    /// Minimum UTXO deposit coefficient (lovelace per byte).
47    #[serde(default)]
48    pub min_utxo_deposit_coefficient: Option<u64>,
49    /// Minimum UTXO deposit constant.
50    #[serde(default)]
51    pub min_utxo_deposit_constant: Option<AdaValue>,
52    /// Plutus cost models.
53    #[serde(default)]
54    pub plutus_cost_models: Option<CostModels>,
55    /// Script execution prices.
56    #[serde(default)]
57    pub script_execution_prices: Option<ScriptExecutionPrices>,
58    /// Maximum execution units per transaction.
59    #[serde(default)]
60    pub max_execution_units_per_transaction: Option<ExUnits>,
61    /// Maximum execution units per block.
62    #[serde(default)]
63    pub max_execution_units_per_block: Option<ExUnits>,
64    /// Maximum collateral inputs.
65    #[serde(default)]
66    pub max_collateral_inputs: Option<u64>,
67    /// Collateral percentage.
68    #[serde(default)]
69    pub collateral_percentage: Option<u64>,
70    /// Maximum value size in bytes.
71    #[serde(default)]
72    pub max_value_size: Option<BlockSize>,
73    /// DRep deposit (Conway).
74    #[serde(default)]
75    pub delegate_representative_deposit: Option<AdaValue>,
76    /// DRep max idle time (Conway).
77    #[serde(default)]
78    pub delegate_representative_max_idle_time: Option<u64>,
79    /// Governance action deposit (Conway).
80    #[serde(default)]
81    pub governance_action_deposit: Option<AdaValue>,
82    /// Governance action lifetime (Conway).
83    #[serde(default)]
84    pub governance_action_lifetime: Option<u64>,
85    /// Constitutional committee min size (Conway).
86    #[serde(default)]
87    pub constitutional_committee_min_size: Option<u64>,
88    /// Constitutional committee max term length (Conway).
89    #[serde(default)]
90    pub constitutional_committee_max_term_length: Option<u64>,
91    /// Stake pool voting thresholds (Conway).
92    #[serde(default)]
93    pub stake_pool_voting_thresholds: Option<StakePoolVotingThresholds>,
94    /// DRep voting thresholds (Conway).
95    #[serde(default)]
96    pub delegate_representative_voting_thresholds: Option<DelegateRepresentativeVotingThresholds>,
97}
98
99/// Minimum fee for reference scripts configuration.
100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
101#[serde(rename_all = "camelCase")]
102pub struct MinFeeReferenceScripts {
103    /// Base fee.
104    pub base: f64,
105    /// Fee range.
106    pub range: u64,
107    /// Multiplier.
108    pub multiplier: f64,
109}
110
111/// Block size specification.
112#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
113#[serde(rename_all = "camelCase")]
114pub struct BlockSize {
115    /// Size in bytes.
116    pub bytes: NumberOfBytes,
117}
118
119/// Protocol version.
120#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct ProtocolVersion {
123    /// Major version.
124    pub major: u32,
125    /// Minor version.
126    pub minor: u32,
127    /// Patch version (optional).
128    #[serde(default)]
129    pub patch: Option<u32>,
130}
131
132/// Cost models for Plutus scripts.
133#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
134#[serde(rename_all = "camelCase")]
135pub struct CostModels {
136    /// Plutus V1 cost model.
137    #[serde(default, rename = "plutus:v1")]
138    pub plutus_v1: Option<Vec<i64>>,
139    /// Plutus V2 cost model.
140    #[serde(default, rename = "plutus:v2")]
141    pub plutus_v2: Option<Vec<i64>>,
142    /// Plutus V3 cost model.
143    #[serde(default, rename = "plutus:v3")]
144    pub plutus_v3: Option<Vec<i64>>,
145}
146
147/// Script execution prices.
148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct ScriptExecutionPrices {
151    /// Memory price (lovelace per unit).
152    pub memory: Ratio,
153    /// CPU price (lovelace per step).
154    pub cpu: Ratio,
155}
156
157/// Stake pool voting thresholds (Conway governance).
158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
159#[serde(rename_all = "camelCase")]
160pub struct StakePoolVotingThresholds {
161    /// No confidence threshold.
162    pub no_confidence: Ratio,
163    /// Constitutional committee update threshold.
164    pub constitutional_committee: ConstitutionalCommitteeThresholds,
165    /// Hard fork initiation threshold.
166    pub hard_fork_initiation: Ratio,
167    /// Protocol parameters update threshold.
168    #[serde(default)]
169    pub protocol_parameters_update: Option<ProtocolParametersUpdateThresholds>,
170}
171
172/// Constitutional committee thresholds.
173#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
174#[serde(rename_all = "camelCase")]
175pub struct ConstitutionalCommitteeThresholds {
176    /// Default threshold.
177    pub default: Ratio,
178    /// State of no confidence threshold.
179    pub state_of_no_confidence: Ratio,
180}
181
182/// Protocol parameters update thresholds.
183#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
184#[serde(rename_all = "camelCase")]
185pub struct ProtocolParametersUpdateThresholds {
186    /// Security threshold.
187    pub security: Ratio,
188}
189
190/// DRep voting thresholds (Conway governance).
191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
192#[serde(rename_all = "camelCase")]
193pub struct DelegateRepresentativeVotingThresholds {
194    /// No confidence threshold.
195    pub no_confidence: Ratio,
196    /// Constitution threshold.
197    pub constitution: Ratio,
198    /// Constitutional committee update threshold.
199    pub constitutional_committee: ConstitutionalCommitteeThresholds,
200    /// Hard fork initiation threshold.
201    pub hard_fork_initiation: Ratio,
202    /// Protocol parameters update thresholds.
203    pub protocol_parameters_update: DRepProtocolParametersUpdateThresholds,
204    /// Treasury withdrawal threshold.
205    pub treasury_withdrawals: Ratio,
206}
207
208/// DRep protocol parameters update thresholds.
209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
210#[serde(rename_all = "camelCase")]
211pub struct DRepProtocolParametersUpdateThresholds {
212    /// Network threshold.
213    pub network: Ratio,
214    /// Economic threshold.
215    pub economic: Ratio,
216    /// Technical threshold.
217    pub technical: Ratio,
218    /// Governance threshold.
219    pub governance: Ratio,
220}
221
222/// Proposed protocol parameter updates.
223pub type ProposedProtocolParameters = HashMap<DigestBlake2b224, PartialProtocolParameters>;
224
225/// Partial protocol parameters for updates.
226#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
227#[serde(rename_all = "camelCase")]
228pub struct PartialProtocolParameters {
229    #[serde(default)]
230    pub min_fee_coefficient: Option<u64>,
231    #[serde(default)]
232    pub min_fee_constant: Option<AdaValue>,
233    #[serde(default)]
234    pub max_block_body_size: Option<BlockSize>,
235    #[serde(default)]
236    pub max_block_header_size: Option<BlockSize>,
237    #[serde(default)]
238    pub max_transaction_size: Option<BlockSize>,
239    #[serde(default)]
240    pub stake_credential_deposit: Option<AdaValue>,
241    #[serde(default)]
242    pub stake_pool_deposit: Option<AdaValue>,
243    #[serde(default)]
244    pub stake_pool_retirement_epoch_bound: Option<u64>,
245    #[serde(default)]
246    pub desired_number_of_stake_pools: Option<u64>,
247    #[serde(default)]
248    pub stake_pool_pledge_influence: Option<Ratio>,
249    #[serde(default)]
250    pub monetary_expansion: Option<Ratio>,
251    #[serde(default)]
252    pub treasury_expansion: Option<Ratio>,
253    #[serde(default)]
254    pub version: Option<ProtocolVersion>,
255    #[serde(default)]
256    pub min_stake_pool_cost: Option<AdaValue>,
257    #[serde(default)]
258    pub plutus_cost_models: Option<CostModels>,
259    #[serde(default)]
260    pub script_execution_prices: Option<ScriptExecutionPrices>,
261    #[serde(default)]
262    pub max_execution_units_per_transaction: Option<ExUnits>,
263    #[serde(default)]
264    pub max_execution_units_per_block: Option<ExUnits>,
265    #[serde(default)]
266    pub max_collateral_inputs: Option<u64>,
267    #[serde(default)]
268    pub collateral_percentage: Option<u64>,
269    #[serde(default)]
270    pub max_value_size: Option<BlockSize>,
271}