Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
scarb 2.11.3
starknet-foundry 0.40.0
starknet-foundry 0.46.0
8 changes: 4 additions & 4 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ dependencies = [

[[package]]
name = "snforge_scarb_plugin"
version = "0.39.0"
version = "0.46.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:61ae2333de26d9e6e4b535916f8da7916bfd95c951c765c6fbd36038289a636c"
checksum = "sha256:6ffa10fe0ff525678138afd584fc2012e7b248f9c8e7b44aeae033cef3ee7826"

[[package]]
name = "snforge_std"
version = "0.39.0"
version = "0.46.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:31f118f54e5d87393e50c07e8c052f03ff4af945a2b65b56e6edbd3b5b7fd127"
checksum = "sha256:a4d4b4d3e8506a3907d1eabacb058c390aa13a70132f475cba5e3dcd7a60d0bb"
dependencies = [
"snforge_scarb_plugin",
]
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ openzeppelin = "1.0.0"
pragma_lib = { git = "https://github.com/astraly-labs/pragma-lib" }

[dev-dependencies]
snforge_std = "0.39.0"
snforge_std = "0.46.0"
assert_macros = "2.9.4"

[[target.starknet-contract]]
Expand Down
120 changes: 118 additions & 2 deletions src/base/events.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Import necessary types
use starknet::ContractAddress;
use starknet::{ContractAddress, ClassHash};
use crate::base::types::Status;

// Events module
pub mod Events {
use super::{ContractAddress, Status};
use super::{ContractAddress, ClassHash, Status};

/// @notice Emitted when a bet is placed on a pool.
/// @param pool_id Pool where bet was placed
Expand All @@ -15,8 +15,10 @@ pub mod Events {
#[derive(Drop, starknet::Event)]
pub struct BetPlaced {
/// @notice The pool ID.
#[key]
pub pool_id: u256,
/// @notice The address of the user who placed the bet.
#[key]
pub address: ContractAddress,
/// @notice The option selected by the user.
pub option: felt252,
Expand All @@ -32,7 +34,9 @@ pub mod Events {
/// @param amount Amount of tokens staked
#[derive(Drop, starknet::Event)]
pub struct UserStaked {
#[key]
pub pool_id: u256,
#[key]
pub address: ContractAddress,
pub amount: u256,
}
Expand Down Expand Up @@ -68,6 +72,7 @@ pub mod Events {
/// @param timestamp Time of the state transition
#[derive(Drop, starknet::Event)]
pub struct PoolStateTransition {
#[key]
pub pool_id: u256,
pub previous_status: Status,
pub new_status: Status,
Expand All @@ -82,6 +87,7 @@ pub mod Events {
/// @param min_bet_amount Minimum bet requirement
#[derive(Drop, starknet::Event)]
pub struct PoolResolved {
#[key]
pub pool_id: u256,
pub winning_option: bool,
pub total_payout: u256,
Expand Down Expand Up @@ -116,7 +122,9 @@ pub mod Events {
/// @param caller Address of the admin who performed the addition
#[derive(Drop, starknet::Event)]
pub struct ValidatorAdded {
#[key]
pub account: ContractAddress,
#[key]
pub caller: ContractAddress,
}

Expand All @@ -125,7 +133,9 @@ pub mod Events {
/// @param caller Address of the admin who performed the removal
#[derive(Drop, starknet::Event)]
pub struct ValidatorRemoved {
#[key]
pub account: ContractAddress,
#[key]
pub caller: ContractAddress,
}

Expand All @@ -135,7 +145,9 @@ pub mod Events {
/// @param timestamp Time of dispute initiation
#[derive(Drop, starknet::Event)]
pub struct DisputeRaised {
#[key]
pub pool_id: u256,
#[key]
pub user: ContractAddress,
pub timestamp: u64,
}
Expand Down Expand Up @@ -258,4 +270,108 @@ pub mod Events {
pub admin: ContractAddress,
pub timestamp: u64,
}

// Configuration Events

/// @notice Emitted when the required validator confirmations count is updated.
#[derive(Drop, starknet::Event)]
pub struct ValidatorConfirmationsUpdated {
pub previous_count: u256,
pub new_count: u256,
#[key]
pub admin: ContractAddress,
pub timestamp: u64,
}

/// @notice Emitted when the dispute threshold is updated.
#[derive(Drop, starknet::Event)]
pub struct DisputeThresholdUpdated {
pub previous_threshold: u256,
pub new_threshold: u256,
pub admin: ContractAddress,
pub timestamp: u64,
}

// Pool Lifecycle Events

/// @notice Emitted when a new pool is created.
#[derive(Drop, starknet::Event)]
pub struct PoolCreated {
#[key]
pub pool_id: u256,
#[key]
pub creator: ContractAddress,
pub pool_name: felt252,
#[key]
pub category: felt252,
pub end_time: u64,
pub min_bet_amount: u256,
pub max_bet_amount: u256,
pub creator_fee: u8,
pub timestamp: u64,
}

// Contract Management Events

/// @notice Emitted when the contract is paused.
#[derive(Drop, starknet::Event)]
pub struct ContractPaused {
#[key]
pub admin: ContractAddress,
pub timestamp: u64,
}

/// @notice Emitted when the contract is unpaused.
#[derive(Drop, starknet::Event)]
pub struct ContractUnpaused {
#[key]
pub admin: ContractAddress,
pub timestamp: u64,
}

/// @notice Emitted when the contract is upgraded.
#[derive(Drop, starknet::Event)]
pub struct ContractUpgraded {
pub admin: ContractAddress,
pub new_class_hash: ClassHash,
pub timestamp: u64,
}

// Fee Collection Events

/// @notice Emitted when protocol fees are collected.
#[derive(Drop, starknet::Event)]
pub struct ProtocolFeesCollected {
pub pool_id: u256,
pub amount: u256,
pub recipient: ContractAddress,
pub timestamp: u64,
}

/// @notice Emitted when creator fees are collected.
#[derive(Drop, starknet::Event)]
pub struct CreatorFeesCollected {
pub pool_id: u256,
pub creator: ContractAddress,
pub amount: u256,
pub timestamp: u64,
}

/// @notice Emitted when validator fees are distributed.
#[derive(Drop, starknet::Event)]
pub struct ValidatorFeesDistributed {
pub pool_id: u256,
pub total_amount: u256,
pub validator_count: u256,
pub timestamp: u64,
}

/// @notice Emitted when pool creation fee is collected.
#[derive(Drop, starknet::Event)]
pub struct PoolCreationFeeCollected {
pub pool_id: u256,
pub creator: ContractAddress,
pub amount: u256,
pub timestamp: u64,
}
}
114 changes: 108 additions & 6 deletions src/predifi.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ pub mod Predifi {
};
use crate::base::errors::Errors;
use crate::base::events::Events::{
BetPlaced, DisputeRaised, DisputeResolved, EmergencyActionCancelled,
BetPlaced, ContractPaused, ContractUnpaused, ContractUpgraded, CreatorFeesCollected,
DisputeRaised, DisputeResolved, DisputeThresholdUpdated, EmergencyActionCancelled,
EmergencyActionExecuted, EmergencyActionScheduled, EmergencyWithdrawal, FeeWithdrawn,
FeesCollected, PoolAutomaticallySettled, PoolCancelled, PoolEmergencyFrozen,
PoolEmergencyResolved, PoolEmergencyUnfrozen, PoolResolved, PoolStateTransition,
PoolSuspended, StakeRefunded, UserStaked, ValidatorAdded, ValidatorRemoved,
FeesCollected, PoolAutomaticallySettled, PoolCancelled, PoolCreated,
PoolCreationFeeCollected, PoolEmergencyFrozen, PoolEmergencyResolved,
PoolEmergencyUnfrozen, PoolResolved, PoolStateTransition, PoolSuspended,
ProtocolFeesCollected, StakeRefunded, UserStaked, ValidatorAdded,
ValidatorConfirmationsUpdated, ValidatorFeesDistributed, ValidatorRemoved,
ValidatorResultSubmitted, ValidatorsAssigned,
};
use crate::base::security::{Security, SecurityTrait};

// package imports
use crate::base::types::{
EmergencyAction, EmergencyActionStatus, EmergencyActionType, EmergencyPoolState,
PoolDetails, PoolOdds, Status, UserStake, u8_to_category, u8_to_pool, u8_to_status,
CategoryType, EmergencyAction, EmergencyActionStatus, EmergencyActionType,
EmergencyPoolState, PoolDetails, PoolOdds, Status, UserStake, u8_to_category, u8_to_pool,
u8_to_status,
};
use crate::interfaces::ipredifi::{IPredifi, IPredifiDispute, IPredifiValidator};

Expand Down Expand Up @@ -205,6 +209,30 @@ pub mod Predifi {
EmergencyActionExecuted: EmergencyActionExecuted,
/// @notice Emitted when a scheduled emergency action is cancelled.
EmergencyActionCancelled: EmergencyActionCancelled,
// Configuration Events
/// @notice Emitted when validator confirmations requirement is updated.
ValidatorConfirmationsUpdated: ValidatorConfirmationsUpdated,
/// @notice Emitted when dispute threshold is updated.
DisputeThresholdUpdated: DisputeThresholdUpdated,
// Pool Lifecycle Events
/// @notice Emitted when a new pool is created.
PoolCreated: PoolCreated,
// Contract Management Events
/// @notice Emitted when the contract is paused.
ContractPaused: ContractPaused,
/// @notice Emitted when the contract is unpaused.
ContractUnpaused: ContractUnpaused,
/// @notice Emitted when the contract is upgraded.
ContractUpgraded: ContractUpgraded,
// Fee Collection Events
/// @notice Emitted when protocol fees are collected.
ProtocolFeesCollected: ProtocolFeesCollected,
/// @notice Emitted when creator fees are collected.
CreatorFeesCollected: CreatorFeesCollected,
/// @notice Emitted when validator fees are distributed.
ValidatorFeesDistributed: ValidatorFeesDistributed,
/// @notice Emitted when pool creation fee is collected.
PoolCreationFeeCollected: PoolCreationFeeCollected,
#[flat]
AccessControlEvent: AccessControlComponent::Event,
#[flat]
Expand Down Expand Up @@ -360,6 +388,35 @@ pub mod Predifi {
// Add to pool count
self.pool_count.write(self.pool_count.read() + 1);

// Emit pool created event
self.emit(
Event::PoolCreated(
PoolCreated {
pool_id,
creator: creator_address,
pool_name: poolName,
category: CategoryType(u8_to_category(category)),
end_time: poolEndTime,
min_bet_amount: minBetAmount,
max_bet_amount: maxBetAmount,
creator_fee: creatorFee,
timestamp: get_block_timestamp(),
}
)
);

// Emit pool creation fee collected event
self.emit(
Event::PoolCreationFeeCollected(
PoolCreationFeeCollected {
pool_id,
creator: creator_address,
amount: ONE_STRK,
timestamp: get_block_timestamp(),
}
)
);

pool_id
}

Expand Down Expand Up @@ -1515,7 +1572,21 @@ pub mod Predifi {
// Only admin can set this
self.accesscontrol.assert_only_role(DEFAULT_ADMIN_ROLE);
self.assert_positive_count(count);

let previous_count = self.required_validator_confirmations.read();
self.required_validator_confirmations.write(count);

// Emit event for validator confirmations update
self.emit(
Event::ValidatorConfirmationsUpdated(
ValidatorConfirmationsUpdated {
previous_count,
new_count: count,
admin: get_caller_address(),
timestamp: get_block_timestamp(),
}
)
);
}

/// @notice Gets the validators assigned to a pool.
Expand Down Expand Up @@ -1723,6 +1794,16 @@ pub mod Predifi {
self.accesscontrol.assert_only_role(DEFAULT_ADMIN_ROLE);

self.pausable.pause();

// Emit custom contract paused event
self.emit(
Event::ContractPaused(
ContractPaused {
admin: get_caller_address(),
timestamp: get_block_timestamp(),
}
)
);
}

/// @notice Unpauses the contract and resumes normal operations
Expand All @@ -1732,6 +1813,16 @@ pub mod Predifi {
self.accesscontrol.assert_only_role(DEFAULT_ADMIN_ROLE);

self.pausable.unpause();

// Emit custom contract unpaused event
self.emit(
Event::ContractUnpaused(
ContractUnpaused {
admin: get_caller_address(),
timestamp: get_block_timestamp(),
}
)
);
}

/// @notice Upgrades the contract implementation
Expand All @@ -1744,6 +1835,17 @@ pub mod Predifi {

// Replace the class hash, hence upgrading the contract
self.upgradeable.upgrade(new_class_hash);

// Emit contract upgraded event
self.emit(
Event::ContractUpgraded(
ContractUpgraded {
admin: get_caller_address(),
new_class_hash,
timestamp: get_block_timestamp(),
}
)
);
}
}

Expand Down
Loading
Loading