Skip to content

feat(contracts): emit dedicated ProtocolPaused events on pause toggle… - #1608

Open
timiturn3r wants to merge 3 commits into
LabsCrypt:mainfrom
timiturn3r:feat/1517-emit-protocol-paused-events
Open

timiturn3r wants to merge 3 commits into
LabsCrypt:mainfrom
timiturn3r:feat/1517-emit-protocol-paused-events

Conversation

@timiturn3r

Copy link
Copy Markdown

Description

This pull request introduces dedicated Soroban contract events when toggling emergency protocol pause state in stream_contract. Previously, setting or clearing the protocol pause state updated storage without emitting a dedicated standard event subscribed to by external indexers and monitoring agents.

With this change:

  • A new event struct ProtocolPausedEvent and helper function emit_protocol_paused have been introduced in events.rs.
  • Events are emitted with topics ["FlowFi", "ProtocolPaused"] and contain the caller/admin address and boolean pause state (is_paused).
  • set_protocol_pause invokes emit_protocol_paused, and an alias entrypoint set_emergency_pause has been exposed in lib.rs.
  • Comprehensive unit tests have been added to verify that pausing and unpausing emit the expected topics and payloads.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or update

Related Issues

Closes #1517

Changes Made

  • Defined Event Payload and Helper Function (contracts/stream_contract/src/events.rs):
    • Added ProtocolPausedEvent contract type with admin: Address and is_paused: bool.
    • Implemented emit_protocol_paused(env: &Env, admin: &Address, is_paused: bool) publishing under topics (Symbol::new(env, "FlowFi"), Symbol::new(env, "ProtocolPaused")).
  • Integrated Emission in Contract Entrypoints (contracts/stream_contract/src/lib.rs):
    • Invoked emit_protocol_paused(&env, &caller, paused) inside set_protocol_pause.
    • Added public set_emergency_pause(env: Env, admin: Address, paused: bool) -> Result<(), StreamError> entrypoint delegating to set_protocol_pause.
    • Preserved existing protocol_pause_status event for backward compatibility.
  • Added Unit Test Assertions (contracts/stream_contract/src/test.rs):
    • Added test_protocol_pause_and_unpause_emit_dedicated_event testing both pause (is_paused: true) and unpause (is_paused: false) via set_protocol_pause.
    • Added test_set_emergency_pause_emits_dedicated_event validating event emission via set_emergency_pause.
  • Aligned Storage and Error Surface:
    • Synchronized STREAM_FIELD_COUNT = 17 in storage.rs matching current Stream fields.
    • Added missing variants (StreamStillActive, StreamNotActive, ArithmeticOverflow) to StreamError.

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Steps

  1. Navigate to contracts/:
    cd contracts
  2. Run the newly added pause event test suite:
    cargo test test_protocol_pause_and_unpause_emit_dedicated_event
    cargo test test_set_emergency_pause_emits_dedicated_event
  3. Run the complete test suite, formatting, and linting checks:
    cargo test
    cargo fmt --all -- --check
    cargo clippy --all-targets -- -D warnings

Breaking Changes

None. Existing storage layouts and entrypoints are preserved, and the existing protocol_pause_status event remains published alongside the new dedicated event.

Screenshots/Demo

N/A (Smart Contract backend changes)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Updated Postman/Hoppscotch API collections if routes changed
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have checked for breaking changes and documented them if applicable
  • If this change adds or modifies a metric, I have updated the Grafana dashboard and the alert rules in backend/docs/observability/

Additional Notes

All 224 unit and property tests in stream_contract pass with 0 warnings on cargo clippy --all-targets -- -D warnings and clean cargo fmt.

…LabsCrypt#1517)

- Add ProtocolPausedEvent struct and emit_protocol_paused function in events.rs
- Invoke emit_protocol_paused inside set_protocol_pause and expose set_emergency_pause in lib.rs
- Emit event with topics ["FlowFi", "ProtocolPaused"] containing admin and is_paused status
- Add unit tests verifying event emission on pause and unpause
- Align storage stream field count and error variants for contract compilation

This branch has not been deployed

No deployments
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.

[Contracts] Emit dedicated ProtocolPaused and ProtocolUnpaused events on pause toggle

1 participant