Accounts
Three PDA account types. Config is global, PriceFeed is per symbol, Position is per (owner, nonce) pair.
Config
Single global account. Seeds: [b"config"].
programs/hwal/src/state/config.rs
rust
#[account]
#[derive(InitSpace)]
pub struct Config {
pub admin: Pubkey,
pub fee_receiver: Pubkey,
pub fee_bps: u16,
pub keeper_reward_bps: u16,
pub total_positions_opened: u64,
pub total_positions_triggered: u64,
pub total_positions_cancelled: u64,
pub total_fees_collected: u64,
pub total_keeper_rewards_paid: u64,
pub bump: u8,
pub _reserved: [u8; 64],
}PriceFeed
One per symbol. Seeds: [b"feed", symbol_16_bytes]. Theauthority is the only signer allowed to push price updates (V0). In V1 this is replaced by a verified-oracle instruction.
programs/hwal/src/state/price_feed.rs
rust
#[account]
#[derive(InitSpace)]
pub struct PriceFeed {
pub authority: Pubkey,
pub symbol: [u8; 16],
pub decimals: u8,
pub price: u64,
pub last_updated: i64,
pub update_count: u64,
pub bump: u8,
pub _reserved: [u8; 32],
}Position
One per (owner, nonce). Seeds: [b"position", owner_pubkey, nonce_le_u64]. Collateral is held as lamports above the rent-exempt minimum on this account itself.
programs/hwal/src/state/position.rs
rust
#[account]
#[derive(InitSpace)]
pub struct Position {
pub owner: Pubkey,
pub feed: Pubkey,
pub vault: Pubkey,
pub nonce: u64,
pub side: u8,
pub status: u8,
pub trigger_reason: u8,
pub _pad: u8,
pub collateral: u64,
pub entry_price: u64,
pub stop_price: u64,
pub take_profit_price: u64,
pub trailing_offset: u64,
pub trailing_extreme: u64,
pub opened_at: i64,
pub last_tick_at: i64,
pub settled_at: i64,
pub tick_count: u64,
pub bump: u8,
pub vault_bump: u8,
pub _reserved: [u8; 32],
}Status values
0 STATUS_OPEN— position accepting ticks1 STATUS_TRIGGERED— fired, collateral settled2 STATUS_CANCELLED— owner closed manually
Trigger reason values
0 TRIGGER_NONE— not triggered yet1 TRIGGER_STOP_LOSS— stop hit2 TRIGGER_TAKE_PROFIT— TP hit3 TRIGGER_TRAILING— trailing offset retraced