Introducing a new way to review your PRs.

Read the announcement

solana-foundation / surfpool

Surfpool is where developers start their Solana journey.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / scenario-execution

Scenario execution

Scenario execution lets an engineer describe a time-ordered set of account-state changes and run that history inside a Surfpool environment. A scenario turns protocol data into a repeatable test condition, so transactions can be observed against the same state changes at the same simulated slots.

Scenario subsystem

The subsystem connects a scenario description to the Surfpool slot clock. A caller registers a scenario through the surfnet_registerScenario RPC cheatcode, and Surfpool schedules each enabled account override relative to a chosen base slot.

The subsystem has three related concerns:

  • Scenario definition: A named scenario groups override instances and descriptive tags.
  • State change description: Each override names an account, a protocol template, field values, and a relative slot.
  • Execution: Surfpool applies the scheduled changes as the simulated chain confirms blocks.

Protocol discovery and template meaning are covered in Scenario registry and protocols. Ready-to-use workflow examples are covered in Scenario examples.

Scenario definition

A scenario is a reusable timeline of account overrides. Each override instance identifies the account to change, the template that explains its account shape, the values to set, and whether the change is active.

The scenario model supports both fixed public keys and program-derived addresses (PDAs). A PDA is an account address calculated from a program ID and seeds; some seeds can use values from the same override, which lets one scenario describe a family of related accounts without hard-coding every address.

Scenario conceptRole in a workflow
Name and descriptionExplain the condition that the workflow creates
Override instanceDescribe one account change at one point in time
Template IDSelect the protocol account shape and editable fields
ValuesSet the selected account fields
Relative slotPlace the change after scenario registration
Enabled flagInclude or skip the change without removing it
TagsGroup scenarios for discovery

References: crates/…/scenarios.rs• L464-589

Scenario registration

Registration establishes the scenario timeline but does not require the caller to know the current slot. The caller can provide a base slot. If it does not, Surfpool uses the current absolute slot and converts each relative slot into an absolute slot.

The registration RPC applies overrides at the base slot at once. This makes a relative slot of 0 visible without waiting for another clock step. Later overrides remain scheduled until their target slots are confirmed.

References: crates/…/surfnet_cheatcodes.rs• L1267-1375 crates/…/surfnet_cheatcodes.rs• L2316-2358 crates/…/svm.rs• L4016-4058

Slot timeline

The slot timeline is the mechanism that makes a scenario reproducible. A scenario-relative slot is an offset from registration, so the same scenario can start at different chain positions while preserving the same order of state changes.

This diagram shows how registration turns relative offsets into account updates in the running Surfpool environment.

flowchart LR
    A[Scenario registration] --> B[Choose base slot]
    B --> C[Convert relative slots to absolute slots]
    C --> D[Store overrides by target slot]
    D --> E[Confirm Surfpool block]
    E --> F{Overrides for current slot?}
    F -- No --> G[Continue chain]
    F -- Yes --> H[Materialize enabled overrides]
    H --> I[Transactions observe updated accounts]
    G --> E

Slot placement

Surfpool groups all overrides that share an absolute target slot. The clock and block-confirmation flow then gives each group one point at which it can change the local account state. Overrides at the same relative slot therefore describe one state transition from the workflow's point of view.

A relative slot is not a wall-clock duration. Its real-time distance depends on the Surfpool slot time, while its ordering remains tied to the simulated slot number.

References: crates/…/scenarios.rs• L464-508 crates/…/svm.rs• L4016-4058

Block confirmation

Block confirmation advances the simulated chain and then checks for overrides scheduled at the current slot. This keeps account changes aligned with the chain state that transactions and account readers observe.

The same materialization path is used when the clock changes through the runloop. Time travel therefore processes scheduled changes as part of the same slot-based model instead of treating them as unrelated direct writes.

References: crates/…/locker.rs• L3801-3811 crates/…/mod.rs• L460-500

Account state materialization

Materialization converts an override description into a new local account state. Surfpool resolves the target address, can refresh the account from the remote source when requested, applies the selected fields, and stores the result in the local SVM.

The process preserves the account's surrounding state while changing only the fields named by the override. Field paths use dot notation so a workflow can change a nested protocol value without supplying a complete replacement account.

Address resolution

Address resolution happens when the target slot is reached. Fixed public keys resolve directly. PDA addresses resolve from their program ID and seeds, including seed values that come from the override's values.

Values used only to derive a PDA are not also treated as account fields. This separation lets one override select the account and change its data without accidentally writing address inputs into the account.

References: crates/…/scenarios.rs• L63-106 crates/…/scenarios.rs• L184-248 crates/…/svm.rs• L2577-2607 crates/…/svm.rs• L2663-2672

Account refresh

An override can request fresh account data immediately before use. This is useful when the scenario starts from a live remote account, such as a price feed or a balance that must reflect the latest source state. Without that request, the override uses the account state already available in Surfpool.

The refresh option depends on a remote client. If no remote source is available, the scenario can still be registered, but the requested refresh cannot supply new data.

References: crates/…/scenarios.rs• L493-507 crates/…/svm.rs• L2614-2661

Field override

Surfpool uses the protocol IDL to understand the account layout. It decodes the existing account, changes the requested field paths, and encodes the account again with its account identity preserved. The IDL is therefore the contract between a template's field names and the bytes stored in the simulated account.

The account must already be available or be fetched before use. Its data must match an account type known by the IDL. A field path that does not match the decoded account cannot produce the intended state.

References: crates/…/svm.rs• L2691-2759 crates/…/svm.rs• L2794-2909

Protocol context

Protocol context gives scenario values meaning. A template pairs an account type with its IDL, address rule, editable properties, and optional constants, so a workflow can express a protocol condition instead of constructing serialized account bytes by hand.

The built-in catalog covers common oracle, exchange, lending, market, and token account use cases. It includes Kamino lending controls for reserve, obligation, market, and queued-withdrawal conditions in the Kamino v1.23.0 catalog. It also supports Pump v1 and PumpSwap v1 for pump.fun bonding-curve and migrated-pool state. Custom protocol workflows need an IDL registered with Surfpool before their account data can be decoded and changed.

Template boundary

Templates are the shared boundary between scenario authors and protocol account data. The scenario supplies values and timing. The template supplies the field vocabulary and the account address recipe.

For discovery of built-in templates, protocol coverage, and runtime IDL registration, see Scenario registry and protocols.

References: crates/…/scenarios.rs• L262-404 crates/…/registry.rs• L35-180 crates/…/README.md• L8-33

Kamino lending context

The Kamino templates let a workflow prepare lending conditions at the source that the protocol reads. Reserve templates cover liquidity, risk limits, fees, oracle settings, rewards, and fixed-term debt. Obligation and market templates cover positions, health observations, and market-wide controls. A queued-withdrawal workflow can also combine reserve limits, a market feature gate, and a withdrawal ticket.

This distinction matters when the protocol refreshes derived state. Obligation health values and a reserve's cached price can be recomputed and replace direct overrides. Durable workflows instead change the reserve risk settings or the oracle input that the refresh uses. The catalog also includes named main-market SOL and USDC reserve templates for common conditions without changing the general address-based model.

References: crates/…/overrides.yaml• L11-36 crates/…/overrides.yaml• L51-82 crates/…/overrides.yaml• L113-169 crates/…/overrides.yaml• L306-335 crates/…/overrides.yaml• L353-415 crates/…/overrides.yaml• L420-458 crates/…/overrides.yaml• L517-566

Pump lifecycle

The Pump integration models the two protocol stages in a pump.fun coin's lifecycle. A new coin trades on a Pump bonding curve. After the curve completes, the coin can migrate to a PumpSwap constant-product pool whose reserves live in token accounts.

The graduation workflow is a prepared scenario for a supported SOL-quoted Token-2022 coin. It places the curve one buy away from completion, keeps enough tokens in the curve vault for migration, and enables migration. A real buy and migration transaction then produce the protocol transition that the workflow evaluates. The PumpSwap templates separately support state changes for a migrated pool, including a canonical pool selected from its mint.

This diagram shows how one prepared scenario moves a coin from the bonding curve to its migrated market.

flowchart LR
    A[Live incomplete Pump curve] --> B[Graduation scenario]
    B --> C[Finishing buy]
    C --> D[Completed curve]
    D --> E[Migration transaction]
    E --> F[PumpSwap pool]
    F --> G[Pool reads and trades]

References: crates/…/README.md• L1-12 crates/…/README.md• L134-163 crates/…/graduation_builder.rs• L78-239 crates/…/README.md• L1-15

Workflow composition

A scenario can change several protocol accounts at one slot or across several slots. This makes it suitable for workflows where one condition depends on several pieces of state, such as a lending position becoming liquidatable while market prices create an action for a trading protocol.

The example collection shows this composition with a Kamino obligation and Whirlpool and Raydium market state. For the full scenario shape and example workflows, see Scenario examples.

References: crates/…/kamino-liquidation-arbitrage.json• L1-59

Scenario observability

Scenario execution changes the local account view used by subsequent reads and transactions. The scenario itself is a schedule of state inputs; the protocol under test remains responsible for reacting to those inputs and producing the behavior being evaluated.

This boundary supports repeatable tests without claiming that a scenario proves a protocol outcome. Engineers use the resulting account state to observe whether the protocol accepts, rejects, or responds to the planned condition.

References: crates/…/README.md• L1-5 crates/…/locker.rs• L3801-3811

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the scenario field contract aligned with the RPC schema and any generated bindings when Scenario, OverrideInstance, or address forms change.
  • Keep every template's field paths, account type, and address recipe aligned with its IDL. A mismatch can leave registration successful but prevent materialization.
  • Preserve the base-slot rule when changing registration or clock confirmation. Slot-zero overrides must still become visible at registration.
  • Preserve the distinction between PDA seed values and account data values when changing address derivation or override application.
  • Keep Kamino template fields aligned with the Kamino v1.23.0 IDL and preserve the distinction between derived health or cached-price fields and the source settings that survive refresh.
  • Keep Kamino feature gates aligned with the state they enable. Queued withdrawals and maturity liquidation need both their account conditions and their market-wide controls.
  • Keep Pump and PumpSwap templates aligned with their bundled IDLs and with the account rules for curve completion, migration, and pool selection.
  • Keep the graduation workflow's eligibility checks and prepared account state aligned with the transactions that complete a Pump curve and create its PumpSwap pool.
  • Update the child pages when protocol coverage or the shape of the example workflows changes: Scenario registry and protocols and Scenario examples.

Important failure modes

TriggerConsequenceGuard
An override uses a PDA seed value that cannot be resolvedSurfpool skips that account changeSupply valid seed values and a valid program ID
The target account is absent and fetchBeforeUse is falseField changes are skipped because there is no account state to editLoad the account first or request a remote refresh
The account owner has no registered IDLSurfpool cannot interpret the account fields and skips the overrideRegister the protocol IDL before execution
A field path does not match the decoded accountThe intended state cannot be forgedUse paths exposed by the selected template and account type
fetchBeforeUse is enabled without a remote sourceFresh data is not availableRun with a remote context or disable the refresh request
An override is disabledThe scheduled entry is ignored at its target slotEnable the override when it is part of the intended workflow
A Kamino workflow changes derived obligation health or reserve cached price before a protocol refreshThe refresh recomputes the value and removes the intended conditionChange the reserve risk settings or the oracle input that the refresh reads
A Kamino queued-withdrawal or maturity workflow omits its market-wide feature gateThe account state is prepared but the protocol path stays inactiveEnable the matching withdrawal or maturity liquidation control on the lending market
A Pump graduation workflow receives a classic SPL-Token mint, a non-SOL quote, an already complete curve, or an existing canonical poolThe preparation is rejected instead of producing a runnable graduation scenarioUse an incomplete SOL-quoted Token-2022 curve with no canonical PumpSwap pool
A PumpSwap canonical-pool template is used for a pre-PumpSwap migration or a non-WSOL poolThe intended pool cannot be selected by the canonical address ruleUse the direct pool-state template with the pool address when the pool is not canonical and WSOL-quoted
Pump or PumpSwap legacy flat fee fields are changed while evaluating a live tradeThe trade fee remains controlled by the external fee configurationTreat the fee configuration used by the trade as the source of fee behavior

Key files

FileWhy to read it
crates/…/scenarios.rsDefines the scenario, override, address, template, and timing contracts shared by the subsystem.
crates/…/surfnet_cheatcodes.rsShows the external registration interface and the base-slot behavior for RPC callers.
crates/…/svm.rsShows how Surfpool schedules and materializes account changes at target slots.
crates/…/locker.rsShows the boundary that coordinates block confirmation and override materialization.
crates/…/mod.rsShows how clock updates cause scheduled changes to be processed during chain progress.
crates/…/registry.rsShows how built-in protocol templates become available for scenario construction.
crates/…/README.mdGives the subsystem's high-level purpose and the relationship between IDLs, registration, and templates.
crates/…/overrides.yamlDefines Kamino v1.23.0 reserve, obligation, lending-market, queued-withdrawal, and named-reserve conditions exposed to scenario authors.
crates/…/kamino-liquidation-arbitrage.jsonIllustrates a multi-protocol scenario that composes several account conditions.
crates/…/README.mdExplains the Pump-to-PumpSwap lifecycle and the supported state-preparation workflows.
crates/…/graduation_builder.rsShows how live Pump accounts become a migration-ready graduation scenario.
crates/…/README.mdExplains the PumpSwap pool templates and the boundary between pool state and vault reserves.
crates/…/overrides.yamlDefines the PumpSwap template choices and the account fields exposed to scenario authors.