Skip to content

refactor: replace env.events().publish() with #[contractevent] structs #5

@aguilar1x

Description

@aguilar1x

Context

Depends on #4 (trait-based architecture). The contract currently emits all events using the deprecated env.events().publish() pattern. Since soroban-sdk 23+ the standard is to define #[contractevent] structs and call .publish(e) on them. OZ v0.6.0 already ships typed event structs for all standard operations.

Current pattern (deprecated)

env.events().publish(
    (Symbol::new(&env, MINT_EVENT), &to),
    amount
);

env.events().publish(
    (Symbol::new(&env, TRANSFER_EVENT), &from, &to),
    amount
);

Target pattern (v0.6.0 / soroban-sdk 23+)

OZ already provides these events in stellar_tokens::fungible:

  • stellar_tokens::fungible::emit_mint(e, &to, amount)
  • stellar_tokens::fungible::emit_transfer(e, &from, &to, None, amount)
  • stellar_tokens::fungible::emit_approve(e, &owner, &spender, amount, live_until_ledger)

And in stellar_contract_utils::pausable:

  • stellar_contract_utils::pausable::emit_paused(e)
  • stellar_contract_utils::pausable::emit_unpaused(e)

For any custom events (e.g., batch_mint) define them as:

#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BatchMint {
    #[topic]
    pub to: Address,
    pub amount: i128,
}

// then emit with:
BatchMint { to: account.clone(), amount }.publish(e);

Files to update

  • Contracts/stablecoin/src/contract.rs — replace all env.events().publish() calls
  • Contracts/stablecoin/src/types.rs — remove MINT_EVENT, BURN_EVENT, TRANSFER_EVENT, PAUSE_EVENT, UNPAUSE_EVENT string constants (no longer needed)
  • Add any custom event struct definitions (e.g., for batch_mint)

Acceptance criteria

  • Zero uses of env.events().publish() in the codebase
  • Standard OZ events (emit_mint, emit_transfer, etc.) are used for SEP-41 operations
  • Custom events use #[contractevent] structs with #[topic] on address fields
  • Event constants in types.rs are removed
  • All existing tests pass (update event assertions to use new event types if needed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions