Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate supply in REST #285

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions rest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,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",
}
})
}
Expand Down Expand Up @@ -1356,6 +1382,7 @@ fn rocket() -> _ {
ibc_apps_transfer_params,
ibc_applications_transfer_params,
bank_supply_unom,
bank_supply,
validators,
validator,
staking_params,
Expand Down
18 changes: 18 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@ impl InnerApp {
Ok(())
}

#[query]
pub fn total_supply(&self) -> Result<Amount> {
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<Amount> {
self.ibc.transfer().symbol_balance::<Nbtc>(address)
Expand Down
Loading