use iota_types::{
base_types::{AuthorityName, EpochId, IotaAddress, ObjectID},
committee::{Committee, StakeUnit},
iota_serde::BigInt,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename = "CommitteeInfo")]
pub struct IotaCommittee {
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub epoch: EpochId,
#[schemars(with = "Vec<(AuthorityName, BigInt<u64>)>")]
#[serde_as(as = "Vec<(_, BigInt<u64>)>")]
pub validators: Vec<(AuthorityName, StakeUnit)>,
}
impl From<Committee> for IotaCommittee {
fn from(committee: Committee) -> Self {
Self {
epoch: committee.epoch,
validators: committee.voting_rights,
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct DelegatedStake {
pub validator_address: IotaAddress,
pub staking_pool: ObjectID,
pub stakes: Vec<Stake>,
}
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct DelegatedTimelockedStake {
pub validator_address: IotaAddress,
pub staking_pool: ObjectID,
pub stakes: Vec<TimelockedStake>,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(tag = "status")]
pub enum StakeStatus {
Pending,
#[serde(rename_all = "camelCase")]
Active {
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
estimated_reward: u64,
},
Unstaked,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct Stake {
pub staked_iota_id: ObjectID,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub stake_request_epoch: EpochId,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub stake_active_epoch: EpochId,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub principal: u64,
#[serde(flatten)]
pub status: StakeStatus,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct TimelockedStake {
pub timelocked_staked_iota_id: ObjectID,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub stake_request_epoch: EpochId,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub stake_active_epoch: EpochId,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub principal: u64,
#[serde(flatten)]
pub status: StakeStatus,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub expiration_timestamp_ms: u64,
pub label: Option<String>,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct ValidatorApys {
pub apys: Vec<ValidatorApy>,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub epoch: EpochId,
}
#[serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
pub struct ValidatorApy {
pub address: IotaAddress,
pub apy: f64,
}