-
-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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 changeConsume/Lower→ negative quantity changeTransfer/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_eventalready 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
VfActiontype - 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
- Define cross-zome interface types for governance-as-operator protocol #41 (Cross-zome interface types)
- Implement pure-function GovernanceEngine for state transition evaluation #42 (GovernanceEngine implementation)
Definition of Done
- Automatic event generation implemented and tested
- PPR integration verified
- All tests pass
- Code review completed
Metadata
Metadata
Assignees
Labels
Type
Projects
Status