gmsol_competition/
lib.rs

1use anchor_lang::prelude::*;
2
3pub mod error;
4pub mod instructions;
5pub mod states;
6
7pub use error::CompetitionError;
8pub use instructions::*;
9
10declare_id!("2AxuNr6euZPKQbTwNsLBjzFTZFAevA85F4PW9m9Dv8pc");
11
12#[program]
13pub mod gmsol_competition {
14    use super::*;
15
16    /// Initialize the global [`Competition`](crate::states::Competition) PDA.
17    #[allow(clippy::too_many_arguments)]
18    pub fn initialize_competition(
19        ctx: Context<InitializeCompetition>,
20        start_time: i64,
21        end_time: i64,
22        volume_threshold: u128,
23        extension_duration: i64,
24        extension_cap: i64,
25        only_count_increase: bool,
26        volume_merge_window: i64,
27    ) -> Result<()> {
28        InitializeCompetition::invoke(
29            ctx,
30            start_time,
31            end_time,
32            volume_threshold,
33            extension_duration,
34            extension_cap,
35            only_count_increase,
36            volume_merge_window,
37        )
38    }
39
40    /// Create [`Participant`](crate::states::Participant) PDA idempotently.
41    pub fn create_participant_idempotent(ctx: Context<CreateParticipantIdempotent>) -> Result<()> {
42        CreateParticipantIdempotent::invoke(ctx)
43    }
44
45    // ---------------------------------------------------------------------
46    // Callbacks expected by the GMX‑Solana store‑program
47    // ---------------------------------------------------------------------
48
49    /// Triggered immediately **after an order is created**.  
50    /// The competition logic is unaffected, so this is a no‑op kept only
51    /// for interface compatibility.
52    pub fn on_created(
53        ctx: Context<OnCreated>,
54        authority_bump: u8,
55        action_kind: u8,
56        callback_version: u8,
57        extra_account_count: u8,
58    ) -> Result<()> {
59        OnCreated::invoke(
60            ctx,
61            authority_bump,
62            action_kind,
63            callback_version,
64            extra_account_count,
65        )
66    }
67
68    /// Triggered when an order is updated.  
69    /// Currently ignored by the competition contract.
70    pub fn on_updated(
71        _ctx: Context<OnCallback>,
72        _authority_bump: u8,
73        _action_kind: u8,
74        _callback_version: u8,
75        _extra_account_count: u8,
76    ) -> Result<()> {
77        Ok(())
78    }
79
80    /// Triggered when an order is **executed**.  
81    /// Updates the participant statistics and the on‑chain leaderboard.
82    pub fn on_executed(
83        ctx: Context<OnExecuted>,
84        authority_bump: u8,
85        action_kind: u8,
86        callback_version: u8,
87        success: bool,
88        extra_account_count: u8,
89    ) -> Result<()> {
90        OnExecuted::invoke(
91            ctx,
92            authority_bump,
93            action_kind,
94            callback_version,
95            success,
96            extra_account_count,
97        )
98    }
99
100    /// Triggered when an order is **closed / cancelled**.  
101    /// Currently ignored by the competition contract.
102    pub fn on_closed(
103        _ctx: Context<OnCallback>,
104        _authority_bump: u8,
105        _action_kind: u8,
106        _callback_version: u8,
107        _extra_account_count: u8,
108    ) -> Result<()> {
109        Ok(())
110    }
111
112    /// Close the participant account and recover rent.
113    pub fn close_participant(ctx: Context<CloseParticipant>) -> Result<()> {
114        CloseParticipant::invoke(ctx)
115    }
116}