Skip to content

Commit

Permalink
sdk: add a query for MASP total rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic authored and brentstone committed Jun 6, 2024
1 parent dd3f19a commit 6d4ff88
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/sdk/src/queries/vp/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub mod client_only_methods {
use borsh::BorshDeserialize;
use namada_core::address::Address;
use namada_core::token;
use namada_token::storage_key::balance_key;
use namada_token::storage_key::{balance_key, masp_total_rewards};

use super::Token;
use crate::queries::{Client, RPC};
Expand Down Expand Up @@ -79,5 +79,28 @@ pub mod client_only_methods {
};
Ok(balance)
}

/// Get the total rewards minted by MASP.
pub async fn masp_total_rewards<CLIENT>(
&self,
client: &CLIENT,
) -> Result<token::Amount, <CLIENT as Client>::Error>
where
CLIENT: Client + Sync,
{
let total_rewards_key = masp_total_rewards();
let response = RPC
.shell()
.storage_value(client, None, None, false, &total_rewards_key)
.await?;

let tokens = if response.data.is_empty() {
token::Amount::zero()
} else {
token::Amount::try_from_slice(&response.data)
.unwrap_or_default()
};
Ok(tokens)
}
}
}
7 changes: 7 additions & 0 deletions crates/sdk/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ pub async fn query_conversions<C: crate::queries::Client + Sync>(
convert_response::<C, _>(RPC.shell().read_conversions(client).await)
}

/// Query the total rewards minted by MASP
pub async fn query_masp_total_rewards<C: crate::queries::Client + Sync>(
client: &C,
) -> Result<token::Amount, error::Error> {
convert_response::<C, _>(RPC.vp().token().masp_total_rewards(client).await)
}

/// Query to read the tokens that earn masp rewards.
pub async fn query_masp_reward_tokens<C: crate::queries::Client + Sync>(
client: &C,
Expand Down

0 comments on commit 6d4ff88

Please sign in to comment.