Skip to content

Commit db36cd9

Browse files
authored
docs: add scenarios README (#405)
1 parent 647b670 commit db36cd9

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

.github/ISSUE_TEMPLATE/native-scenario-support-for-protocol.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ assignees: ''
88

99
---
1010

11-
*Protocol Name*:
11+
**Protocol Name**:
1212

13-
# If you have an IDL, that makes supporting the protocol much easier for us. Please provide it here
13+
<!-- If you have an IDL, that makes supporting the protocol much easier for us. Please provide it here -->
1414

1515
<details>
1616
<summary>Protocol IDL</summary>

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Includes Stream Oracles, Universal Faucet, Transaction Inspector, and Time Trave
4646
Surfpool Studio is your local dashboard to visualize, inspect, and manage your networks in real time.
4747
Surfpool Cloud extends that same experience to the cloud — letting you index mainnet data and run large-scale simulations with the same developer experience. It’s serverless, backend-as-a-service, and built for analytics at scale.
4848

49+
### 🧪 Surfpool Scenarios
50+
With Surfpool Scenarios you can curate slot-by-slot account states for key accounts, mixing live mainnet data with overridden account states.
51+
This allows you to stress test your protocol in key real-world situations and to reproduce any chain-state conditions. See the [Scenarios Docs](./crates/core/src/scenarios/README.md) for more details.
52+
4953
## Installation
5054

5155
Install pre-built binaries:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Surfpool Scenarios
2+
This module contains pre-defined scenarios that can be executed within the Surfpool environment.
3+
These scenarios allow you to create a time-sequence of account states.
4+
As the scenario is executed, each step, which is associated with a subsequent slot in the surfnet, will override the surfnet accounts db with the account states defined in that step.
5+
This powerful tool allows for testing and simulation of various account states over time, enabling developers to observe how different scenarios will impact their protocol.
6+
7+
8+
## Scenario Components
9+
There are a few components that allow a scenario to function.
10+
11+
### Program IDL
12+
For Surfpool to understand how to serialize and deserialize account data, it needs to have access to the program's IDL.
13+
Protocol's that are natively supported by Surfpool will have their IDLs included by default.
14+
For custom protocols, an IDL can be registered at runtime using the [`surfnet_registerIdl`](https://docs.surfpool.run/rpc/cheatcodes#surfnet-registeridl) RPC cheatcode.
15+
16+
### Scenario Registration
17+
Scenarios can be registered at runtime using the [`surfnet_registerScenario`](https://docs.surfpool.run/rpc/cheatcodes#surfnet-registerscenario) RPC cheatcode.
18+
This cheatcode takes in a scenario definition in JSON format, which includes the scenario name, description, and a list of overrides to apply to accounts.
19+
Each override contains a map of the field in the account to override (as indexed in the IDL), and the value to apply for that key.
20+
21+
### Override Templates
22+
Directly using the `surfnet_registerScenario` endpoint requires building out a map of account keys that are specific to the schema of the account that is being written to.
23+
This is a cumbersome process in most cases.
24+
Override templates that are registered in the Surfpool repo will automatically be available in Surfpool Studio's drag-and-drop UI for creating scenarios.
25+
This UI will automatically create the `surfnet_registerScenario` payload for you, eliminating the complexity from the process.
26+
27+
## Creating Native Scenario Support for a Protocol
28+
Having a protocol being natively supported by Surfpool Scenarios will allow users to easily create scenarios to override account states for that protocol.
29+
All accounts in a surfnet's account db that are owned by the protocol will include automatic IDL-parsing, and the protocol's account overrides will be available in Surfpool Studio's drag-and-drop UI.
30+
31+
The following steps can be followed to natively support a protocol:
32+
1. Create a folder for the protocol in the `crates/core/src/scenarios/protocols` folder. For example, `crates/core/src/scenarios/protocols/pyth/v2`.
33+
2. Add a file called `idl.json` containing the protocol's anchor IDL to the folder. For example, see [Pyth's IDL](./protocols/pyth/v2/idl.json)
34+
3. Add a file called `overrides.yaml` to the folder. For example, see [Pyth's Override File](./protocols/pyth/v2/overrides.yaml).
35+
1. This file is what will populate Surfpool Studio's UI with the protocol details. The Pyth override file linked above produces the following in the UI:
36+
![Pyth Overrides](../../../..//doc/assets/pyth-overrides.png)
37+
4. Update the [registry.rs](./registry.rs) file. A small amount of code has to be written to wire together the template registry, the `overrides.yaml`, and the `idl.json`. See the `load_pyth_overrides` function for example.
38+
39+
If any part of these instructions are beyond your skill level or availability, but you'd like to see a specific protocol supported, feel free to [Open an Issue to Support a new Protocol](https://github.com/txtx/surfpool/issues/new?template=native-scenario-support-for-protocol.md)!
40+
Opening an issue to signal interest is a big help.
41+
If you're able to find an IDL for the protocol, even better!

crates/core/src/scenarios/protocols/pyth/v2/overrides.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ tags:
99
- defi
1010

1111
templates:
12+
- id: pyth-sol-usd-v2
13+
name: Override SOL/USD Price Feed
14+
description: Override Pyth SOL/USD price feed with custom price data
15+
idl_account_name: PriceUpdateV2
16+
properties: ["price_message.price", "price_message.publish_time"]
17+
address:
18+
type: pubkey
19+
value: 7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE
20+
1221
- id: pyth-btc-usd-v2
1322
name: Override BTC/USD Price Feed
1423
description: Override Pyth BTC/USD price feed with custom price data

doc/assets/pyth-overrides.png

429 KB
Loading

0 commit comments

Comments
 (0)