gmsol_treasury/
lib.rs

1/// States.
2pub mod states;
3
4/// Instructions.
5pub mod instructions;
6
7/// Roles.
8pub mod roles;
9
10/// Constants.
11pub mod constants;
12
13use anchor_lang::prelude::*;
14use gmsol_store::utils::CpiAuthenticate;
15use instructions::*;
16
17declare_id!("GTuvYD5SxkTq4FLG6JV1FQ5dkczr1AfgDcBHaFsBdtBg");
18
19#[program]
20pub mod gmsol_treasury {
21
22    use super::*;
23
24    /// Initialize a treasury [`Config`](crate::states::Config) account.
25    pub fn initialize_config(ctx: Context<InitializeConfig>) -> Result<()> {
26        instructions::initialize_config(ctx)
27    }
28
29    /// Set treasury vault config.
30    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
31    pub fn set_treasury_vault_config(ctx: Context<SetTreasuryVaultConfig>) -> Result<()> {
32        instructions::unchecked_set_treasury_vault_config(ctx)
33    }
34
35    /// Set GT factor.
36    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
37    pub fn set_gt_factor(ctx: Context<UpdateConfig>, factor: u128) -> Result<()> {
38        instructions::unchecked_set_gt_factor(ctx, factor)
39    }
40
41    /// Set buyback factor.
42    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
43    pub fn set_buyback_factor(ctx: Context<UpdateConfig>, factor: u128) -> Result<()> {
44        instructions::unchecked_set_buyback_factor(ctx, factor)
45    }
46
47    /// Initialize a [`TreasuryVaultConfig`](crate::states::TreasuryVaultConfig) account.
48    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
49    pub fn initialize_treasury_vault_config(
50        ctx: Context<InitializeTreasuryVaultConfig>,
51        index: u16,
52    ) -> Result<()> {
53        instructions::unchecked_initialize_treasury_vault_config(ctx, index)
54    }
55
56    /// Insert a token to the given [`TreasuryVaultConfig`](crate::states::TreasuryVaultConfig) account.
57    ///
58    /// # Errors
59    /// - The [`token`](InsertTokenToTreasuryVault::token) must not have been inserted.
60    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
61    pub fn insert_token_to_treasury_vault(ctx: Context<InsertTokenToTreasuryVault>) -> Result<()> {
62        instructions::unchecked_insert_token_to_treasury_vault(ctx)
63    }
64
65    /// Remove a token from the given [`TreasuryVaultConfig`](crate::states::TreasuryVaultConfig) account.
66    ///
67    /// # Errors
68    /// - The [`token`](RemoveTokenFromTreasuryVault::token) must have been inserted.
69    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
70    pub fn remove_token_from_treasury_vault(
71        ctx: Context<RemoveTokenFromTreasuryVault>,
72    ) -> Result<()> {
73        instructions::unchecked_remove_token_from_treasury_vault(ctx)
74    }
75
76    /// Toggle a flag of the given token.
77    ///
78    /// # Arguments
79    /// - `flag`: the flag to toggle.
80    /// - `value`: the value to be changed to.
81    ///
82    /// # Errors.
83    /// - The [`token`](ToggleTokenFlag::token) must be in the token list.
84    /// - `flag` must be defined in [`TokenFlag`](crate::states::treasury::TokenFlag).
85    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
86    pub fn toggle_token_flag(
87        ctx: Context<ToggleTokenFlag>,
88        flag: String,
89        value: bool,
90    ) -> Result<()> {
91        instructions::unchecked_toggle_token_flag(ctx, &flag, value)
92    }
93
94    /// Deposit to treasury vault.
95    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_KEEPER))]
96    pub fn deposit_to_treasury_vault(ctx: Context<DepositToTreasuryVault>) -> Result<()> {
97        instructions::unchecked_deposit_to_treasury_vault(ctx)
98    }
99
100    /// Withdraw from treasury vault.
101    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_WITHDRAWER))]
102    pub fn withdraw_from_treasury_vault(
103        ctx: Context<WithdrawFromTreasuryVault>,
104        amount: u64,
105        decimals: u8,
106    ) -> Result<()> {
107        instructions::unchecked_withdraw_from_treasury_vault(ctx, amount, decimals)
108    }
109
110    /// Confirm GT buyback.
111    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_KEEPER))]
112    pub fn confirm_gt_buyback<'info>(
113        ctx: Context<'_, '_, 'info, 'info, ConfirmGtBuyback<'info>>,
114    ) -> Result<()> {
115        instructions::unchecked_confirm_gt_buyback(ctx)
116    }
117
118    /// Transfer the receiver permission to a new address.
119    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_OWNER))]
120    pub fn transfer_receiver(ctx: Context<TransferReceiver>) -> Result<()> {
121        instructions::unchecked_transfer_receiver(ctx)
122    }
123
124    /// Set referral reward factors.
125    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_ADMIN))]
126    pub fn set_referral_reward(ctx: Context<SetReferralReward>, factors: Vec<u128>) -> Result<()> {
127        instructions::unchecked_set_referral_reward(ctx, factors)
128    }
129
130    /// Claim fees.
131    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_KEEPER))]
132    pub fn claim_fees(ctx: Context<ClaimFees>, min_amount: u64) -> Result<()> {
133        instructions::unchecked_claim_fees(ctx, min_amount)
134    }
135
136    /// Prepare GT Bank.
137    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_KEEPER))]
138    pub fn prepare_gt_bank(ctx: Context<PrepareGtBank>) -> Result<()> {
139        instructions::unchecked_prepare_gt_bank(ctx)
140    }
141
142    /// Sync GT Bank.
143    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_WITHDRAWER))]
144    pub fn sync_gt_bank(ctx: Context<SyncGtBank>) -> Result<()> {
145        instructions::unchecked_sync_gt_bank(ctx)
146    }
147
148    /// Complete GT Exchange.
149    pub fn complete_gt_exchange<'info>(
150        ctx: Context<'_, '_, 'info, 'info, CompleteGtExchange<'info>>,
151    ) -> Result<()> {
152        instructions::complete_gt_exchange(ctx)
153    }
154
155    /// Create a swap.
156    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_KEEPER))]
157    pub fn create_swap<'info>(
158        ctx: Context<'_, '_, 'info, 'info, CreateSwap<'info>>,
159        nonce: [u8; 32],
160        swap_path_length: u8,
161        swap_in_amount: u64,
162        min_swap_out_amount: Option<u64>,
163    ) -> Result<()> {
164        instructions::unchecked_create_swap(
165            ctx,
166            nonce,
167            swap_path_length,
168            swap_in_amount,
169            min_swap_out_amount,
170        )
171    }
172
173    /// Cancel a swap.
174    #[access_control(CpiAuthenticate::only(&ctx, roles::TREASURY_KEEPER))]
175    pub fn cancel_swap(ctx: Context<CancelSwap>) -> Result<()> {
176        instructions::unchecked_cancel_swap(ctx)
177    }
178}