Skip to main content

tape_api/
consts.rs

1use array_const_fn_init::array_const_fn_init;
2use const_crypto::ed25519;
3use solana_program::pubkey::Pubkey;
4
5pub const ARCHIVE: &[u8]                   = b"archive";
6pub const EPOCH: &[u8]                     = b"epoch";
7pub const TREASURY: &[u8]                  = b"treasury";
8pub const SPOOL: &[u8]                     = b"spool";
9pub const TAPE: &[u8]                      = b"tape";
10pub const WRITER: &[u8]                    = b"writer";
11pub const MINER: &[u8]                     = b"miner";
12
13pub const MINT: &[u8]                      = b"mint";
14pub const MINT_SEED: &[u8]                 = &[152, 68, 212, 200, 25, 113, 221, 71];
15
16pub const METADATA: &[u8]                  = b"metadata";
17pub const METADATA_NAME: &str              = "TAPE";
18pub const METADATA_SYMBOL: &str            = "TAPE";
19pub const METADATA_URI: &str               = "https://tapedrive.io/metadata.json";
20
21pub const TREE_HEIGHT: usize               = 18;
22pub const PROOF_LEN: usize                 = TREE_HEIGHT;
23
24pub const MAGIC_NUMBER: usize              = 8;   // Chunks per segment (1 chunk is used for each recall proof)
25pub const CHUNK_SIZE: usize                = 128; // Bytes per chunk (chosen to fit recall proofs
26                                                  // comfortably in a single Solana transaction)
27
28pub const SEGMENT_SIZE: usize              = CHUNK_SIZE * MAGIC_NUMBER;                      // 1024 bytes 
29pub const MAX_TAPE_SEGMENTS: usize         = 2_usize.pow(TREE_HEIGHT as u32) / MAGIC_NUMBER; // 32,768
30pub const MAX_TAPE_SIZE: usize             = 2_usize.pow(TREE_HEIGHT as u32) * CHUNK_SIZE;   // 32MB
31
32pub const SPOOL_COUNT: usize               = 8;
33pub const MAX_NAME_LEN: usize              = 32;
34
35pub const TOKEN_DECIMALS: u8               = 10;
36pub const ONE_TAPE: u64                    = 10u64.pow(TOKEN_DECIMALS as u32);
37pub const MAX_SUPPLY: u64                  = 7_000_000 * ONE_TAPE;
38
39pub const ONE_SECOND: i64                  = 1;
40pub const ONE_MINUTE: i64                  = 60 * ONE_SECOND;
41pub const EPOCH_DURATION_MINUTES: i64      = 15;
42pub const EPOCH_SECONDS: i64               = EPOCH_DURATION_MINUTES * ONE_MINUTE;
43pub const GRACE_PERIOD_SECONDS: i64        = 15 * ONE_SECOND;
44
45// -- Const Addresses --
46// (There isn't a better way to do this yet; maybe a build.rs + include)
47
48pub const PROGRAM_ID: [u8; 32] = 
49    unsafe { *(&crate::id() as *const Pubkey as *const [u8; 32]) };
50
51pub const ARCHIVE_ADDRESS: Pubkey =
52    Pubkey::new_from_array(ed25519::derive_program_address(&[ARCHIVE], &PROGRAM_ID).0);
53
54pub const ARCHIVE_BUMP: u8 =
55    ed25519::derive_program_address(&[ARCHIVE], &PROGRAM_ID).1;
56
57pub const EPOCH_ADDRESS: Pubkey =
58    Pubkey::new_from_array(ed25519::derive_program_address(&[EPOCH], &PROGRAM_ID).0);
59
60pub const EPOCH_BUMP: u8 =
61    ed25519::derive_program_address(&[EPOCH], &PROGRAM_ID).1;
62
63pub const MINT_ADDRESS: Pubkey =
64    Pubkey::new_from_array(ed25519::derive_program_address(&[MINT, &MINT_SEED], &PROGRAM_ID).0);
65
66pub const MINT_BUMP: u8 = 
67    ed25519::derive_program_address(&[MINT, &MINT_SEED], &PROGRAM_ID).1;
68
69pub const TREASURY_ADDRESS: Pubkey =
70    Pubkey::new_from_array(ed25519::derive_program_address(&[TREASURY], &PROGRAM_ID).0);
71
72pub const TREASURY_BUMP: u8 = 
73    ed25519::derive_program_address(&[TREASURY], &PROGRAM_ID).1;
74
75pub const TREASURY_ATA: Pubkey = Pubkey::new_from_array(
76    ed25519::derive_program_address(
77        &[
78            unsafe { &*(&TREASURY_ADDRESS as *const Pubkey as *const [u8; 32]) },
79            unsafe { &*(&spl_token::id() as *const Pubkey as *const [u8; 32]) },
80            unsafe { &*(&MINT_ADDRESS as *const Pubkey as *const [u8; 32]) },
81        ],
82        unsafe { &*(&spl_associated_token_account::id() as *const Pubkey as *const [u8; 32]) },
83    )
84    .0,
85);
86
87pub const SPOOL_ADDRESSES: [Pubkey; SPOOL_COUNT] = 
88    array_const_fn_init![const_spool_address; 8];
89
90const fn const_spool_address(i: usize) -> Pubkey {
91    Pubkey::new_from_array(
92        ed25519::derive_program_address(&[SPOOL, &[i as u8]], &PROGRAM_ID).0
93    )
94}