Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/core/src/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ This is a cumbersome process in most cases.
Override templates that are registered in the Surfpool repo will automatically be available in Surfpool Studio's drag-and-drop UI for creating scenarios.
This UI will automatically create the `surfnet_registerScenario` payload for you, eliminating the complexity from the process.

A collection tagged `clock-sensitive` holds accounts with a time or slot the program checks against the Clock, such as a
Pyth price's `publish_time` or the oracle staleness window of Phoenix markets. Playing such a scenario with the clock paused
leaves fetched accounts ahead of the surfnet's time, and the program can refuse transactions; Studio warns before pausing for
them. The tag applies to every template in the collection, including ones without a time check.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would help to say that the tag is read at collection level only, because entry-level tags are ignored (YamlOverrideTemplateEntry has no tags field). Otherwise a contributor may add it to a single template and wonder why Studio never warns.


## Creating Native Scenario Support for a Protocol
Having a protocol being natively supported by Surfpool Scenarios will allow users to easily create scenarios to override account states for that protocol.
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags:
- perpetuals
- collateral
- risk
- clock-sensitive

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tags all eight Phoenix templates, including ones with no time check, which means extra warnings in Studio. That's acceptable as a stopgap. Consider adding a short YAML comment explaining why the tag is here, and adding entry-level tags support to YamlOverrideTemplateEntry later so the warning can be scoped to the templates that actually need it.


templates:
- id: phoenix-oracle-price
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/scenarios/protocols/pyth/v2/overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tags:
- oracle
- price-feed
- defi
- clock-sensitive

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Studio now relies on this tag, but no test checks it. Suggest adding an assertion in registry.rs (e.g. next to test_filter_by_tags) that by_tags(["clock-sensitive"]) includes pyth-price-feed-v2 and the Phoenix templates. That way a rename or a dropped tag fails CI instead of silently removing the warning.


constants:
price_feed:
Expand Down
24 changes: 24 additions & 0 deletions crates/core/src/scenarios/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,30 @@ templates: []
);
}

#[test]
fn test_clock_sensitive_tag_marks_pyth_and_every_phoenix_template() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the test only checks that the tag is present. Consider also asserting that a collection known to be insensitive, e.g. a Jupiter or Whirlpool template (until its branch lands), is not tagged. Otherwise a tag put on the wrong collection by mistake would go unnoticed, since Studio would just warn for it.

let registry = TemplateRegistry::new();
let tagged: Vec<&str> = registry
.by_tags(&["clock-sensitive".to_string()])
.iter()
.map(|template| template.id.as_str())
.collect();

let phoenix = registry.by_protocol("Phoenix Eternal");
assert!(
!phoenix.is_empty(),
"the Phoenix Eternal templates are registered"
);
for template in std::iter::once("pyth-price-feed-v2")
.chain(phoenix.iter().map(|template| template.id.as_str()))
{
assert!(
tagged.contains(&template),
"{template} must be clock-sensitive"
);
}
}

#[test]
fn test_jupiter_idl_has_token_ledger_account() {
let registry = TemplateRegistry::new();
Expand Down
Loading