Skip to main content

Competitition contract

Consumers can use a competition template. For example, in the competition contract, store the following:

  • Creation time: Timestamp of the competition contract creation
  • Duration: Time until the end of the competition
  • Staking amounts: Amount of tokens staked by users in the protocol
  • Slash parameters: Conditions under which the consumer is penalized for cheating and how the validator can detect such cheating
  • Post-competition parameters: Details for modeler compensation
  • Cancellation parameters: Conditions under which the competition creator can cancel (e.g., phrase A, phrase B, phrase C)
  • Data return to Credio: Based on template rules, specify whether data is pushed or pulled

Overview

The competition contract is designed to manage competitions involving modelers and validators. It includes mechanisms for model submission, evaluation, and reward distribution.

Dependencies

IVault

Interface for vault operations: Includes methods for checking balance (balanceOf), depositing funds (deposit), and withdrawing funds (withdraw).

ICredio

Interface for managing competitions: Includes methods for validating addresses and closing competitions.

TransferHelper

Library for safe token transfers: Provides functions for securely transferring tokens.

BytesLib

Library for byte manipulation: Provides functions for handling and processing byte data.

State Variables

factory

Address of the factory contract.

creator

Address of the competition creator.

vault

Address of the vault contract.

token

Address of the ERC20 token used for staking and rewards.

totalStake

Total amount staked in the competition.

totalClaimed

Total amount of rewards claimed.

ipfsCompetitionDetail

IPFS hash containing competition details.

payer

Address responsible for paying rewards.

consumer

Address consuming the service or competition results.

feePerRequest

Fee per request made during the competition.

modelerFeePercent

Percentage of the total fee allocated to modelers.

validatorFeePercent

Percentage of the total fee allocated to validators.

minStakeAmount

Minimum stake amount required for modelers.

batchSizes

Array of batch sizes for validation.

ipfsGradingDetail

IPFS hash containing grading details.

winner

Address of the competition winner.

startCompetition

Timestamp of when the competition starts.

submitDeadline

Timestamp of the submission deadline.

isCompetitionEnd

Boolean indicating whether the competition has ended.

balances

Mapping of address to balance (stake amount).

modelers

Mapping of address to ModelerCommit struct (commit details and stake amount).

verifiers

Mapping of modeler address to batch size and verifier address.

claimed

Mapping of address to amount claimed.

Structs

ModelerCommit

Struct containing IPFS commit details and stake amount.

Events

ModelCommitted

Emitted when a modeler commits a model.

Grading

Emitted when grading is completed.

Withdrawal

Emitted when a stake is withdrawn.

Collected

Emitted when rewards are collected.

Errors

Unauthorized

Thrown when an unauthorized action is attempted.

AlreadyCommitted

Thrown when a modeler attempts to commit more than once.

LengthMismatch

Thrown when the length of verifiers and batch sizes mismatch.

WinnerCannotUnstake

Thrown when the winner attempts to unstake.

LateSubmission

Thrown when a submission is made after the deadline.

GradingUnavailable

Thrown when grading is attempted before the submission deadline.

UnstakeUnavailable

Thrown when unstaking is attempted before the competition ends.

InvalidFeeDistribution

Thrown when the sum of modeler and validator fees is not 100.

InSufficientAmount

Thrown when the stake amount is below the minimum required.

Modifiers

onlyValidator

Restricts function access to validators only.

Functions

initialize

Initializes the contract with creator, vault, token, and competition details.

_beforeCommit

Internal function to handle pre-commit checks and token transfers.

commitModel

Allows a modeler to commit a model with a stake amount.

grading

Allows a validator to grade the competition and declare a winner.

endCompetition

Internal function to end the competition and close it in the factory contract.

withdrawStake

Allows participants to withdraw their stake after the competition ends.

collect

Allows validators and winners to collect their rewards.

_decodeParams

Internal function to decode competition parameters from calldata.