Scenario registry and protocols
Scenarios describe repeatable changes to protocol account state over simulated time. The registry turns protocol account schemas and workflow metadata into selectable templates. Callers discover those templates, choose a stable template ID, provide its supported values, and then submit a scenario for storage or execution. This page is a child of Scenario execution and relates to Scenario examples.
Scenario model
The scenario system separates a reusable account recipe from a concrete timeline. A template defines how to address one protocol account and which account fields can change. A scenario contains override instances that use those templates at selected relative slots.
Template registry
The TemplateRegistry is the catalog of built-in protocol templates. It loads each protocol's account IDL with its override description, then indexes the resulting templates by their unique IDs. Callers can read the full catalog, find one template by ID, or filter templates by protocol or tag. References: crates/…/registry.rs• L35-180
The registry is created in the core runtime and in the caller-facing services. This gives the SVM the account schemas needed to apply overrides and gives Studio and MCP the same catalog for discovery and validation. References: crates/…/svm.rs• L612-617, crates/…/mod.rs• L57-68, crates/…/mod.rs• L132-145
Scenario definitions
An OverrideTemplate identifies a protocol, account type, editable property paths, address rule, constants, and tags. An OverrideInstance supplies values for one template and assigns the change to a relative slot. A Scenario groups those instances into a named timeline. References: crates/…/scenarios.rs• L373-404, crates/…/scenarios.rs• L464-508, crates/…/scenarios.rs• L535-588
The scenario timeline is relative to a base slot. When the runtime registers a scenario, it converts each relative slot to an absolute slot and stores the override for later materialization. Disabled instances are skipped when their slot is reached. References: crates/…/svm.rs• L4016-4057, crates/…/svm.rs• L2541-2581
Protocol template catalog
Protocol support is expressed as data that describes real account layouts and valid state changes. Each protocol directory pairs an IDL with an overrides.yaml file. The IDL supplies the account shape. The YAML file supplies the template names, property paths, address rules, constants, and tags.
Protocol coverage
The built-in registry loads 24 templates across the following supported workflow groups. The table groups them by the kind of state a caller can model rather than listing every template ID.
| Protocol group | Workflow focus | Template count |
|---|---|---|
| Pyth | Price-feed account changes | 1 |
| Jupiter | Intermediate token amounts in multi-hop swaps | 1 |
| Raydium CLMM | Concentrated-liquidity pool state and dynamic pool selection | 1 |
| Raydium AMM v4 | Pool state, fees, swap statistics, and OpenBook market selection | 4 |
| Meteora DLMM | Fixed pool state for selected token pairs | 2 |
| Kamino | Reserve liquidity, risk settings, and obligation health | 3 |
| Drift | Perpetual, spot, user, and global market state | 4 |
| Whirlpool | Fixed or custom concentrated-liquidity pool state | 6 |
| SPL Token | Token account balances and mint supply | 2 |
The registry's load sequence is the source of truth for which protocol templates are available to callers. A protocol asset in the source tree is not selectable until its IDL and override definition are included in that sequence. References: crates/…/registry.rs• L5-33, crates/…/registry.rs• L42-112, crates/…/registry.rs• L329-371
Account addressing
Templates use either a fixed public key or a program-derived address (PDA). A fixed-address template expects the caller to identify the account. A PDA template derives the account from its program ID and seed rules after the caller supplies the referenced values.
PDA seed values serve two separate roles. Values named by seed references select the account address. Other values update fields in the account data. The runtime removes seed-only values before it applies account changes, so an address selector does not become an account field update. References: crates/…/scenarios.rs• L63-106, crates/…/scenarios.rs• L184-248, crates/…/svm.rs• L2663-2697
Protocol constants
A constant definition is a named set of valid choices such as a price feed, token mint, fee tier, or market. A property marked as a constant_ref points to one of these sets. This lets a caller select a known value while preserving the protocol-specific meaning of that value and its metadata.
Some constant sets are written inline. Others are built from the verified token registry. The runtime resolves those sources into the same option form before it exposes a template. References: crates/…/scenarios.rs• L16-57, crates/…/scenarios.rs• L693-798, crates/…/overrides.yaml• L65-101
Workflow selection
Callers select workflows through template discovery rather than by inventing protocol names or account layouts. The normal path is to read the catalog, choose a template ID, resolve any constant choices, fill the template properties, and submit the resulting scenario.
The diagram shows how a caller moves from a supported workflow to a scheduled account change.
flowchart LR
A[Discover templates] --> B[Choose template ID]
B --> C[Resolve constant choices]
C --> D[Fill supported properties]
D --> E[Create scenario timeline]
E --> F{Caller path}
F -->|Studio or MCP| G[Store scenario]
F -->|Surfnet RPC| H[Register scenario]
G --> I[Runtime consumes scenario]
H --> I
I --> J[Materialize override at target slot]
Template discovery
Studio exposes the complete template catalog at GET /v1/scenarios/templates. MCP exposes the same registry through get_override_templates; its response keeps constant option lists compact and reports their counts. A caller should use the returned id, properties, address, and constant names as the contract for the next request. References: crates/…/mod.rs• L146-161, crates/…/mod.rs• L52-87, crates/…/mod.rs• L886-907
Constant selection
MCP callers resolve large or ambiguous constant sets with search_constant_options. The search accepts a template ID and an optional constant name, then returns the option value that belongs in the scenario. This keeps selection tied to the chosen template and avoids copying a large catalog into the create request. References: crates/…/mod.rs• L90-105, crates/…/mod.rs• L909-990
Scenario submission
The MCP create_scenario path checks every templateId against the registry. It also checks constant-reference values and replaces a PDA account description with the address rule from the selected template. It then stores the validated scenario through the Studio scenario endpoint and returns a Studio URL.
The direct surfnet_registerScenario RPC path sends a scenario to the runtime. The runtime schedules its overrides against the supplied base slot or the current slot. It materializes the base-slot overrides immediately, so a relative slot of zero is visible without waiting for another slot. References: crates/…/mod.rs• L598-641, crates/…/mod.rs• L642-803, crates/…/mod.rs• L805-883, crates/…/surfnet_cheatcodes.rs• L1369-1375, crates/…/surfnet_cheatcodes.rs• L2316-2352
Caller contracts
The caller contract is small but strict. Template IDs and property paths come from discovery. Scenario data uses native JSON objects and arrays. Address selectors must contain enough values for every PDA seed to resolve.
Selection inputs
| Input | Meaning | Source of truth |
|---|---|---|
templateId | The reusable protocol account recipe | Template catalog id |
values | Account fields and any PDA seed references | Template properties and address |
scenarioRelativeSlot | The slot offset for the override | Caller timeline |
account | Fixed address or template-derived address | Template address |
enabled | Whether the runtime applies the instance | Caller scenario |
For a PDA template, callers normally omit a hand-built account address when using MCP. The service copies the template's PDA rule and resolves it from values. For a fixed-address template, the caller supplies the intended account address. References: crates/…/mod.rs• L608-640, crates/…/scenarios.rs• L464-508
Storage identity
Studio stores scenarios by scenario ID. Repeating the same ID with identical content is a no-op. Reusing that ID with different content returns a conflict. A caller that wants new content must choose another ID or update the existing scenario through the patch route. References: crates/…/mod.rs• L175-220, crates/…/mod.rs• L259-290
Change checklist
When these files or sections are changed, remember to consider these:
- When adding a protocol template, update the registry load sequence so the template is visible to the runtime, Studio, and MCP.
- Keep each override property path aligned with the account name and fields in its IDL. A valid template ID with a stale field path can fail only when the account is materialized.
- Keep PDA seed references aligned with the names in
propertiesand with the values accepted by constant definitions. - Preserve template IDs once callers may have stored scenarios that refer to them. An ID change is a caller contract change.
- Keep the direct RPC registration path and the discovery-based caller path aligned when changing base-slot or slot-zero behavior.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A caller invents a templateId | MCP rejects the scenario and lists valid IDs | Discover templates first and use the returned ID |
| A constant-reference value is not one of the template options | MCP rejects the override before storage | Resolve the option through search_constant_options |
| A PDA seed value is missing or has the wrong form | The account address cannot be derived, so the override is skipped | Supply every referenced seed value in values |
| A seed-only value is treated as account data | The override may attempt to write a field that is only an address selector | Keep PDA references separate from editable account fields |
| A protocol IDL or override file is loaded incorrectly | Registry creation fails and the supported catalog is unavailable | Treat the paired IDL and YAML definition as one change |
| A different scenario uses an existing scenario ID | Studio returns HTTP 409 and does not replace the stored scenario | Use a new ID or patch the existing scenario |
Key files
| File | Why to read it |
|---|---|
| crates/…/registry.rs | Defines the built-in catalog, protocol load sequence, lookup methods, and registry-level contracts. |
| crates/…/scenarios.rs | Defines the shared template, scenario, address, PDA seed, constant, and YAML-to-runtime concepts. |
| crates/…/svm.rs | Shows how registered scenarios become slot-based runtime changes and how account addresses and values are materialized. |
| crates/…/surfnet_cheatcodes.rs | Defines the direct surfnet_registerScenario caller contract and its initial materialization behavior. |
| crates/…/mod.rs | Defines template discovery and scenario storage through the Studio HTTP API. |
| crates/…/mod.rs | Defines discovery, constant lookup, validation, and scenario creation for MCP callers. |
| crates/…/overrides.yaml | Illustrates a data-driven oracle template with constants and a PDA derived from caller values. |
| crates/…/overrides.yaml | Illustrates dynamic protocol account selection with nested PDA derivation and verified-token choices. |
| crates/…/overrides.yaml | Illustrates simple fixed-address account templates and their role in broader pool workflows. |