Shared contracts and generated types
The surfpool-types crate is the shared contract layer for the Rust runtime, RPC services, scenario tools, and TypeScript clients. It gives these systems one meaning for network state, startup readiness, account changes, scenario inputs, bundle simulation, and developer controls. See Runtime and RPC service, Scenario execution, and Developer integrations for the systems that use these contracts.
Contract boundary
The public crate boundary is assembled by crates/…/lib.rs. Its Serde rules define the JSON shapes that cross RPC and language boundaries. A field name, enum tag, null value, or number form can therefore affect both Rust callers and generated TypeScript.
Runtime values
Runtime values describe transaction results, account state, profiles, snapshots, network settings, clock actions, and status data. They keep Solana values in Rust while exposing stable forms for RPC and client views. For example, account maps use public-key strings on the wire, and older transaction data can omit loaded account data size and read it as zero.
Account profile values compare state before and after execution. Client views classify accounts as read-only or as created, changed, deleted, or unchanged. Snapshot values provide an account image that other parts of the system can restore into a simulated network.
Account update values also support Token-2022 confidential-transfer test state. The related balance response keeps unavailable balances as explicit null values, so clients can distinguish an unreadable balance from a zero balance.
References: crates/…/lib.rs• L1-19 crates/…/types.rs• L35-70 crates/…/types.rs• L251-335 crates/…/types.rs• L1150-1355
Event delivery
SimnetEvent carries runtime lifecycle, clock, transaction, account, profile, runbook, and log changes to readers. The event sender assigns a delivery rule to each class so useful telemetry can yield under load without losing lifecycle progress.
- Log and state-observation events such as startup status, clock, account, and transaction updates use lossy delivery.
- Lifecycle events use lossless delivery and can block when the buffer is full.
- Lossless sends must occur outside the SVM lock because the reader may need that lock to drain the buffer.
References: crates/…/types.rs• L438-483 crates/…/types.rs• L576-663 crates/…/types.rs• L665-745
Configuration values
Shared configuration gives the CLI, embedded runtime, and clients the same defaults for RPC, WebSocket, Studio, gossip, TPU, and slot timing. Surfnet settings also describe the remote data source, block production mode, snapshots, profiling, and the startup planner.
The startup planner identifies the one actor that seals the startup task plan. The runloop can seal an empty plan. An external planner can inspect a project and seal declared work. Public data-source URLs are reduced to scheme and host so credentials do not cross a client or log boundary.
References: crates/…/constants.rs• L1-3 crates/…/types.rs• L35-42 crates/…/types.rs• L876-975 crates/…/types.rs• L981-1035
Cheatcode controls
Cheatcode controls define which Surfnet management methods remain available to a client. The shared contract distinguishes ordinary cheatcode disabling from a permanent lockout, and a full lock also gates selected standard RPC and process-control methods such as airdrops and plugin loading.
The canonical method list feeds client discovery and validates configured filters. A lockout is one-way for the affected methods, so a client cannot re-enable a method after the system applies the lock.
References: crates/…/types.rs• L1817-1857 crates/…/types.rs• L1875-1957 crates/…/types.rs• L1992-2126
Feature definitions
Feature definitions describe changes to the simulated SVM relative to its mainnet-beta feature baseline. They let callers reproduce older behavior or enable known gates without rebuilding the full feature set.
Feature selection
Callers can select a known Agave feature by kebab-case name, snake_case name, or base58 public key. The parser checks names and keys against the known feature set, so an arbitrary public key cannot become a feature gate.
SvmFeatureConfig keeps separate enable and disable sets. A later choice for a feature removes it from the opposite set. An empty configuration means the mainnet baseline. The all-features form explicitly enables every known gate.
References: crates/…/features.rs• L7-16 crates/…/features.rs• L77-107 crates/…/features.rs• L109-178
Startup lifecycle
The startup contract tells clients when a Surfnet is safe to use. Readiness means the sealed startup plan completed its required account hydration and runbook work. It does not mean only that servers have bound their ports.
Startup phases
Startup begins in planning and moves to a sealed task plan. The public phase is derived from the plan and its task states, so an unsealed plan cannot report readiness and terminal states cannot move again.
The main phase flow is shown below. Remote account work and runbook work can overlap, but incomplete remote-account work has priority in the phase view.
flowchart LR
Planning -->|seal plan| CloningRemoteAccounts
Planning -->|planning error| Failed
CloningRemoteAccounts -->|remote accounts complete| ExecutingRunbooks
CloningRemoteAccounts -->|task error| Failed
ExecutingRunbooks -->|all tasks complete| Ready
ExecutingRunbooks -->|task error| Failed
Ready -->|terminal| EndReady(( ))
Failed -->|terminal| EndFailed(( ))
References: crates/…/startup.rs• L74-112 crates/…/startup.rs• L310-341 crates/…/startup.rs• L457-481
Task transitions
Sealing fixes the required task kinds and starts each declared task as Pending. Repeated task kinds become one obligation. An empty sealed plan is ready at once.
Each task moves from Pending to Running and then to Succeeded. A task can fail from Pending or Running. Succeeded and Failed are terminal. A refused transition leaves the state unchanged and reports both the attempted move and the state that rejected it.
References: crates/…/startup.rs• L92-176 crates/…/startup.rs• L418-565 crates/…/startup.rs• L615-701
Readiness compatibility
The wire status exposes phase, planSealed, tasks, and error. Deserialization rebuilds state from the authoritative fields instead of trusting a claimed phase. It removes duplicate task kinds, repairs missing failure text, removes stray task errors, and rejects a top-level error with no failed task.
Older clients read startup through runbookExecutions. During planning or active startup, the response adds one incomplete synthetic runbook entry. A failed startup adds a completed entry with errors. A ready startup omits the entry. CoreStarted is an earlier event, so clients must use the startup phase or its compatibility view for readiness.
References: crates/…/startup.rs• L8-71 crates/…/startup.rs• L343-415 crates/…/types.rs• L438-457
Scenario models
Scenario types describe planned account-state changes over simulated slots. A scenario combines reusable account templates with concrete override instances so tools can model protocol conditions without repeating each account layout.
Templates and constants
An OverrideTemplate describes a protocol account through its IDL, account type, address rule, editable properties, and optional constants. A property names an IDL path and can be a normal field, a constant choice, a live value source, or a protocol input. A ConstantDefinition supplies named values and UI metadata.
Templates can use a shared or embedded IDL. When no usable IDL exists, the template uses rawLayout to describe byte positions and encodings. IDL documentation can fill a property description when the template does not provide one. This keeps file-based templates and RPC-provided templates in the same runtime model.
References: crates/…/scenarios.rs• L14-60 crates/…/scenarios.rs• L254-332 crates/…/scenarios.rs• L386-424 crates/…/scenarios.rs• L437-479 crates/…/scenarios.rs• L1405-1505
Account address rules
An AccountAddress identifies either a fixed public key or a program-derived address. PDA seeds can use literals, bytes, public keys, numeric encodings, property values, or a nested PDA.
Property references used in seeds affect address derivation only. They remain separate from account fields, so a value used to choose an address is not also written into account data. Address resolution fails when a program ID, seed, or required encoding is invalid.
References: crates/…/scenarios.rs• L63-248 crates/…/scenarios.rs• L1493-1577
Scenario timelines
An OverrideInstance binds a template to concrete values, an account address, and a slot relative to scenario registration. It can be enabled or disabled and can request fresh account data before use. A Scenario groups these instances and keeps them ordered by relative slot.
At a target slot, execution selects enabled overrides whose relative slot matches that slot. Scenario configuration separately controls whether scenarios are active and whether changes are saved automatically.
References: crates/…/scenarios.rs• L555-703
Keep-alive updates
Keep-alive imports model protocol actors that refresh related accounts every slot after an override starts. An import can write the importing override's account, an address supplied through an input, or a fixed or derived address. Its values can use slot and block-time placeholders, so the refresh follows the simulated clock until the network resets.
File-level imports apply to each template unless that template replaces them or opts out. The shared model keeps these input addresses and PDA seed references separate from fields written by the main override.
References: crates/…/scenarios.rs• L475-479 crates/…/scenarios.rs• L1020-1048 crates/…/scenarios.rs• L1537-1714
Raw account layouts
Raw layouts provide a controlled write path for programs without a usable IDL. A writable property names a byte offset and exact encoding. Encodings can write scalar values, repeated values with a fixed stride, XOR-transformed values, or values derived from the materialization slot. A selector property supplies a constant choice for an address or catalog value, while an input supplies a value to the override without writing account bytes.
Validation rejects duplicate paths, missing write metadata, invalid strides, overlapping ranges, and writes beyond the account. Large integers use decimal strings when a JSON number cannot preserve them exactly. Slot-derived values move with the materialization slot and reject positive overflow.
References: crates/…/scenarios.rs• L254-322 crates/…/scenarios.rs• L1072-1245 crates/…/scenarios.rs• L1259-1377
Constant definitions
Constant definitions turn fixed protocol choices into shared named options. They give a UI or caller a label, safe value, description, and context instead of a bare address.
Option sources
YAML constants can define options inline or load them from the verified-token registry. Registry-backed options can filter by mint-address suffix and limit the result. They use the mint address as both option ID and value. Symbol and decimal data provide client context, while label and address sorting give stable results.
A constant_ref property is valid only when it names an existing definition. Raw-layout validation applies the same rule and prevents a selector from also claiming byte-write metadata.
References: crates/…/scenarios.rs• L14-60 crates/…/scenarios.rs• L731-846 crates/…/scenarios.rs• L1125-1172
Jito bundle models
The Jito bundle models define the JSON contract for simulateBundle. They let Jito-compatible clients submit encoded transaction bundles and receive one summary plus one result for each transaction.
Bundle requests and results
The request carries encoded transactions, optional per-transaction account snapshots, and simulation choices such as base64 encoding, blockhash replacement, signature checks, and the simulation bank. When snapshot lists are present, each list must match the bundle length.
The summary is Succeeded only when every transaction simulates cleanly. A failed summary carries a typed bundle error and, when known, the first failing transaction. Per-transaction fields are optional because the server may provide only the enrichment it has. null means not provided, not necessarily failed.
Bundle execution is serialized with other live-VM mutations. The shared command contract treats the snapshot, sandbox simulation, and commit as one operation, so a regular transaction cannot change live state between the bundle's snapshot and its commit.
References: crates/…/jito_bundles.rs• L1-12 crates/…/jito_bundles.rs• L26-93 crates/…/jito_bundles.rs• L95-165 crates/…/types.rs• L767-826
Verified-token data
The verified-token registry supplies trusted token choices to shared templates and clients. The bundled CSV is the source data for an ordered catalog and a symbol lookup map.
Token registry
Each TokenInfo contains a mint address, name, symbol, decimal count, and optional logo URI. The ordered catalog preserves valid CSV rows and is the source for option lists. The symbol map normalizes symbols to uppercase and keeps the last token when symbols repeat.
Blank and malformed rows are skipped. A catalog change must therefore be checked against both mint-based option lists and symbol-based lookup. Duplicate symbols are safe only when callers do not need unique symbol resolution.
References: crates/…/verified_tokens.rs• L5-12 crates/…/verified_tokens.rs• L48-91 crates/…/verified_tokens.csv• L1-5 crates/…/lib.rs• L11-19
TypeScript bindings
TypeScript bindings give Node clients the same wire shapes as the Rust contracts. The optional ts-bindings feature enables exports from Rust types, while mirror types describe foreign Solana values that cannot derive bindings directly.
Binding sources and mirrors
Rust types and their Serde shapes are the source of truth for exported types. This includes scenario values, startup responses, account updates, profiles, snapshots, confidential-token values, and RPC data. Large numeric fields use explicit client-safe forms such as number | bigint.
Nullable fields must keep their wire meaning during generation. For example, confidential balance fields are nullable because a missing decryption key produces null; they are not optional fields that disappear from the response. The startup status field stays out of the generated shape because its hand-written wire form is represented through the compatibility response for older clients.
Mirror types preserve the JSON shape of foreign account values and local enums that carry them. Serialization checks compare real and mirror values. Exhaustive enum matches force binding work when a source enum gains a variant.
References: crates/…/Cargo.toml• L43-58 crates/…/types.rs• L251-315 crates/…/types.rs• L1150-1355 crates/…/types.rs• L1730-1745 crates/…/scenarios.rs• L63-71 crates/…/ts_bindings.rs• L1-85 crates/…/ts_bindings.rs• L136-175
Generation pipeline
The Node binding generator removes the old generated set, runs the full surfpool-types test suite with ts-bindings, and writes the resulting files into the Kit SDK generated directory. It adds a generated header and creates the export index and cheatcode method manifest.
SURFNET_CHEATCODE_METHODS is the shared list for the surfnet_* method manifest. Runtime registration checks keep that list aligned with methods exposed by the server. Generated files are committed for the Node package and are not hand-edited.
References: crates/…/types.rs• L1900-1936 crates/…/ts_bindings.rs• L307-326 crates/…/generate-kit-types.js• L1-60
RPC endpoint catalog
crates/…/rpc_endpoints.json is a descriptive catalog of RPC methods for tools that need to discover the available service surface. It groups standard transaction, account, health, and network methods with Surfpool cheatcodes and records their inputs and output purpose. It also describes aggregate transaction lookup and account-state controls such as scenario registration and confidential token-account setup.
The MCP integration exposes this catalog as a resource. It is a discovery aid rather than the Rust type source for every response, so changes to an endpoint must keep the catalog aligned with the RPC service and its shared request or response contracts.
References: crates/…/rpc_endpoints.json• L1-7 crates/…/rpc_endpoints.json• L127-151 crates/…/rpc_endpoints.json• L634-738 crates/…/mod.rs• L1423-1456
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to a Serde field, enum tag, nullability rule, or numeric type require checking generated TypeScript and RPC clients that consume the shape.
- Changes to startup phases, task kinds, or startup events require checking both the readiness phase and the older
runbookExecutionscompatibility view. - Changes to event classification require checking whether the event can be dropped and whether a lossless send can block while a runtime lock is held.
- Changes to scenario property paths, PDA seeds, raw encodings, or layout validation require checking template loading and account materialization together.
- Changes to keep-alive addresses, placeholders, inheritance, or input references require checking per-slot refreshes and the importing override's write set.
- Changes to constant sources or verified-token rows require checking selector options, deterministic ordering, and symbol lookup behavior.
- Changes to the Jito bundle shape require checking per-transaction array lengths, optional enrichment, and the external Jito JSON contract.
- Changes to bundle mutation ordering require checking the serialized snapshot, sandbox, and commit boundary against regular transactions and other state mutations.
- Changes to
SURFNET_CHEATCODE_METHODSrequire checking runtime registration, the generated method manifest, and the endpoint catalog. - Changes to cheatcode lockout or gated standard methods require checking filter validation, permanent-disable behavior, and the methods available after startup.
- Changes to rpc_endpoints.json require checking MCP discovery and the corresponding RPC method contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A client treats CoreStarted or server bind completion as readiness | A transaction can run before account hydration or runbooks complete | Wait for startup phase ready or its compatibility projection |
| A lifecycle event uses lossy delivery | A reader can miss a startup, shutdown, or runbook state change | Use the event delivery class and send lossless events outside the SVM lock |
| A malformed startup response trusts its claimed phase | A client can appear ready too early | Derive readiness from planSealed, task states, and errors |
| A scenario has an invalid PDA seed or property value | Address resolution fails instead of selecting a different account | Validate the address rule and referenced values before registration |
| A raw layout overlaps ranges or writes beyond the account | Account bytes are ambiguous or cannot be materialized | Validate all placements before writing |
| A raw layout uses an incorrect repeat stride, XOR mask, or slot lead | The materialized account contains valid bytes with the wrong protocol meaning | Treat the layout metadata as part of the protocol contract and verify it against the target account format |
| A large raw-layout integer is sent as an inexact JSON number | Encoded bytes can differ from the intended value | Send large values as decimal strings |
| A slot-derived raw value overflows the target slot | Materialization fails instead of writing a wrapped slot | Reject positive overflow and use the defined saturating behavior for negative offsets |
| A keep-alive import has an invalid target, value, or placeholder | The related account is not refreshed at the expected slot | Validate imports and resolve values against the simulated clock |
| A bundle supplies non-empty account hint arrays with the wrong length | The request is rejected as invalid parameters | Keep pre- and post-account hint arrays aligned with transaction count |
| A bundle allows another VM mutation between snapshot and commit | The bundle can commit against state different from the state it simulated | Keep bundle execution inside one serialized live-VM operation |
| A verified-token symbol is repeated | Symbol lookup returns only the last matching mint | Use the ordered catalog when mint identity matters |
| A source enum changes without the TypeScript mirror update | Generated bindings can expose the wrong JSON shape | Use mirror serialization and exhaustiveness checks during regeneration |
A confidential balance field is treated as absent when its value is null | A client can confuse an unreadable balance with a zero balance | Preserve nullable fields as explicit wire keys |
| The cheatcode list and runtime registration diverge | Clients advertise missing methods or omit methods that exist | Keep SURFNET_CHEATCODE_METHODS aligned with runtime registration |
| A full cheatcode lock is treated as a normal temporary disable | Protected RPC or process-control methods remain available after the lock | Preserve the full-lock contract for all methods in GATED_RPC_METHODS |
| The endpoint catalog is stale | MCP users can discover methods or schemas that do not match the service | Update the catalog with the RPC contract |
Key files
| File | Why to read it |
|---|---|
| crates/…/lib.rs | Shows the public shared boundary and domain modules. |
| crates/…/types.rs | Defines runtime values, configuration, events, account updates, snapshots, client responses, VM operation contracts, and the cheatcode method source. |
| crates/…/features.rs | Defines known feature selection and SVM feature overrides. |
| crates/…/startup.rs | Defines startup evidence, phase derivation, transitions, and compatibility projection. |
| crates/…/scenarios.rs | Defines scenario templates, address rules, timelines, constants, IDL paths, raw layouts, keep-alive updates, and protocol-specific raw encodings. |
| crates/…/jito_bundles.rs | Defines the Jito-compatible bundle simulation request and result shapes. |
| crates/…/verified_tokens.rs and crates/…/verified_tokens.csv | Define the bundled token catalog and its lookup source. |
| crates/…/ts_bindings.rs | Defines mirrors and checks for foreign types used in TypeScript exports. |
| crates/…/rpc_endpoints.json | Describes the RPC discovery catalog exposed to MCP clients. |
| crates/…/generate-kit-types.js | Shows how Rust contracts become generated Kit bindings. |
| crates/…/surfnet_cheatcodes.rs | Shows the runtime check that keeps cheatcode registration aligned with the shared method list. |