sui_jsonrpc/msgs/
sui_extended.rs

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