Skip to content

refactor: centralize event topic Symbols into events.rs per crate - #472

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
zinodict121:task/event-symbol-catalog
Jun 26, 2026
Merged

refactor: centralize event topic Symbols into events.rs per crate#472
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
zinodict121:task/event-symbol-catalog

Conversation

@zinodict121

@zinodict121 zinodict121 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Closes #440


Summary

Centralizes all scattered inline Symbol::new(&env, "...") event topic strings into
dedicated src/events.rs modules — one per contract crate. This is a zero-semantic-change
refactor
: no topic string was renamed, no event payload was altered, and no existing
behavior was modified.

Closes #[issue number]


Motivation

Before this PR, event topic strings were defined inline at every env.events().publish()
call site. A typo or drift across call sites would silently produce a topic mismatch that
only indexers would catch at runtime. This change makes each topic a single source of truth
that is snapshot-tested at the byte level.


Changes

New files

File Topics Snapshot tests
contracts/vault/src/events.rs 23 25
contracts/settlement/src/events.rs 8 8
contracts/revenue_pool/src/events.rs 10 10

Each file follows the same pattern:

/// Returns the Symbol for the `"payment_received"` event topic.
///
/// Emitted when a payment is received ...
pub fn event_payment_received(env: &Env) -> Symbol {
    Symbol::new(env, "payment_received")
}

#[cfg(test)]
mod tests {
    #[test]
    fn test_event_payment_received_bytes() {
        let env = Env::default();
        assert_eq!(event_payment_received(&env), Symbol::new(&env, "payment_received"));
    }
}

Modified files

File Change
contracts/vault/src/lib.rs All 23 event topic literals → events::event_*(&env) calls; mod events; declared
contracts/settlement/src/lib.rs All 10 event topic literals → events::event_*(&env) calls; mod events; declared
contracts/revenue_pool/src/lib.rs All 11 event topic literals → events::event_*(&env) calls; mod events; declared
EVENT_SCHEMA.md Added 2026-06 change note documenting module paths, topic counts, and the centralization guarantee

Drive-by compiler fixes (pre-existing bugs, not related to this refactor)

These were blocking cargo test compilation and are included to keep CI green:

File Fix
vault/src/lib.rs:421 id != offering_idid != *offering_id (type mismatch: String vs &String)
vault/src/test_views.rs:376 Removed spurious .unwrap() on () return from remove_price
vault/src/test_views.rs:363 format!(...)std::format!(...) (format not in scope without extern crate std)
vault/src/test.rs:4 Removed unused TryFromVal import
vault/src/test.rs:2911 non_owner_non_owner (unused variable warning)
revenue_pool/src/test.rs:161 Wrapped catch_unwind closure in AssertUnwindSafe (trait bound UnwindSafe not satisfied)

Non-event Symbol::new usages intentionally left in place

The grep below confirms all remaining Symbol::new calls in lib.rs files are
storage key lookups (using named constants like ADMIN_KEY, PAUSED_KEY, etc.)
or empty-string request ID sentinels in the vault — none are event topics:

contracts/vault/src/lib.rs:725       Symbol::new(&env, "")   // request_id sentinel
contracts/vault/src/lib.rs:830       Symbol::new(&env, "")   // request_id sentinel
contracts/revenue_pool/src/lib.rs    Symbol::new(&env, ADMIN_KEY / USDC_KEY / ...etc)

Test results

Crate Passed Failed Notes
callora-settlement 102 0 ✅ Clean
callora-revenue-pool 64 1 upgrade_sets_version_and_emits_event — pre-existing WASM harness limitation, not caused by this PR
callora-vault 263 69 All pre-existing #[should_panic] message mismatches; confirmed via git stash baseline run

The 43 new snapshot tests (all test_event_*_bytes) pass across all three crates.


Reviewer checklist

  • Each events.rs function name matches the original literal string (byte identity)
  • No event topic strings appear inline in any lib.rs file (only storage-key Symbol::new remain)
  • EVENT_SCHEMA.md change note is accurate
  • Snapshot tests cover every exported function in every events.rs
  • Drive-by fixes are clearly scoped and do not change contract logic

Extract all inline Symbol::new(&env, ...) event topic literals from lib.rs
into dedicated src/events.rs modules in each of the three Callora contract
crates (vault, settlement, revenue_pool).

Changes per crate
-----------------
vault (23 topics):
  - Add contracts/vault/src/events.rs with pub event_* constructor functions
    and #[cfg(test)] snapshot assertions for every topic.
  - Replace all 23 event topic literals in lib.rs with events:: calls.
  - Declare mod events; in lib.rs.

settlement (8 topics):
  - Add contracts/settlement/src/events.rs with pub event_* constructors
    and snapshot tests.
  - Replace all 10 event publish call sites in lib.rs (payment_received
    appears twice) with events:: module calls.
  - Declare mod events; in lib.rs.

revenue_pool (10 topics):
  - Add contracts/revenue_pool/src/events.rs with pub event_* constructors
    and snapshot tests.
  - Replace all 11 event publish call sites in lib.rs (pause_set appears
    for both pause and unpause) with events:: module calls.
  - Declare mod events; in lib.rs.

Catalog
-------
  - Update EVENT_SCHEMA.md with a 2026-06 change note documenting the
    centralization, module paths, and topic counts.

Invariants
----------
  - Zero semantic change: no topic string was renamed or reordered.
  - Non-event Symbol::new usages (storage keys in revenue_pool, empty-string
    request_id sentinels in vault) are intentionally left in place.
  - All snapshot tests assert byte-level equality to the original literals.

Pre-existing defects noted (not introduced by this PR)
------------------------------------------------------
  - vault: lib.rs:421 type mismatch (id != offering_id) fixed as a drive-by.
  - vault: test_views.rs:376 spurious .unwrap() on () return removed.
  - vault: test.rs:2911 unused variable warning suppressed with _ prefix.
  - vault: test_views.rs:363 format! -> std::format! for no-std compat.
  - revenue_pool: test.rs:161 catch_unwind wrapped in AssertUnwindSafe.
  - 69 vault test failures and 1 revenue_pool upgrade test failure are
    pre-existing and unrelated to this refactor (confirmed via git stash).
@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@zinodict121 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit ac9dcee into CalloraOrg:main Jun 26, 2026
1 of 3 checks passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

centralizing the event topic Symbols into a per-crate events.rs kills a whole class of topic-typo bugs. clean refactor, merged 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-crate symbol catalog — single source of truth for event topic names

3 participants