Skip to content

Commit dadfd0c

Browse files
committed
docs: add rustdoc to disputes public entrypoints
1 parent 489fb5a commit dadfd0c

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

contracts/predictify-hybrid/src/disputes.rs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,22 @@ impl DisputeManager {
813813
Ok(())
814814
}
815815

816+
/// Validates that a market is ready for dispute resolution.
817+
///
818+
/// Checks that an oracle result is available and that the market has at least
819+
/// one dispute stake. Called by [`DisputeManager::resolve_dispute`] before
820+
/// computing the final outcome.
821+
///
822+
/// # Parameters
823+
///
824+
/// * `_env` - The Soroban environment (unused in this function)
825+
/// * `market` - The market to validate
826+
/// * `admin` - Address of the admin performing resolution
827+
///
828+
/// # Errors
829+
///
830+
/// - [`Error::OracleResultNotAvailable`] — no oracle result has been submitted
831+
/// - [`Error::NoDisputesFound`] — no dispute stakes exist on this market
816832
pub fn validate_market_for_resolution(
817833
_env: &Env,
818834
market: &Market,
@@ -829,13 +845,29 @@ impl DisputeManager {
829845
Ok(())
830846
}
831847

848+
/// Validates dispute timeout parameters.
849+
///
850+
/// `timeout_hours` must be between 1 and 720 (30 days). Used by
851+
/// [`DisputeManager::set_dispute_timeout`].
852+
///
853+
/// # Errors
854+
///
855+
/// - [`Error::InvalidDuration`] — `timeout_hours` is 0 or exceeds 720
832856
pub fn validate_dispute_timeout_parameters(timeout_hours: u32) -> Result<(), Error> {
833857
if timeout_hours == 0 || timeout_hours > 720 {
834858
return Err(Error::InvalidDuration);
835859
}
836860
Ok(())
837861
}
838862

863+
/// Validates dispute timeout extension parameters.
864+
///
865+
/// `extension_hours` must be between 1 and 168 (7 days). Used by
866+
/// [`DisputeManager::extend_dispute_timeout`].
867+
///
868+
/// # Errors
869+
///
870+
/// - [`Error::InvalidDuration`] — `extension_hours` is 0 or exceeds 168
839871
pub fn validate_dispute_timeout_extension_parameters(extension_hours: u32) -> Result<(), Error> {
840872
if extension_hours == 0 || extension_hours > 168 {
841873
return Err(Error::InvalidDuration);
@@ -847,6 +879,35 @@ impl DisputeManager {
847879
pub struct DisputeManager;
848880

849881
impl DisputeManager {
882+
/// Processes a user's formal dispute against a market's oracle resolution.
883+
///
884+
/// Validates market eligibility, dispute parameters, and anti-grief floor
885+
/// before creating and persisting the dispute record.
886+
///
887+
/// # Authorization
888+
///
889+
/// Requires `user.require_auth()`.
890+
///
891+
/// # Parameters
892+
///
893+
/// * `env` - The Soroban environment for blockchain operations
894+
/// * `user` - Address of the user initiating the dispute
895+
/// * `market_id` - Unique identifier of the market being disputed
896+
/// * `stake` - Amount to stake on the dispute (in stroops)
897+
/// * `reason` - Optional explanation for the dispute
898+
///
899+
/// # Returns
900+
///
901+
/// Returns the created [`Dispute`] record on success.
902+
///
903+
/// # Errors
904+
///
905+
/// - [`Error::MarketClosed`] — market has not ended yet
906+
/// - [`Error::MarketResolved`] — market is already resolved
907+
/// - [`Error::OracleUnavailable`] — no oracle result to dispute
908+
/// - [`Error::InsufficientStake`] — stake below minimum
909+
/// - [`Error::AlreadyDisputed`] — user already disputed this market
910+
/// - [`Error::DisputeStakeCapExceeded`] — per-user or cumulative cap exceeded
850911
pub fn process_dispute(
851912
env: &Env,
852913
user: Address,
@@ -892,6 +953,27 @@ impl DisputeManager {
892953
Ok(dispute)
893954
}
894955

956+
/// Casts a vote on a dispute, transferring stake as economic commitment.
957+
///
958+
/// Records the vote in the market's vote map, updates the total staked
959+
/// amount, and runs collusion detection against recent dispute activity.
960+
///
961+
/// # Authorization
962+
///
963+
/// Requires `user.require_auth()`.
964+
///
965+
/// # Parameters
966+
///
967+
/// * `env` - The Soroban environment for blockchain operations
968+
/// * `user` - Address of the user casting the vote
969+
/// * `market_id` - Unique identifier of the disputed market
970+
/// * `vote` - The outcome the user is voting for
971+
/// * `stake` - Amount to stake with the vote (in stroops)
972+
///
973+
/// # Errors
974+
///
975+
/// - [`Error::InsufficientStake`] — `stake` is zero or negative
976+
/// - [`Error::Overflow`] — arithmetic overflow when adding stakes
895977
pub fn vote_on_dispute(
896978
env: &Env,
897979
user: Address,
@@ -957,6 +1039,32 @@ impl DisputeManager {
9571039
Ok(())
9581040
}
9591041

1042+
/// Resolves a dispute by combining oracle data with community voting.
1043+
///
1044+
/// Computes the final outcome by weighing the oracle result against
1045+
/// community consensus. If the oracle is overturned, all disputers
1046+
/// receive their stakes back via refund transfers.
1047+
///
1048+
/// # Authorization
1049+
///
1050+
/// Requires `admin.require_auth()` and that `admin` matches the stored
1051+
/// contract admin.
1052+
///
1053+
/// # Parameters
1054+
///
1055+
/// * `env` - The Soroban environment for blockchain operations
1056+
/// * `market_id` - Unique identifier of the market to resolve
1057+
/// * `admin` - Address of the admin performing the resolution
1058+
///
1059+
/// # Returns
1060+
///
1061+
/// Returns a [`DisputeResolution`] containing the final outcome and metadata.
1062+
///
1063+
/// # Errors
1064+
///
1065+
/// - [`Error::Unauthorized`] — caller does not match stored contract admin
1066+
/// - [`Error::OracleResultNotAvailable`] — no oracle result submitted
1067+
/// - [`Error::NoDisputesFound`] — no dispute stakes exist on this market
9601068
pub fn resolve_dispute(
9611069
env: &Env,
9621070
market_id: Symbol,
@@ -3335,6 +3443,15 @@ impl DisputeAnalytics {
33353443
}
33363444
}
33373445

3446+
/// Returns a snapshot of timeout analytics for a specific dispute.
3447+
///
3448+
/// Includes remaining time, expiration status, and extension count.
3449+
/// Returns a zero-valued snapshot when no timeout is configured.
3450+
///
3451+
/// # Parameters
3452+
///
3453+
/// * `env` - The Soroban environment for blockchain operations
3454+
/// * `dispute_id` - Unique identifier of the dispute to inspect
33383455
pub fn get_timeout_analytics(env: &Env, dispute_id: &Symbol) -> TimeoutAnalytics {
33393456
match DisputeUtils::get_dispute_timeout(env, dispute_id) {
33403457
Ok(timeout) => {

0 commit comments

Comments
 (0)