Skip to main content

streak_api/state/
mod.rs

1//! On-chain accounts; one module per [`StreakAccount`] variant / PDA name.
2
3mod ledger;
4mod market;
5mod position;
6mod treasury;
7
8pub use ledger::*;
9pub use market::*;
10pub use position::*;
11pub use treasury::*;
12
13use crate::consts::{LEDGER, MARKET, POSITION, TREASURY};
14
15use num_enum::{IntoPrimitive, TryFromPrimitive};
16use steel::*;
17
18#[repr(u8)]
19#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
20pub enum StreakAccount {
21    Treasury = 1,
22    Ledger = 2,
23    Market = 3,
24    Position = 4,
25}
26
27pub fn treasury_pda() -> (Pubkey, u8) {
28    Pubkey::find_program_address(&[TREASURY], &crate::ID)
29}
30
31pub fn ledger_pda(authority: Pubkey) -> (Pubkey, u8) {
32    Pubkey::find_program_address(&[LEDGER, authority.as_ref()], &crate::ID)
33}
34
35pub fn market_pda(series_id: u16, period: u64) -> (Pubkey, u8) {
36    Pubkey::find_program_address(
37        &[
38            MARKET,
39            &series_id.to_le_bytes(),
40            &period.to_le_bytes(),
41        ],
42        &crate::ID,
43    )
44}
45
46pub fn position_pda(series_id: u16, period: u64, authority: Pubkey) -> (Pubkey, u8) {
47    Pubkey::find_program_address(
48        &[
49            POSITION,
50            &series_id.to_le_bytes(),
51            &period.to_le_bytes(),
52            authority.as_ref(),
53        ],
54        &crate::ID,
55    )
56}