Skip to main content

streak_api/state/
position.rs

1//! One stake per trader per **`(Market::series_id, Market::period)`** (**`PlaceBet`** creates / tops up). PDA: [`position_pda`](super::position_pda).
2
3use steel::*;
4
5use super::{position_pda, StreakAccount};
6
7#[repr(C)]
8#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
9pub struct Position {
10    pub authority: Pubkey,
11    pub series_id: u16,
12    pub _pad_series: [u8; 6],
13    pub period: u64,
14    pub stake: u64,
15    /// [`Market::SIDE_UP`](super::Market::SIDE_UP) or [`Market::SIDE_DOWN`](super::Market::SIDE_DOWN); matches [`Market::outcome`] after settle.
16    pub side: u8,
17    /// [`STATE_PENDING`] / [`STATE_COMMITTED_PREOPEN`] / [`STATE_CLAIMED_WIN`] / [`STATE_FINALIZED_LOSS`] / [`STATE_COMMIT_REFUNDED`].
18    pub state: u8,
19    pub _pad: [u8; 6],
20}
21
22impl Position {
23    /// Open (**`PlaceBet`** may add stake until settle).
24    pub const STATE_PENDING: u8 = 0;
25
26    /// Winner paid via **`ExecutorTreasury`** (**`distribute`**) (**executor**).
27    pub const STATE_CLAIMED_WIN: u8 = 1;
28
29    /// Loser bookkeeping: the next period’s **`BuyTickets`** or **`PlaceBet`** finalizes this after settlement.
30    pub const STATE_FINALIZED_LOSS: u8 = 2;
31
32    /// Locked **before** open-anchor / early window: tickets debited; merged into **`STATE_PENDING`** + **`total_*`** during live window via **`PlaceBet`** (**`ticket_units == 0`**, user), first live **`PlaceBet`** with stake, or **`ExecutorTreasury`** **`EXECUTOR_KIND_MERGE_COMMITTED_POSITION`** (executor).
33    pub const STATE_COMMITTED_PREOPEN: u8 = 3;
34
35    /// Reserved legacy state (**no instruction writes this today**); **`PlaceBet`** commit path may recycle **`stake == 0`** accounts.
36    pub const STATE_COMMIT_REFUNDED: u8 = 4;
37
38    pub fn pda(series_id: u16, period: u64, authority: Pubkey) -> (Pubkey, u8) {
39        position_pda(series_id, period, authority)
40    }
41}
42
43account!(StreakAccount, Position);