From 6d4ff88afa117d966b03e2d3b0f643b364671f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 5 Jun 2024 17:06:21 +0200 Subject: [PATCH] sdk: add a query for MASP total rewards --- crates/sdk/src/queries/vp/token.rs | 25 ++++++++++++++++++++++++- crates/sdk/src/rpc.rs | 7 +++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/sdk/src/queries/vp/token.rs b/crates/sdk/src/queries/vp/token.rs index 18e994ebc9..89d8a15e55 100644 --- a/crates/sdk/src/queries/vp/token.rs +++ b/crates/sdk/src/queries/vp/token.rs @@ -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}; @@ -79,5 +79,28 @@ pub mod client_only_methods { }; Ok(balance) } + + /// Get the total rewards minted by MASP. + pub async fn masp_total_rewards( + &self, + client: &CLIENT, + ) -> Result::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) + } } } diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index 52f079c5ad..5e674c86b7 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -347,6 +347,13 @@ pub async fn query_conversions( convert_response::(RPC.shell().read_conversions(client).await) } +/// Query the total rewards minted by MASP +pub async fn query_masp_total_rewards( + client: &C, +) -> Result { + convert_response::(RPC.vp().token().masp_total_rewards(client).await) +} + /// Query to read the tokens that earn masp rewards. pub async fn query_masp_reward_tokens( client: &C,