|
| 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 | +  |
| 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! |
0 commit comments