oil_api/state/
mod.rs

1mod automation;
2mod auction;
3mod bid;
4mod board;
5mod config;
6mod miner;
7mod pool;
8mod referral;
9mod round;
10mod well;
11mod stake;
12mod treasury;
13
14pub use automation::*;
15pub use auction::*;
16pub use bid::*;
17pub use board::*;
18pub use config::*;
19pub use miner::*;
20pub use pool::*;
21pub use referral::*;
22pub use round::*;
23pub use well::*;
24pub use stake::*;
25pub use treasury::*;
26
27use crate::consts::*;
28
29use steel::*;
30
31#[repr(u8)]
32#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
33pub enum OilAccount {
34    Automation = 100,
35    Config = 101,
36    Miner = 103,
37    Treasury = 104,
38    Board = 105,
39    Stake = 108,
40    Round = 109,
41    Referral = 110,
42    Pool = 111,
43    Bid = 113,
44    Auction = 114,
45    Well = 115,
46}
47
48pub fn automation_pda(authority: Pubkey) -> (Pubkey, u8) {
49    Pubkey::find_program_address(&[AUTOMATION, &authority.to_bytes()], &crate::ID)
50}
51
52pub fn board_pda() -> (Pubkey, u8) {
53    Pubkey::find_program_address(&[BOARD], &crate::ID)
54}
55
56pub fn config_pda() -> (Pubkey, u8) {
57    Pubkey::find_program_address(&[CONFIG], &crate::ID)
58}
59
60pub fn miner_pda(authority: Pubkey) -> (Pubkey, u8) {
61    Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID)
62}
63
64pub fn round_pda(id: u64) -> (Pubkey, u8) {
65    Pubkey::find_program_address(&[ROUND, &id.to_le_bytes()], &crate::ID)
66}
67
68pub fn stake_pda(authority: Pubkey) -> (Pubkey, u8) {
69    Pubkey::find_program_address(&[STAKE, &authority.to_bytes()], &crate::ID)
70}
71
72pub fn stake_pda_with_id(authority: Pubkey, stake_id: u64) -> (Pubkey, u8) {
73    Pubkey::find_program_address(&[STAKE, &authority.to_bytes(), &stake_id.to_le_bytes()], &crate::ID)
74}
75
76pub fn referral_pda(authority: Pubkey) -> (Pubkey, u8) {
77    Pubkey::find_program_address(&[REFERRAL, &authority.to_bytes()], &crate::ID)
78}
79
80pub fn treasury_pda() -> (Pubkey, u8) {
81    Pubkey::find_program_address(&[TREASURY], &crate::ID)
82}
83
84pub fn treasury_tokens_address() -> Pubkey {
85    spl_associated_token_account::get_associated_token_address(&TREASURY_ADDRESS, &MINT_ADDRESS)
86}
87
88pub fn pool_pda() -> (Pubkey, u8) {
89    Pubkey::find_program_address(&[POOL], &crate::ID)
90}
91
92pub fn pool_tokens_address() -> Pubkey {
93    let pool_address = pool_pda().0;
94    spl_associated_token_account::get_associated_token_address(&pool_address, &MINT_ADDRESS)
95}
96
97pub fn bid_pda(authority: Pubkey, well_id: u64, epoch_id: u64) -> (Pubkey, u8) {
98    Pubkey::find_program_address(&[BID, &authority.to_bytes(), &well_id.to_le_bytes(), &epoch_id.to_le_bytes()], &crate::ID)
99}
100
101pub fn auction_pda() -> (Pubkey, u8) {
102    Pubkey::find_program_address(&[AUCTION], &crate::ID)
103}
104
105pub fn well_pda(well_id: u64) -> (Pubkey, u8) {
106    Pubkey::find_program_address(&[WELL, &well_id.to_le_bytes()], &crate::ID)
107}