Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [
"contracts/fees",
"contracts/compliance_registry",
"contracts/fractional",
"contracts/property-management",
"contracts/prediction-market",
]
resolver = "2"

Expand Down
59 changes: 59 additions & 0 deletions contracts/analytics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ mod propchain_analytics {
pub risk_score: u8,
}

/// Crowd wisdom sentiment derived from prediction markets
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct MarketSentiment {
pub bull_volume: u128,
pub bear_volume: u128,
pub bull_bear_ratio_bips: u32, // Ratio in basis points (10000 = 100%)
}

/// Market Report.
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
Expand All @@ -66,6 +77,7 @@ mod propchain_analytics {
pub generated_at: u64,
pub metrics: MarketMetrics,
pub trend: MarketTrend,
pub sentiment: MarketSentiment,
pub insights: String,
}

Expand All @@ -79,6 +91,10 @@ mod propchain_analytics {
historical_trends: ink::storage::Mapping<u64, MarketTrend>,
/// Trend count
trend_count: u64,
/// Sentiments per property
property_sentiments: ink::storage::Mapping<u64, MarketSentiment>,
/// Overall aggregated sentiment
overall_sentiment: MarketSentiment,
}

impl AnalyticsDashboard {
Expand All @@ -94,6 +110,12 @@ mod propchain_analytics {
},
historical_trends: ink::storage::Mapping::default(),
trend_count: 0,
property_sentiments: ink::storage::Mapping::default(),
overall_sentiment: MarketSentiment {
bull_volume: 0,
bear_volume: 0,
bull_bear_ratio_bips: 5000,
},
}
}

Expand Down Expand Up @@ -162,12 +184,48 @@ mod propchain_analytics {
generated_at: self.env().block_timestamp(),
metrics: self.current_metrics.clone(),
trend: latest_trend,
sentiment: self.overall_sentiment.clone(),
insights: String::from(
"Market is relatively stable. Gas optimization is recommended.",
),
}
}

/// Update market sentiment from prediction markets
#[ink(message)]
pub fn update_market_sentiment(
&mut self,
property_id: u64,
bull_volume: u128,
bear_volume: u128,
) {
self.ensure_admin(); // Prediction market or admin updates this

let total_volume = bull_volume + bear_volume;
let ratio = if total_volume > 0 {
((bull_volume * 10000) / total_volume) as u32
} else {
5000 // default unbiased
};

let new_sentiment = MarketSentiment {
bull_volume,
bear_volume,
bull_bear_ratio_bips: ratio,
};

self.property_sentiments.insert(property_id, &new_sentiment);

// Update overall recursively or by moving average
self.overall_sentiment.bull_volume = self.overall_sentiment.bull_volume.saturating_add(bull_volume);
self.overall_sentiment.bear_volume = self.overall_sentiment.bear_volume.saturating_add(bear_volume);

let total_overall = self.overall_sentiment.bull_volume + self.overall_sentiment.bear_volume;
if total_overall > 0 {
self.overall_sentiment.bull_bear_ratio_bips = ((self.overall_sentiment.bull_volume * 10000) / total_overall) as u32;
}
}

/// Add gas usage optimization recommendations
#[ink(message)]
pub fn get_gas_optimization_recommendations(&self) -> String {
Expand Down Expand Up @@ -227,6 +285,7 @@ mod propchain_analytics {
let contract = AnalyticsDashboard::new();
let report = contract.generate_market_report();
assert_eq!(report.metrics.average_price, 0);
assert_eq!(report.sentiment.bull_bear_ratio_bips, 5000);
assert!(report.insights.contains("Gas optimization"));
}
}
Expand Down
24 changes: 24 additions & 0 deletions contracts/prediction-market/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "propchain-prediction-market"
version = "1.0.0"
authors = ["PropChain Team <dev@propchain.io>"]
edition = "2021"

[dependencies]
ink = { workspace = true }
scale = { workspace = true }
scale-info = { workspace = true }
propchain-traits = { path = "../traits", default-features = false }

[lib]
path = "src/lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
"propchain-traits/std",
]
ink-as-dependency = []
Loading
Loading