Skip to content

Commit

Permalink
adding staking providers and tos (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougEfresh authored May 2, 2024
1 parent 1642450 commit fa5dbf8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
4 changes: 2 additions & 2 deletions SUPPORTED_ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/api/staking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::client::Client;
use crate::types::StakingProvider;
use crate::{
types::{
asset::SupportedAsset,
Expand All @@ -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<Vec<StakingProvider>> {
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::<serde_json::Value, ()>(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<Vec<Asset>> {
let u = self.build_url("staking/chains")?.0;
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
28 changes: 20 additions & 8 deletions src/types/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit fa5dbf8

Please sign in to comment.