Skip to main content

qualia_core_db/domains/financial/economics/
node_pricing.rs

1//! Node-local economic pricing helpers.
2
3/// Context regarding the physical state of the node.
4pub struct SystemContext {
5    pub current_battery_level: f32,
6    pub cpu_temperature: f32,
7    pub network_congestion_index: f64,
8}
9
10/// Get mock system context.
11pub fn get_current_system_context() -> SystemContext {
12    SystemContext {
13        current_battery_level: 0.8,
14        cpu_temperature: 45.0,
15        network_congestion_index: 0.2,
16    }
17}
18
19/// Calculates bandwidth liability in USD based on routed bytes and context.
20pub fn calculate_bandwidth_liability(bytes: usize, context: &SystemContext) -> f64 {
21    let gb_routed = bytes as f64 / 1_073_741_824.0;
22    let mut base_rate = 0.05;
23
24    base_rate += context.network_congestion_index * 0.05;
25    if context.current_battery_level < 0.2 {
26        base_rate += 0.05;
27    }
28    if context.cpu_temperature > 70.0 {
29        base_rate += 0.02;
30    }
31
32    gb_routed * base_rate
33}