Repository navigation
feat(scenarios): add PancakeSwap CLMM templates #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
92Infinitus92
merged 27 commits into
feat/scenarios/override/pancakeswap-support
from
feat/scenarios/pancakeswap
Dec 4, 2026
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e5e4b2e
feat(scenarios): add PancakeSwap CLMM templates
92Infinitus92 1ef5c2b
docs(scenarios): document the PancakeSwap liquidity rule for price sh…
92Infinitus92 2fe14b5
docs(scenarios): rewrite the PancakeSwap README as a how-to and add t…
92Infinitus92 9d04670
test(scenarios): cover the PancakeSwap sqrt_price_x64 u128 write
92Infinitus92 88d116b
test(pancakeswap): read the template IDL through idl() after the raw-…
92Infinitus92 717f81d
feat(scenarios): let an override collection share its llm_context
92Infinitus92 1fd2035
fix(mcp): keep call_surfnet_rpc's tagged params and explain them with…
92Infinitus92 fda7373
fix(scenarios): find PancakeSwap pools by pair or address and shorten…
92Infinitus92 981dd85
ci: add the Claude Code review
92Infinitus92 18ed5e4
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 22d0247
fix(scenarios): address the PancakeSwap fee tier by its pool's AmmCon…
92Infinitus92 a3d965e
test: share diff_indices through tests/helpers
92Infinitus92 dc0dbc7
docs(scenarios): drop the PancakeSwap README link to the Raydium README
92Infinitus92 ce8aeaf
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 8446cb7
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 8f0f065
fix(scenarios): use the PancakeSwap IDL published on chain
92Infinitus92 a839376
chore(scenarios): indent the PancakeSwap IDL like the other bundled IDLs
92Infinitus92 1d5542f
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 3d5d43b
test(pancakeswap): register the scenario at the next slot
92Infinitus92 d80767f
fix(scenarios): check the owner of a PancakeSwap pool the user gives
92Infinitus92 3cf6cad
test(scenarios): move the PancakeSwap tests to tests/protocols with t…
92Infinitus92 09481ed
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 373d700
ci: remove the Claude pull request review
92Infinitus92 1dfb620
Merge remote-tracking branch 'upstream/main' into feat/scenarios/panc…
92Infinitus92 8ce23f3
docs(scenarios): a PancakeSwap CLMM swap does not need the tick array…
92Infinitus92 84df0e7
docs(scenarios): drop the slot number from the PancakeSwap IDL note
92Infinitus92 9829660
Merge remote-tracking branch 'upstream/main' into feat/scenarios/panc…
92Infinitus92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
crates/core/src/scenarios/protocols/pancakeswap/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # PancakeSwap CLMM | ||
|
|
||
| PancakeSwap's concentrated-liquidity AMM on Solana, a fork of Raydium CLMM with the same account | ||
| layouts. Two templates: a pool, and the fee tier a pool points to. Units and rules match Raydium | ||
| CLMM; only the program, pools and fee tiers differ. | ||
|
|
||
| # Template index | ||
|
|
||
| **PancakeSwap CLMM** · `HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq` | ||
|
|
||
| | Template | Overrides | | ||
| |---|---| | ||
| | `pancakeswap-clmm-pool-state` | a pool's price, active liquidity and status, selected by the pool address | | ||
| | `pancakeswap-clmm-amm-config` | the fee tier a pool points to, shared by every pool on it | | ||
|
|
||
| ## Number formats | ||
|
|
||
| | You'll see | It means | Example | | ||
| |---|---|---| | ||
| | `sqrt_price_x64` | `sqrt(price_raw) x 2^64`, as a decimal **string** | `"5833372668713515884"` = 100 USDC per SOL | | ||
| | `liquidity` | raw `u128`, as a decimal **string** | no fixed scale; read it from the pool | | ||
| | `status` | bitmask of disabled instructions | `16` = swaps off, `0` = everything on | | ||
| | `trade_fee_rate` | parts per million of the input, below `1000000` | `100` = 0.01% | | ||
|
|
||
| ## Picking a pool | ||
|
|
||
| Find the pools of a pair with `getProgramAccounts` on the program, filtered by size `1544` and the | ||
| two mints at offsets `73` and `105`. A pair has a pool per fee tier; the one whose vaults hold the | ||
| most is usually the one you want. For SOL/USDC that is | ||
| `DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ` (0.01% fee, tick spacing 10). Pools are also listed | ||
| at `https://solana.pancakeswap.finance/liquidity-pools/`. | ||
|
|
||
| **Check the owner.** The layouts match Raydium's, so a PancakeSwap template pointed at a Raydium | ||
|
92Infinitus92 marked this conversation as resolved.
Resolved
|
||
| pool writes it without complaint. The templates' `llm_context` tells the model to check the owner of | ||
| a pool address the user gives. | ||
|
|
||
| Set `fetchBeforeUse: true` to pull the pool from upstream first. | ||
|
|
||
| # Recipes | ||
|
|
||
| ## Shock the price | ||
|
|
||
| Use **Scenario presets → PancakeSwap state → CLMM price shock** in Studio. It reads the pool and | ||
|
92Infinitus92 marked this conversation as resolved.
Resolved
|
||
| the tick arrays the move crosses, and writes all three coupled fields: | ||
|
|
||
| ``` | ||
| template: pancakeswap-clmm-pool-state | ||
| sqrt_price_x64: "<round(sqrt_price_x64 x sqrt(factor))>" | ||
| tick_current: <floor(2 x ln(new_sqrt_price_x64 / 2^64) / ln(1.0001))> | ||
| liquidity: "<live liquidity +/- liquidity_net of every initialized tick crossed>" | ||
| ``` | ||
|
|
||
| The shock reads the pool when the scenario is created and stores absolute values, so if the pool's | ||
| liquidity changes before Play, create the scenario again. | ||
|
|
||
| **Never move the price without `liquidity`.** The pool keeps the old range's depth at the new | ||
| price, and swaps succeed with wrong amounts: a +10% move on the SOL/USDC pool left it about 2.5x | ||
| too deep. Going up, a tick `t` is crossed when `old < t <= new` and its `liquidity_net` is added; | ||
| going down, when `new < t <= old` and it is subtracted. | ||
|
|
||
| **The destination tick array may be missing.** A tick array is the PDA | ||
| `["tick_array", pool, start_index as i32 big-endian]` with 60 ticks of `tick_spacing` each. When the | ||
| array of the new tick does not exist, a swap starts from the next initialized array in its | ||
| direction, so pass that one first. | ||
|
|
||
| ## Freeze swaps | ||
|
|
||
| ``` | ||
| template: pancakeswap-clmm-pool-state | ||
| status: 16 # bit 4: swaps off, liquidity still moves | ||
| ``` | ||
|
|
||
| ## Change a pool's fee tier | ||
|
|
||
| Use **Scenario presets → PancakeSwap state → CLMM fee tier** in Studio with the pool address, or | ||
| read the pool's `amm_config` with `getAccountInfo`, `dataSlice {offset 9, length 32}` and encoding | ||
| `base58`, and override that account: | ||
|
|
||
| ``` | ||
| template: pancakeswap-clmm-amm-config | ||
| account: {"pubkey": "<the pool's amm_config>"} | ||
| trade_fee_rate: 10000 # 1% | ||
| ``` | ||
|
|
||
| Every pool on that tier shares the account, so the change reaches all of them. | ||
|
|
||
| # Troubleshooting | ||
|
|
||
| | Symptom | Fix | | ||
| |---|---| | ||
| | The swap succeeds but the amounts look wrong after a price change | `liquidity` was not moved with the price. Use the Studio price shock | | ||
| | The swap fails right after a price change | `sqrt_price_x64` and `tick_current` disagree, or the swap passes tick arrays from before the change (`InvalidFirstTickArrayAccount`) | | ||
| | The swap fails on the token transfer | The paying vault holds less than the output. Fund it with `spl-token-account-balance` | | ||
|
|
||
| # IDL | ||
|
|
||
| `v1/idl.json` is the IDL PancakeSwap publishes on chain in its Anchor IDL account | ||
| `CAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf`, indented with two spaces like the other bundled | ||
| IDLs. Only whitespace changed: `jq -j -c . v1/idl.json` gives back the on-chain bytes. | ||
|
|
||
| | IDL | sha256 | | ||
| |---|---| | ||
| | On chain (compact) | `661eb632c441b2adb681ecd547fd8cea18e836be2305064e84b14bb90d7efb4c` | | ||
| | Bundled `v1/idl.json` | `5ff647614c8f157ff00fbef92e4569e8a8bcfe0725641bb3a6d372024cc366ef` | | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.