Skip to content
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
46 changes: 1 addition & 45 deletions contracts/earn-quest/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,48 +127,4 @@ pub fn badge_granted(env: &Env, user: Address, badge: Badge) {
let data = (badge,);
env.events().publish(topics, data);
}

const TOPIC_ESCROW_DEPOSITED: Symbol = symbol_short!("esc_dep");
const TOPIC_ESCROW_PAYOUT: Symbol = symbol_short!("esc_pay");
const TOPIC_ESCROW_REFUNDED: Symbol = symbol_short!("esc_ref");
const TOPIC_QUEST_CANCELLED: Symbol = symbol_short!("q_cancel");

/// Emit when tokens are deposited into escrow
pub fn escrow_deposited(
env: &Env,
quest_id: Symbol,
depositor: Address,
amount: i128,
total_balance: i128,
) {
let topics = (TOPIC_ESCROW_DEPOSITED, quest_id, depositor);
let data = (amount, total_balance);
env.events().publish(topics, data);
}

/// Emit when tokens are paid out from escrow
pub fn escrow_payout(
env: &Env,
quest_id: Symbol,
recipient: Address,
amount: i128,
remaining: i128,
) {
let topics = (TOPIC_ESCROW_PAYOUT, quest_id, recipient);
let data = (amount, remaining);
env.events().publish(topics, data);
}

/// Emit when remaining escrow is refunded to creator
pub fn escrow_refunded(env: &Env, quest_id: Symbol, recipient: Address, amount: i128) {
let topics = (TOPIC_ESCROW_REFUNDED, quest_id, recipient);
let data = (amount,);
env.events().publish(topics, data);
}

/// Emit when a quest is cancelled
pub fn quest_cancelled(env: &Env, quest_id: Symbol, creator: Address, refunded: i128) {
let topics = (TOPIC_QUEST_CANCELLED, quest_id, creator);
let data = (refunded,);
env.events().publish(topics, data);
}
main
2 changes: 2 additions & 0 deletions contracts/earn-quest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mod submission;
pub mod types;
pub mod validation;

main

use crate::errors::Error;
use crate::types::{Badge, BatchApprovalInput, BatchQuestInput, EscrowInfo, UserStats};
use soroban_sdk::{contract, contractimpl, Address, BytesN, Env, Symbol, Vec};
Expand Down
46 changes: 46 additions & 0 deletions contracts/earn-quest/src/stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ============================================================
// ADD THESE STRUCTS TO contracts/earn-quest/src/types.rs
// ============================================================
// Paste both structs at the bottom of the existing types.rs
// file. They reuse the existing `#[contracttype]` + `#[derive]` pattern.
// ============================================================

use soroban_sdk::contracttype;

/// Platform-wide aggregated statistics.
///
/// Updated atomically on every quest creation, submission, and claim.
/// Queried via `EarnQuestContract::get_platform_stats()`.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PlatformStats {
/// Total number of quests ever registered (never decremented).
pub total_quests_created: u64,
/// Total number of proof submissions ever received.
pub total_submissions: u64,
/// Sum of `reward_amount` across all quests ever created (in token base units).
/// Represents total value posted, not necessarily paid out.
pub total_rewards_distributed: u128,
/// Number of unique wallet addresses that have submitted at least once.
pub total_active_users: u64,
/// Number of rewards that reached the `Paid` status (successful claims).
pub total_rewards_claimed: u64,
}

/// Per-creator statistics, scoped to a single quest creator address.
///
/// Updated on quest creation and whenever a submission or claim
/// targets a quest owned by this creator.
/// Queried via `EarnQuestContract::get_creator_stats(creator)`.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CreatorStats {
/// Total quests created by this address.
pub quests_created: u64,
/// Sum of `reward_amount` across all quests created by this address.
pub total_rewards_posted: u128,
/// Total submissions received across all of this creator's quests.
pub total_submissions_received: u64,
/// Total successful claims paid out across all of this creator's quests.
pub total_claims_paid: u64,
}
Loading