From 7d55f53b90405ff87ba9f584f36df593cc208560 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Mon, 26 Oct 2026 17:45:29 +0200 Subject: [PATCH 1/5] feat(scenarios): tag the Pyth v2 and Phoenix collections clock-sensitive --- crates/core/src/scenarios/README.md | 4 ++++ .../src/scenarios/protocols/phoenix-eternal/v1/overrides.yaml | 1 + crates/core/src/scenarios/protocols/pyth/v2/overrides.yaml | 1 + 3 files changed, 6 insertions(+) diff --git a/crates/core/src/scenarios/README.md b/crates/core/src/scenarios/README.md index 65e2d5683..66bc7a157 100644 --- a/crates/core/src/scenarios/README.md +++ b/crates/core/src/scenarios/README.md @@ -85,6 +85,10 @@ 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. Playing such a +scenario with the clock paused leaves fetched accounts ahead of the surfnet's time, and the program can refuse transactions +(Whirlpool `InvalidTimestamp`, Project 0 `PythPushStalePrice`); Studio warns before pausing for them. + ## 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. diff --git a/crates/core/src/scenarios/protocols/phoenix-eternal/v1/overrides.yaml b/crates/core/src/scenarios/protocols/phoenix-eternal/v1/overrides.yaml index c0f6ec721..7db11f400 100644 --- a/crates/core/src/scenarios/protocols/phoenix-eternal/v1/overrides.yaml +++ b/crates/core/src/scenarios/protocols/phoenix-eternal/v1/overrides.yaml @@ -7,6 +7,7 @@ tags: - perpetuals - collateral - risk + - clock-sensitive templates: - id: phoenix-trader-collateral-stress diff --git a/crates/core/src/scenarios/protocols/pyth/v2/overrides.yaml b/crates/core/src/scenarios/protocols/pyth/v2/overrides.yaml index 415fe4347..bdc65802d 100644 --- a/crates/core/src/scenarios/protocols/pyth/v2/overrides.yaml +++ b/crates/core/src/scenarios/protocols/pyth/v2/overrides.yaml @@ -7,6 +7,7 @@ tags: - oracle - price-feed - defi + - clock-sensitive constants: price_feed: From 55187e30b9852d1e052e81237cda49b21f4936ff Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Mon, 26 Oct 2026 17:45:30 +0200 Subject: [PATCH 2/5] ci: add the Claude Code pull request review --- .github/workflows/claude-review.yml | 141 ++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 .github/workflows/claude-review.yml diff --git a/.github/workflows/claude-review.yml b/.github/workflows/claude-review.yml new file mode 100644 index 000000000..844c44d68 --- /dev/null +++ b/.github/workflows/claude-review.yml @@ -0,0 +1,141 @@ +name: Perform a code review when a pull request is created. +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + claude: + # Skip drafts, and skip fork PRs: on `pull_request` they don't get the + # ANTHROPIC_API_KEY secret, so the review would only fail. + if: >- + !github.event.pull_request.draft && + github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + structured_output: ${{ steps.run_claude.outputs.structured_output }} + steps: + - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 + with: + # Explicitly check out the PR's merge commit. + ref: refs/pull/${{ github.event.pull_request.number }}/merge + persist-credentials: false + + - name: Pre-fetch base and head refs for the PR + env: + PR_BASE_REF: ${{ github.event.pull_request.base.ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + # Pass GitHub expressions through env and quote shell expansions. + git fetch --no-tags origin \ + "$PR_BASE_REF" \ + "+refs/pull/$PR_NUMBER/head" + + # If you want Claude to build and run code, install any dependencies that + # need to be downloaded before the "Run Claude" step, and add the commands + # it may run to --allowedTools below (e.g. "Bash(npm test:*)"). Any tool + # not listed there is denied. + + - name: Run Claude + id: run_claude + uses: anthropics/claude-code-action@86d88e619d8e6caf07b5c3944dd14f441c533718 # v1.0.243 + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + # Use this job's read-only token instead of the Claude GitHub App, + # which needs `id-token: write` and would get write access. + github_token: ${{ github.token }} + prompt: | + This is PR #${{ github.event.pull_request.number }} for ${{ github.repository }}. + + Review ONLY the changes introduced by the PR, so consider: + git log --oneline ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} + git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} + + Suggest any improvements, potential bugs, or issues. + Be concise and specific in your feedback. + + Return your review in two parts: + - `summary`: a short Markdown overview of the PR and your overall assessment. + - `comments`: one entry per specific issue, anchored to the line it concerns. + `path` is relative to the repository root. `line` is the line number in + the PR head version of the file (${{ github.event.pull_request.head.sha }}), + and must be a line shown in the diff above. The working tree is the merge + commit, so its line numbers can differ; check them with + `git show ${{ github.event.pull_request.head.sha }}:`. + Put issues that don't belong to a single line in `summary` instead. + + Pull request title and body: + ---- + ${{ github.event.pull_request.title }} + ${{ github.event.pull_request.body }} + claude_args: | + --allowedTools "Read,Grep,Glob,Bash(git log:*),Bash(git diff:*),Bash(git show:*)" + --json-schema '{ + "type": "object", + "properties": { + "summary": { + "type": "string", + "description": "Overall review as Markdown, posted as the review body." + }, + "comments": { + "type": "array", + "description": "Inline comments, each anchored to one line of the PR diff.", + "items": { + "type": "object", + "properties": { + "path": { "type": "string", "description": "File path relative to the repository root." }, + "line": { "type": "integer", "minimum": 1, "description": "Line number in the PR head version of the file. Must be within the diff." }, + "body": { "type": "string", "description": "The comment, as Markdown." } + }, + "required": ["path", "line", "body"] + } + } + }, + "required": ["summary", "comments"] + }' + + post_feedback: + runs-on: ubuntu-latest + needs: claude + if: needs.claude.outputs.structured_output != '' + permissions: + issues: write + pull-requests: write + steps: + - name: Report Claude feedback + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 + env: + CLAUDE_STRUCTURED_OUTPUT: ${{ needs.claude.outputs.structured_output }} + with: + github-token: ${{ github.token }} + script: | + const { summary = '', comments = [] } = JSON.parse(process.env.CLAUDE_STRUCTURED_OUTPUT); + const pr = context.payload.pull_request; + if (!summary.trim() && comments.length === 0) { + core.info('Claude returned an empty review; nothing to post.'); + return; + } + + try { + await github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number, + commit_id: pr.head.sha, + event: 'COMMENT', + body: summary.trim() || 'See inline comments.', + comments: comments.map(({ path, line, body }) => ({ path, line, side: 'RIGHT', body })), + }); + } catch (error) { + // GitHub rejects the whole review if any comment points outside the + // diff. Fall back to a single PR comment so no feedback is lost. + core.warning(`Could not post inline review (${error.message}); posting a plain comment instead.`); + const details = comments.map(({ path, line, body }) => `**\`${path}:${line}\`**\n\n${body}`); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body: [summary.trim(), ...details].filter(Boolean).join('\n\n---\n\n'), + }); + } From 475277c9978735338e8d8d5f63bd134880b9d237 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Mon, 26 Oct 2026 17:51:53 +0200 Subject: [PATCH 3/5] test(scenarios): pin the clock-sensitive tag and name the tagged collections in the README --- crates/core/src/scenarios/README.md | 7 ++++--- crates/core/src/scenarios/registry.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/crates/core/src/scenarios/README.md b/crates/core/src/scenarios/README.md index 66bc7a157..199ae704c 100644 --- a/crates/core/src/scenarios/README.md +++ b/crates/core/src/scenarios/README.md @@ -85,9 +85,10 @@ 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. Playing such a -scenario with the clock paused leaves fetched accounts ahead of the surfnet's time, and the program can refuse transactions -(Whirlpool `InvalidTimestamp`, Project 0 `PythPushStalePrice`); Studio warns before pausing for them. +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. ## 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. diff --git a/crates/core/src/scenarios/registry.rs b/crates/core/src/scenarios/registry.rs index edef806d0..c2e2d2c8c 100644 --- a/crates/core/src/scenarios/registry.rs +++ b/crates/core/src/scenarios/registry.rs @@ -1051,6 +1051,32 @@ templates: [] ); } + #[test] + fn test_clock_sensitive_tag_marks_pyth_and_every_phoenix_template() { + let registry = TemplateRegistry::new(); + let mut tagged: Vec<&str> = registry + .by_tags(&["clock-sensitive".to_string()]) + .iter() + .map(|template| template.id.as_str()) + .collect(); + tagged.sort_unstable(); + + let mut expected: Vec<&str> = registry + .all() + .iter() + .map(|template| template.id.as_str()) + .filter(|id| *id == "pyth-price-feed-v2" || id.starts_with("phoenix-")) + .collect(); + expected.sort_unstable(); + + assert_eq!( + expected.len(), + 9, + "Pyth price feed v2 and the eight Phoenix templates" + ); + assert_eq!(tagged, expected); + } + #[test] fn test_jupiter_idl_has_token_ledger_account() { let registry = TemplateRegistry::new(); From 1df5dab70d0845405f6143d90f91b38d2a363172 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 27 Oct 2026 07:44:52 +0200 Subject: [PATCH 4/5] test(scenarios): check the clock-sensitive tag per template so other tagged collections can join --- crates/core/src/scenarios/registry.rs | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/crates/core/src/scenarios/registry.rs b/crates/core/src/scenarios/registry.rs index c2e2d2c8c..6c1abe618 100644 --- a/crates/core/src/scenarios/registry.rs +++ b/crates/core/src/scenarios/registry.rs @@ -1054,27 +1054,25 @@ templates: [] #[test] fn test_clock_sensitive_tag_marks_pyth_and_every_phoenix_template() { let registry = TemplateRegistry::new(); - let mut tagged: Vec<&str> = registry + let tagged: Vec<&str> = registry .by_tags(&["clock-sensitive".to_string()]) .iter() .map(|template| template.id.as_str()) .collect(); - tagged.sort_unstable(); - let mut expected: Vec<&str> = registry - .all() - .iter() - .map(|template| template.id.as_str()) - .filter(|id| *id == "pyth-price-feed-v2" || id.starts_with("phoenix-")) - .collect(); - expected.sort_unstable(); - - assert_eq!( - expected.len(), - 9, - "Pyth price feed v2 and the eight Phoenix templates" + let phoenix = registry.by_protocol("Phoenix Eternal"); + assert!( + !phoenix.is_empty(), + "the Phoenix Eternal templates are registered" ); - assert_eq!(tagged, expected); + 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] From 4779c48b58cb6ede155cd9c407bf14d2834a326f Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Fri, 30 Oct 2026 16:25:55 +0200 Subject: [PATCH 5/5] ci: drop the Claude review workflow --- .github/workflows/claude-review.yml | 141 ---------------------------- 1 file changed, 141 deletions(-) delete mode 100644 .github/workflows/claude-review.yml diff --git a/.github/workflows/claude-review.yml b/.github/workflows/claude-review.yml deleted file mode 100644 index 844c44d68..000000000 --- a/.github/workflows/claude-review.yml +++ /dev/null @@ -1,141 +0,0 @@ -name: Perform a code review when a pull request is created. -on: - pull_request: - types: [opened, synchronize, reopened, ready_for_review] - -jobs: - claude: - # Skip drafts, and skip fork PRs: on `pull_request` they don't get the - # ANTHROPIC_API_KEY secret, so the review would only fail. - if: >- - !github.event.pull_request.draft && - github.event.pull_request.head.repo.full_name == github.repository - runs-on: ubuntu-latest - permissions: - contents: read - outputs: - structured_output: ${{ steps.run_claude.outputs.structured_output }} - steps: - - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 - with: - # Explicitly check out the PR's merge commit. - ref: refs/pull/${{ github.event.pull_request.number }}/merge - persist-credentials: false - - - name: Pre-fetch base and head refs for the PR - env: - PR_BASE_REF: ${{ github.event.pull_request.base.ref }} - PR_NUMBER: ${{ github.event.pull_request.number }} - run: | - # Pass GitHub expressions through env and quote shell expansions. - git fetch --no-tags origin \ - "$PR_BASE_REF" \ - "+refs/pull/$PR_NUMBER/head" - - # If you want Claude to build and run code, install any dependencies that - # need to be downloaded before the "Run Claude" step, and add the commands - # it may run to --allowedTools below (e.g. "Bash(npm test:*)"). Any tool - # not listed there is denied. - - - name: Run Claude - id: run_claude - uses: anthropics/claude-code-action@86d88e619d8e6caf07b5c3944dd14f441c533718 # v1.0.243 - with: - anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - # Use this job's read-only token instead of the Claude GitHub App, - # which needs `id-token: write` and would get write access. - github_token: ${{ github.token }} - prompt: | - This is PR #${{ github.event.pull_request.number }} for ${{ github.repository }}. - - Review ONLY the changes introduced by the PR, so consider: - git log --oneline ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} - git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} - - Suggest any improvements, potential bugs, or issues. - Be concise and specific in your feedback. - - Return your review in two parts: - - `summary`: a short Markdown overview of the PR and your overall assessment. - - `comments`: one entry per specific issue, anchored to the line it concerns. - `path` is relative to the repository root. `line` is the line number in - the PR head version of the file (${{ github.event.pull_request.head.sha }}), - and must be a line shown in the diff above. The working tree is the merge - commit, so its line numbers can differ; check them with - `git show ${{ github.event.pull_request.head.sha }}:`. - Put issues that don't belong to a single line in `summary` instead. - - Pull request title and body: - ---- - ${{ github.event.pull_request.title }} - ${{ github.event.pull_request.body }} - claude_args: | - --allowedTools "Read,Grep,Glob,Bash(git log:*),Bash(git diff:*),Bash(git show:*)" - --json-schema '{ - "type": "object", - "properties": { - "summary": { - "type": "string", - "description": "Overall review as Markdown, posted as the review body." - }, - "comments": { - "type": "array", - "description": "Inline comments, each anchored to one line of the PR diff.", - "items": { - "type": "object", - "properties": { - "path": { "type": "string", "description": "File path relative to the repository root." }, - "line": { "type": "integer", "minimum": 1, "description": "Line number in the PR head version of the file. Must be within the diff." }, - "body": { "type": "string", "description": "The comment, as Markdown." } - }, - "required": ["path", "line", "body"] - } - } - }, - "required": ["summary", "comments"] - }' - - post_feedback: - runs-on: ubuntu-latest - needs: claude - if: needs.claude.outputs.structured_output != '' - permissions: - issues: write - pull-requests: write - steps: - - name: Report Claude feedback - uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 - env: - CLAUDE_STRUCTURED_OUTPUT: ${{ needs.claude.outputs.structured_output }} - with: - github-token: ${{ github.token }} - script: | - const { summary = '', comments = [] } = JSON.parse(process.env.CLAUDE_STRUCTURED_OUTPUT); - const pr = context.payload.pull_request; - if (!summary.trim() && comments.length === 0) { - core.info('Claude returned an empty review; nothing to post.'); - return; - } - - try { - await github.rest.pulls.createReview({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: pr.number, - commit_id: pr.head.sha, - event: 'COMMENT', - body: summary.trim() || 'See inline comments.', - comments: comments.map(({ path, line, body }) => ({ path, line, side: 'RIGHT', body })), - }); - } catch (error) { - // GitHub rejects the whole review if any comment points outside the - // diff. Fall back to a single PR comment so no feedback is lost. - core.warning(`Could not post inline review (${error.message}); posting a plain comment instead.`); - const details = comments.map(({ path, line, body }) => `**\`${path}:${line}\`**\n\n${body}`); - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pr.number, - body: [summary.trim(), ...details].filter(Boolean).join('\n\n---\n\n'), - }); - }