Instructions
Every on-chain call Shain exposes. Each section is complete: signature, accounts, errors, compute units.
initialize
One-time bootstrap. The authority signs, the program creates the config PDA and the treasury ATA, and future sessions derive from this config.
pub fn initialize(
ctx: Context<Initialize>,
params: InitializeParams,
) -> Result<()>;
pub struct InitializeParams {
pub session_duration: Option<i64>, // default 86_400
pub session_fee: Option<u64>, // default 1_000_000
pub min_holding: Option<u64>, // default 10_000_000
}| Account | Signer | Writable | Notes |
|---|---|---|---|
authority | ✓ | ✓ | Pays for init |
shain_mint | — | — | The $SHAIN SPL mint |
shain_config | — | ✓ | PDA, created here |
treasury_authority | — | — | PDA, owns the ATA |
treasury_ata | — | ✓ | ATA, created here |
system_program | — | — | For account creation |
token_program | — | — | SPL Token classic |
associated_token_program | — | — | For ATA create |
rent | — | — | Sysvar |
CU cost: ~4,128 · IX size: 137 B · Errors: InvalidSessionDuration if duration is outside [60, 2_592_000] seconds.
start_session
The holder opens a 24-hour window. Verifies balance, charges the session fee, writes the session PDA.
pub fn start_session(ctx: Context<StartSession>) -> Result<()>;| Account | Signer | Writable | Notes |
|---|---|---|---|
user | ✓ | ✓ | The holder |
shain_config | — | ✓ | lifetime counters |
shain_mint | — | — | has_one check |
user_token_account | — | ✓ | holder's SHAIN ATA |
treasury_ata | — | ✓ | fee destination |
shain_session | — | ✓ | init_if_needed |
token_program | — | — | for fee CPI |
system_program | — | — | for PDA init |
CU cost: ~3,812 · IX size: 88 B · Errors: TokenAccountOwnerMismatch, TokenAccountMintMismatch, InsufficientHolding, SessionStillActive, Overflow.
gated_action
The integration hook. Downstream dapps CPI here to prove the caller has a live session before performing their private action.
pub fn gated_action(ctx: Context<GatedAction>, tag: u64) -> Result<()>;| Account | Signer | Writable | Notes |
|---|---|---|---|
user | ✓ | — | session owner |
shain_session | — | ✓ | counter++ |
CU cost: ~1,914 · IX size: 22 B · Errors: Unauthorized (constraint), SessionNotFound, SessionExpired, Overflow.
close_session
After expiry, any signer may close. Rent is refunded to the session's original owner regardless of who initiates.
pub fn close_session(ctx: Context<CloseSession>) -> Result<()>;| Account | Signer | Writable | Notes |
|---|---|---|---|
user | ✓ | ✓ | close = user rent refund |
shain_session | — | ✓ | closed |
CU cost: ~2,206 · IX size: 16 B · Errors: Unauthorized, SessionStillActive.