Skip to main content

oil_api/state/
mod.rs

1mod automation;
2mod auction;
3mod board;
4mod config;
5mod micro;
6mod miner;
7mod pool;
8mod referral;
9mod round;
10mod share;
11mod well;
12mod stake;
13mod treasury;
14mod whitelist;
15mod plot;
16mod rig;
17mod refinery;
18mod oracle;
19
20pub use automation::*;
21pub use auction::*;
22pub use board::*;
23pub use config::*;
24pub use micro::*;
25pub use miner::*;
26pub use pool::*;
27pub use referral::*;
28pub use round::*;
29pub use share::*;
30pub use well::*;
31pub use stake::*;
32pub use treasury::*;
33#[allow(unused_imports)] // Exported for use in other crates (e.g., program crate)
34pub use whitelist::*;
35pub use plot::*;
36pub use rig::*;
37pub use refinery::*;
38pub use oracle::*;
39use crate::consts::*;
40
41use steel::*;
42
43#[repr(u8)]
44#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
45pub enum OilAccount {
46    Automation = 100,
47    Config = 101,
48    Miner = 103,
49    Treasury = 104,
50    Board = 105,
51    Stake = 108,
52    Round = 109,
53    Referral = 110,
54    Pool = 111,
55    Auction = 114,
56    Well = 115,
57    Whitelist = 117,
58    Micro = 118,
59    Share = 119,
60    Plot = 120,
61    Rig = 121,
62    Refinery = 122,
63    OilPriceOracle = 123,
64}
65
66pub fn automation_pda(authority: Pubkey) -> (Pubkey, u8) {
67    Pubkey::find_program_address(&[AUTOMATION, &authority.to_bytes()], &crate::ID)
68}
69
70pub fn board_pda() -> (Pubkey, u8) {
71    Pubkey::find_program_address(&[BOARD], &crate::ID)
72}
73
74pub fn config_pda() -> (Pubkey, u8) {
75    Pubkey::find_program_address(&[CONFIG], &crate::ID)
76}
77
78pub fn miner_pda(authority: Pubkey) -> (Pubkey, u8) {
79    Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID)
80}
81
82pub fn round_pda(id: u64) -> (Pubkey, u8) {
83    Pubkey::find_program_address(&[ROUND, &id.to_le_bytes()], &crate::ID)
84}
85
86pub fn stake_pda(authority: Pubkey) -> (Pubkey, u8) {
87    Pubkey::find_program_address(&[STAKE, &authority.to_bytes()], &crate::ID)
88}
89
90pub fn stake_pda_with_id(authority: Pubkey, stake_id: u64) -> (Pubkey, u8) {
91    Pubkey::find_program_address(&[STAKE, &authority.to_bytes(), &stake_id.to_le_bytes()], &crate::ID)
92}
93
94pub fn referral_pda(authority: Pubkey) -> (Pubkey, u8) {
95    Pubkey::find_program_address(&[REFERRAL, &authority.to_bytes()], &crate::ID)
96}
97
98pub fn treasury_pda() -> (Pubkey, u8) {
99    Pubkey::find_program_address(&[TREASURY], &crate::ID)
100}
101
102pub fn treasury_tokens_address() -> Pubkey {
103    spl_associated_token_account::get_associated_token_address(&TREASURY_ADDRESS, &MINT_ADDRESS)
104}
105
106pub fn pool_pda() -> (Pubkey, u8) {
107    Pubkey::find_program_address(&[POOL], &crate::ID)
108}
109
110pub fn pool_tokens_address() -> Pubkey {
111    let pool_address = pool_pda().0;
112    spl_associated_token_account::get_associated_token_address(&pool_address, &MINT_ADDRESS)
113}
114
115pub fn auction_pda() -> (Pubkey, u8) {
116    Pubkey::find_program_address(&[AUCTION], &crate::ID)
117}
118
119pub fn well_pda(well_id: u64) -> (Pubkey, u8) {
120    Pubkey::find_program_address(&[WELL, &well_id.to_le_bytes()], &crate::ID)
121}
122
123pub fn whitelist_pda(code_hash: [u8; 32]) -> (Pubkey, u8) {
124    Pubkey::find_program_address(&[WHITELIST, &code_hash], &crate::ID)
125}
126
127pub fn micro_pda(well_id: u64, epoch_id: u64) -> (Pubkey, u8) {
128    Pubkey::find_program_address(&[MICRO, &well_id.to_le_bytes(), &epoch_id.to_le_bytes()], &crate::ID)
129}
130
131pub fn share_pda(authority: Pubkey, well_id: u64, epoch_id: u64) -> (Pubkey, u8) {
132    Pubkey::find_program_address(&[SHARE, &authority.to_bytes(), &well_id.to_le_bytes(), &epoch_id.to_le_bytes()], &crate::ID)
133}
134
135pub fn plot_pda(authority: Pubkey) -> (Pubkey, u8) {
136    Pubkey::find_program_address(&[PLOT, &authority.to_bytes()], &crate::ID)
137}
138
139pub fn rig_pda(mint: Pubkey) -> (Pubkey, u8) {
140    Pubkey::find_program_address(&[RIG, &mint.to_bytes()], &crate::ID)
141}
142
143pub fn refinery_pda() -> (Pubkey, u8) {
144    Pubkey::find_program_address(&[REFINERY], &crate::ID)
145}
146
147pub fn oil_oracle_pda() -> (Pubkey, u8) {
148    Pubkey::find_program_address(&[ORACLE], &crate::ID)
149}