From e06010a1af4b0aa45b76475f34e0ff9cc9fcded3 Mon Sep 17 00:00:00 2001 From: Daniil Okhlopkov <5613295+ohld@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:46:40 +0100 Subject: [PATCH] show total supply --- src/tgbot/handlers/treasury/commands.py | 4 ++++ src/tgbot/handlers/treasury/service.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/tgbot/handlers/treasury/commands.py b/src/tgbot/handlers/treasury/commands.py index 9574ad4..8f014ec 100644 --- a/src/tgbot/handlers/treasury/commands.py +++ b/src/tgbot/handlers/treasury/commands.py @@ -9,6 +9,7 @@ get_leaderboard, get_user_balance, get_user_place_in_leaderboard, + get_token_supply, ) from src.tgbot.senders.utils import get_random_emoji @@ -94,6 +95,9 @@ async def handle_show_leaderbaord( "To see your place in the leaderboard, set your /nickname ⬅️\n\n" ) + tokens = await get_token_supply() + LEADERBOARD_TEXT += f"\n Total supply: {tokens} 🍔" + return await update.message.reply_text(LEADERBOARD_TEXT, parse_mode=ParseMode.HTML) diff --git a/src/tgbot/handlers/treasury/service.py b/src/tgbot/handlers/treasury/service.py index 8f66124..dcbddb9 100644 --- a/src/tgbot/handlers/treasury/service.py +++ b/src/tgbot/handlers/treasury/service.py @@ -32,6 +32,12 @@ async def get_leaderboard(limit=10) -> list[dict[str, Any]]: return await fetch_all(select_statement) +async def get_token_supply() -> int: + select_statement = select(func.sum(treasury_trx.c.amount)) + result = await execute(select_statement) + return result.scalar() + + async def get_user_place_in_leaderboard(user_id: int) -> int: return await fetch_one( text(