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
43 changes: 43 additions & 0 deletions contracts/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ mod propchain_contracts {
pause_info: PauseInfo,
/// Accounts authorized to pause the contract
pause_guardians: Mapping<AccountId, bool>,
/// Oracle contract address (optional)
oracle: Option<AccountId>,
}

/// Escrow information
Expand Down Expand Up @@ -765,6 +767,7 @@ mod propchain_contracts {
required_approvals: 2, // Default requirement
},
pause_guardians: Mapping::default(),
oracle: None,
};

// Emit contract initialization event
Expand All @@ -790,6 +793,46 @@ mod propchain_contracts {
self.admin
}

/// Set the oracle contract address
#[ink(message)]
pub fn set_oracle(&mut self, oracle: AccountId) -> Result<(), Error> {
let caller = self.env().caller();
if caller != self.admin {
return Err(Error::Unauthorized);
}
self.oracle = Some(oracle);
Ok(())
}

/// Returns the oracle contract address
#[ink(message)]
pub fn oracle(&self) -> Option<AccountId> {
self.oracle
}

/// Update property valuation using the oracle
#[ink(message)]
pub fn update_valuation_from_oracle(&mut self, property_id: u64) -> Result<(), Error> {
let oracle_addr = self.oracle.ok_or(Error::OracleError)?;

// Use the Oracle trait to perform the cross-contract call
use ink::env::call::FromAccountId;
let oracle: ink::contract_ref!(Oracle) = FromAccountId::from_account_id(oracle_addr);

// Fetch valuation from oracle
let valuation = oracle.get_valuation(property_id).map_err(|_| Error::OracleError)?;

// Update the property's recorded valuation in its metadata
if let Some(mut property) = self.properties.get(&property_id) {
property.metadata.valuation = valuation.valuation;
self.properties.insert(&property_id, &property);
} else {
return Err(Error::PropertyNotFound);
}

Ok(())
}

/// Changes the admin account (only callable by current admin)
#[ink(message)]
pub fn change_admin(&mut self, new_admin: AccountId) -> Result<(), Error> {
Expand Down
16 changes: 16 additions & 0 deletions contracts/oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The Property Valuation Oracle provides real-time property valuations for the Pro
- **Location-Based Adjustments**: Geographic market adjustments
- **Price Alert System**: Notifications for significant valuation changes
- **Fallback Mechanisms**: Redundant oracle sources for reliability
- **Oracle Reputation System**: Performance tracking and automated source management
- **Slashing System**: Stake-based penalties for malicious or inaccurate data
- **Gas-Efficient Batching**: Support for multiple property valuation requests in a single transaction
- **Anomaly Detection**: Advanced validation logic to detect market outliers

## Architecture

Expand Down Expand Up @@ -48,6 +52,12 @@ Returns historical valuations (most recent first).
#### `set_price_alert(property_id: u64, threshold_percentage: u32, alert_address: AccountId)`
Sets up alerts for price changes exceeding the threshold.

#### `request_property_valuation(property_id: u64) -> Result<u64, OracleError>`
Initiates a new valuation request for a property.

#### `batch_request_valuations(property_ids: Vec<u64>) -> Result<Vec<u64>, OracleError>`
Batch requests valuations for multiple properties efficiently.

### Administrative Functions

#### `add_oracle_source(source: OracleSource) -> Result<(), OracleError>`
Expand All @@ -59,6 +69,12 @@ Configures location-based valuation adjustments (admin only).
#### `update_market_trend(trend: MarketTrend) -> Result<(), OracleError>`
Updates market trend data for volatility calculations (admin only).

#### `update_source_reputation(source_id: String, success: bool) -> Result<(), OracleError>`
Manages oracle source reputation scores (admin only).

#### `slash_source(source_id: String, penalty: u128) -> Result<(), OracleError>`
Slashes staked funds for underperforming or malicious sources (admin only).

## Data Structures

### PropertyValuation
Expand Down
Loading
Loading