Skip to main content

sss_token/state/
config.rs

1use anchor_lang::prelude::*;
2
3#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug)]
4pub enum StablecoinPreset {
5    SSS1,   // Minimal: metadata + mint/freeze authority
6    SSS2,   // Compliant: + permanent delegate, transfer hook, blacklist
7    SSS3,   // Private: + confidential transfers (bonus)
8    Custom, // User-defined feature flags
9}
10
11#[account]
12pub struct StablecoinConfig {
13    pub bump: u8,
14    pub mint: Pubkey,
15    pub master_authority: Pubkey,
16    pub pending_authority: Pubkey, // Pubkey::default() if none nominated
17
18    // Token metadata
19    pub name: String,   // max 32
20    pub symbol: String, // max 10
21    pub uri: String,    // max 200
22    pub decimals: u8,
23
24    // Feature flags (set at init, immutable)
25    pub preset: StablecoinPreset,
26    pub enable_permanent_delegate: bool,
27    pub enable_transfer_hook: bool,
28    pub default_account_frozen: bool,
29    pub enable_confidential_transfers: bool, // SSS-3
30
31    // Operational state
32    pub is_paused: bool,
33    pub supply_cap: u64, // 0 = unlimited
34    pub total_minted: u64,
35    pub total_burned: u64,
36    pub total_seized: u64,
37    pub audit_log_index: u64,
38    pub reserve_attestation_index: u64,
39
40    // Timestamps
41    pub created_at: i64,
42    pub updated_at: i64,
43}
44
45impl StablecoinConfig {
46    pub const MAX_NAME_LEN: usize = 32;
47    pub const MAX_SYMBOL_LEN: usize = 10;
48    pub const MAX_URI_LEN: usize = 200;
49
50    pub const SEED_PREFIX: &'static [u8] = b"config";
51
52    // 8 (discriminator) + 1 + 32 + 32 + 32 + (4 + 32) + (4 + 10) + (4 + 200)
53    // + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 8 + 8 + 8 + 8 + 8 + 8 + 8 + 8
54    pub const SPACE: usize = 8
55        + 1
56        + 32
57        + 32
58        + 32
59        + (4 + 32)
60        + (4 + 10)
61        + (4 + 200)
62        + 1
63        + 1
64        + 1
65        + 1
66        + 1
67        + 1
68        + 1
69        + 8
70        + 8
71        + 8
72        + 8
73        + 8
74        + 8
75        + 8
76        + 8;
77
78    pub fn current_supply(&self) -> u64 {
79        self.total_minted.saturating_sub(self.total_burned)
80    }
81}