Skip to content

feat(iota-sdk): add GovernanceApi::{get_timelocked_stakes, get_validators_apy} #6950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#[path = "../utils.rs"]
mod utils;

use iota_json_rpc_api::GovernanceReadApiClient;
use iota_json_rpc_types::{IotaObjectDataFilter, IotaObjectDataOptions, IotaObjectResponseQuery};
use iota_keys::keystore::{AccountKeystore, FileBasedKeystore, Keystore};
use iota_sdk::{
Expand Down Expand Up @@ -115,7 +114,10 @@ async fn main() -> Result<(), anyhow::Error> {
tokio::time::sleep(std::time::Duration::from_secs(3)).await;

// Check DelegatedTimelockedStake object
let staked_iota = client.http().get_timelocked_stakes(address).await?;
let staked_iota = client
.governance_api()
.get_timelocked_stakes(address)
.await?;
println!("Staked: {staked_iota:?}\n\n");

// Unstake timelocked IOTA, if staking for longer than 1 epoch already
Expand Down Expand Up @@ -171,7 +173,10 @@ async fn main() -> Result<(), anyhow::Error> {
tokio::time::sleep(std::time::Duration::from_secs(3)).await;

// Check DelegatedTimelockedStake object
let staked_iota = client.http().get_timelocked_stakes(address).await?;
let staked_iota = client
.governance_api()
.get_timelocked_stakes(address)
.await?;
println!("Staked: {staked_iota:?}");
} else {
println!("No stake found that can be unlocked (must be staked >= 1 epoch)")
Expand Down
15 changes: 14 additions & 1 deletion crates/iota-sdk/src/apis/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::sync::Arc;

use iota_json_rpc_api::GovernanceReadApiClient;
use iota_json_rpc_types::{DelegatedStake, IotaCommittee};
use iota_json_rpc_types::{DelegatedStake, DelegatedTimelockedStake, IotaCommittee, ValidatorApys};
use iota_types::{
base_types::IotaAddress, iota_serde::BigInt,
iota_system_state::iota_system_state_summary::IotaSystemStateSummary,
Expand All @@ -29,6 +29,14 @@ impl GovernanceApi {
Ok(self.api.http.get_stakes(owner).await?)
}

/// Get a list of delegated timelocked stakes for the given address.
pub async fn get_timelocked_stakes(
&self,
owner: IotaAddress,
) -> IotaRpcResult<Vec<DelegatedTimelockedStake>> {
Ok(self.api.http.get_timelocked_stakes(owner).await?)
}

/// Get committee information for the given epoch.
///
/// The epoch defaults to the current epoch.
Expand Down Expand Up @@ -76,4 +84,9 @@ impl GovernanceApi {
pub async fn get_reference_gas_price(&self) -> IotaRpcResult<u64> {
Ok(*self.api.http.get_reference_gas_price().await?)
}

/// Get the validators APY.
pub async fn get_validators_apy(&self) -> IotaRpcResult<ValidatorApys> {
Ok(self.api.http.get_validators_apy().await?)
}
}
Loading