Skip to content

Automatic economic event generation on approved state transitions #44

@Soushi888

Description

@Soushi888

Summary

Replace the current manual log_economic_event() approach with automatic economic event generation whenever a state transition is approved by the governance engine. Every approved state change should produce a corresponding economic event for audit trails and reputation tracking.

Context

Currently, economic events are created manually via log_economic_event() — callers must explicitly decide when and what to log. The governance-as-operator architecture requires that event generation is automatic and mandatory as part of the governance evaluation, ensuring a complete audit trail with no gaps.

Technical Implementation

1. Event Generation in GovernanceEngine

Economic events are generated as part of the GovernanceTransitionResult when a transition is approved:

fn generate_economic_event(
    request: &GovernanceTransitionRequest,
    evaluation: &TransitionEvaluation,
) -> ExternResult<EconomicEvent> {
    Ok(EconomicEvent {
        action: request.action.clone(),
        provider: request.resource.custodian,
        receiver: request.requesting_agent.clone(),
        resource_inventoried_as: Some(request.resource.conforms_to),
        affects: get_resource_hash(&request.resource)?,
        resource_quantity: calculate_quantity_change(
            &request.resource, &request.action, &request.context,
        )?,
        event_time: sys_time()?,
        note: Some(format!("State transition: {:?} approved", request.action)),
    })
}

2. Quantity Change Calculation

Map each VfAction to its quantity impact:

  • Produce / Raise → positive quantity change
  • Consume / Lower → negative quantity change
  • Transfer / Move / Use → zero quantity change (custodian/state change only)

3. PPR Integration

Connect automatic event generation with the existing PPR system:

  • Approved transitions that generate economic events should also trigger PPR generation (as generate_pprs_for_economic_event already does)
  • Ensure the existing PPR flow works with auto-generated events

4. Deprecation of Manual Logging

  • Keep log_economic_event() for backward compatibility initially
  • Mark as deprecated in favor of the automatic flow
  • Plan removal once all callers migrate to request_resource_transition

Acceptance Criteria

  • Every approved state transition automatically generates an EconomicEvent
  • Quantity changes calculated correctly per VfAction type
  • Generated events include proper provider/receiver/resource references
  • PPR generation integrates with auto-generated events
  • Rejected transitions do NOT generate economic events
  • Audit trail is complete — no state changes without corresponding events
  • Unit tests verify event generation for each action type
  • Integration tests verify end-to-end event creation through governance flow

Dependencies

Definition of Done

  • Automatic event generation implemented and tested
  • PPR integration verified
  • All tests pass
  • Code review completed

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-highHigh priority - important for milestone completioncross-zomeCross-zome integration and coordinationphase-2-governancePhase 2 - Enhanced governance & process integration (current)valueflowsValueFlows ontology compliance and integrationzome-governanceGovernance zome - validation, economic events, commitments

    Type

    No type

    Projects

    Status

    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions