-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: replace env.events().publish() with #[contractevent] structs #5
Copy link
Copy link
Open
Description
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 allenv.events().publish()callsContracts/stablecoin/src/types.rs— removeMINT_EVENT,BURN_EVENT,TRANSFER_EVENT,PAUSE_EVENT,UNPAUSE_EVENTstring 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.rsare removed - All existing tests pass (update event assertions to use new event types if needed)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels