Skip to content
Runner · Reference

PluginContext

The ctx passed to decide().

Derived from packages/runtime-core/src/types.ts

Every tick, the runtime builds a fresh PluginContext and hands it to your decide(). It is everything your strategy gets to see and the only sanctioned way to touch the outside world.

Read from ctx, return Action[]. Side effects go through ctx.state only — never RPC, keys, or a tx you build yourself.

The six fields

  • vault: Vault — fresh on-chain vault snapshot at trigger time (SDK Vault class). Getters below.
  • suiClient: SuiClient — the runtime's shared client, for SDK read helpers. A plugin does not create its own.
  • now: numberDate.now() injected for testability. Call this, never Date.now() directly.
  • state: PluginStateAPI — KV store scoped by plugin name. See Plugin state API.
  • logger: Logger — pre-bound with pluginName / vaultId. debug / info / warn / error, plus bind(fields) and timing(name, fn).
  • lifecycle: LifecycleContext{ closures: ClosureEvent[] }, the positions that closed since the last tick (delta semantics). [] on the first tick, when nothing closed, on dry-runs, and after a restart.

ctx.vault — read getters

The vault state, decoded. All bigint unless noted.

  • quoteBalance: free quote held by the vault.
  • plpBalance: PLP balance.
  • totalShares: total LP shares outstanding.
  • nav: net asset value.
  • navPerShare: NAV per share.
  • aggregateExposure: summed exposure across open positions.
  • highWaterMark: HWM for performance fees.
  • lastSnapshotTs: ts of the last NAV snapshot.
  • pendingDepositsTotal / pendingWithdrawalSharesTotal: queued deposits (quote) and withdrawals (shares).
  • accruedFeesQuote / lastCrystallizationTs: fees accrued and when they last crystallized.
  • predictManagerId: string | null — the vault's Predict manager object.
  • authorizedWitnessType: string — the witness type that gates strategy calls.
  • strategyPermissions: the raw permission bitfield (decoded by the can* getters below).
  • paused / strategyPaused: boolean — governance pause and strategy pause flags.
  • pauseReason: number. pauseTs: bigint | null.
  • governanceAdmin / emergencyAdmin: string — admin addresses.
  • trackedMarketKeys: MarketKey[] — open binary positions ({ oracle_id, expiry, strike, direction, is_up }).
  • trackedRangeKeys: RangeKey[] — open range positions ({ oracle_id, expiry, lower_strike, higher_strike }).
  • navParams: NavParams{ snapshot_interval_seconds, deposit_cooldown_seconds, withdrawal_cooldown_seconds }.
  • riskParams: RiskParamsState — the anti-rug caps { max_position_bps, max_aggregate_exposure_bps, max_drawdown_bps, max_share_concentration_bps }.
  • feeParams: FeeParamsState{ performance_fee_bps, management_fee_bps_annual, entry_fee_bps, exit_fee_bps, platform_split_bps }.
  • uniqueOracleIds: string[] — deduplicated, sorted oracle IDs across both key lists.
  • rawState: VaultState — the full decoded struct, if you need a field with no getter.

ctx.vault — computed getters

Derived arithmetic, so you don't re-roll it (and the bugs that come with it).

  • isFrozen: booleanpaused || strategyPaused. If true, don't bother trading.
  • maxSinglePosition: bigintnav × max_position_bps / 10_000. Larger trades abort with EPositionTooLarge.
  • maxAggregateExposure: bigintnav × max_aggregate_exposure_bps / 10_000. Crossing it aborts with EExposureLimitExceeded.
  • exposureHeadroom: bigintmaxAggregateExposure − aggregateExposure, clamped >= 0n. Size new positions against this.
  • openPositionsCount: numbertrackedMarketKeys.length + trackedRangeKeys.length.
  • timeSinceLastSnapshotMs(atMs?): number — ms since the last NAV snapshot; POSITIVE_INFINITY if never snapshotted. Pass ctx.now to align with the tick.

ctx.vault — permission getters

Each is a boolean decoded from strategyPermissions (the full Permissions bitfield). Use one as a pre-flight before returning an action. The runtime's executor re-checks before submitting and the vault enforces on-chain too, so a missing check costs one rejected tick (no gas, no chain mutation).

  • canMintBinary / canRedeemBinary / canMintRange / canRedeemRange
  • canSupplyPlp / canWithdrawPlp / canPmDeposit / canPmWithdraw
  • grantedPermissions: PermissionName[] — every permission currently granted, for logging and error messages.

Next: the Actions you return, and the Result and error you get back.