Budokan: Key Functions
This section details the primary functions exposed by the Budokan tournament system and its core data structures.
Component Architecture
Budokan is built by composing reusable Cairo components from the open-source game-components library:
| Component | Purpose |
|---|---|
| PrizeComponent | Prize pool management, ERC20/ERC721 deposits, distribution, and claims |
| EntryFeeComponent | Entry fee collection, share splitting (creator, refund, protocol fee, prize pool), and payouts |
| LeaderboardComponent | Score submission, ranking, and position tracking with hooks |
| RegistrationComponent | Entry tracking, entry counts, and ban management |
| EntryRequirementComponent | Entry gating via token ownership, tournament qualification, or extension validators |
These components are not Budokan-specific — they are general-purpose building blocks from the Metagame Extensions package. Anyone can compose them to build their own tournament or competition system with custom prize logic, entry fee handling, or scoring rules.
For example, you could build a platform that uses the same PrizeComponent and LeaderboardComponent but with entirely different entry mechanics, or extend the EntryFeeComponent with a custom distribution strategy.
IBudokan Interface
Signatures match the deployed mainnet contract, which was upgraded on 14 October 2026.
create_tournament
fn create_tournament(
ref self: TState,
creator_rewards_address: ContractAddress,
metadata: Metadata,
schedule: Schedule,
game_config: GameConfig,
entry_fee: Option<EntryFeeKind>,
entry_requirement: Option<EntryRequirement>,
leaderboard_config: LeaderboardConfig,
max_entries: u32,
) -> Tournament;Purpose: Create a tournament. A tournament with an entry fee also mints a creator token to creator_rewards_address. That token receives any prize positions nobody filled. A free tournament mints no creator token: creator_token_id is 0, and creator_rewards_address is unused.
Parameters:
creator_rewards_address: Receives the creator token when there is an entry fee.metadata: Name and description.schedule: Delay-based schedule. See Schedule and its limits.game_config: The game, its settings id, and whether entry tokens are soulbound or sponsored.entry_fee: Optional. Either Budokan's built-in ERC20 fee (EntryFeeKind::BuiltIn) or an external fee extension (EntryFeeKind::Extension).entry_requirement: Optional gate: token ownership or an extension validator.leaderboard_config: Score order, and whether the game must be over before a score counts.max_entries: Caps the field at this many entries (0= uncapped). Once the cap is filled and every entry has a ranked score, the tournament finishes early instead of waiting for its schedule. Set it whenever the field is exact, such as an invite list or fixed roster times entries per player.
Returns: the Tournament struct.
enter_tournament
fn enter_tournament(
ref self: TState,
tournament_id: u64,
player_address: Option<ContractAddress>,
qualifier: Option<ContractAddress>,
qualification: Option<QualificationProof>,
entry_fee_pay_params: Option<Span<felt252>>,
) -> (felt252, u32);Purpose: Enter a tournament. This mints a game token and pays the entry fee from the caller.
Parameters:
player_address: Who receives the game token.Nonemeans the caller. When there is an entry requirement, a different recipient is honoured only if the caller is the qualifier.qualifier: Who qualifies for entry.Nonemeans the caller. Token gates checkowner_of; extension validators receive this address and verify the proof themselves.qualification: Optional proof: an NFT token id, or extension-specific data.entry_fee_pay_params: Required forEntryFeeKind::Extensionfees. Otherwise passNone.
Returns: (game token id, entry number).
enter_tournament_for_recipients
fn enter_tournament_for_recipients(
ref self: TState,
tournament_id: u64,
recipients: Array<TournamentRecipientParams>,
) -> Array<felt252>;Purpose: Enter one tournament for many recipients in a single transaction. With the built-in fee, the caller pays N × fee in one transfer. Returns the token ids in recipient order. Each TournamentRecipientParams has the same player_address, qualifier and qualification options as enter_tournament.
submit_score
fn submit_score(
ref self: TState,
tournament_id: u64,
token_id: felt252,
position: u32,
);Purpose: Place an entry's score on the leaderboard at a claimed position, which is 1-based. The contract checks that the score belongs at that position.
claim_reward
fn claim_reward(
ref self: TState,
tournament_id: u64,
reward_type: RewardType,
);Purpose: The single settlement entrypoint after a tournament is finalized. It pays sponsored prizes and every slice of the entry-fee pool. The recipient is worked out on-chain: the leaderboard winner for a position, the creator token for an unfilled position, and the declared recipients for the creator share and protocol fee. Anyone can call it.
Parameters:
reward_type:Prize(PrizeClaim)orEntryFee(EntryFeeClaim). See RewardType.
add_prize
fn add_prize(
ref self: TState,
tournament_id: u64,
prize: Prize,
position: Option<u32>,
) -> u64;Purpose: Sponsor a prize. Prize::Token deposits ERC20 or ERC721 tokens. An ERC20 prize can be paid to a single position or spread over several with a Distribution. Prize::Extension forwards its config to an IPrizeExtension contract, which owns its own payout rules.
Returns: the new prize_id. Read the full payload from the PrizeAdded event.
ban_entry
fn ban_entry(
ref self: TState,
tournament_id: u64,
game_token_id: felt252,
proof: Span<felt252>,
);Purpose: Permissionlessly ban an entry that no longer meets the tournament's extension validator. The validator confirms the ban through should_ban. See Entry Requirements: Banning Mechanism.
View Functions
fn total_tournaments(self: @TState) -> u64;
fn tournament(self: @TState, tournament_id: u64) -> Tournament;
fn tournament_game_address(self: @TState, tournament_id: u64) -> ContractAddress;
fn current_phase(self: @TState, tournament_id: u64) -> Phase;
fn max_entries(self: @TState, tournament_id: u64) -> u32;
fn is_token_registered(self: @TState, tournament_id: u64, token_id: felt252) -> bool;
fn tournament_distribution_shares(self: @TState, tournament_id: u64) -> Array<u16>;
fn prize_distribution_shares(self: @TState, prize_id: u64) -> Array<u16>;
fn schedule_limits(self: @TState) -> ScheduleLimits;tournament_game_address: Just the game address, in one storage read. Returns zero for an unknown id.current_phase: Accounts for early finish. Once every entry has a ranked score, it reportsFinalizedearly: during the submission window for any tournament, and during play for a full, capped one.is_token_registered: Whether a game token is entered in a given tournament. Validators use it to qualify players by past participation.tournament_distribution_shares/prize_distribution_shares: The full basis-point array forDistribution::Custom. Bothtournament()and thePrizeAddedevent carry an emptyCustomto stay small.schedule_limits: The allowed range for each schedule duration. See Schedule.
Data Structures
Schedule
Phases are worked out from delays relative to the creation timestamp:
pub struct Schedule {
pub registration_start_delay: u32,
pub registration_end_delay: u32,
pub game_start_delay: u32,
pub game_end_delay: u32,
pub submission_duration: u32,
}If a tournament is created at time T:
- Registration opens at
T + registration_start_delayand closes atT + registration_end_delay. - The game starts at
T + game_start_delayand ends atT + game_start_delay + game_end_delay. - Submission ends
submission_durationafter the game ends.
A registration delay of 0 means there is no separate registration period.
Each duration must fall within the owner-set schedule_limits(). On mainnet these are currently:
| Duration | Minimum | Maximum |
|---|---|---|
| Registration period | 1 hour | 90 days |
Tournament length (game_end_delay) | 1 hour | 365 days |
| Submission period | 1 hour | 90 days |
Phase
pub enum Phase {
Scheduled,
Registration,
Staging,
Live,
Submission,
Finalized,
}LeaderboardConfig
pub struct LeaderboardConfig {
pub ascending: bool, // true = lower scores better
pub game_must_be_over: bool, // true = game_over() must be true before submission
}GameConfig
pub struct GameConfig {
pub game_address: ContractAddress, // the game is also its token
pub settings_id: u32, // must exist on the game
pub soulbound: bool,
pub paymaster: bool, // inert flag packed into the token id for sponsored play
}EntryFeeKind and EntryFee
pub enum EntryFeeKind {
BuiltIn: EntryFee,
Extension: ExtensionConfig, // an IEntryFeeExtension decides collection and payout
}
pub struct EntryFee {
pub token_address: ContractAddress,
pub amount: u128,
pub tournament_creator_share: u16, // basis points, paid to the tournament creator
pub game_fee_share: u16, // basis points; must be 0 for current game tokens
pub refund_share: u16, // basis points returned to each entry's owner
pub distribution: Distribution, // how the prize pool splits across positions
pub distribution_count: u32, // paid positions (0 = sized to the leaderboard)
}Budokan's protocol fee is set by the owner (currently 5%, 500 bps) and fixed for each tournament when it's created. The prize pool is what remains after the creator share, refund share and protocol fee.
Current game tokens have no game-fee recipient, so game_fee_share must be 0. Creation reverts otherwise.
Distribution is one of Uniform, Linear(weight), Exponential(10 × k), Geometric(a, b), Tiered(TieredConfig) or Custom(shares). See Distribution Strategies.
RewardType
pub enum RewardType {
Prize: PrizeClaim,
EntryFee: EntryFeeClaim,
}
pub enum PrizeClaim {
Token: PrizeType, // Single(prize_id) or Distributed((prize_id, position))
Extension: ExtensionPrizeClaim,
}
pub enum EntryFeeClaim {
Token: EntryFeeRewardType,
Extension: ExtensionEntryFeeClaim,
}
pub enum EntryFeeRewardType {
Position: u32,
TournamentCreator,
GameFee,
Refund: felt252, // the entry's game token id
ProtocolFee,
}Tournament
pub struct Tournament {
pub id: u64,
pub created_at: u64,
pub created_by: ContractAddress,
pub creator_token_id: felt252, // 0 for free tournaments
pub metadata: Metadata,
pub schedule: Schedule,
pub game_config: GameConfig,
pub entry_fee: Option<EntryFeeKind>,
pub entry_requirement: Option<EntryRequirement>,
pub leaderboard_config: LeaderboardConfig,
}Metadata
pub struct Metadata {
pub name: felt252,
pub description: ByteArray,
}Brackets
Knockout brackets run on a separate Bracket contract, which creates one Budokan tournament per match. See Brackets.