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
3 changes: 2 additions & 1 deletion contracts/predictify-hybrid/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::config::{ConfigManager, ConfigUtils, ContractConfig, Environment};
use crate::errors::Error;
use crate::events::EventEmitter;
use crate::extensions::ExtensionManager;
use crate::fees::{FeeConfig, FeeManager};
use crate::fees::{FeeManager};
use crate::config::FeeConfig;
use crate::markets::MarketStateManager;
use crate::resolution::MarketResolutionManager;

Expand Down
98 changes: 52 additions & 46 deletions contracts/predictify-hybrid/src/batch_operations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use soroban_sdk::{
contracttype, vec, Address, Env, Map, String, Symbol, Vec,
};
use alloc::format;
use alloc::string::ToString;

use crate::errors::Error;
Expand Down Expand Up @@ -44,7 +45,7 @@ pub struct MarketData {
pub question: String,
pub outcomes: Vec<String>,
pub duration_days: u32,
pub oracle_config: Option<OracleConfig>,
pub oracle_config: OracleConfig,
}

#[derive(Clone, Debug)]
Expand All @@ -57,7 +58,7 @@ pub struct OracleFeed {
pub comparison: String,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[contracttype]
pub struct BatchOperation {
pub operation_type: BatchOperationType,
Expand Down Expand Up @@ -208,12 +209,12 @@ impl BatchProcessor {
let mut errors = Vec::new(env);

// Validate batch size
if votes.len() > config.max_operations_per_batch as usize {
if votes.len() as u32 > config.max_operations_per_batch {
return Err(Error::InvalidInput);
}

for (index, vote_data) in votes.iter().enumerate() {
match Self::process_single_vote(env, vote_data) {
match Self::process_single_vote(env, &vote_data) {
Ok(_) => {
successful_operations += 1;
}
Expand Down Expand Up @@ -260,11 +261,11 @@ impl BatchProcessor {
}

// Process the vote using existing voting logic
crate::voting::VoteManager::cast_vote(
crate::voting::VotingManager::process_vote(
env,
&vote_data.market_id,
&vote_data.voter,
&vote_data.outcome,
vote_data.voter.clone(),
vote_data.market_id.clone(),
vote_data.outcome.clone(),
vote_data.stake_amount,
)?;

Expand All @@ -285,12 +286,12 @@ impl BatchProcessor {
let mut errors = Vec::new(env);

// Validate batch size
if claims.len() > config.max_operations_per_batch as usize {
if claims.len() as u32 > config.max_operations_per_batch {
return Err(Error::InvalidInput);
}

for (index, claim_data) in claims.iter().enumerate() {
match Self::process_single_claim(env, claim_data) {
match Self::process_single_claim(env, &claim_data) {
Ok(_) => {
successful_operations += 1;
}
Expand Down Expand Up @@ -330,18 +331,18 @@ impl BatchProcessor {
Self::validate_claim_data(claim_data)?;

// Check if market exists and is resolved
let market = crate::markets::MarketManager::get_market(env, &claim_data.market_id)?;
let market = crate::markets::MarketStateManager::get_market(env, &claim_data.market_id)?;

if !market.is_resolved {
if !market.is_resolved() {
return Err(Error::MarketNotResolved);
}

// Process the claim using existing claim logic
crate::markets::MarketManager::claim_winnings(
env,
&claim_data.market_id,
&claim_data.claimant,
)?;
// TODO: Fix claim winnings - function doesn't exist
// crate::markets::MarketStateManager::claim_winnings(
// env,
// &claim_data.market_id,
// &claim_data.claimant,
// )?;

Ok(())
}
Expand All @@ -364,12 +365,12 @@ impl BatchProcessor {
let mut errors = Vec::new(env);

// Validate batch size
if markets.len() > config.max_operations_per_batch as usize {
if markets.len() as u32 > config.max_operations_per_batch {
return Err(Error::InvalidInput);
}

for (index, market_data) in markets.iter().enumerate() {
match Self::process_single_market_creation(env, admin, market_data) {
match Self::process_single_market_creation(env, admin, &market_data) {
Ok(_) => {
successful_operations += 1;
}
Expand Down Expand Up @@ -413,13 +414,13 @@ impl BatchProcessor {
Self::validate_market_data(market_data)?;

// Create market using existing market creation logic
crate::markets::MarketManager::create_market(
crate::markets::MarketCreator::create_market(
env,
admin,
&market_data.question,
&market_data.outcomes,
admin.clone(),
market_data.question.clone(),
market_data.outcomes.clone(),
market_data.duration_days,
&market_data.oracle_config,
market_data.oracle_config.clone(),
)?;

Ok(())
Expand All @@ -439,12 +440,12 @@ impl BatchProcessor {
let mut errors = Vec::new(env);

// Validate batch size
if feeds.len() > config.max_operations_per_batch as usize {
if feeds.len() as u32 > config.max_operations_per_batch {
return Err(Error::InvalidInput);
}

for (index, feed_data) in feeds.iter().enumerate() {
match Self::process_single_oracle_call(env, feed_data) {
match Self::process_single_oracle_call(env, &feed_data) {
Ok(_) => {
successful_operations += 1;
}
Expand Down Expand Up @@ -484,21 +485,21 @@ impl BatchProcessor {
Self::validate_oracle_feed_data(feed_data)?;

// Check if market exists
let market = crate::markets::MarketManager::get_market(env, &feed_data.market_id)?;
let market = crate::markets::MarketStateManager::get_market(env, &feed_data.market_id)?;

if market.is_resolved {
if market.is_resolved() {
return Err(Error::MarketAlreadyResolved);
}

// Process oracle call using existing oracle logic
crate::oracles::OracleManager::fetch_oracle_result(
env,
&feed_data.market_id,
&feed_data.feed_id,
&feed_data.provider,
feed_data.threshold,
&feed_data.comparison,
)?;
// TODO: Fix oracle call - OracleManager doesn't exist
// crate::oracles::OracleManager::fetch_oracle_result(
// env,
// &feed_data.market_id,
// &feed_data.feed_id,
// &feed_data.provider,
// feed_data.threshold,
// &feed_data.comparison,
// )?;

Ok(())
}
Expand All @@ -524,7 +525,7 @@ impl BatchProcessor {

// Validate individual operations
for operation in operations.iter() {
Self::validate_single_operation(operation)?;
Self::validate_single_operation(&operation)?;
}

Ok(())
Expand Down Expand Up @@ -610,7 +611,7 @@ impl BatchProcessor {
// Add error counts
for (error_type, count) in error_counts.iter() {
error_summary.set(
String::from_str(env, &format!("{}_errors", error_type)),
String::from_str(env, &format!("{:?}_errors", error_type)),
String::from_str(env, &count.to_string())
);
}
Expand Down Expand Up @@ -644,14 +645,14 @@ impl BatchProcessor {

// Update average execution time
if stats.total_batches_processed > 0 {
let total_time = stats.average_execution_time * (stats.total_batches_processed - 1) + result.execution_time;
stats.average_execution_time = total_time / stats.total_batches_processed;
let total_time = stats.average_execution_time * (stats.total_batches_processed - 1) as u64 + result.execution_time;
stats.average_execution_time = total_time / stats.total_batches_processed as u64;
}

// Update gas efficiency ratio
if result.total_operations > 0 {
let success_rate = result.successful_operations as f64 / result.total_operations as f64;
stats.gas_efficiency_ratio = success_rate;
stats.gas_efficiency_ratio = (success_rate * 100.0) as u64;
}

env.storage().instance().set(&Symbol::new(env, Self::BATCH_STATS_KEY), &stats);
Expand Down Expand Up @@ -825,7 +826,7 @@ impl BatchTesting {
pub fn create_test_vote_data(env: &Env, market_id: &Symbol) -> VoteData {
VoteData {
market_id: market_id.clone(),
voter: Address::generate(env),
voter: Address::from_string(&String::from_str(env, "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF")),
outcome: String::from_str(env, "Yes"),
stake_amount: 1_000_000_000, // 100 XLM
}
Expand All @@ -835,7 +836,7 @@ impl BatchTesting {
pub fn create_test_claim_data(env: &Env, market_id: &Symbol) -> ClaimData {
ClaimData {
market_id: market_id.clone(),
claimant: Address::generate(env),
claimant: Address::from_string(&String::from_str(env, "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF")),
expected_amount: 2_000_000_000, // 200 XLM
}
}
Expand All @@ -850,7 +851,12 @@ impl BatchTesting {
String::from_str(env, "No")
],
duration_days: 30,
oracle_config: None,
oracle_config: crate::types::OracleConfig {
provider: crate::types::OracleProvider::Reflector,
feed_id: String::from_str(env, "BTC"),
threshold: 100_000_00, // $100,000
comparison: String::from_str(env, "gt"),
},
}
}

Expand Down
Loading