From a2935742a1514b245ef38afdcdadc205d54a32d0 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sat, 24 Feb 2024 05:03:30 +0300 Subject: [PATCH 1/2] Calculate supply in REST --- rest/src/main.rs | 31 +++++++++++++++++++++++++++++-- src/app.rs | 12 ++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/rest/src/main.rs b/rest/src/main.rs index 5939b706..cf808ecf 100644 --- a/rest/src/main.rs +++ b/rest/src/main.rs @@ -874,11 +874,37 @@ async fn staking_pool() -> Value { } #[get("/cosmos/bank/v1beta1/supply/unom")] -fn bank_supply_unom() -> Value { +async fn bank_supply_unom() -> Value { + let supply = app_client() + .query(|app| app.total_supply()) + .await + .unwrap(); + json!({ "amount": { "denom": "unom", - "amount": "1" + "amount": supply.to_string(), + } + }) +} + +#[get("/cosmos/bank/v1beta1/supply")] +async fn bank_supply() -> Value { + let supply = app_client() + .query(|app| app.total_supply()) + .await + .unwrap(); + + json!({ + "supply": [ + { + "denom": "unom", + "amount": supply.to_string() + } + ], + "pagination": { + "next_key": null, + "total": "1", } }) } @@ -1350,6 +1376,7 @@ fn rocket() -> _ { ibc_apps_transfer_params, ibc_applications_transfer_params, bank_supply_unom, + bank_supply, validators, validator, staking_params, diff --git a/src/app.rs b/src/app.rs index f1f5fc36..155b5ccb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -202,6 +202,18 @@ impl InnerApp { Ok(()) } + #[query] + pub fn total_supply(&self) -> Result { + let initial_supply: u64 = 17_500_000_000_000; + + let staking_rewards_minted: u64 = self.staking_rewards.amount_minted.into(); + let dev_rewards_minted: u64 = self.dev_rewards.amount_minted.into(); + let community_pool_rewards_minted: u64 = self.community_pool_rewards.amount_minted.into(); + let incentive_pool_rewards_minted: u64 = self.incentive_pool_rewards.amount_minted.into(); + + Ok(Amount::new(initial_supply + staking_rewards_minted + dev_rewards_minted + community_pool_rewards_minted + incentive_pool_rewards_minted)) + } + #[query] pub fn escrowed_nbtc(&self, address: Address) -> Result { self.ibc.transfer().symbol_balance::(address) From 68386ef27639e6c7aed729350b154746656e17d9 Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 21 Mar 2024 22:44:15 +0300 Subject: [PATCH 2/2] Format --- src/app.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 155b5ccb..84c8f6eb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -211,7 +211,13 @@ impl InnerApp { let community_pool_rewards_minted: u64 = self.community_pool_rewards.amount_minted.into(); let incentive_pool_rewards_minted: u64 = self.incentive_pool_rewards.amount_minted.into(); - Ok(Amount::new(initial_supply + staking_rewards_minted + dev_rewards_minted + community_pool_rewards_minted + incentive_pool_rewards_minted)) + Ok(Amount::new( + initial_supply + + staking_rewards_minted + + dev_rewards_minted + + community_pool_rewards_minted + + incentive_pool_rewards_minted, + )) } #[query]