iota_json_rpc_types/
iota_governance.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use iota_types::{
6    base_types::{AuthorityName, EpochId, IotaAddress, ObjectID},
7    committee::{Committee, StakeUnit},
8    iota_serde::BigInt,
9};
10use schemars::JsonSchema;
11use serde::{Deserialize, Serialize};
12use serde_with::serde_as;
13
14/// RPC representation of the [Committee] type.
15#[serde_as]
16#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
17#[serde(rename = "CommitteeInfo")]
18pub struct IotaCommittee {
19    #[schemars(with = "BigInt<u64>")]
20    #[serde_as(as = "BigInt<u64>")]
21    pub epoch: EpochId,
22    #[schemars(with = "Vec<(AuthorityName, BigInt<u64>)>")]
23    #[serde_as(as = "Vec<(_, BigInt<u64>)>")]
24    pub validators: Vec<(AuthorityName, StakeUnit)>,
25}
26
27impl From<Committee> for IotaCommittee {
28    fn from(committee: Committee) -> Self {
29        Self {
30            epoch: committee.epoch,
31            validators: committee.voting_rights,
32        }
33    }
34}
35
36#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
37#[serde(rename_all = "camelCase")]
38pub struct DelegatedStake {
39    /// Validator's Address.
40    pub validator_address: IotaAddress,
41    /// Staking pool object id.
42    pub staking_pool: ObjectID,
43    pub stakes: Vec<Stake>,
44}
45
46#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
47#[serde(rename_all = "camelCase")]
48pub struct DelegatedTimelockedStake {
49    pub validator_address: IotaAddress,
50    pub staking_pool: ObjectID,
51    pub stakes: Vec<TimelockedStake>,
52}
53
54#[serde_as]
55#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
56#[serde(tag = "status")]
57pub enum StakeStatus {
58    Pending,
59    #[serde(rename_all = "camelCase")]
60    Active {
61        #[schemars(with = "BigInt<u64>")]
62        #[serde_as(as = "BigInt<u64>")]
63        estimated_reward: u64,
64    },
65    Unstaked,
66}
67
68#[serde_as]
69#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
70#[serde(rename_all = "camelCase")]
71pub struct Stake {
72    /// ID of the StakedIota receipt object.
73    pub staked_iota_id: ObjectID,
74    #[schemars(with = "BigInt<u64>")]
75    #[serde_as(as = "BigInt<u64>")]
76    pub stake_request_epoch: EpochId,
77    #[schemars(with = "BigInt<u64>")]
78    #[serde_as(as = "BigInt<u64>")]
79    pub stake_active_epoch: EpochId,
80    #[schemars(with = "BigInt<u64>")]
81    #[serde_as(as = "BigInt<u64>")]
82    pub principal: u64,
83    #[serde(flatten)]
84    pub status: StakeStatus,
85}
86
87#[serde_as]
88#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
89#[serde(rename_all = "camelCase")]
90pub struct TimelockedStake {
91    pub timelocked_staked_iota_id: ObjectID,
92    #[schemars(with = "BigInt<u64>")]
93    #[serde_as(as = "BigInt<u64>")]
94    pub stake_request_epoch: EpochId,
95    #[schemars(with = "BigInt<u64>")]
96    #[serde_as(as = "BigInt<u64>")]
97    pub stake_active_epoch: EpochId,
98    #[schemars(with = "BigInt<u64>")]
99    #[serde_as(as = "BigInt<u64>")]
100    pub principal: u64,
101    #[serde(flatten)]
102    pub status: StakeStatus,
103    #[schemars(with = "BigInt<u64>")]
104    #[serde_as(as = "BigInt<u64>")]
105    pub expiration_timestamp_ms: u64,
106    pub label: Option<String>,
107}
108
109#[serde_as]
110#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
111pub struct ValidatorApys {
112    pub apys: Vec<ValidatorApy>,
113    #[schemars(with = "BigInt<u64>")]
114    #[serde_as(as = "BigInt<u64>")]
115    pub epoch: EpochId,
116}
117
118#[serde_as]
119#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
120pub struct ValidatorApy {
121    pub address: IotaAddress,
122    pub apy: f64,
123}