From fa5dbf82e3b472fa0e57958e9ff4bd9455f6b5be Mon Sep 17 00:00:00 2001 From: Douglas Chimento Date: Thu, 2 May 2024 12:44:07 +0300 Subject: [PATCH] adding staking providers and tos (#15) --- SUPPORTED_ENDPOINTS.md | 4 ++-- src/api/staking.rs | 29 +++++++++++++++++++++++++++++ src/lib.rs | 5 +++++ src/types/staking.rs | 28 ++++++++++++++++++++-------- 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/SUPPORTED_ENDPOINTS.md b/SUPPORTED_ENDPOINTS.md index 169dec1..7fc3a66 100644 --- a/SUPPORTED_ENDPOINTS.md +++ b/SUPPORTED_ENDPOINTS.md @@ -48,8 +48,8 @@ | GET /staking/positions/summary | ✓ | | GET /staking/positions/summary/vaults | ✗ | | GET /staking/positions/{id} | ✗ | -| GET /staking/providers | ✗ | -| POST /staking/providers/{providerId}/approveTermsOfService | ✗ | +| GET /staking/providers | ✓ | +| POST /staking/providers/{providerId}/approveTermsOfService | ✓ | ## Exchange accounts diff --git a/src/api/staking.rs b/src/api/staking.rs index e061097..26b9b26 100644 --- a/src/api/staking.rs +++ b/src/api/staking.rs @@ -1,4 +1,5 @@ use crate::client::Client; +use crate::types::StakingProvider; use crate::{ types::{ asset::SupportedAsset, @@ -15,6 +16,34 @@ impl Client { self.get(u).await } + /// Get info about available providers + /// + /// See + /// + /// * [getProviders](https://docs.fireblocks.com/api/swagger-ui/#/Staking%20(Beta)/getProviders) + #[tracing::instrument(level = "debug", skip(self))] + pub async fn staking_providers(&self) -> Result> { + let u = self.build_url("staking/providers")?.0; + self.get(u).await + } + + /// Approve TOS for a provider + /// + /// See + /// + /// * [approveTermsOfServiceByProviderId](https://docs.fireblocks.com/api/swagger-ui/#/Staking%20(Beta)/approveTermsOfServiceByProviderId) + #[tracing::instrument(level = "debug", skip(self))] + pub async fn staking_accept_terms(&self, provider_id: &str) -> Result<()> { + let u = self.build_url(format!("staking/providers/{provider_id}/approveTermsOfService"))?.0; + let id = self.post::(u, None).await?.1; + Ok(((), id)) + } + + /// Get available chains + /// + /// See + /// + /// * [getChains](https://docs.fireblocks.com/api/swagger-ui/#/Staking%20(Beta)/getChains) #[tracing::instrument(level = "debug", skip(self))] pub async fn staking_chains(&self) -> Result> { let u = self.build_url("staking/chains")?.0; diff --git a/src/lib.rs b/src/lib.rs index 6138585..5734ef6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -438,6 +438,11 @@ mod tests { assert!(!chains.is_empty()); c.staking_positions().await?; c.staking_positions_summary().await?; + let providers = c.staking_providers().await?.0; + assert!(!providers.is_empty()); + for p in providers { + c.staking_accept_terms(&p.id).await?; + } for chain in [ASSET_SOL, ASSET_SOL_TEST, ASSET_ETH, ASSET_ETH_TEST] { c.staking_chain_info(&chain).await?; diff --git a/src/types/staking.rs b/src/types/staking.rs index 1a005d1..6bd4871 100644 --- a/src/types/staking.rs +++ b/src/types/staking.rs @@ -86,17 +86,29 @@ pub struct StakingAmounts { #[derive(Debug, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub struct StakingAdditionalInfo { - estimated_annual_reward: BigDecimal, - lockup_period: u64, - activation_period: u64, + pub estimated_annual_reward: BigDecimal, + pub lockup_period: u64, + pub activation_period: u64, } #[derive(Debug, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub struct StakingChainInfo { - chain_descriptor: Asset, - current_epoch: u64, - epoch_elapsed: f64, - epoch_duration: u64, - additional_info: StakingAdditionalInfo, + pub chain_descriptor: Asset, + pub current_epoch: u64, + pub epoch_elapsed: f64, + pub epoch_duration: u64, + pub additional_info: StakingAdditionalInfo, +} + +#[derive(Debug, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct StakingProvider { + pub id: String, + #[serde(rename = "providerName")] + pub name: String, + pub icon_url: String, + pub terms_of_service_url: String, + #[serde(rename = "isTermsOfServiceApproved")] + pub terms_of_service_approved: bool, }