gmsol_callback/
lib.rs

1//! This crate defines the callback interface for the GMX-Solana protocol
2//! and provide an example implementation.
3
4/// Definition of the core structure.
5pub mod states;
6
7/// Definition of the instructions.
8pub mod instructions;
9
10/// Definitions of common types.
11#[cfg(feature = "types")]
12pub mod types;
13
14/// Definition of the callback interface.
15#[cfg(feature = "interface")]
16pub mod interface;
17
18use anchor_lang::prelude::*;
19
20use instructions::*;
21
22declare_id!("9JtQ9fBS91b2YxmHXNeGE8ipQYhLd2DRGGZSV8SPTJGw");
23
24/// Seed for the callback authority.
25#[constant]
26pub const CALLBACK_AUTHORITY_SEED: &[u8] = b"callback";
27
28#[program]
29pub mod gmsol_callback {
30    use super::*;
31
32    /// Initialize the [`Config`](crate::states::Config) account.
33    pub fn initialize_config(ctx: Context<InitializeConfig>) -> Result<()> {
34        InitializeConfig::invoke(ctx, "callback".to_string())
35    }
36
37    /// Create [`ActionStats`](crate::states::ActionStats) account idempotently.
38    pub fn create_action_stats_idempotent(
39        ctx: Context<CreateActionStatsIdempotent>,
40        action_kind: u8,
41    ) -> Result<()> {
42        CreateActionStatsIdempotent::invoke(ctx, action_kind)
43    }
44
45    /// Callback expected to be invoked when an action is created.
46    pub fn on_created(
47        ctx: Context<OnCallback>,
48        authority_bump: u8,
49        action_kind: u8,
50        callback_version: u8,
51        extra_account_count: u8,
52    ) -> Result<()> {
53        OnCallback::invoke(
54            On::Created,
55            ctx,
56            authority_bump,
57            action_kind,
58            callback_version,
59            true,
60            extra_account_count,
61        )
62    }
63
64    /// Callback expected to be invoked when an action is updated.
65    pub fn on_updated(
66        ctx: Context<OnCallback>,
67        authority_bump: u8,
68        action_kind: u8,
69        callback_version: u8,
70        extra_account_count: u8,
71    ) -> Result<()> {
72        OnCallback::invoke(
73            On::Updated,
74            ctx,
75            authority_bump,
76            action_kind,
77            callback_version,
78            true,
79            extra_account_count,
80        )
81    }
82
83    /// Callback expected to be invoked when an action is executed.
84    pub fn on_executed(
85        ctx: Context<OnCallback>,
86        authority_bump: u8,
87        action_kind: u8,
88        callback_version: u8,
89        success: bool,
90        extra_account_count: u8,
91    ) -> Result<()> {
92        OnCallback::invoke(
93            On::Executed,
94            ctx,
95            authority_bump,
96            action_kind,
97            callback_version,
98            success,
99            extra_account_count,
100        )
101    }
102
103    /// Callback expected to be invoked when an action is closed.
104    pub fn on_closed(
105        ctx: Context<OnCallback>,
106        authority_bump: u8,
107        action_kind: u8,
108        callback_version: u8,
109        extra_account_count: u8,
110    ) -> Result<()> {
111        OnCallback::invoke(
112            On::Closed,
113            ctx,
114            authority_bump,
115            action_kind,
116            callback_version,
117            true,
118            extra_account_count,
119        )
120    }
121}