Repository navigation
feat(scenarios): add PancakeSwap CLMM templates - #24
92Infinitus92 merged 27 commits into
Conversation
ff84d74 to
d41bc68
Compare
51b8819 to
38e7797
Compare
Shared IDL definitions match Raydium’s exactly. Tests could not run because rustup attempted to write to a read-only directory. |
|
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 I couldn’t run the Rust tests: rustup attempted to write to a read-only directory. |
|
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 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. |
|
No concrete bugs found in the PR changes. The PDA definitions and One improvement: add an offline fixture test for the Review was static; tests were not run. |
There was a problem hiding this comment.
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.ymlis 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 limitedallowedToolscontain 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-statetakes any pubkey, so a cheap check would help: reject the override, or at least warn, when the forked account's owner is notHpNfyc…. This could be a follow-up. - Minor README gap: in the "Number formats" table, the
sqrt_price_x64andliquidityrows have an empty Example cell. Fill them in or drop the column for those rows.
a9eba96 to
691c199
Compare
…he liquidity rule to the custom template
4e3b1ea to
1fd2035
Compare
There was a problem hiding this comment.
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/AmmConfiglayout:PoolState: mints at 73 and 105,token_vault_0at 137,liquidityat 237,sqrt_price_x64at 253,tick_currentat 269,statusat 389, size 1544.AmmConfig:trade_fee_rateat 47,tick_spacingat 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.ymlis 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_contextreaches every template. It is now also prepended topancakeswap-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.
There was a problem hiding this comment.
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-customtemplate and "22 fee tiers by config index, address derived". After 22d0247 there are only 2 templates, andamm-configis 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_contextrepeats itself. The collection context (pool lookup plus the PRICE rule) is now prepended toamm-configas well. Both that and the template's own context explain how to readamm_configat 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 onegetProgramAccountscall would replace the "try both orders" instruction and halve the RPC calls.
There was a problem hiding this comment.
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_config9, mints 73/105,token_vault_0137,liquidity237,sqrt_price_x64253,tick_current269,status389. 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 <= newgoing up,new < t <= oldgoing 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 sayspancakeswap-clmm-amm-configcovers "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.ymlhas 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_contexthas noraw_layout: falsecoverage. The new unit test only covers araw_layout: truecollection. 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.
There was a problem hiding this comment.
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-customand an AmmConfig template with "22 fee tiers by config index, address derived". After 22f0247 the code ships onlypool-stateandamm-config, and the AmmConfig is addressed by the pool's ownamm_configpubkey. 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.ymlis a new CI workflow, and thecall_surfnet_rpcschema description is an MCP change. Neither is PancakeSwap-specific, so consider splitting them out.- The workflow interpolates
pull_request.titleandbodystraight 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_contextcovers 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.
# Conflicts: # crates/core/src/scenarios/registry.rs
There was a problem hiding this comment.
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_contextthat is prepended to each template's own context diff_indices, moved into the shared test helpers- a longer MCP
call_surfnet_rpcparams 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-customtemplate and "22 fee tiers by config index, address derived". The code ships two templates, and the AMM config is addressed by the pool'samm_configpubkey (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 MCPcall_surfnet_rpcschema description and the new collection-levelllm_contextincrates/typesdon't belong to a PancakeSwap template PR. Thellm_contextchange 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_contextreaches every template. Pool-finding and price instructions are also prepended topancakeswap-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
addresswhen a template is applied would be a cheap, generic fix and worth a follow-up. - Tests. The
llm_contextmerge 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.
There was a problem hiding this comment.
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_config9..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
i32and 60 ticks)
Issues
- The PR description doesn't match the diff. It names a
pancakeswap-clmm-customtemplate and anamm-configtemplate with "22 fee tiers by config index, address derived". It also claims a test that "checks every fee tier against its liveAmmConfig". None of these exist. Only two templates ship (the registry tests assert 83 total and 2 for PancakeSwap).pancakeswap-clmm-amm-configtakes a raw pubkey, has no index constant like Raydium'samm_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.paramsschema description incrates/mcp/src/surfpool/mod.rs
- There is no validation for the documented fee-rate limits.
trade_fee_rate < 1_000_000andprotocol + fund ≤ 1_000_000are 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).
fetchintests/pancakeswap/mod.rsis nearly identical to thefetchintests/pump/mod.rs. It could move totests/helpers.rsthe same waydiff_indicesdid.
|
Have you checked all the comments from above and are there any valuable ones? If not - resolve them all please |
…heir own diff_indices
…akeswap # Conflicts: # crates/core/src/scenarios/README.md # crates/core/src/scenarios/registry.rs # crates/core/src/tests/protocols/mod.rs
964aee0
into
feat/scenarios/override/pancakeswap-support
Adds PancakeSwap CLMM templates. PancakeSwap's Solana CLMM (
HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq) is a fork of Raydium CLMM with the samePoolStateandAmmConfiglayouts. 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_currentandstatusof a pool, given by address or found by pair.pancakeswap-clmm-amm-config:trade_fee_rate,protocol_fee_rateandfund_fee_rateof a fee tier. The tier is addressed by pubkey, read from a pool'samm_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_contextfinds a pool by pair withgetProgramAccountsand tells the model not to move the price by hand:sqrt_price_x64,tick_currentandliquiditymust change together, so price shocks go through the Studio card (LimeChain/surfpool-web-ui#22).IDL:
v1/idl.jsonis the IDL published in the program's Anchor IDL accountCAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf, with only whitespace changed (sha256 in the README).Also in this PR, shared with the other AMM PRs: a collection-level
llm_contextthat leads every template's own context, and a description of thecall_surfnet_rpcparams for MCP clients.Tests: three live tests on the SOL/USDC pool
DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ: the pool round-trips unchanged through the IDL, the pool'samm_configis a liveAmmConfigthat 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_contexttells the model to check the owner of a pool address the user gives.