sui_jsonrpc/msgs/
sui_governance.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5use serde_with::{IfIsHumanReadable, serde_as};
6use sui_sdk_types::{Address, Bls12381PublicKey, EpochId};
7
8use super::SuiValidatorSummary;
9use crate::serde::BigInt;
10
11/// Originally `sui_types::committee::StakeUnit`.
12pub type StakeUnit = u64;
13
14/// This is the JSON-RPC type for the SUI system state object.
15///
16/// It flattens all fields to make them top-level fields such that it as minimum
17/// dependencies to the internal data structures of the SUI system state type.
18///
19/// Originally `sui_types::sui_system_state::sui_system_state_summary::SuiSystemStateSummary`.
20#[serde_as]
21#[derive(Debug, Serialize, Deserialize, Clone)]
22#[serde(rename_all = "camelCase")]
23pub struct SuiSystemStateSummary {
24    /// The current epoch ID, starting from 0.
25    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
26    pub epoch: u64,
27    /// The current protocol version, starting from 1.
28    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
29    pub protocol_version: u64,
30    /// The current version of the system state data structure type.
31    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
32    pub system_state_version: u64,
33    /// The storage rebates of all the objects on-chain stored in the storage fund.
34    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
35    pub storage_fund_total_object_storage_rebates: u64,
36    /// The non-refundable portion of the storage fund coming from storage reinvestment, non-refundable
37    /// storage rebates and any leftover staking rewards.
38    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
39    pub storage_fund_non_refundable_balance: u64,
40    /// The reference gas price for the current epoch.
41    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
42    pub reference_gas_price: u64,
43    /// Whether the system is running in a downgraded safe mode due to a non-recoverable bug.
44    /// This is set whenever we failed to execute advance_epoch, and ended up executing advance_epoch_safe_mode.
45    /// It can be reset once we are able to successfully execute advance_epoch.
46    pub safe_mode: bool,
47    /// Amount of storage rewards accumulated (and not yet distributed) during safe mode.
48    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
49    pub safe_mode_storage_rewards: u64,
50    /// Amount of computation rewards accumulated (and not yet distributed) during safe mode.
51    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
52    pub safe_mode_computation_rewards: u64,
53    /// Amount of storage rebates accumulated (and not yet burned) during safe mode.
54    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
55    pub safe_mode_storage_rebates: u64,
56    /// Amount of non-refundable storage fee accumulated during safe mode.
57    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
58    pub safe_mode_non_refundable_storage_fee: u64,
59    /// Unix timestamp of the current epoch start
60    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
61    pub epoch_start_timestamp_ms: u64,
62
63    // System parameters
64    /// The duration of an epoch, in milliseconds.
65    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
66    pub epoch_duration_ms: u64,
67
68    /// The starting epoch in which stake subsidies start being paid out
69    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
70    pub stake_subsidy_start_epoch: u64,
71
72    /// Maximum number of active validators at any moment.
73    /// We do not allow the number of validators in any epoch to go above this.
74    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
75    pub max_validator_count: u64,
76
77    /// Lower-bound on the amount of stake required to become a validator.
78    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
79    pub min_validator_joining_stake: u64,
80
81    /// Validators with stake amount below `validator_low_stake_threshold` are considered to
82    /// have low stake and will be escorted out of the validator set after being below this
83    /// threshold for more than `validator_low_stake_grace_period` number of epochs.
84    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
85    pub validator_low_stake_threshold: u64,
86
87    /// Validators with stake below `validator_very_low_stake_threshold` will be removed
88    /// immediately at epoch change, no grace period.
89    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
90    pub validator_very_low_stake_threshold: u64,
91
92    /// A validator can have stake below `validator_low_stake_threshold`
93    /// for this many epochs before being kicked out.
94    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
95    pub validator_low_stake_grace_period: u64,
96
97    // Stake subsidy information
98    /// Balance of SUI set aside for stake subsidies that will be drawn down over time.
99    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
100    pub stake_subsidy_balance: u64,
101    /// This counter may be different from the current epoch number if
102    /// in some epochs we decide to skip the subsidy.
103    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
104    pub stake_subsidy_distribution_counter: u64,
105    /// The amount of stake subsidy to be drawn down per epoch.
106    /// This amount decays and decreases over time.
107    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
108    pub stake_subsidy_current_distribution_amount: u64,
109    /// Number of distributions to occur before the distribution amount decays.
110    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
111    pub stake_subsidy_period_length: u64,
112    /// The rate at which the distribution amount decays at the end of each
113    /// period. Expressed in basis points.
114    pub stake_subsidy_decrease_rate: u16,
115
116    // Validator set
117    /// Total amount of stake from all active validators at the beginning of the epoch.
118    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
119    pub total_stake: u64,
120    /// The list of active validators in the current epoch.
121    pub active_validators: Vec<SuiValidatorSummary>,
122    /// ID of the object that contains the list of new validators that will join at the end of the epoch.
123    pub pending_active_validators_id: Address,
124    /// Number of new validators that will join at the end of the epoch.
125    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
126    pub pending_active_validators_size: u64,
127    /// Removal requests from the validators. Each element is an index
128    /// pointing to `active_validators`.
129    #[serde_as(as = "Vec<IfIsHumanReadable<BigInt<u64>, _>>")]
130    pub pending_removals: Vec<u64>,
131    /// ID of the object that maps from staking pool's ID to the sui address of a validator.
132    pub staking_pool_mappings_id: Address,
133    /// Number of staking pool mappings.
134    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
135    pub staking_pool_mappings_size: u64,
136    /// ID of the object that maps from a staking pool ID to the inactive validator that has that pool as its staking pool.
137    pub inactive_pools_id: Address,
138    /// Number of inactive staking pools.
139    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
140    pub inactive_pools_size: u64,
141    /// ID of the object that stores preactive validators, mapping their addresses to their `Validator` structs.
142    pub validator_candidates_id: Address,
143    /// Number of preactive validators.
144    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
145    pub validator_candidates_size: u64,
146    /// Map storing the number of epochs for which each validator has been below the low stake threshold.
147    #[serde_as(as = "Vec<(_, IfIsHumanReadable<BigInt<u64>, _>)>")]
148    pub at_risk_validators: Vec<(Address, u64)>,
149    /// A map storing the records of validator reporting each other.
150    pub validator_report_records: Vec<(Address, Vec<Address>)>,
151}
152
153/// RPC representation of the [Committee](https://mystenlabs.github.io/sui/sui_types/committee/struct.Committee.html)
154/// type.
155#[serde_as]
156#[derive(Debug, Serialize, Deserialize, Clone)]
157#[serde(rename = "CommitteeInfo")]
158pub struct SuiCommittee {
159    #[serde_as(as = "BigInt<u64>")]
160    pub epoch: EpochId,
161    #[serde_as(as = "Vec<(_, BigInt<u64>)>")]
162    pub validators: Vec<(Bls12381PublicKey, StakeUnit)>,
163}
164
165#[derive(Debug, Serialize, Deserialize, Clone)]
166#[serde(rename_all = "camelCase")]
167pub struct DelegatedStake {
168    /// Validator's Address.
169    pub validator_address: Address,
170    /// Staking pool object id.
171    pub staking_pool: Address,
172    pub stakes: Vec<Stake>,
173}
174
175#[serde_as]
176#[derive(Debug, Serialize, Deserialize, Clone)]
177#[serde(tag = "status")]
178pub enum StakeStatus {
179    Pending,
180    #[serde(rename_all = "camelCase")]
181    Active {
182        #[serde_as(as = "BigInt<u64>")]
183        estimated_reward: u64,
184    },
185    Unstaked,
186}
187
188#[serde_as]
189#[derive(Debug, Serialize, Deserialize, Clone)]
190#[serde(rename_all = "camelCase")]
191pub struct Stake {
192    /// ID of the StakedSui receipt object.
193    pub staked_sui_id: Address,
194    #[serde_as(as = "BigInt<u64>")]
195    pub stake_request_epoch: EpochId,
196    #[serde_as(as = "BigInt<u64>")]
197    pub stake_active_epoch: EpochId,
198    #[serde_as(as = "BigInt<u64>")]
199    pub principal: u64,
200    #[serde(flatten)]
201    pub status: StakeStatus,
202}
203
204#[serde_as]
205#[derive(Debug, Serialize, Deserialize, Clone)]
206pub struct ValidatorApys {
207    pub apys: Vec<ValidatorApy>,
208    #[serde_as(as = "BigInt<u64>")]
209    pub epoch: EpochId,
210}
211
212#[serde_as]
213#[derive(Debug, Serialize, Deserialize, Clone)]
214pub struct ValidatorApy {
215    pub address: Address,
216    pub apy: f64,
217}