Docs, Build

API reference

Every instruction and account

All instructions of the reckless program. Amounts are USDC base units (6 decimals) unless noted.

Trading

InstructionArgumentsSignerEffect
request_opennonce: u64, side: Side, margin: u64, leverage: u16TraderCreates the position, escrows margin and two keeper fees, reserves open interest
execute_opennoneAnyoneFills a PendingOpen at the first signed price at or after the target
cancel_opennoneAnyone (refund goes to the owner)Returns margin and both keeper fees to the owner once fill_target + fill_max_gap_secs + cancel_grace_secs has passed
request_closenoneTraderMoves an Open position to PendingClose and sets its fill_target; takes owner, config, position
execute_closenoneAnyoneFills the close, pays or queues a win, records a loss for emission
liquidatenoneAnyoneBusts a position past its trigger and pays the liquidator's reward
harvestnoneAnyonePays the head of the payout queue from pool cash

Prices

InstructionArgumentsSignerEffect
post_pricefeed_id: [u8; 32], publish_time: i64Anyone (pays the rent)Writes one market's signed price for one second into PriceUpdate (PDA ["price", feed_id, publish_time i64 LE]). The instruction right before it must be an ed25519 check carrying oracle_threshold signatures from the signer set over the 108-byte message
close_pricenoneThe payerCloses a used price account and returns its rent

The signed message is "RKLSPX01", the program id, the feed id, price: i64, conf: u64, exponent: i32, publish_time: i64 and prev_publish_time: i64, little endian, 108 bytes. The ed25519 instruction holds exactly oracle_threshold signatures. It lists the offset entries first, then each key followed by its signature, then the message, with every instruction index set to u16::MAX.

Ownership

InstructionArgumentsSignerEffect
close_epochremaining accounts: every market and its price, in index orderAnyoneMarks the pool to market and fixes the epoch's tokens
claim_emissionnoneAnyone pays (payer), tokens go to the ownerMints an AwaitingMint position's share of its closed epoch's tokens, then closes the position and returns its rent to the owner
stakeamount: u64StakerMoves venue tokens into the stake vault
unstakeamount: u64StakerReturns tokens after unstake_cooldown_secs
claim_rewardsnoneStakerPays accrued USDC rewards
close_stakenoneStakerCloses an empty stake account and returns its rent
sweep_surplusnoneAnyoneMoves pool cash above pool_soft_cap to stakers while the queue is empty
buyback_burnnoneAnyoneSpends the buyback bucket on the venue token through the configured pool and burns it

Admin

InstructionArgumentsEffect
initializeparams: ParamsCreates Config and the venue mint; only the upgrade authority may call it
finish_setupnoneCreates the emission ledger, the USDC vault, the stake vault and the buyback account
update_paramsparams: ParamsReplaces parameters inside their bounds
set_opens_pausedpaused: boolStops or resumes new opens
add_marketfeed_id: [u8; 32], price_expo: i32, params: MarketParamsAdds a market; the feed id is the pair name in ASCII, zero padded (BTC/USD)
set_oracle_signerssigners: Vec<Pubkey>, threshold: u8Sets one to three price signer keys and how many must sign each price
update_marketparams: MarketParamsChanges one market's parameters for new positions
set_treasury, set_buyback_poolaccount, Option<Pubkey>Sets fee destinations
transfer_admin, accept_adminnew_admin: PubkeyTwo-step admin handover
collect_protocol_feesnoneSends the protocol's fee share to the treasury

Accounts a position carries

Position (PDA ["position", owner, nonce u64 LE]): owner, market, nonce, side, status (PendingOpen, Open, PendingClose, Queued, AwaitingMint), margin, leverage, terms (bust buffer, impact base and knee, win fee, fixed at open), keeper_fee, entry_price (market exponent), open_requested_at, fill_target, opened_at, close_requested_at, queue_seq, claim, mint_epoch, mint_weight.

Parameters

Params fieldMeaning
exec_delay_secsDelay between a request and the price that fills it (1 to 60)
fill_max_gap_secsHow late after the target the fill update may be published
cancel_grace_secsWait after the fill window before a pending open can be cancelled
max_conf_bpsWidest exchange spread behind a signed price (its conf) accepted, as a share of the price
win_fee_bps, loss_fee_bpsFees on wins and on lost margin
liquidation_reward_bpsLiquidator's share of forfeited margin
staker_fee_share_bps, burn_fee_share_bpsFee split; the rest goes to the treasury
min_margin, max_position_notionalPosition size bounds
keeper_feePaid per fill
pool_soft_capPool cash above this goes to stakers
oi_floor, oi_equity_multiple_bpsOpen interest cap per side
epoch_secs, emission_per_usd, emission_knee, emission_decay_scale, venue_supply_capVenue token emission
unstake_cooldown_secsStaking cooldown
buyback_max_per_call, buyback_interval_secsBuyback limits
MarketParams fieldMeaning
max_leverageUp to 1000
bust_buffer_bpsHow far before zero equity the bust fires; max_leverage x bust_buffer_bps must stay under 10,000
impact_base_bps, impact_knee_ppbHaircut curve on winning closes
open_enabledNew positions allowed in this market
NextError reference