sui_jsonrpc/msgs/
sui_governance.rs

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