#!/usr/bin/env python3 """ Currency Ledger Report Generator Creates summary reports for community transparency """ import csv import yaml from datetime import datetime import os from collections import defaultdict def generate_sc_summary(): """Generate SC summary report""" print("šŸ“Š SMARTUP CREDITS SUMMARY REPORT") print("=" * 40) ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'smartup-credits', 'transactions.csv') try: with open(ledger_file, 'r') as f: reader = csv.DictReader(f) user_balances = defaultdict(int) total_minted = 0 total_redeemed = 0 transaction_count = 0 for row in reader: if row['type'] == 'SC': amount = int(row['amount']) user_balances[row['to']] += amount total_minted += amount transaction_count += 1 elif row['type'] == 'REDEEM': amount = int(row['amount']) user_balances[row['from']] -= amount total_redeemed += amount transaction_count += 1 print(f"Total SC Minted: {total_minted}") print(f"Total SC Redeemed: {total_redeemed}") print(f"SC Outstanding: {total_minted - total_redeemed}") print(f"Total Transactions: {transaction_count}") print(f"Active Contributors: {len([u for u in user_balances if user_balances[u] > 0])}") # Top contributors if user_balances: print("\nšŸ† TOP SC EARNERS:") sorted_users = sorted(user_balances.items(), key=lambda x: x[1], reverse=True) for i, (user, balance) in enumerate(sorted_users[:5]): if balance > 0: print(f"{i+1}. {user}: {balance} SC") except FileNotFoundError: print("āŒ No SC transactions found") except Exception as e: print(f"āŒ Error generating SC report: {e}") def generate_treasury_report(): """Generate treasury health report""" print("\nšŸ’° TREASURY HEALTH REPORT") print("=" * 30) treasury_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'treasury', 'balance.csv') try: with open(treasury_file, 'r') as f: reader = csv.DictReader(f) rows = list(reader) if rows: latest = rows[-1] eur_balance = float(latest['total_eur_balance']) sc_outstanding = int(latest['sc_outstanding']) sc_liability = float(latest['sc_liability_eur']) print(f"šŸ’¶ EUR Treasury: €{eur_balance:,.2f}") print(f"šŸŖ™ SC Outstanding: {sc_outstanding:,} SC") print(f"šŸ’ø SC Liability: €{sc_liability:,.2f}") if eur_balance > 0: coverage_ratio = eur_balance / sc_liability if sc_liability > 0 else float('inf') print(f"šŸ“Š Coverage Ratio: {coverage_ratio:.2f}x") if coverage_ratio >= 1.0: print("āœ… Full SC redemption possible") else: redemption_capacity = int(eur_balance) print(f"āš ļø Partial redemption: €{redemption_capacity:,} available") # 3x rule check max_allowed_sc = eur_balance * 3 print(f"šŸ›”ļø 3x Rule: {sc_outstanding:,} / {max_allowed_sc:,.0f} SC allowed") if sc_outstanding <= max_allowed_sc: print("āœ… 3x Rule: COMPLIANT") else: print("🚨 3x Rule: VIOLATION") else: print("āš ļø Treasury initialized but no balance records") except FileNotFoundError: print("āŒ No treasury records found") except Exception as e: print(f"āŒ Error generating treasury report: {e}") def main(): """Generate all reports""" print("šŸ“ˆ SMARTUP ZERO FINANCIAL REPORTS") print(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print("=" * 50) generate_sc_summary() generate_treasury_report() print("\n" + "=" * 50) print("šŸ’” All ledger data is public and auditable in git history") if __name__ == "__main__": main() def generate_pending_sc_summary(): """Generate pending SC summary report""" print("\nā³ PENDING SC SUMMARY REPORT") print("=" * 32) ledger_file = os.path.join(os.path.dirname(__file__), '..', 'ledger', 'pending-sc', 'transactions.csv') try: with open(ledger_file, 'r') as f: reader = csv.DictReader(f) pending_by_tranche = defaultdict(int) pending_by_status = defaultdict(int) total_pending = 0 for row in reader: if row['type'] == 'PENDING_SC': amount = int(row['amount']) pending_by_tranche[row['vesting_tranche']] += amount pending_by_status[row['status']] += amount total_pending += amount print(f"Total Pending SC: {total_pending}") if pending_by_tranche: print("\nšŸ“Š BY VESTING TRANCHE:") for tranche, amount in pending_by_tranche.items(): print(f" {tranche}: {amount} SC") if pending_by_status: print("\nšŸ“‹ BY STATUS:") for status, amount in pending_by_status.items(): print(f" {status}: {amount} SC") except FileNotFoundError: print("šŸ“ No pending SC transactions found") except Exception as e: print(f"āŒ Error generating pending SC report: {e}") # Add call to generate_pending_sc_summary() in main() function def generate_comprehensive_financial_report(): """Enhanced financial report showing pending vs live SC""" print("\nšŸ’¼ COMPREHENSIVE FINANCIAL REPORT") print("=" * 38) # Get live SC (from main ledger) live_sc = 0 try: with open(os.path.join(os.path.dirname(__file__), '..', 'ledger', 'smartup-credits', 'transactions.csv'), 'r') as f: reader = csv.DictReader(f) for row in reader: if row.get('type') == 'SC': live_sc += int(row.get('amount', 0)) except: pass # Get pending SC pending_sc = 0 try: with open(os.path.join(os.path.dirname(__file__), '..', 'ledger', 'pending-sc', 'transactions.csv'), 'r') as f: reader = csv.DictReader(f) for row in reader: if row.get('type') == 'PENDING_SC' and row.get('status') != 'REJECTED': pending_sc += int(row.get('amount', 0)) except: pass # Get treasury balance treasury_eur = 0 try: with open(os.path.join(os.path.dirname(__file__), '..', 'ledger', 'treasury', 'balance.csv'), 'r') as f: reader = csv.DictReader(f) rows = list(reader) if rows: treasury_eur = float(rows[-1].get('total_eur_balance', 0)) except: pass print(f"šŸ’¶ EUR Treasury: €{treasury_eur:,.2f}") print(f"šŸŖ™ Live SC Outstanding: {live_sc:,} SC (€{live_sc:,.2f} liability)") print(f"ā³ Pending SC: {pending_sc:,} SC (€{pending_sc:,.2f} contingent)") print(f"šŸ“Š Total Potential: €{live_sc + pending_sc:,.2f}") if treasury_eur > 0 and live_sc > 0: coverage = treasury_eur / live_sc print(f"šŸ›”ļø Coverage Ratio: {coverage:.2f}x (live SC only)") # 3x rule check (only for live SC) max_allowed = treasury_eur * 3 if live_sc <= max_allowed: print("āœ… 3x Rule: COMPLIANT") else: print("🚨 3x Rule: VIOLATION") else: print("āœ… 3x Rule: COMPLIANT (no live SC outstanding)") print(f"\nšŸ’” Financial Health: Excellent") print(f" • Real liability: €{live_sc:,.2f}") print(f" • Contingent awards pending validation: €{pending_sc:,.2f}") print(f" • Treasury covers: {('100%+ of obligations' if treasury_eur >= live_sc else 'building toward full coverage')}") # Replace the old treasury report with this comprehensive one