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
45 changes: 41 additions & 4 deletions contracts/raffle/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::AdminOp;
// LIFECYCLE EVENTS
// ============================================================================

/// Emitted when a new raffle is initialized
/// Emitted when a new raffle instance is initialized
#[derive(Clone)]
#[contracttype]
pub struct RaffleCreated {
Expand Down Expand Up @@ -51,6 +51,7 @@ pub struct TicketPurchased {
pub buyer: Address,
pub ticket_ids: Vec<u32>,
pub quantity: u32,
pub ticket_price: i128,
pub total_paid: i128,
pub timestamp: u64,
}
Expand Down Expand Up @@ -119,6 +120,7 @@ pub struct RaffleCancelled {
pub creator: Address,
pub reason: CancelReason,
pub tickets_sold: u32,
pub prize_refunded: bool,
pub timestamp: u64,
}

Expand All @@ -127,7 +129,7 @@ pub struct RaffleCancelled {
#[contracttype]
pub struct TicketRefunded {
pub buyer: Address,
pub ticket_id: u32,
pub ticket_number: u32,
pub amount: i128,
pub timestamp: u64,
}
Expand All @@ -148,6 +150,7 @@ pub struct CreatorVerified {
pub struct PrizeClaimed {
pub winner: Address,
pub tier_index: u32,
pub payment_token: Address,
pub gross_amount: i128,
pub net_amount: i128,
pub platform_fee: i128,
Expand All @@ -159,6 +162,7 @@ pub struct PrizeClaimed {
#[contracttype]
pub struct BuybackAndBurnExecuted {
pub router: Address,
pub payment_token: Address,
pub tikka_token: Address,
pub amount_in: i128,
pub amount_out: i128,
Expand Down Expand Up @@ -210,7 +214,7 @@ pub struct TreasuryUpdated {
pub timestamp: u64,
}

/// Emitted when accumulated fees are withdrawn
/// Emitted when accumulated fees are withdrawn to the treasury
#[derive(Clone)]
#[contracttype]
pub struct FeesWithdrawn {
Expand Down Expand Up @@ -313,11 +317,44 @@ pub struct AdminOpCancelled {
pub cancelled_at: u64,
}

// ============================================================================
// FACTORY EVENTS
// ============================================================================

/// Emitted when the factory is initialized
#[derive(Clone)]
#[contracttype]
pub struct FactoryInitialized {
pub admin: Address,
pub protocol_fee_bp: u32,
pub treasury: Address,
pub timestamp: u64,
}

/// Emitted when a new raffle instance is deployed by the factory
#[derive(Clone)]
#[contracttype]
pub struct RaffleDeployed {
pub raffle_address: Address,
pub creator: Address,
pub timestamp: u64,
}

/// Emitted when the factory protocol fee or treasury is updated via set_config
#[derive(Clone)]
#[contracttype]
pub struct FactoryConfigUpdated {
pub protocol_fee_bp: u32,
pub treasury: Address,
pub updated_by: Address,
pub timestamp: u64,
}

// ============================================================================
// INTERNAL STATE CHANGE EVENT
// ============================================================================

/// Emitted when raffle status changes
/// Emitted on every raffle status transition
#[derive(Clone)]
#[contracttype]
pub struct RaffleStatusChanged {
Expand Down
6 changes: 4 additions & 2 deletions contracts/raffle/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,7 @@ impl Contract {
"buyback_and_burn_executed",
crate::events::BuybackAndBurnExecuted {
router: contract_address.clone(),
payment_token: raffle.payment_token.clone(),
tikka_token: tikka.clone(),
amount_in: platform_fee,
amount_out: platform_fee,
Expand All @@ -1560,6 +1561,7 @@ impl Contract {
PrizeClaimed {
winner: winner.clone(),
tier_index,
payment_token: raffle.payment_token.clone(),
gross_amount: tier_prize_amount,
net_amount,
platform_fee,
Expand Down Expand Up @@ -1672,9 +1674,9 @@ impl Contract {
publish_event(
&env,
"ticket_refunded",
crate::events::TicketRefunded {
TicketRefunded {
buyer: ticket.owner.clone(),
ticket_id,
ticket_number: ticket_id,
amount: raffle.ticket_price,
timestamp: env.ledger().timestamp(),
},
Expand Down
12 changes: 12 additions & 0 deletions contracts/raffle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ impl RaffleFactory {
env.storage()
.persistent()
.set(&DataKey::Treasury, &treasury);

publish_factory_event(
&env,
"factory_initialized",
events::FactoryInitialized {
admin,
protocol_fee_bp,
treasury,
timestamp: env.ledger().timestamp(),
},
);

Ok(())
}

Expand Down
Loading