Skip to content
Merged
Show file tree
Hide file tree
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 Sep 24, 2026
1ef5c2b
docs(scenarios): document the PancakeSwap liquidity rule for price sh…
92Infinitus92 Sep 29, 2026
2fe14b5
docs(scenarios): rewrite the PancakeSwap README as a how-to and add t…
92Infinitus92 Sep 29, 2026
9d04670
test(scenarios): cover the PancakeSwap sqrt_price_x64 u128 write
92Infinitus92 Sep 29, 2026
88d116b
test(pancakeswap): read the template IDL through idl() after the raw-…
92Infinitus92 Oct 8, 2026
717f81d
feat(scenarios): let an override collection share its llm_context
92Infinitus92 Oct 11, 2026
1fd2035
fix(mcp): keep call_surfnet_rpc's tagged params and explain them with…
92Infinitus92 Oct 11, 2026
fda7373
fix(scenarios): find PancakeSwap pools by pair or address and shorten…
92Infinitus92 Oct 12, 2026
981dd85
ci: add the Claude Code review
92Infinitus92 Oct 12, 2026
18ed5e4
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 Oct 12, 2026
22d0247
fix(scenarios): address the PancakeSwap fee tier by its pool's AmmCon…
92Infinitus92 Oct 13, 2026
a3d965e
test: share diff_indices through tests/helpers
92Infinitus92 Oct 13, 2026
dc0dbc7
docs(scenarios): drop the PancakeSwap README link to the Raydium README
92Infinitus92 Oct 13, 2026
ce8aeaf
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 Oct 17, 2026
8446cb7
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 Oct 30, 2026
8f0f065
fix(scenarios): use the PancakeSwap IDL published on chain
92Infinitus92 Oct 30, 2026
a839376
chore(scenarios): indent the PancakeSwap IDL like the other bundled IDLs
92Infinitus92 Nov 6, 2026
1d5542f
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 Nov 17, 2026
3d5d43b
test(pancakeswap): register the scenario at the next slot
92Infinitus92 Nov 17, 2026
d80767f
fix(scenarios): check the owner of a PancakeSwap pool the user gives
92Infinitus92 Nov 20, 2026
3cf6cad
test(scenarios): move the PancakeSwap tests to tests/protocols with t…
92Infinitus92 Nov 20, 2026
09481ed
Merge upstream/main into feat/scenarios/pancakeswap
92Infinitus92 Nov 27, 2026
373d700
ci: remove the Claude pull request review
92Infinitus92 Dec 2, 2026
1dfb620
Merge remote-tracking branch 'upstream/main' into feat/scenarios/panc…
92Infinitus92 Dec 2, 2026
8ce23f3
docs(scenarios): a PancakeSwap CLMM swap does not need the tick array…
92Infinitus92 Dec 2, 2026
84df0e7
docs(scenarios): drop the slot number from the PancakeSwap IDL note
92Infinitus92 Dec 4, 2026
9829660
Merge remote-tracking branch 'upstream/main' into feat/scenarios/panc…
92Infinitus92 Dec 4, 2026
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
1 change: 1 addition & 0 deletions crates/core/src/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Protocols that are natively supported by Surfpool will have their IDLs included
- **Whirlpool v1** - Orca's concentrated-liquidity AMM, addressed by pool, with the shared fee config override template. See [protocols/whirlpool/README.md](./protocols/whirlpool/README.md)
- **Meteora DLMM / DAMM v2** - Dynamic liquidity market maker and constant-product pools, with by-address pool templates covering price, status, and fees. See [protocols/meteora/README.md](./protocols/meteora/README.md)
- **Raydium AMM v4 / CLMM / CPMM** - Classic constant-product pools, concentrated-liquidity pools and CP-Swap pools, with pool state, fees, and swap stats override templates. See [protocols/raydium/README.md](./protocols/raydium/README.md)
- **PancakeSwap CLMM (Solana)** - Concentrated liquidity AMM, a fork of Raydium CLMM with identical account layouts. See [protocols/pancakeswap/README.md](./protocols/pancakeswap/README.md)

For custom protocols, an IDL can be registered at runtime using the [`surfnet_registerIdl`](https://docs.surfpool.run/rpc/cheatcodes#surfnet-registeridl) RPC cheatcode.

Expand Down
104 changes: 104 additions & 0 deletions crates/core/src/scenarios/protocols/pancakeswap/README.md
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
Comment thread
92Infinitus92 marked this conversation as resolved.
Resolved
Comment thread
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
Comment thread
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` |
Loading
Loading