Skip to content

feat(scenarios): add PancakeSwap CLMM templates - #24

Merged
92Infinitus92 merged 27 commits into
feat/scenarios/override/pancakeswap-supportfrom
feat/scenarios/pancakeswap
Dec 4, 2026
Merged

92Infinitus92 merged 27 commits into
feat/scenarios/override/pancakeswap-supportfrom
feat/scenarios/pancakeswap

Conversation

@92Infinitus92

@92Infinitus92 92Infinitus92 commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Adds PancakeSwap CLMM templates. PancakeSwap's Solana CLMM (HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq) is a fork of Raydium CLMM with the same PoolState and AmmConfig layouts. The PR is based on upstream main, not stacked on #21.

Heads up on the size: 5833 lines of the diff are the bundled IDL.

Templates:

  • pancakeswap-clmm-pool-state: liquidity, sqrt_price_x64, tick_current and status of a pool, given by address or found by pair.
  • pancakeswap-clmm-amm-config: trade_fee_rate, protocol_fee_rate and fund_fee_rate of a fee tier. The tier is addressed by pubkey, read from a pool's amm_config (offset 9). There is no hardcoded list of fee tiers.

YAML and IDL only, like Kamino: no protocol Rust and no MCP tool. The llm_context finds a pool by pair with getProgramAccounts and tells the model not to move the price by hand: sqrt_price_x64, tick_current and liquidity must change together, so price shocks go through the Studio card (LimeChain/surfpool-web-ui#22).

IDL: v1/idl.json is the IDL published in the program's Anchor IDL account CAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf, with only whitespace changed (sha256 in the README).

Also in this PR, shared with the other AMM PRs: a collection-level llm_context that leads every template's own context, and a description of the call_surfnet_rpc params for MCP clients.

Tests: three live tests on the SOL/USDC pool DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ: the pool round-trips unchanged through the IDL, the pool's amm_config is a live AmmConfig that round-trips, and overrides through the materializer change only their own bytes. Checked in Studio on a forked surfnet with real swaps (price shock, freeze, fee tier) before the IDL refresh; the account layouts did not change.

Known limitation (in the README): the engine picks the IDL by account owner, so a PancakeSwap template pointed at a Raydium CLMM pool writes the same bytes. The llm_context tells the model to check the owner of a pool address the user gives.

@github-actions

Copy link
Copy Markdown
  • [P2] Custom template omits the liquidity rule — overrides.yaml:270. Its price-shock guidance only couples price and tick. Crossing initialized ticks also requires updating active liquidity; otherwise swaps can silently return incorrect amounts. Include the liquidity and tick-array guidance already present in the address-based template.

  • [P3] Worked example cannot deserialize as an override — README.md:59. Replace "address" with "account": {"pubkey": "..."} and include required id, scenarioRelativeSlot, and enabled fields so the example is usable.

Shared IDL definitions match Raydium’s exactly. Tests could not run because rustup attempted to write to a read-only directory.

@github-actions

Copy link
Copy Markdown

No confirmed bugs found in the PR changes. The three core account layouts match Raydium’s, and the new IDL discriminators are correct.

One improvement: the materializer test omits sqrt_price_x64, despite price shocks being the main use case. Include a decimal-string override above u64::MAX and assert that only bytes 253..269 change, covering the critical u128 write path.

I couldn’t run the Rust tests: rustup attempted to write to a read-only directory.

@github-actions

Copy link
Copy Markdown

No concrete bugs found in the specified PR changes.

One improvement: add an offline account fixture for the byte-level materializer test in pancakeswap/mod.rs. Currently, that coverage requires mainnet access and integration-tests, so ordinary CI misses it.

Validation: IDL layouts and discriminators checked; diff whitespace checks passed. Rust tests could not run because rustup attempted to write to a read-only directory.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

No concrete bugs found in the PR changes. The PDA definitions and PoolState/AmmConfig layouts match the existing Raydium implementation.

One improvement: add an offline fixture test for the sqrt_price_x64 u128 override. Its current coverage requires mainnet RPC and integration-tests, so default test runs won’t catch regressions in that write path.

Review was static; tests were not run.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR adds PancakeSwap CLMM templates (pancakeswap-clmm-custom, -pool-state, -amm-config), its vendored IDL, a how-to README, registry wiring and tests. Unit tests check that all 22 fee-tier PDAs derive to their documented addresses. Live tests fetch real mainnet accounts: one round-trips a pool, one checks each AmmConfig against its tier, and one confirms an override changes only the targeted bytes.

Overall the PR is clean and mirrors the Raydium CLMM setup closely. The IDL address matches the program id, the status bit meanings match the program, and the template count and protocol assertions are updated consistently.

Issues

  • Unrelated CI change: .github/workflows/claude-review.yml is not mentioned in the PR description and has nothing to do with PancakeSwap.
    • It should go in its own PR so it can be reviewed separately.
    • It pastes the PR title and body straight into the prompt (${{ github.event.pull_request.body }}), so anyone who can open a same-repo PR can inject instructions into the review. The read-only token and limited allowedTools contain the damage, but the risk should be stated in that PR.
  • Duplicated llm_context: the PRICE/TICK, TICK ARRAYS, LIQUIDITY RULE and VAULTS blocks appear word for word in both pool templates, and are probably close copies of the Raydium v3 text too. If the engine supports shared/protocol-level context or YAML anchors (&/*), using them would stop these copies from drifting apart.
  • Owner check: the README admits that a PancakeSwap template pointed at a Raydium pool writes it without complaint. pancakeswap-clmm-pool-state takes any pubkey, so a cheap check would help: reject the override, or at least warn, when the forked account's owner is not HpNfyc…. This could be a follow-up.
  • Minor README gap: in the "Number formats" table, the sqrt_price_x64 and liquidity rows have an empty Example cell. Fill them in or drop the column for those rows.

Comment thread crates/core/src/scenarios/registry.rs Resolved
Comment thread .github/workflows/claude-review.yml Resolved
@92Infinitus92
92Infinitus92 force-pushed the feat/scenarios/raydium branch from a9eba96 to 691c199 Compare October 11, 2026 05:46
@92Infinitus92
92Infinitus92 changed the base branch from feat/scenarios/raydium to feat/scenarios/override/pancakeswap-support October 12, 2026 05:31
@92Infinitus92
92Infinitus92 force-pushed the feat/scenarios/pancakeswap branch from 4e3b1ea to 1fd2035 Compare October 12, 2026 05:31

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overview. This PR adds PancakeSwap CLMM support: a vendored IDL, three templates (pancakeswap-clmm-custom, -pool-state and -amm-config), a README, and unit and integration tests. It also adds a collection-level llm_context that is prepended to each template's own context, and it expands the description of the MCP call_surfnet_rpc params.

What I checked.

  • The hard-coded byte offsets match the Raydium CLMM PoolState / AmmConfig layout:
    • PoolState: mints at 73 and 105, token_vault_0 at 137, liquidity at 237, sqrt_price_x64 at 253, tick_current at 269, status at 389, size 1544.
    • AmmConfig: trade_fee_rate at 47, tick_spacing at 51, size 117.
  • The PDA seeds and the price/tick formulas are consistent.
  • The tick-crossing rule in the README is correct (up: old < t <= new, add; down: new < t <= old, subtract).
  • The tests are well targeted. Deriving every fee tier's address offline, and asserting that only the targeted bytes change, are good guards.

Concerns and nits.

  • Out-of-scope workflow. .github/workflows/claude-review.yml is unrelated to PancakeSwap and isn't mentioned in the PR body. Consider splitting it into its own PR. As written it is reasonably hardened (read-only token for the Claude job, fork PRs skipped, pinned SHAs). However, the PR title and body are interpolated straight into the prompt, so a same-repo author can steer the review text.
  • Shared llm_context reaches every template. It is now also prepended to pancakeswap-clmm-amm-config, which gets the full pool-search and price-shock guidance (see the inline comment).
  • Tests depend on the public mainnet RPC. The integration tests rely on api.mainnet-beta.solana.com, which is often rate-limited. They are feature-gated, so this is acceptable, but it's worth noting for CI flakiness.

Overall this looks correct and ready, apart from the scope and nit items above.

Comment thread crates/types/src/scenarios.rs Resolved
Comment thread crates/mcp/src/surfpool/mod.rs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overview

Adds PancakeSwap CLMM templates (YAML and vendored IDL), a collection-level llm_context that gets prepended to each template's own context, live integration tests, and a shared diff_indices test helper. It also bundles some unrelated changes: a new claude-review.yml workflow and a rewrite of the MCP call_surfnet_rpc params description.

I checked the hard-coded byte offsets against the PoolState layout and they're correct (amm_config 9, mints 73/105, vault0 137, liquidity 237, sqrt_price 253, tick 269, status 389). The README math also checks out: the sqrt_price_x64 example for 100 USDC/SOL, the tick formula, and the rule for which ticks are crossed and what happens to liquidity_net. The llm_context merge in to_override_templates is simple and has a unit test.

Issues

  • The PR description no longer matches the code. It lists a pancakeswap-clmm-custom template and "22 fee tiers by config index, address derived". After 22d0247 there are only 2 templates, and amm-config is addressed by a plain pubkey. Please update the body. The test-plan line "check every fee tier against its live AmmConfig" is out of date too: the tests now check only the SOL/USDC pool's config.
  • Unrelated changes. The CI workflow (.github/workflows/claude-review.yml) and the MCP schema description are separate concerns. They'd be easier to review and revert as their own PRs. The workflow puts the PR body straight into the prompt; fork PRs are skipped, so this only matters for same-repo branches.
  • The shared llm_context repeats itself. The collection context (pool lookup plus the PRICE rule) is now prepended to amm-config as well. Both that and the template's own context explain how to read amm_config at offset 9, so there's some duplication. That's fine, but it's worth knowing before you add more templates.
  • Minor: CLMM pools store mints ordered so that mint0 < mint1. Telling the LLM to sort the two mints by bytes and run one getProgramAccounts call would replace the "try both orders" instruction and halve the RPC calls.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Adds PancakeSwap CLMM (a Raydium CLMM fork) as a YAML + IDL protocol with two templates (pancakeswap-clmm-pool-state, pancakeswap-clmm-amm-config). It also adds a collection-level llm_context that is prepended to each template's own context, moves diff_indices into tests/helpers, expands the call_surfnet_rpc params description, and adds live mainnet integration tests.

I checked the hard-coded values against the Raydium layout and they're correct:

  • PoolState offsets: amm_config 9, mints 73/105, token_vault_0 137, liquidity 237, sqrt_price_x64 253, tick_current 269, status 389. Total size 1544.
  • AmmConfig: size 117.
  • Status bits: bit 4 is swap.
  • Tick array PDA: big-endian start_index.
  • Tick formula: floor(2·ln(sqrt/2^64)/ln(1.0001)).
  • Crossing rules: old < t <= new going up, new < t <= old going down.

The code is in good shape. Remaining points:

  • The PR description is out of date. It lists a third template, pancakeswap-clmm-custom, and says pancakeswap-clmm-amm-config covers "22 fee tiers by config index, address derived". After 22d0247 there are only two templates, and the AmmConfig is addressed by pubkey read from the pool. Please update the body so reviewers and release notes match the code.
  • Unrelated change in this PR. .github/workflows/claude-review.yml has nothing to do with PancakeSwap and should go in its own PR. Within it, the PR title and body are put straight into the prompt. Fork PRs are skipped, so the exposure is limited, but untrusted text is still being placed into an instruction prompt.
  • Collection-level llm_context has no raw_layout: false coverage. The new unit test only covers a raw_layout: true collection. That's fine for testing the merge logic. PancakeSwap is the only YAML that uses the field so far, so the change is low risk.
  • The "known limitation" could be guarded. The PancakeSwap template writes Raydium pools without complaint. If the engine already knows the template's program id, a warning or an owner check at materialization time would turn that README caveat into a guard.

Comment thread crates/types/src/scenarios.rs Resolved
Comment thread crates/mcp/src/surfpool/mod.rs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR adds PancakeSwap CLMM templates, which are YAML plus a vendored IDL. It also adds a collection-level llm_context that is prepended to each template's own context, moves diff_indices into the shared test helpers, extends the call_surfnet_rpc param description, and adds live mainnet integration tests. Overall it is clean and well tested: the round-trip and materializer byte-diff tests are a good fit for an IDL-only protocol.

Notes

  • The PR description is out of date. It mentions pancakeswap-clmm-custom and an AmmConfig template with "22 fee tiers by config index, address derived". After 22f0247 the code ships only pool-state and amm-config, and the AmmConfig is addressed by the pool's own amm_config pubkey. The registry count (72) agrees with the code, so only the description needs updating.
  • Some changes are outside the PR's scope.
    • .github/workflows/claude-review.yml is a new CI workflow, and the call_surfnet_rpc schema description is an MCP change. Neither is PancakeSwap-specific, so consider splitting them out.
    • The workflow interpolates pull_request.title and body straight into the prompt. Fork PRs are excluded, but anyone who can open a same-repo PR can steer the reviewer this way. Its tools are read-only, so the risk is low.
  • The README depends on another repo. Both Studio presets it describes (price shock and fee tier) need LimeChain/surfpool-web-ui#22. Until that merges, the README points users to UI that doesn't exist.
  • Test coverage gap. collection_llm_context_leads_every_template_context covers the merge logic. Nothing asserts that the shipped PancakeSwap templates actually carry the shared lookup text. A small assertion in the registry tests would catch a YAML regression.

Comment thread crates/types/src/scenarios.rs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overview

This PR adds PancakeSwap CLMM state templates. PancakeSwap is a Raydium CLMM fork, so the PR bundles its on-chain IDL, adds pancakeswap-clmm-pool-state and pancakeswap-clmm-amm-config, registers them and adds a README. It also brings in some supporting changes:

  • a new collection-level llm_context that is prepended to each template's own context
  • diff_indices, moved into the shared test helpers
  • a longer MCP call_surfnet_rpc params description
  • live integration tests

I checked the hardcoded offsets against the PoolState layout and they are correct: amm_config at 9, mints at 73 and 105, token_vault_0 at 137, liquidity at 237, sqrt_price_x64 at 253, tick_current at 269 and status at 389. The README's sqrt_price_x64 example (100 USDC/SOL), the tick formula and the tick-array PDA seed (i32 big-endian) also check out. The code is clean overall.

Issues

  • The PR description is out of date. It lists a pancakeswap-clmm-custom template and "22 fee tiers by config index, address derived". The code ships two templates, and the AMM config is addressed by the pool's amm_config pubkey (commit 22d0247 removed the catalog). Please update the body so reviewers and release notes match the code.
  • Some changes are out of scope. .github/workflows/claude-review.yml (new CI, ~141 lines), the MCP call_surfnet_rpc schema description and the new collection-level llm_context in crates/types don't belong to a PancakeSwap template PR. The llm_context change is a generic engine change that every protocol can now use. Consider splitting these out, or at least listing them in the description.
  • The shared llm_context reaches every template. Pool-finding and price instructions are also prepended to pancakeswap-clmm-amm-config, where they mostly don't apply (see inline comment).
  • Owner check is documentation only. The known limitation (a PancakeSwap template pointed at a Raydium pool writes it silently) is only covered by a README warning. Validating the account owner against the IDL address when a template is applied would be a cheap, generic fix and worth a follow-up.
  • Tests. The llm_context merge has a unit test, which is good. The only PancakeSwap coverage outside the integration feature is the template count, so a broken property path in the YAML would only show up as a load failure.

Comment thread crates/types/src/scenarios.rs Resolved
Comment thread crates/mcp/src/surfpool/mod.rs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed PR #24, which adds PancakeSwap CLMM override templates (a vendored on-chain IDL plus YAML). It also adds a collection-level llm_context that is placed before each template's own context, moves diff_indices into the shared test helpers, and adds live mainnet tests.

The change is small and tidy. I checked these against the Raydium CLMM layout and they are correct:

  • the PoolState offsets: amm_config 9..41, mints at 73 and 105, vault0 at 137, liquidity 237..253, sqrt_price 253..269, tick 269..273, status 389
  • the account sizes, 1544 and 117
  • the README math (sqrt price example, tick formula, tick array PDA with a big-endian i32 and 60 ticks)

Issues

  • The PR description doesn't match the diff. It names a pancakeswap-clmm-custom template and an amm-config template with "22 fee tiers by config index, address derived". It also claims a test that "checks every fee tier against its live AmmConfig". None of these exist. Only two templates ship (the registry tests assert 83 total and 2 for PancakeSwap). pancakeswap-clmm-amm-config takes a raw pubkey, has no index constant like Raydium's amm_config_index, and the only live AmmConfig test covers the SOL/USDC pool's tier. Please either update the description or add what's missing.
  • The PR includes changes unrelated to PancakeSwap, which should be split out or justified:
    • .github/workflows/claude-review.yml (a new CI workflow)
    • the long CallSurfnetRpcParams.params schema description in crates/mcp/src/surfpool/mod.rs
  • There is no validation for the documented fee-rate limits. trade_fee_rate < 1_000_000 and protocol + fund ≤ 1_000_000 are only written down. An LLM or user can set values that make the program's fee math fail or overflow, so the limits are only advisory.
  • Duplicated test helper (minor). fetch in tests/pancakeswap/mod.rs is nearly identical to the fetch in tests/pump/mod.rs. It could move to tests/helpers.rs the same way diff_indices did.

Comment thread crates/types/src/scenarios.rs Resolved
Comment thread .github/workflows/claude-review.yml Resolved
@bakasura980

Copy link
Copy Markdown
Collaborator

Have you checked all the comments from above and are there any valuable ones? If not - resolve them all please

@92Infinitus92
92Infinitus92 merged commit 964aee0 into feat/scenarios/override/pancakeswap-support Dec 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants