Description
The contract's event system emits events for significant state changes (DustColl, Routed, YeldFail, GasBufIn, GasBufTp, GasBufWd, GDepLock, GDepSlshed, DebtSettl, ClwbkStr, ClwbkRec, FeeSet, VaultSet, ThreshSet), but there is no standardized event schema, no event versioning, and no backward compatibility guarantees. Events use symbol_short with truncated 4-character names that are cryptic for off-chain consumers. The security_analysis.rs (6.9KB) identifies some risks but is a standalone analysis file with no integration to the actual contract code.
Event-specific gaps:
- Event names are truncated to 4 characters (
symbol_short!), making them unreadable
- No
EventVersion field to allow schema evolution
- Events lack correlation IDs (can't link related events across multiple operations)
security_analysis.rs findings are not tracked as issues or test cases
- No event filtering or indexing support for off-chain observers
- Same event structure used for both admin and user operations (no distinction)
Technical Context & Impact
- Affected Components/Files:
contracts/utility_contracts/src/lib.rs (all env.events().publish() calls), contracts/utility_contracts/src/security_analysis.rs
- Impact: Observability, Off-Chain Integration, Auditing
Step-by-Step Implementation Guide
- Define event schema convention: Create
docs/event_schema.md with EventName(domain_action), required fields, and versioning
- Implement
EventBuilder helper: Create src/event_helper.rs with EventBuilder::new(domain: &str, action: &str) that constructs proper event names (>4 chars using full symbols)
- Add event versioning: Include
version: u32 in every event struct, starting at EVENT_VERSION_V1 = 1
- Add correlation IDs: Add optional
correlation_id: Option<BytesN<32>> to events, passed through from operation entry points
- Differentiate event types: Use
EventType::{Admin, User, System} enum tag in each event
- Convert security analysis to tests: Move findings from
security_analysis.rs into tests/security_test_cases.rs as executable test scenarios
- Add event index hints: Include
indexed_fields: Vec<Symbol> hint for Soroban event indexing
Verification & Testing Steps
- Write integration test that captures all published events and validates them against schema
- Verify event names are descriptive (not truncated to 4 chars)
- Test event versioning: parse v1 events, verify version field is present and correct
- Test correlation ID propagation: call multi-step operation and verify all events share correlation ID
- Run full test suite:
cargo test --package utility_contracts
- Deploy to testnet and verify events appear correctly in Stellar Expert or similar block explorer
Description
The contract's event system emits events for significant state changes (
DustColl,Routed,YeldFail,GasBufIn,GasBufTp,GasBufWd,GDepLock,GDepSlshed,DebtSettl,ClwbkStr,ClwbkRec,FeeSet,VaultSet,ThreshSet), but there is no standardized event schema, no event versioning, and no backward compatibility guarantees. Events usesymbol_shortwith truncated 4-character names that are cryptic for off-chain consumers. Thesecurity_analysis.rs(6.9KB) identifies some risks but is a standalone analysis file with no integration to the actual contract code.Event-specific gaps:
symbol_short!), making them unreadableEventVersionfield to allow schema evolutionsecurity_analysis.rsfindings are not tracked as issues or test casesTechnical Context & Impact
contracts/utility_contracts/src/lib.rs(allenv.events().publish()calls),contracts/utility_contracts/src/security_analysis.rsStep-by-Step Implementation Guide
docs/event_schema.mdwithEventName(domain_action), required fields, and versioningEventBuilderhelper: Createsrc/event_helper.rswithEventBuilder::new(domain: &str, action: &str)that constructs proper event names (>4 chars using full symbols)version: u32in every event struct, starting atEVENT_VERSION_V1 = 1correlation_id: Option<BytesN<32>>to events, passed through from operation entry pointsEventType::{Admin, User, System}enum tag in each eventsecurity_analysis.rsintotests/security_test_cases.rsas executable test scenariosindexed_fields: Vec<Symbol>hint for Soroban event indexingVerification & Testing Steps
cargo test --package utility_contracts