magicblock_magic_program_api/
args.rs

1use serde::{Deserialize, Serialize};
2use solana_program::{
3    account_info::AccountInfo,
4    instruction::{AccountMeta, Instruction},
5};
6
7use crate::Pubkey;
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub struct ActionArgs {
11    pub escrow_index: u8,
12    pub data: Vec<u8>,
13}
14
15#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
16pub struct BaseActionArgs {
17    pub args: ActionArgs,
18    pub compute_units: u32, // compute units your action will use
19    pub escrow_authority: u8, // index of account authorizing action on actor pda
20    pub destination_program: Pubkey, // address of destination program
21    pub accounts: Vec<ShortAccountMeta>, // short account metas
22}
23
24#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
25pub enum CommitTypeArgs {
26    Standalone(Vec<u8>), // indices on accounts
27    WithBaseActions {
28        committed_accounts: Vec<u8>, // indices of accounts
29        base_actions: Vec<BaseActionArgs>,
30    },
31}
32
33impl CommitTypeArgs {
34    pub fn committed_accounts_indices(&self) -> &Vec<u8> {
35        match self {
36            Self::Standalone(value) => value,
37            Self::WithBaseActions {
38                committed_accounts, ..
39            } => committed_accounts,
40        }
41    }
42}
43
44#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
45pub enum UndelegateTypeArgs {
46    Standalone,
47    WithBaseActions { base_actions: Vec<BaseActionArgs> },
48}
49
50#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
51pub struct CommitAndUndelegateArgs {
52    pub commit_type: CommitTypeArgs,
53    pub undelegate_type: UndelegateTypeArgs,
54}
55
56impl CommitAndUndelegateArgs {
57    pub fn committed_accounts_indices(&self) -> &Vec<u8> {
58        self.commit_type.committed_accounts_indices()
59    }
60}
61
62#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
63pub enum MagicBaseIntentArgs {
64    BaseActions(Vec<BaseActionArgs>),
65    Commit(CommitTypeArgs),
66    CommitAndUndelegate(CommitAndUndelegateArgs),
67}
68
69/// A compact account meta used for base-layer actions.
70///
71/// Unlike `solana_sdk::instruction::AccountMeta`, this type **does not** carry an
72/// `is_signer` flag. Users cannot request signatures: the only signer available
73/// is the validator.
74#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
75pub struct ShortAccountMeta {
76    pub pubkey: Pubkey,
77    /// Whether this account should be marked **writable**
78    /// in the Base layer instruction built from this action.
79    pub is_writable: bool,
80}
81impl From<AccountMeta> for ShortAccountMeta {
82    fn from(value: AccountMeta) -> Self {
83        Self {
84            pubkey: value.pubkey,
85            is_writable: value.is_writable,
86        }
87    }
88}
89
90impl<'a> From<AccountInfo<'a>> for ShortAccountMeta {
91    fn from(value: AccountInfo<'a>) -> Self {
92        Self::from(&value)
93    }
94}
95
96impl<'a> From<&AccountInfo<'a>> for ShortAccountMeta {
97    fn from(value: &AccountInfo<'a>) -> Self {
98        Self {
99            pubkey: *value.key,
100            is_writable: value.is_writable,
101        }
102    }
103}
104
105#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
106pub struct ScheduleTaskArgs {
107    pub task_id: u64,
108    pub execution_interval_millis: u64,
109    pub iterations: u64,
110    pub instructions: Vec<Instruction>,
111}