coal_api/
consts.rs

1use array_const_fn_init::array_const_fn_init;
2use const_crypto::ed25519;
3use solana_program::{
4    pubkey, 
5    pubkey::Pubkey,
6    native_token::LAMPORTS_PER_SOL
7};
8
9/// The authority allowed to initialize the program.
10pub const INITIALIZER_ADDRESS: Pubkey = pubkey!("FJka1yJHn1SWux2X1o8VqHC8uaAWGv6CbNQvPWLJQufq");
11
12/// The base reward rate to intialize the program with.
13pub const INITIAL_BASE_COAL_REWARD_RATE: u64 = BASE_COAL_REWARD_RATE_MIN_THRESHOLD;
14pub const INITIAL_BASE_WOOD_REWARD_RATE: u64 = BASE_WOOD_REWARD_RATE_MIN_THRESHOLD;
15
16/// The minimum allowed base reward rate, at which point the min difficulty should be increased
17pub const BASE_COAL_REWARD_RATE_MIN_THRESHOLD: u64 = 2u64.pow(5);
18
19/// The maximum allowed base reward rate, at which point the min difficulty should be decreased.
20pub const BASE_COAL_REWARD_RATE_MAX_THRESHOLD: u64 = 2u64.pow(8) * COAL_EXTRACTION_MULTIPLIER;
21
22/// The minimum allowed base reward rate, at which point the min difficulty should be increased
23pub const BASE_WOOD_REWARD_RATE_MIN_THRESHOLD: u64 = 2u64.pow(5) * WOOD_EXTRACTION_MULTIPLIER;
24
25/// The maximum allowed base reward rate, at which point the min difficulty should be decreased.
26pub const BASE_WOOD_REWARD_RATE_MAX_THRESHOLD: u64 = 2u64.pow(8) * WOOD_EXTRACTION_MULTIPLIER;
27
28/// The spam/liveness tolerance in seconds.
29pub const TOLERANCE: i64 = 5;
30
31pub const REPROCESS_TARGET_SLOT: u64 = 20;
32pub const REPROCESS_SLOT_BUFFER: u64 = 6;
33pub const REPROCESS_MAX_MULTIPLIER: u64 = 100;
34pub const REPROCESS_FEE: u64 = LAMPORTS_PER_SOL / 200;
35
36/// The liveness tolerance for WOOD in seconds.
37pub const WOOD_LIVENESS_TOLERANCE: i64 = 65;
38
39/// The minimum difficulty to initialize the program with.
40pub const INITIAL_MIN_DIFFICULTY: u32 = 1;
41
42/// The decimal precision of the COAL token.
43/// There are 100 billion indivisible units per COAL (called "grains").
44pub const TOKEN_DECIMALS: u8 = 11;
45
46/// One COAL token, denominated in indivisible units.
47pub const ONE_COAL: u64 = 10u64.pow(TOKEN_DECIMALS as u32);
48
49/// One WOOD token, denominated in indivisible units.
50pub const ONE_WOOD: u64 = 10u64.pow(TOKEN_DECIMALS as u32);
51
52/// The duration of one minute, in seconds.
53pub const ONE_MINUTE: i64 = 60;
54
55/// The number of minutes in a program epoch.
56pub const COAL_EPOCH_MINUTES: i64 = 2;
57pub const WOOD_EPOCH_MINUTES: i64 = 5;
58
59/// The duration of a program epoch, in seconds.
60pub const COAL_EPOCH_DURATION: i64 = ONE_MINUTE * COAL_EPOCH_MINUTES;
61pub const WOOD_EPOCH_DURATION: i64 = ONE_MINUTE * WOOD_EPOCH_MINUTES;
62/// The maximum token supply (21 million).
63pub const MAX_COAL_SUPPLY: u64 = ONE_COAL * 21_000_000;
64
65/// The multiplier for the target quantity of COAL to be mined per epoch.
66pub const COAL_EXTRACTION_MULTIPLIER: u64 = 1000;
67pub const WOOD_EXTRACTION_MULTIPLIER: u64 = 10;
68
69/// The target quantity of COAL to be mined per epoch.
70pub const TARGET_COAL_EPOCH_REWARDS: u64 = ONE_COAL * COAL_EXTRACTION_MULTIPLIER * COAL_EPOCH_MINUTES as u64;
71
72/// The initial quantity of WOOD distributed to each bus (1000 WOOD).
73pub const INITIAL_WOOD_EPOCH_REWARDS: u64 = ONE_WOOD * 1000;
74
75/// The minimum rewards a bus can have for each epoch 0.1 WOOD
76pub const MIN_WOOD_EPOCH_REWARDS: u64 = ONE_WOOD / 10;
77/// The maximum rewards a bus can have for each epoch 4000 WOOD
78pub const MAX_WOOD_EPOCH_REWARDS: u64 = ONE_WOOD * 4000;
79
80/// WOOD propogation rate is 5% per epoch
81/// New bus rewards = remaining + (remaining rewards / WOOD_PROPOGATION_RATE)
82pub const WOOD_PROPOGATION_RATE: u64 = 20;
83
84/// The maximum quantity of COAL that can be mined per epoch.
85/// Inflation rate ≈ 1000 COAL / min (min 0, max 8)
86pub const MAX_COAL_EPOCH_REWARDS: u64 = TARGET_COAL_EPOCH_REWARDS * BUS_COUNT as u64;
87
88/// The quantity of COAL each bus is allowed to issue per epoch.
89pub const BUS_COAL_EPOCH_REWARDS: u64 = MAX_COAL_EPOCH_REWARDS / BUS_COUNT as u64;
90
91/// The number of bus accounts, for parallelizing mine operations.
92pub const BUS_COUNT: usize = 8;
93
94/// The smoothing factor for reward rate changes. The reward rate cannot change by mCOAL or less
95/// than a factor of this constant from one epoch to the next.
96pub const SMOOTHING_FACTOR: u64 = 2;
97// WOOD delcines at a faster rate to prevent busses emptying too quickly
98pub const WOOD_DECREMENTAL_SMOOTHING_FACTOR: u64 = 10;
99
100// Assert MAX_EPOCH_REWARDS is evenly divisible by BUS_COUNT.
101static_assertions::const_assert!(
102    (MAX_COAL_EPOCH_REWARDS / BUS_COUNT as u64) * BUS_COUNT as u64 == MAX_COAL_EPOCH_REWARDS
103);
104
105/// The seed of the bus account PDA.
106pub const COAL_BUS: &[u8] = b"bus";
107pub const WOOD_BUS: &[u8] = b"wood_bus";
108
109/// The seed of the config account PDA.
110pub const COAL_CONFIG: &[u8] = b"config";
111pub const WOOD_CONFIG: &[u8] = b"wood_config";
112
113/// The seed of the metadata account PDA.
114pub const METADATA: &[u8] = b"metadata";
115
116/// The seed of the mint account PDA.
117pub const COAL_MINT: &[u8] = b"mint";
118pub const WOOD_MINT: &[u8] = b"wood_mint";
119pub const CHROMIUM_MINT: &[u8] = b"chromium_mint";
120
121/// The seed of proof account PDAs.
122pub const COAL_PROOF: &[u8] = b"proof";
123pub const WOOD_PROOF: &[u8] = b"wood_proof";
124
125/// The seed of the tool account PDA.
126pub const COAL_MAIN_HAND_TOOL: &[u8] = b"coal_main_hand_tool";
127pub const WOOD_MAIN_HAND_TOOL: &[u8] = b"wood_main_hand_tool";
128
129/// The seed of the treasury account PDA.
130pub const TREASURY: &[u8] = b"treasury";
131
132/// The seed of the plugin update authority PDA.
133pub const PLUGIN_UPDATE_AUTHORITY: &[u8] = b"update_authority";
134
135/// The seed of the reprocessor PDA.
136pub const REPROCESSOR: &[u8] = b"reprocessor";
137
138/// Noise for deriving the mint pda
139pub const MINT_NOISE: [u8; 16] = [
140    89, 157, 88, 232, 243, 249, 197, 132, 199, 49, 19, 234, 91, 94, 150, 41,
141];
142
143/// The name for token metadata.
144pub const COAL_METADATA_NAME: &str = "coal";
145pub const WOOD_METADATA_NAME: &str = "wood";
146pub const CHROMIUM_METADATA_NAME: &str = "chromium";
147
148/// The ticker symbol for token metadata.
149pub const COAL_METADATA_SYMBOL: &str = "COAL";
150pub const WOOD_METADATA_SYMBOL: &str = "WOOD";
151pub const CHROMIUM_METADATA_SYMBOL: &str = "CHROMIUM";
152
153/// The uri for token metdata.
154pub const COAL_METADATA_URI: &str = "https://coal.digital/metadata.json";
155pub const WOOD_METADATA_URI: &str = "https://coal.digital/metadata.wood.json";
156pub const CHROMIUM_METADATA_URI: &str = "https://coal.digital/metadata.chromium.json";
157
158/// Program id for const pda derivations
159const PROGRAM_ID: [u8; 32] = unsafe { *(&crate::id() as *const Pubkey as *const [u8; 32]) };
160
161/// ORE program id 
162pub const ORE_PROGRAM_ID: Pubkey = pubkey!("oreV2ZymfyeXgNgBdqMkumTqqAprVqgBWQfoYkrtKWQ");
163pub const ORE_PROGRAM_ID_BYTES: [u8; 32] = unsafe { *(&ORE_PROGRAM_ID as *const Pubkey as *const [u8; 32]) };
164
165/// Forge collection ids
166pub const FORGE_PICKAXE_COLLECTION: Pubkey = pubkey!("CuaLHUJA1dyQ6AYcTcMZrCoBqssSJbqkY7VfEEFdxzCk");
167
168/// The addresses of the bus accounts.
169pub const COAL_BUS_ADDRESSES: [Pubkey; BUS_COUNT] = array_const_fn_init![const_coal_bus_address; 8];
170pub const WOOD_BUS_ADDRESSES: [Pubkey; BUS_COUNT] = array_const_fn_init![const_wood_bus_address; 8];
171
172/// Function to derive const bus addresses.
173const fn const_coal_bus_address(i: usize) -> Pubkey {
174    Pubkey::new_from_array(ed25519::derive_program_address(&[COAL_BUS, &[i as u8]], &PROGRAM_ID).0)
175}
176
177const fn const_wood_bus_address(i: usize) -> Pubkey {
178    Pubkey::new_from_array(ed25519::derive_program_address(&[WOOD_BUS, &[i as u8]], &PROGRAM_ID).0)
179}
180
181/// The address of the config account.
182pub const COAL_CONFIG_ADDRESS: Pubkey =
183    Pubkey::new_from_array(ed25519::derive_program_address(&[COAL_CONFIG], &PROGRAM_ID).0);
184pub const WOOD_CONFIG_ADDRESS: Pubkey =
185    Pubkey::new_from_array(ed25519::derive_program_address(&[WOOD_CONFIG], &PROGRAM_ID).0);
186
187/// The address of the mint metadata account.
188pub const COAL_METADATA_ADDRESS: Pubkey = Pubkey::new_from_array(
189    ed25519::derive_program_address(
190        &[
191            METADATA,
192            unsafe { &*(&mpl_token_metadata::ID as *const Pubkey as *const [u8; 32]) },
193            unsafe { &*(&COAL_MINT_ADDRESS as *const Pubkey as *const [u8; 32]) },
194        ],
195        unsafe { &*(&mpl_token_metadata::ID as *const Pubkey as *const [u8; 32]) },
196    )
197    .0,
198);
199pub const WOOD_METADATA_ADDRESS: Pubkey = Pubkey::new_from_array(
200    ed25519::derive_program_address(
201        &[
202            METADATA,
203            unsafe { &*(&mpl_token_metadata::ID as *const Pubkey as *const [u8; 32]) },
204            unsafe { &*(&WOOD_MINT_ADDRESS as *const Pubkey as *const [u8; 32]) },
205        ],
206        unsafe { &*(&mpl_token_metadata::ID as *const Pubkey as *const [u8; 32]) },
207    )
208    .0,
209);
210
211/// The address of the COAL mint account.
212pub const COAL_MINT_ADDRESS: Pubkey =
213    Pubkey::new_from_array(ed25519::derive_program_address(&[COAL_MINT, &MINT_NOISE], &PROGRAM_ID).0);
214
215/// The address of the WOOD mint account.
216pub const WOOD_MINT_ADDRESS: Pubkey =
217    Pubkey::new_from_array(ed25519::derive_program_address(&[WOOD_MINT, &MINT_NOISE], &PROGRAM_ID).0);
218
219/// The address of the CHROMIUM mint account.
220pub const CHROMIUM_MINT_ADDRESS: Pubkey =
221    Pubkey::new_from_array(ed25519::derive_program_address(&[CHROMIUM_MINT, &MINT_NOISE], &PROGRAM_ID).0);
222
223/// The address of the treasury account.
224pub const TREASURY_ADDRESS: Pubkey =
225    Pubkey::new_from_array(ed25519::derive_program_address(&[TREASURY], &PROGRAM_ID).0);
226
227/// The bump of the treasury account, for cpis.
228pub const TREASURY_BUMP: u8 = ed25519::derive_program_address(&[TREASURY], &PROGRAM_ID).1;
229
230/// The address of the COAL treasury token account.
231pub const COAL_TREASURY_TOKENS_ADDRESS: Pubkey = Pubkey::new_from_array(
232    ed25519::derive_program_address(
233        &[
234            unsafe { &*(&TREASURY_ADDRESS as *const Pubkey as *const [u8; 32]) },
235            unsafe { &*(&spl_token::id() as *const Pubkey as *const [u8; 32]) },
236            unsafe { &*(&COAL_MINT_ADDRESS as *const Pubkey as *const [u8; 32]) },
237        ],
238        unsafe { &*(&spl_associated_token_account::id() as *const Pubkey as *const [u8; 32]) },
239    )
240    .0,
241);
242
243/// The address of the WOOD treasury token account.
244pub const WOOD_TREASURY_TOKENS_ADDRESS: Pubkey = Pubkey::new_from_array(
245    ed25519::derive_program_address(
246        &[
247            unsafe { &*(&TREASURY_ADDRESS as *const Pubkey as *const [u8; 32]) },
248            unsafe { &*(&spl_token::id() as *const Pubkey as *const [u8; 32]) },
249            unsafe { &*(&WOOD_MINT_ADDRESS as *const Pubkey as *const [u8; 32]) },
250        ],
251        unsafe { &*(&spl_associated_token_account::id() as *const Pubkey as *const [u8; 32]) },
252    )
253    .0,
254);
255
256pub const COAL_MAIN_HAND_TOOL_ADDRESS: Pubkey = Pubkey::new_from_array(ed25519::derive_program_address(&[COAL_MAIN_HAND_TOOL], &PROGRAM_ID).0);
257
258
259/// The address of the CU-optimized Solana noop program.
260pub const NOOP_PROGRAM_ID: Pubkey = pubkey!("noop8ytexvkpCuqbf6FB89BSuNemHtPRqaNC31GWivW");