sui_jsonrpc/msgs/
sui_extended.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5use serde_with::base64::Base64;
6use serde_with::{DisplayFromStr, IfIsHumanReadable, serde_as};
7use sui_sdk_types::{Address, CheckpointSequenceNumber, EpochId, Identifier};
8
9use super::Page;
10use crate::serde::BigInt;
11
12pub type EpochPage = Page<EpochInfo, BigInt<u64>>;
13
14#[serde_as]
15#[derive(Serialize, Deserialize, Debug)]
16#[serde(rename_all = "camelCase")]
17pub struct EpochInfo {
18    /// epoch number
19    #[serde_as(as = "BigInt<u64>")]
20    pub epoch: EpochId,
21    /// list of validators included in epoch
22    pub validators: Vec<SuiValidatorSummary>,
23    /// count of tx in epoch
24    #[serde_as(as = "BigInt<u64>")]
25    pub epoch_total_transactions: u64,
26    /// first, last checkpoint sequence numbers
27    #[serde_as(as = "BigInt<u64>")]
28    pub first_checkpoint_id: CheckpointSequenceNumber,
29    #[serde_as(as = "BigInt<u64>")]
30    pub epoch_start_timestamp: u64,
31    pub end_of_epoch_info: Option<EndOfEpochInfo>,
32    pub reference_gas_price: Option<u64>,
33}
34
35/// This is the JSON-RPC type for the SUI validator. It flattens all inner structures
36/// to top-level fields so that they are decoupled from the internal definitions.
37///
38/// Originally from `sui_types::sui_system_state::sui_system_state_summary`.
39#[serde_as]
40#[derive(Debug, Serialize, Deserialize, Clone)]
41#[serde(rename_all = "camelCase")]
42pub struct SuiValidatorSummary {
43    // Metadata
44    pub sui_address: Address,
45    #[serde_as(as = "Base64")]
46    pub protocol_pubkey_bytes: Vec<u8>,
47    #[serde_as(as = "Base64")]
48    pub network_pubkey_bytes: Vec<u8>,
49    #[serde_as(as = "Base64")]
50    pub worker_pubkey_bytes: Vec<u8>,
51    #[serde_as(as = "Base64")]
52    pub proof_of_possession_bytes: Vec<u8>,
53    pub name: String,
54    pub description: String,
55    pub image_url: String,
56    pub project_url: String,
57    pub net_address: String,
58    pub p2p_address: String,
59    pub primary_address: String,
60    pub worker_address: String,
61    #[serde_as(as = "Option<Base64>")]
62    pub next_epoch_protocol_pubkey_bytes: Option<Vec<u8>>,
63    #[serde_as(as = "Option<Base64>")]
64    pub next_epoch_proof_of_possession: Option<Vec<u8>>,
65    #[serde_as(as = "Option<Base64>")]
66    pub next_epoch_network_pubkey_bytes: Option<Vec<u8>>,
67    #[serde_as(as = "Option<Base64>")]
68    pub next_epoch_worker_pubkey_bytes: Option<Vec<u8>>,
69    pub next_epoch_net_address: Option<String>,
70    pub next_epoch_p2p_address: Option<String>,
71    pub next_epoch_primary_address: Option<String>,
72    pub next_epoch_worker_address: Option<String>,
73
74    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
75    pub voting_power: u64,
76    pub operation_cap_id: Address,
77    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
78    pub gas_price: u64,
79    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
80    pub commission_rate: u64,
81    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
82    pub next_epoch_stake: u64,
83    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
84    pub next_epoch_gas_price: u64,
85    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
86    pub next_epoch_commission_rate: u64,
87
88    // Staking pool information
89    /// ID of the staking pool object.
90    pub staking_pool_id: Address,
91    /// The epoch at which this pool became active.
92    #[serde_as(as = "Option<IfIsHumanReadable<BigInt<u64>, _>>")]
93    pub staking_pool_activation_epoch: Option<u64>,
94    /// The epoch at which this staking pool ceased to be active. `None` = {pre-active, active},
95    #[serde_as(as = "Option<IfIsHumanReadable<BigInt<u64>, _>>")]
96    pub staking_pool_deactivation_epoch: Option<u64>,
97    /// The total number of SUI tokens in this pool.
98    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
99    pub staking_pool_sui_balance: u64,
100    /// The epoch stake rewards will be added here at the end of each epoch.
101    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
102    pub rewards_pool: u64,
103    /// Total number of pool tokens issued by the pool.
104    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
105    pub pool_token_balance: u64,
106    /// Pending stake amount for this epoch.
107    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
108    pub pending_stake: u64,
109    /// Pending stake withdrawn during the current epoch, emptied at epoch boundaries.
110    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
111    pub pending_total_sui_withdraw: u64,
112    /// Pending pool token withdrawn during the current epoch, emptied at epoch boundaries.
113    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
114    pub pending_pool_token_withdraw: u64,
115    /// ID of the exchange rate table object.
116    pub exchange_rates_id: Address,
117    /// Number of exchange rates in the table.
118    #[serde_as(as = "IfIsHumanReadable<BigInt<u64>, _>")]
119    pub exchange_rates_size: u64,
120}
121
122#[serde_as]
123#[derive(Serialize, Deserialize, Debug)]
124#[serde(rename_all = "camelCase")]
125pub struct EndOfEpochInfo {
126    #[serde_as(as = "BigInt<u64>")]
127    pub last_checkpoint_id: CheckpointSequenceNumber,
128    #[serde_as(as = "BigInt<u64>")]
129    pub epoch_end_timestamp: u64,
130    /// existing fields from `SystemEpochInfo`
131    #[serde_as(as = "BigInt<u64>")]
132    pub protocol_version: u64,
133    #[serde_as(as = "BigInt<u64>")]
134    pub reference_gas_price: u64,
135    #[serde_as(as = "BigInt<u64>")]
136    pub total_stake: u64,
137    #[serde_as(as = "BigInt<u64>")]
138    pub storage_fund_reinvestment: u64,
139    #[serde_as(as = "BigInt<u64>")]
140    pub storage_charge: u64,
141    #[serde_as(as = "BigInt<u64>")]
142    pub storage_rebate: u64,
143    #[serde_as(as = "BigInt<u64>")]
144    pub storage_fund_balance: u64,
145    #[serde_as(as = "BigInt<u64>")]
146    pub stake_subsidy_amount: u64,
147    #[serde_as(as = "BigInt<u64>")]
148    pub total_gas_fees: u64,
149    #[serde_as(as = "BigInt<u64>")]
150    pub total_stake_rewards_distributed: u64,
151    #[serde_as(as = "BigInt<u64>")]
152    pub leftover_storage_fund_inflow: u64,
153}
154
155#[serde_as]
156#[derive(Serialize, Deserialize, Debug)]
157#[serde(rename_all = "camelCase")]
158pub struct MoveFunctionName {
159    pub package: Address,
160    #[serde_as(as = "DisplayFromStr")]
161    pub module: Identifier,
162    #[serde_as(as = "DisplayFromStr")]
163    pub function: Identifier,
164}