SSSwap

First Flight #41
Beginner FriendlyRust
100 EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

No Event Emission for Critical Operations in the `liquidity_operations.rs` and also in the `swap_operations.rs` files.

Description: The AMM doesn't emit events for critical operations like pool initialization, liquidity provision/removal, and swaps. The AMM doesn't emit events (using Anchor's emit! macro) for critical operations. Events are essential for off-chain monitoring, indexing, and user interfaces to track activities. Without events, it's difficult to track pool creation, liquidity changes, and swap activities.

Impact:

  1. Difficulty in building user interfaces that need to track pool activities

  2. Challenges in monitoring and auditing pool operations

  3. Limited ability to index and analyze pool data off-chain

Proof of Concept: None of the critical functions emit events:

pub fn initialize_pool(context: Context<InitializePool>, amount_token_a: u64, amount_token_b: u64) -> Result<()> {
// Function logic...
// No event emission
Ok(())
}
pub fn provide_liquidity(context: Context<ModifyLiquidity>, amount_a: u64) -> Result<()> {
// Function logic...
// No event emission
Ok(())
}
pub fn swap_exact_in(context: Context<SwapContext>, amount_in: u64, min_out: u64, zero_for_one: bool) -> Result<()> {
// Function logic...
// No event emission
Ok(())
}

Recommended Mitigation: Implement events for all critical operations:

// In lib.rs or a separate events.rs file
#[event]
pub struct PoolInitialized {
pub pool: Pubkey,
pub token_a: Pubkey,
pub token_b: Pubkey,
pub initial_amount_a: u64,
pub initial_amount_b: u64,
pub lp_tokens_minted: u64,
pub creator: Pubkey,
}
#[event]
pub struct LiquidityProvided {
pub pool: Pubkey,
pub provider: Pubkey,
pub amount_a: u64,
pub amount_b: u64,
pub lp_tokens_minted: u64,
}
#[event]
pub struct LiquidityRemoved {
pub pool: Pubkey,
pub provider: Pubkey,
pub amount_a: u64,
pub amount_b: u64,
pub lp_tokens_burned: u64,
}
#[event]
pub struct Swap {
pub pool: Pubkey,
pub user: Pubkey,
pub token_in: Pubkey,
pub token_out: Pubkey,
pub amount_in: u64,
pub amount_out: u64,
pub fee_amount: u64,
}
// Then in each function, emit the appropriate event
pub fn initialize_pool(context: Context<InitializePool>, amount_token_a: u64, amount_token_b: u64) -> Result<()> {
// Existing code...
emit!(PoolInitialized {
pool: context.accounts.liquidity_pool.key(),
token_a: context.accounts.token_mint_a.key(),
token_b: context.accounts.token_mint_b.key(),
initial_amount_a: amount_token_a,
initial_amount_b: amount_token_b,
lp_tokens_minted: lp_amount_to_mint,
creator: context.accounts.creator.key(),
});
Ok(())
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge 13 days ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.