From e5e4b2e06bddbef7abd13a0123770d382b8521da Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Thu, 24 Sep 2026 15:30:51 +0300 Subject: [PATCH 01/20] feat(scenarios): add PancakeSwap CLMM templates --- crates/core/src/scenarios/README.md | 1 + .../scenarios/protocols/pancakeswap/README.md | 111 + .../protocols/pancakeswap/v1/idl.json | 1854 +++++++++++++++++ .../protocols/pancakeswap/v1/overrides.yaml | 431 ++++ crates/core/src/scenarios/registry.rs | 101 +- crates/core/src/tests/mod.rs | 2 + crates/core/src/tests/pancakeswap/mod.rs | 247 +++ 7 files changed, 2744 insertions(+), 3 deletions(-) create mode 100644 crates/core/src/scenarios/protocols/pancakeswap/README.md create mode 100644 crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json create mode 100644 crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml create mode 100644 crates/core/src/tests/pancakeswap/mod.rs diff --git a/crates/core/src/scenarios/README.md b/crates/core/src/scenarios/README.md index 65e2d5683..81cb204ec 100644 --- a/crates/core/src/scenarios/README.md +++ b/crates/core/src/scenarios/README.md @@ -21,6 +21,7 @@ Protocols that are natively supported by Surfpool will have their IDLs included - **Pump v1** - Bonding curve launchpad with curve reserve and global config override templates - **Phoenix Eternal** - Perpetuals venue with trader collateral, mark price, maintenance margin, market fee, withdraw limit, trader capability, stop-loss trigger and delegated permission templates. See [protocols/phoenix-eternal/README.md](./protocols/phoenix-eternal/README.md) - **PumpSwap v1** - Constant-product AMM with pool state and global config override templates, including canonical pool derivation for migrated pump.fun coins +- **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. diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md new file mode 100644 index 000000000..37c56ba0e --- /dev/null +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -0,0 +1,111 @@ +# PancakeSwap CLMM (Solana) + +Declarative state-preparation templates for PancakeSwap's concentrated liquidity AMM on +Solana, a fork of Raydium CLMM (`amm_v3`) with identical `PoolState`, `AmmConfig` and +`TickArrayState` layouts and discriminators. The templates use the standard IDL override +path. For how scenarios work in general see the [scenarios README](../../README.md). + +## Program identity (verified 2026-09-21) + +| | | +| -------------------- | --------------------------------------------------------------------------------------- | +| Program ID | `HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq` | +| On-chain IDL account | `CAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf` | +| Fork of | Raydium CLMM (`CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK`) | +| Bundled IDL | `v1/idl.json`, decompressed from the on-chain IDL account 2026-09-21; `amm_v3` `0.1.0` | + +The bundled IDL keeps every account and type from the on-chain IDL and drops +`instructions`, `errors` and `events`. A later on-chain IDL with a different +`types`/`accounts` shape means the program was upgraded and this integration must be +revisited. + +## Templates + +| Template | Account | Address | Use for | +| ----------------------------- | ----------- | ------------------------------------------------------------------------- | ------------------------------------------------------- | +| `pancakeswap-clmm-custom` | `PoolState` | PDA `["pool", PDA(["amm_config", index_be]), token_mint_0, token_mint_1]` | any pool, selected by fee tier index and the two mints | +| `pancakeswap-clmm-pool-state` | `PoolState` | caller-provided pubkey | any pool by raw address | +| `pancakeswap-clmm-amm-config` | `AmmConfig` | PDA `["amm_config", index_be]` | a fee tier shared by every pool created with that index | + +`token_mint_0` must be the mint whose raw 32-byte pubkey is numerically smaller (compare +decoded bytes, not base58). Nothing checks the order: a reversed pair derives an empty +address. `amm_config_index` lists all 22 live fee tiers, each with its tick spacing, fee +and derived address. + +## Finding a pool + +- Browse pools at `https://solana.pancakeswap.finance/liquidity-pools/`. +- A pool account is owned by `HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq`, is 1544 + bytes, and starts with `PoolState`'s discriminator from `v1/idl.json`. +- Example: the deepest SOL/USDC pool (fee tier index 0, tick spacing 10) at + `DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ`. + +## Field reference + +Every field, unit and rule is the same as Raydium CLMM's; see the +[Raydium CLMM field reference](../raydium/v3/README.md#field-reference). In short: +`sqrt_price_x64` and `tick_current` must satisfy +`tick_current = floor(log((sqrt_price_x64 / 2^64)^2) / log(1.0001))`, the `status` bitmask +disables instructions (bit4 = swap), and the three `AmmConfig` rates are parts per +million. + +## Worked example: halve the SOL/USDC pool's price and disable swaps + +Starting from `sqrt_price_x64` 6213368270497578833 (tick -21765), halving the price +multiplies `sqrt_price_x64` by `sqrt(0.5)`: + +```json +{ + "templateId": "pancakeswap-clmm-pool-state", + "address": "DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ", + "values": { + "sqrt_price_x64": "4393514838078169088", + "tick_current": -28697, + "status": 16 + }, + "fetchBeforeUse": true +} +``` + +`(4393514838078169088 / 2^64)^2 = 0.056726` and `floor(log(0.056726) / log(1.0001)) = +-28697`, so the pair satisfies the coupling rule. `status: 16` sets bit4 (disable swap) +only. The pool's price moves between reads, so recompute both fields from its current +`sqrt_price_x64`. + +## Price shock + +Multiplying the price by `f` means `sqrt_price_x64' = round(sqrt_price_x64 * sqrt(f))`, +bounded to `[4295048016, 79226673521066979257578248091)`, and +`tick_current' = floor(2 * ln(sqrt_price_x64' / 2^64) / ln(1.0001))`, bounded to +`[-443636, 443636]`. Set both fields in one `pancakeswap-clmm-pool-state` override with +`fetchBeforeUse: true`. + +A swap resumes from the tick array covering `tick_current'`: PDA +`["tick_array", pool, start_index as i32 big-endian]` under the program, 60 ticks per +array, `start_index = floor(tick / (tick_spacing * 60)) * tick_spacing * 60`. A move that +stays inside the pool's current array is always safe; a larger one needs the destination +array to exist (a null `getAccountInfo` on its PDA means the swap will fail). The Studio +card computes this for you. + +## Verification + +- Static: the `PoolState` and `TickArrayState` type definitions (fields, types, order) and + the `PoolState` discriminator are identical in `pancakeswap/v1/idl.json` and + `raydium/v3/idl.json`. +- Unit: `cargo test -p surfpool-core --lib pancakeswap` covers the pool PDA for a live fee + tier and mint pair and every `amm_config_index` option's derived address. +- Live fork (`cargo test -p surfpool-core --features integration-tests pancakeswap -- + --test-threads=1`, needs network; `SURFPOOL_TEST_RPC_URL` overrides the endpoint): + round-trips the live SOL/USDC `PoolState` byte-for-byte, checks every + `amm_config_index` option's live size, discriminator, `tick_spacing` and + `trade_fee_rate`, runs `status`, `liquidity` and `tick_current` through the + materializer and asserts only their bytes changed. + +## Known limitations + +- `token_mint_0`/`token_mint_1` are plain `property_ref` seeds, so the caller orders them. + Raydium CLMM has the same gap. +- No swap simulation compares baseline and shocked prices, so the evidence for a price + override is byte-level, not trade-level. +- The layouts are identical and the engine picks the IDL by account owner, so a PancakeSwap + template pointed at a Raydium CLMM pool writes the same bytes. Check the pool's owner. diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json b/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json new file mode 100644 index 000000000..6661fa4b1 --- /dev/null +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json @@ -0,0 +1,1854 @@ +{ + "address": "HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq", + "metadata": { + "name": "amm_v3", + "version": "0.1.0", + "spec": "0.1.0", + "description": "Anchor client and source for Pancake concentrated liquidity AMM" + }, + "instructions": [], + "accounts": [ + { + "name": "AmmConfig", + "discriminator": [ + 218, + 244, + 33, + 104, + 203, + 203, + 43, + 111 + ] + }, + { + "name": "ObservationState", + "discriminator": [ + 122, + 174, + 197, + 53, + 129, + 9, + 165, + 132 + ] + }, + { + "name": "OperationState", + "discriminator": [ + 19, + 236, + 58, + 237, + 81, + 222, + 183, + 252 + ] + }, + { + "name": "PermissionlessFarmSwitch", + "discriminator": [ + 37, + 92, + 147, + 78, + 250, + 100, + 147, + 137 + ] + }, + { + "name": "PersonalPositionState", + "discriminator": [ + 70, + 111, + 150, + 126, + 230, + 15, + 25, + 117 + ] + }, + { + "name": "PoolState", + "discriminator": [ + 247, + 237, + 227, + 245, + 215, + 195, + 222, + 70 + ] + }, + { + "name": "ProtocolPositionState", + "discriminator": [ + 100, + 226, + 145, + 99, + 146, + 218, + 160, + 106 + ] + }, + { + "name": "SupportMintAssociated", + "discriminator": [ + 134, + 40, + 183, + 79, + 12, + 112, + 162, + 53 + ] + }, + { + "name": "TickArrayBitmapExtension", + "discriminator": [ + 60, + 150, + 36, + 219, + 97, + 128, + 139, + 153 + ] + }, + { + "name": "TickArrayState", + "discriminator": [ + 192, + 155, + 85, + 205, + 49, + 249, + 129, + 42 + ] + } + ], + "types": [ + { + "name": "AmmConfig", + "docs": [ + "Holds the current owner of the factory" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "index", + "type": "u16" + }, + { + "name": "owner", + "docs": [ + "Address of the protocol owner" + ], + "type": "pubkey" + }, + { + "name": "protocol_fee_rate", + "docs": [ + "The protocol fee" + ], + "type": "u32" + }, + { + "name": "trade_fee_rate", + "docs": [ + "The trade fee, denominated in hundredths of a bip (10^-6)" + ], + "type": "u32" + }, + { + "name": "tick_spacing", + "docs": [ + "The tick spacing" + ], + "type": "u16" + }, + { + "name": "fund_fee_rate", + "docs": [ + "The fund fee, denominated in hundredths of a bip (10^-6)" + ], + "type": "u32" + }, + { + "name": "padding_u32", + "type": "u32" + }, + { + "name": "fund_owner", + "type": "pubkey" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 3 + ] + } + } + ] + } + }, + { + "name": "CollectPersonalFeeEvent", + "docs": [ + "Emitted when tokens are collected for a position" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "position_nft_mint", + "docs": [ + "The ID of the token for which underlying tokens were collected" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The token account that received the collected token_0 tokens" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The token account that received the collected token_1 tokens" + ], + "type": "pubkey" + }, + { + "name": "amount_0", + "docs": [ + "The amount of token_0 owed to the position that was collected" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The amount of token_1 owed to the position that was collected" + ], + "type": "u64" + } + ] + } + }, + { + "name": "CollectProtocolFeeEvent", + "docs": [ + "Emitted when the collected protocol fees are withdrawn by the factory owner" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool whose protocol fee is collected" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The address that receives the collected token_0 protocol fees" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The address that receives the collected token_1 protocol fees" + ], + "type": "pubkey" + }, + { + "name": "amount_0", + "docs": [ + "The amount of token_0 protocol fees that is withdrawn" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The amount of token_0 protocol fees that is withdrawn" + ], + "type": "u64" + } + ] + } + }, + { + "name": "ConfigChangeEvent", + "docs": [ + "Emitted when create or update a config" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "index", + "type": "u16" + }, + { + "name": "owner", + "type": "pubkey" + }, + { + "name": "protocol_fee_rate", + "type": "u32" + }, + { + "name": "trade_fee_rate", + "type": "u32" + }, + { + "name": "tick_spacing", + "type": "u16" + }, + { + "name": "fund_fee_rate", + "type": "u32" + }, + { + "name": "fund_owner", + "type": "pubkey" + } + ] + } + }, + { + "name": "CreatePersonalPositionEvent", + "docs": [ + "Emitted when create a new position" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool for which liquidity was added" + ], + "type": "pubkey" + }, + { + "name": "minter", + "docs": [ + "The address that create the position" + ], + "type": "pubkey" + }, + { + "name": "nft_owner", + "docs": [ + "The owner of the position and recipient of any minted liquidity" + ], + "type": "pubkey" + }, + { + "name": "tick_lower_index", + "docs": [ + "The lower tick of the position" + ], + "type": "i32" + }, + { + "name": "tick_upper_index", + "docs": [ + "The upper tick of the position" + ], + "type": "i32" + }, + { + "name": "liquidity", + "docs": [ + "The amount of liquidity minted to the position range" + ], + "type": "u128" + }, + { + "name": "deposit_amount_0", + "docs": [ + "The amount of token_0 was deposit for the liquidity" + ], + "type": "u64" + }, + { + "name": "deposit_amount_1", + "docs": [ + "The amount of token_1 was deposit for the liquidity" + ], + "type": "u64" + }, + { + "name": "deposit_amount_0_transfer_fee", + "docs": [ + "The token transfer fee for deposit_amount_0" + ], + "type": "u64" + }, + { + "name": "deposit_amount_1_transfer_fee", + "docs": [ + "The token transfer fee for deposit_amount_1" + ], + "type": "u64" + } + ] + } + }, + { + "name": "DecreaseLiquidityEvent", + "docs": [ + "Emitted when liquidity is decreased." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "position_nft_mint", + "docs": [ + "The ID of the token for which liquidity was decreased" + ], + "type": "pubkey" + }, + { + "name": "liquidity", + "docs": [ + "The amount by which liquidity for the position was decreased" + ], + "type": "u128" + }, + { + "name": "decrease_amount_0", + "docs": [ + "The amount of token_0 that was paid for the decrease in liquidity" + ], + "type": "u64" + }, + { + "name": "decrease_amount_1", + "docs": [ + "The amount of token_1 that was paid for the decrease in liquidity" + ], + "type": "u64" + }, + { + "name": "fee_amount_0", + "type": "u64" + }, + { + "name": "fee_amount_1", + "docs": [ + "The amount of token_1 fee" + ], + "type": "u64" + }, + { + "name": "reward_amounts", + "docs": [ + "The amount of rewards" + ], + "type": { + "array": [ + "u64", + 3 + ] + } + }, + { + "name": "transfer_fee_0", + "docs": [ + "The amount of token_0 transfer fee" + ], + "type": "u64" + }, + { + "name": "transfer_fee_1", + "docs": [ + "The amount of token_1 transfer fee" + ], + "type": "u64" + } + ] + } + }, + { + "name": "IncreaseLiquidityEvent", + "docs": [ + "Emitted when liquidity is increased." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "position_nft_mint", + "docs": [ + "The ID of the token for which liquidity was increased" + ], + "type": "pubkey" + }, + { + "name": "liquidity", + "docs": [ + "The amount by which liquidity for the NFT position was increased" + ], + "type": "u128" + }, + { + "name": "amount_0", + "docs": [ + "The amount of token_0 that was paid for the increase in liquidity" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The amount of token_1 that was paid for the increase in liquidity" + ], + "type": "u64" + }, + { + "name": "amount_0_transfer_fee", + "docs": [ + "The token transfer fee for amount_0" + ], + "type": "u64" + }, + { + "name": "amount_1_transfer_fee", + "docs": [ + "The token transfer fee for amount_1" + ], + "type": "u64" + } + ] + } + }, + { + "name": "InitializeRewardParam", + "type": { + "kind": "struct", + "fields": [ + { + "name": "open_time", + "docs": [ + "Reward open time" + ], + "type": "u64" + }, + { + "name": "end_time", + "docs": [ + "Reward end time" + ], + "type": "u64" + }, + { + "name": "emissions_per_second_x64", + "docs": [ + "Token reward per second are earned per unit of liquidity" + ], + "type": "u128" + } + ] + } + }, + { + "name": "LiquidityCalculateEvent", + "docs": [ + "Emitted when liquidity decreased or increase." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_liquidity", + "docs": [ + "The pool liquidity before decrease or increase" + ], + "type": "u128" + }, + { + "name": "pool_sqrt_price_x64", + "docs": [ + "The pool price when decrease or increase in liquidity" + ], + "type": "u128" + }, + { + "name": "pool_tick", + "docs": [ + "The pool tick when decrease or increase in liquidity" + ], + "type": "i32" + }, + { + "name": "calc_amount_0", + "docs": [ + "The amount of token_0 that was calculated for the decrease or increase in liquidity" + ], + "type": "u64" + }, + { + "name": "calc_amount_1", + "docs": [ + "The amount of token_1 that was calculated for the decrease or increase in liquidity" + ], + "type": "u64" + }, + { + "name": "trade_fee_owed_0", + "type": "u64" + }, + { + "name": "trade_fee_owed_1", + "docs": [ + "The amount of token_1 fee" + ], + "type": "u64" + }, + { + "name": "transfer_fee_0", + "docs": [ + "The amount of token_0 transfer fee without trade_fee_amount_0" + ], + "type": "u64" + }, + { + "name": "transfer_fee_1", + "docs": [ + "The amount of token_1 transfer fee without trade_fee_amount_0" + ], + "type": "u64" + } + ] + } + }, + { + "name": "LiquidityChangeEvent", + "docs": [ + "Emitted pool liquidity change when increase and decrease liquidity" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool for swap" + ], + "type": "pubkey" + }, + { + "name": "tick", + "docs": [ + "The tick of the pool" + ], + "type": "i32" + }, + { + "name": "tick_lower", + "docs": [ + "The tick lower of position" + ], + "type": "i32" + }, + { + "name": "tick_upper", + "docs": [ + "The tick lower of position" + ], + "type": "i32" + }, + { + "name": "liquidity_before", + "docs": [ + "The liquidity of the pool before liquidity change" + ], + "type": "u128" + }, + { + "name": "liquidity_after", + "docs": [ + "The liquidity of the pool after liquidity change" + ], + "type": "u128" + } + ] + } + }, + { + "name": "Observation", + "docs": [ + "The element of observations in ObservationState" + ], + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "block_timestamp", + "docs": [ + "The block timestamp of the observation" + ], + "type": "u32" + }, + { + "name": "tick_cumulative", + "docs": [ + "the cumulative of tick during the duration time" + ], + "type": "i64" + }, + { + "name": "padding", + "docs": [ + "padding for feature update" + ], + "type": { + "array": [ + "u64", + 4 + ] + } + } + ] + } + }, + { + "name": "ObservationState", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "initialized", + "docs": [ + "Whether the ObservationState is initialized" + ], + "type": "bool" + }, + { + "name": "recent_epoch", + "docs": [ + "recent update epoch" + ], + "type": "u64" + }, + { + "name": "observation_index", + "docs": [ + "the most-recently updated index of the observations array" + ], + "type": "u16" + }, + { + "name": "pool_id", + "docs": [ + "belongs to which pool" + ], + "type": "pubkey" + }, + { + "name": "observations", + "docs": [ + "observation array" + ], + "type": { + "array": [ + { + "defined": { + "name": "Observation" + } + }, + 100 + ] + } + }, + { + "name": "padding", + "docs": [ + "padding for feature update" + ], + "type": { + "array": [ + "u64", + 4 + ] + } + } + ] + } + }, + { + "name": "OperationState", + "docs": [ + "Holds the current owner of the factory" + ], + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "operation_owners", + "docs": [ + "Address of the operation owner" + ], + "type": { + "array": [ + "pubkey", + 10 + ] + } + }, + { + "name": "whitelist_mints", + "docs": [ + "The mint address of whitelist to emit reward" + ], + "type": { + "array": [ + "pubkey", + 100 + ] + } + } + ] + } + }, + { + "name": "PermissionlessFarmSwitch", + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "is_on", + "docs": [ + "Is the permissionless farm allowed or not" + ], + "type": "bool" + } + ] + } + }, + { + "name": "PersonalPositionState", + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": { + "array": [ + "u8", + 1 + ] + } + }, + { + "name": "nft_mint", + "docs": [ + "Mint address of the tokenized position" + ], + "type": "pubkey" + }, + { + "name": "pool_id", + "docs": [ + "The ID of the pool with which this token is connected" + ], + "type": "pubkey" + }, + { + "name": "tick_lower_index", + "docs": [ + "The lower bound tick of the position" + ], + "type": "i32" + }, + { + "name": "tick_upper_index", + "docs": [ + "The upper bound tick of the position" + ], + "type": "i32" + }, + { + "name": "liquidity", + "docs": [ + "The amount of liquidity owned by this position" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_0_last_x64", + "docs": [ + "The token_0 fee growth of the aggregate position as of the last action on the individual position" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_1_last_x64", + "docs": [ + "The token_1 fee growth of the aggregate position as of the last action on the individual position" + ], + "type": "u128" + }, + { + "name": "token_fees_owed_0", + "docs": [ + "The fees owed to the position owner in token_0, as of the last computation" + ], + "type": "u64" + }, + { + "name": "token_fees_owed_1", + "docs": [ + "The fees owed to the position owner in token_1, as of the last computation" + ], + "type": "u64" + }, + { + "name": "reward_infos", + "type": { + "array": [ + { + "defined": { + "name": "PositionRewardInfo" + } + }, + 3 + ] + } + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 7 + ] + } + } + ] + } + }, + { + "name": "PoolCreatedEvent", + "docs": [ + "Emitted when a pool is created and initialized with a starting price", + "" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "token_mint_0", + "docs": [ + "The first token of the pool by address sort order" + ], + "type": "pubkey" + }, + { + "name": "token_mint_1", + "docs": [ + "The second token of the pool by address sort order" + ], + "type": "pubkey" + }, + { + "name": "tick_spacing", + "docs": [ + "The minimum number of ticks between initialized ticks" + ], + "type": "u16" + }, + { + "name": "pool_state", + "docs": [ + "The address of the created pool" + ], + "type": "pubkey" + }, + { + "name": "sqrt_price_x64", + "docs": [ + "The initial sqrt price of the pool, as a Q64.64" + ], + "type": "u128" + }, + { + "name": "tick", + "docs": [ + "The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool" + ], + "type": "i32" + }, + { + "name": "token_vault_0", + "docs": [ + "Vault of token_0" + ], + "type": "pubkey" + }, + { + "name": "token_vault_1", + "docs": [ + "Vault of token_1" + ], + "type": "pubkey" + } + ] + } + }, + { + "name": "PoolState", + "docs": [ + "The pool state", + "", + "PDA of `[POOL_SEED, config, token_mint_0, token_mint_1]`", + "" + ], + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": { + "array": [ + "u8", + 1 + ] + } + }, + { + "name": "amm_config", + "type": "pubkey" + }, + { + "name": "owner", + "type": "pubkey" + }, + { + "name": "token_mint_0", + "docs": [ + "Token pair of the pool, where token_mint_0 address < token_mint_1 address" + ], + "type": "pubkey" + }, + { + "name": "token_mint_1", + "type": "pubkey" + }, + { + "name": "token_vault_0", + "docs": [ + "Token pair vault" + ], + "type": "pubkey" + }, + { + "name": "token_vault_1", + "type": "pubkey" + }, + { + "name": "observation_key", + "docs": [ + "observation account key" + ], + "type": "pubkey" + }, + { + "name": "mint_decimals_0", + "docs": [ + "mint0 and mint1 decimals" + ], + "type": "u8" + }, + { + "name": "mint_decimals_1", + "type": "u8" + }, + { + "name": "tick_spacing", + "docs": [ + "The minimum number of ticks between initialized ticks" + ], + "type": "u16" + }, + { + "name": "liquidity", + "docs": [ + "The currently in range liquidity available to the pool." + ], + "type": "u128" + }, + { + "name": "sqrt_price_x64", + "docs": [ + "The current price of the pool as a sqrt(token_1/token_0) Q64.64 value" + ], + "type": "u128" + }, + { + "name": "tick_current", + "docs": [ + "The current tick of the pool, i.e. according to the last tick transition that was run." + ], + "type": "i32" + }, + { + "name": "padding3", + "type": "u16" + }, + { + "name": "padding4", + "type": "u16" + }, + { + "name": "fee_growth_global_0_x64", + "docs": [ + "The fee growth as a Q64.64 number, i.e. fees of token_0 and token_1 collected per", + "unit of liquidity for the entire life of the pool." + ], + "type": "u128" + }, + { + "name": "fee_growth_global_1_x64", + "type": "u128" + }, + { + "name": "protocol_fees_token_0", + "docs": [ + "The amounts of token_0 and token_1 that are owed to the protocol." + ], + "type": "u64" + }, + { + "name": "protocol_fees_token_1", + "type": "u64" + }, + { + "name": "swap_in_amount_token_0", + "docs": [ + "The amounts in and out of swap token_0 and token_1" + ], + "type": "u128" + }, + { + "name": "swap_out_amount_token_1", + "type": "u128" + }, + { + "name": "swap_in_amount_token_1", + "type": "u128" + }, + { + "name": "swap_out_amount_token_0", + "type": "u128" + }, + { + "name": "status", + "docs": [ + "Bitwise representation of the state of the pool", + "bit0, 1: disable open position and increase liquidity, 0: normal", + "bit1, 1: disable decrease liquidity, 0: normal", + "bit2, 1: disable collect fee, 0: normal", + "bit3, 1: disable collect reward, 0: normal", + "bit4, 1: disable swap, 0: normal" + ], + "type": "u8" + }, + { + "name": "padding", + "docs": [ + "Leave blank for future use" + ], + "type": { + "array": [ + "u8", + 7 + ] + } + }, + { + "name": "reward_infos", + "type": { + "array": [ + { + "defined": { + "name": "RewardInfo" + } + }, + 3 + ] + } + }, + { + "name": "tick_array_bitmap", + "docs": [ + "Packed initialized tick array state" + ], + "type": { + "array": [ + "u64", + 16 + ] + } + }, + { + "name": "total_fees_token_0", + "docs": [ + "except protocol_fee and fund_fee" + ], + "type": "u64" + }, + { + "name": "total_fees_claimed_token_0", + "docs": [ + "except protocol_fee and fund_fee" + ], + "type": "u64" + }, + { + "name": "total_fees_token_1", + "type": "u64" + }, + { + "name": "total_fees_claimed_token_1", + "type": "u64" + }, + { + "name": "fund_fees_token_0", + "type": "u64" + }, + { + "name": "fund_fees_token_1", + "type": "u64" + }, + { + "name": "open_time", + "type": "u64" + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding1", + "type": { + "array": [ + "u64", + 24 + ] + } + }, + { + "name": "padding2", + "type": { + "array": [ + "u64", + 32 + ] + } + } + ] + } + }, + { + "name": "PositionRewardInfo", + "type": { + "kind": "struct", + "fields": [ + { + "name": "growth_inside_last_x64", + "type": "u128" + }, + { + "name": "reward_amount_owed", + "type": "u64" + } + ] + } + }, + { + "name": "ProtocolPositionState", + "docs": [ + "Info stored for each user's position" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "pool_id", + "docs": [ + "The ID of the pool with which this token is connected" + ], + "type": "pubkey" + }, + { + "name": "tick_lower_index", + "docs": [ + "The lower bound tick of the position" + ], + "type": "i32" + }, + { + "name": "tick_upper_index", + "docs": [ + "The upper bound tick of the position" + ], + "type": "i32" + }, + { + "name": "liquidity", + "docs": [ + "The amount of liquidity owned by this position" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_0_last_x64", + "docs": [ + "The token_0 fee growth per unit of liquidity as of the last update to liquidity or fees owed" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_1_last_x64", + "docs": [ + "The token_1 fee growth per unit of liquidity as of the last update to liquidity or fees owed" + ], + "type": "u128" + }, + { + "name": "token_fees_owed_0", + "docs": [ + "The fees owed to the position owner in token_0" + ], + "type": "u64" + }, + { + "name": "token_fees_owed_1", + "docs": [ + "The fees owed to the position owner in token_1" + ], + "type": "u64" + }, + { + "name": "reward_growth_inside", + "docs": [ + "The reward growth per unit of liquidity as of the last update to liquidity" + ], + "type": { + "array": [ + "u128", + 3 + ] + } + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 7 + ] + } + } + ] + } + }, + { + "name": "RewardInfo", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "reward_state", + "docs": [ + "Reward state" + ], + "type": "u8" + }, + { + "name": "open_time", + "docs": [ + "Reward open time" + ], + "type": "u64" + }, + { + "name": "end_time", + "docs": [ + "Reward end time" + ], + "type": "u64" + }, + { + "name": "last_update_time", + "docs": [ + "Reward last update time" + ], + "type": "u64" + }, + { + "name": "emissions_per_second_x64", + "docs": [ + "Q64.64 number indicates how many tokens per second are earned per unit of liquidity." + ], + "type": "u128" + }, + { + "name": "reward_total_emissioned", + "docs": [ + "The total amount of reward emissioned" + ], + "type": "u64" + }, + { + "name": "reward_claimed", + "docs": [ + "The total amount of claimed reward" + ], + "type": "u64" + }, + { + "name": "token_mint", + "docs": [ + "Reward token mint." + ], + "type": "pubkey" + }, + { + "name": "token_vault", + "docs": [ + "Reward vault token account." + ], + "type": "pubkey" + }, + { + "name": "authority", + "docs": [ + "The owner that has permission to set reward param" + ], + "type": "pubkey" + }, + { + "name": "reward_growth_global_x64", + "docs": [ + "Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward", + "emissions were turned on." + ], + "type": "u128" + } + ] + } + }, + { + "name": "SupportMintAssociated", + "docs": [ + "Holds the current owner of the factory" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "mint", + "docs": [ + "Address of the supported token22 mint" + ], + "type": "pubkey" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 8 + ] + } + } + ] + } + }, + { + "name": "SwapEvent", + "docs": [ + "Emitted by when a swap is performed for a pool" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool for which token_0 and token_1 were swapped" + ], + "type": "pubkey" + }, + { + "name": "sender", + "docs": [ + "The address that initiated the swap call, and that received the callback" + ], + "type": "pubkey" + }, + { + "name": "token_account_0", + "docs": [ + "The payer token account in zero for one swaps, or the recipient token account", + "in one for zero swaps" + ], + "type": "pubkey" + }, + { + "name": "token_account_1", + "docs": [ + "The payer token account in one for zero swaps, or the recipient token account", + "in zero for one swaps" + ], + "type": "pubkey" + }, + { + "name": "amount_0", + "docs": [ + "The real delta amount of the token_0 of the pool or user" + ], + "type": "u64" + }, + { + "name": "transfer_fee_0", + "docs": [ + "The transfer fee charged by the withheld_amount of the token_0" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The real delta of the token_1 of the pool or user" + ], + "type": "u64" + }, + { + "name": "transfer_fee_1", + "docs": [ + "The transfer fee charged by the withheld_amount of the token_1" + ], + "type": "u64" + }, + { + "name": "zero_for_one", + "docs": [ + "if true, amount_0 is negtive and amount_1 is positive" + ], + "type": "bool" + }, + { + "name": "sqrt_price_x64", + "docs": [ + "The sqrt(price) of the pool after the swap, as a Q64.64" + ], + "type": "u128" + }, + { + "name": "liquidity", + "docs": [ + "The liquidity of the pool after the swap" + ], + "type": "u128" + }, + { + "name": "tick", + "docs": [ + "The log base 1.0001 of price of the pool after the swap" + ], + "type": "i32" + } + ] + } + }, + { + "name": "TickArrayBitmapExtension", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_id", + "type": "pubkey" + }, + { + "name": "positive_tick_array_bitmap", + "docs": [ + "Packed initialized tick array state for start_tick_index is positive" + ], + "type": { + "array": [ + { + "array": [ + "u64", + 8 + ] + }, + 14 + ] + } + }, + { + "name": "negative_tick_array_bitmap", + "docs": [ + "Packed initialized tick array state for start_tick_index is negitive" + ], + "type": { + "array": [ + { + "array": [ + "u64", + 8 + ] + }, + 14 + ] + } + } + ] + } + }, + { + "name": "TickArrayState", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_id", + "type": "pubkey" + }, + { + "name": "start_tick_index", + "type": "i32" + }, + { + "name": "ticks", + "type": { + "array": [ + { + "defined": { + "name": "TickState" + } + }, + 60 + ] + } + }, + { + "name": "initialized_tick_count", + "type": "u8" + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 107 + ] + } + } + ] + } + }, + { + "name": "TickState", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "tick", + "type": "i32" + }, + { + "name": "liquidity_net", + "docs": [ + "Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)" + ], + "type": "i128" + }, + { + "name": "liquidity_gross", + "docs": [ + "The total position liquidity that references this tick" + ], + "type": "u128" + }, + { + "name": "fee_growth_outside_0_x64", + "docs": [ + "Fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)", + "only has relative meaning, not absolute \u2014 the value depends on when the tick is initialized" + ], + "type": "u128" + }, + { + "name": "fee_growth_outside_1_x64", + "type": "u128" + }, + { + "name": "reward_growths_outside_x64", + "type": { + "array": [ + "u128", + 3 + ] + } + }, + { + "name": "padding", + "type": { + "array": [ + "u32", + 13 + ] + } + } + ] + } + }, + { + "name": "UpdateRewardInfosEvent", + "docs": [ + "Emitted when Reward are updated for a pool" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "reward_growth_global_x64", + "docs": [ + "Reward info" + ], + "type": { + "array": [ + "u128", + 3 + ] + } + } + ] + } + } + ] +} diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml new file mode 100644 index 000000000..533fbc913 --- /dev/null +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml @@ -0,0 +1,431 @@ +protocol: PancakeSwap +version: v1 +account_type: PoolState +idl_file_path: idl.json + +tags: + - amm + - concentrated-liquidity + - defi + +# Protocol-specific constants that can be referenced by templates +constants: + # PancakeSwap CLMM AMM Config index (for dynamic derivation) + # The AMM config PDA is derived as: ["amm_config", index.to_be_bytes()] + # Captured 2026-09-21 from all 22 live AmmConfig accounts on mainnet + # (getProgramAccounts, dataSize 117, AmmConfig discriminator memcmp). + amm_config_index: + label: Fee Tier (by index) + description: | + AMM config index for dynamic PDA derivation, captured live 2026-09-21 from all + 22 AmmConfig accounts owned by the PancakeSwap program. + The config address is derived from ["amm_config", index.to_be_bytes()]. + options: + - id: index_0 + label: "Fee tier 0.01% (tick spacing 10)" + description: AMM config index 0, trade fee 100 / 1,000,000 + value: "0" + metadata: + tick_spacing: 10 + fee_rate_bps: 1 + derived_address: HZzqEWHEvSiqYt6PxxLs7zXETmqGuryqfmvggjAkqisp + - id: index_1 + label: "Fee tier 0.25% (tick spacing 60)" + description: AMM config index 1, trade fee 2500 / 1,000,000 + value: "1" + metadata: + tick_spacing: 60 + fee_rate_bps: 25 + derived_address: He4brjK7TRKiqJ8szpRmhuueDwC4837BFRRBmWfmjo14 + - id: index_2 + label: "Fee tier 0.05% (tick spacing 10)" + description: AMM config index 2, trade fee 500 / 1,000,000 + value: "2" + metadata: + tick_spacing: 10 + fee_rate_bps: 5 + derived_address: GUNzSDNbhcWpS6Ymj7kgyYmhgHimwfzpRdhJnbKDAi9K + - id: index_3 + label: "Fee tier 1% (tick spacing 120)" + description: AMM config index 3, trade fee 10000 / 1,000,000 + value: "3" + metadata: + tick_spacing: 120 + fee_rate_bps: 100 + derived_address: EtgcyD5Yk6Kuqf1fahAjTrsRCDgoUmgeZ7xJDS3giaE + - id: index_4 + label: "Fee tier 0.01% (tick spacing 1)" + description: AMM config index 4, trade fee 100 / 1,000,000 + value: "4" + metadata: + tick_spacing: 1 + fee_rate_bps: 1 + derived_address: EvKEMSRSdxJUcpVTaB2isqMyF5G4yETvMbQxbfwSuwZa + - id: index_5 + label: "Fee tier 0.05% (tick spacing 1)" + description: AMM config index 5, trade fee 500 / 1,000,000 + value: "5" + metadata: + tick_spacing: 1 + fee_rate_bps: 5 + derived_address: 2cc6jRdZgmN7uG3PxbuVEkYwQNPS7qQinKYYCwG53cpr + - id: index_6 + label: "Fee tier 0.02% (tick spacing 1)" + description: AMM config index 6, trade fee 200 / 1,000,000 + value: "6" + metadata: + tick_spacing: 1 + fee_rate_bps: 2 + derived_address: GcJVsj5MxokA4eRMUkB4cJHuZ6o9Y8MooXBViN5F1mYW + - id: index_7 + label: "Fee tier 0.03% (tick spacing 1)" + description: AMM config index 7, trade fee 300 / 1,000,000 + value: "7" + metadata: + tick_spacing: 1 + fee_rate_bps: 3 + derived_address: 2zmg7259ahZkrSn6M3PEM7eFvEfBU8obgfVHT3AL9Qwu + - id: index_8 + label: "Fee tier 0.04% (tick spacing 1)" + description: AMM config index 8, trade fee 400 / 1,000,000 + value: "8" + metadata: + tick_spacing: 1 + fee_rate_bps: 4 + derived_address: 5kosJrgZ6rHyqqweWGpp11nNqdwPTHbyXVczvzPM9h7M + - id: index_9 + label: "Fee tier 2% (tick spacing 120)" + description: AMM config index 9, trade fee 20000 / 1,000,000 + value: "9" + metadata: + tick_spacing: 120 + fee_rate_bps: 200 + derived_address: 2W1ToXSAUDwRQtZdgCjgXmFfiSvPmGDPx3CijKpVKArw + - id: index_10 + label: "Fee tier 0.1% (tick spacing 10)" + description: AMM config index 10, trade fee 1000 / 1,000,000 + value: "10" + metadata: + tick_spacing: 10 + fee_rate_bps: 10 + derived_address: 5szFcjKA7UU93nhgb3fE1o1cfcurwpFQEzywZyb2qAYF + - id: index_11 + label: "Fee tier 0.15% (tick spacing 10)" + description: AMM config index 11, trade fee 1500 / 1,000,000 + value: "11" + metadata: + tick_spacing: 10 + fee_rate_bps: 15 + derived_address: J1SzfvdJ3p4ixWdyhoHmVpnixfjUBcEZiJ3M66JHGTKz + - id: index_12 + label: "Fee tier 0.16% (tick spacing 10)" + description: AMM config index 12, trade fee 1600 / 1,000,000 + value: "12" + metadata: + tick_spacing: 10 + fee_rate_bps: 16 + derived_address: 5B9wMiyqe7maHxAKACrTiGYwTeSX3ZmpmxRgALUMTcdZ + - id: index_13 + label: "Fee tier 0.18% (tick spacing 10)" + description: AMM config index 13, trade fee 1800 / 1,000,000 + value: "13" + metadata: + tick_spacing: 10 + fee_rate_bps: 18 + derived_address: 5tbvQTWV2btAgX5NwzCbd8aFwTfDWeCZANRQUcWuKRan + - id: index_14 + label: "Fee tier 0.2% (tick spacing 10)" + description: AMM config index 14, trade fee 2000 / 1,000,000 + value: "14" + metadata: + tick_spacing: 10 + fee_rate_bps: 20 + derived_address: G3BrCQzNu93v1acayMA23CmCMH8tf6iAFb3PYUHUHtcg + - id: index_15 + label: "Fee tier 0.4% (tick spacing 60)" + description: AMM config index 15, trade fee 4000 / 1,000,000 + value: "15" + metadata: + tick_spacing: 60 + fee_rate_bps: 40 + derived_address: 2G7HZiydoxtDqQU5SPsyc66nCGRUaP6H85FRKunKpmPs + - id: index_16 + label: "Fee tier 0.6% (tick spacing 60)" + description: AMM config index 16, trade fee 6000 / 1,000,000 + value: "16" + metadata: + tick_spacing: 60 + fee_rate_bps: 60 + derived_address: A3qKMAUV2JsBUeRssKeLm2xJr9w9PKFNWGxPfSV6E7vu + - id: index_17 + label: "Fee tier 0.8% (tick spacing 60)" + description: AMM config index 17, trade fee 8000 / 1,000,000 + value: "17" + metadata: + tick_spacing: 60 + fee_rate_bps: 80 + derived_address: GaWZjVasTQLCNmag5n34eyhhD4T56TN39ckNcuUmu7x4 + - id: index_18 + label: "Fee tier 3% (tick spacing 120)" + description: AMM config index 18, trade fee 30000 / 1,000,000 + value: "18" + metadata: + tick_spacing: 120 + fee_rate_bps: 300 + derived_address: 3EKNN4mNKSzBnfB5gC9q4eeL7WMWBrnuaoagMQVCL2vq + - id: index_19 + label: "Fee tier 4% (tick spacing 120)" + description: AMM config index 19, trade fee 40000 / 1,000,000 + value: "19" + metadata: + tick_spacing: 120 + fee_rate_bps: 400 + derived_address: GeNe8uDSMpCip17DmToci8XNhTgwJJ4QdXP3HNrZbA21 + - id: index_20 + label: "Fee tier 0.3% (tick spacing 60)" + description: AMM config index 20, trade fee 3000 / 1,000,000 + value: "20" + metadata: + tick_spacing: 60 + fee_rate_bps: 30 + derived_address: 4LTiLQbjodjCy8dFWqgUx6fzQ93Pq37c5jWGX9jRsRtC + - id: index_21 + label: "Fee tier 0.08% (tick spacing 1)" + description: AMM config index 21, trade fee 800 / 1,000,000 + value: "21" + metadata: + tick_spacing: 1 + fee_rate_bps: 8 + derived_address: 9rrh2c8w15HExZnLFzcEgkvHg846TBBFEPUuFG7RMGmm + + # Token mints loaded from verified tokens registry + token_mint: + label: Token + description: Select a token mint address from verified tokens + source: verified_tokens + +templates: + - id: pancakeswap-clmm-custom + name: Override Any CLMM Pool (Custom) + description: | + Override any PancakeSwap CLMM pool by specifying the fee tier index and token + mints. Both the AMM config address AND the pool address are dynamically derived: + - AMM Config: PDA from ["amm_config", config_index.to_be_bytes()] + - Pool: PDA from ["pool", amm_config, token_mint_0, token_mint_1] + idl_account_name: PoolState + properties: + - path: liquidity + label: Liquidity + description: Total liquidity in the current tick range (raw u128, no decimals) + - path: sqrt_price_x64 + label: Square Root Price (Q64.64) + description: sqrt(token_1/token_0) in Q64.64 fixed point (raw u128); must agree with tick_current + - path: tick_current + label: Current Tick + description: Tick index of the current price (i32); must agree with sqrt_price_x64 + - path: status + label: Pool Status + description: "Disable bitmask (u8): bit0 open/increase liquidity, bit1 decrease liquidity, bit2 collect fee, bit3 collect reward, bit4 swap; 0 = all enabled" + - path: config_index + type: constant_ref + label: Fee Tier + constant: amm_config_index + description: Fee tier of the pool. Together with the two mints it selects the pool address. + - path: token_mint_0 + type: constant_ref + label: Token 0 Mint + constant: token_mint + description: First mint of the pair as the program stores it, the lower of the two by raw bytes. + - path: token_mint_1 + type: constant_ref + label: Token 1 Mint + constant: token_mint + description: Second mint of the pair as the program stores it, the higher of the two by raw bytes. + llm_context: | + Set fetchBeforeUse: true so the live account is forked first and every field you + don't override keeps its live value; set it to false only for a later override + that builds on state an earlier override in the same scenario already prepared. + + CRITICAL: token_mint_0 and token_mint_1 must be SPL TOKEN MINT addresses, NOT + program IDs! + + CORRECT examples of token mints: + - SOL (wrapped): So11111111111111111111111111111111111111112 + - USDC: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v + + WRONG - these are PROGRAM IDs, not token mints: + - HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq (PancakeSwap CLMM) + - CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK (Raydium CLMM) + + Always use get_token_address tool to look up token mints by symbol (e.g., "SOL", + "USDC"). + + MINT ORDER: token_mint_0 must be the mint whose raw 32-byte pubkey is numerically + smaller than token_mint_1's (compare the decoded bytes, not the base58 string). + The pool PDA is ["pool", amm_config, token_mint_0, token_mint_1] in that exact + order, so swapping the two mints derives a different, almost certainly empty, + address. token_mint_0/token_mint_1 are plain property_ref seeds here and the + caller is responsible for the ordering. + + PRICE / TICK COUPLING (sqrt_price_x64 and tick_current must agree): + - raw price = (sqrt_price_x64 / 2^64)^2, a token_1-per-token_0 ratio in raw + (undecimaled) units; multiply by 10^(mint_decimals_0 - mint_decimals_1) for a + human-readable price + - tick_current = floor(log(raw price) / log(1.0001)) + - a swap walks TickArrayState accounts starting from tick_current; if + tick_current doesn't match sqrt_price_x64, or the tick array covering it was + never initialized, the swap fails. Overriding one of the pair without + recomputing the other from the formula above leaves the pool in a state no + real swap can trade against. + + VAULTS: sqrt_price_x64/tick_current only change the pool's quoted price; they do + not move token_vault_0/token_vault_1 balances. A swap that would trade at the new + price is still bounded by what the vaults actually hold, so fund the vaults (or + accept that only small trades succeed) when the override should support a real + swap at depth. + + FINDING A POOL: the PancakeSwap CLMM program is + HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq. A live PoolState account is 1544 + bytes and starts with the 8-byte discriminator [247, 237, 227, 245, 215, 195, + 222, 70]. The deepest SOL/USDC pool is DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ + (fee tier index 0, tick spacing 10). Browse pools at + https://solana.pancakeswap.finance/liquidity-pools/. + address: + type: pda + program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq + seeds: + - type: string + value: pool + # Dynamically derive the AMM config PDA from the index + - type: derived_pda + program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq + seeds: + - type: string + value: amm_config + - type: u16_be_ref + value: config_index + - type: property_ref + value: token_mint_0 + - type: property_ref + value: token_mint_1 + + - id: pancakeswap-clmm-pool-state + name: Override CLMM Pool State (By Address) + description: | + Override any PancakeSwap CLMM pool by its own address, for a pubkey the caller + already has (no mint/config lookup). + idl_account_name: PoolState + properties: + - path: liquidity + label: Liquidity + description: Total liquidity in the current tick range (raw u128, no decimals) + - path: sqrt_price_x64 + label: Square Root Price (Q64.64) + description: sqrt(token_1/token_0) in Q64.64 fixed point (raw u128); must agree with tick_current + - path: tick_current + label: Current Tick + description: Tick index of the current price (i32); must agree with sqrt_price_x64 + - path: status + label: Pool Status + description: "Disable bitmask (u8): bit0 open/increase liquidity, bit1 decrease liquidity, bit2 collect fee, bit3 collect reward, bit4 swap; 0 = all enabled" + llm_context: | + Set fetchBeforeUse: true so the live account is forked first and every field you + don't override keeps its live value; set it to false only for a later override + that builds on state an earlier override in the same scenario already prepared. + + This template takes the pool's own address directly (no PDA derivation): supply a + pubkey you already have. If you only have the fee tier index and the two mints, + use pancakeswap-clmm-custom instead, which derives the address for you. + + PRICE / TICK COUPLING (sqrt_price_x64 and tick_current must agree): + - raw price = (sqrt_price_x64 / 2^64)^2, a token_1-per-token_0 ratio in raw + (undecimaled) units; multiply by 10^(mint_decimals_0 - mint_decimals_1) for a + human-readable price + - tick_current = floor(log(raw price) / log(1.0001)) + - a swap walks TickArrayState accounts starting from tick_current; if + tick_current doesn't match sqrt_price_x64, or the tick array covering it was + never initialized, the swap fails. Overriding one of the pair without + recomputing the other from the formula above leaves the pool in a state no + real swap can trade against. + + TICK ARRAYS: the array covering a tick is the PDA ["tick_array", pool, + start_index as i32 big-endian] under HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq, + 60 ticks per array, start_index = floor(tick / (tick_spacing * 60)) * + tick_spacing * 60. A move whose new tick stays inside the array covering the + current tick is always safe. A larger move needs the destination array to exist: + check it with getAccountInfo on the derived PDA; a null result means the swap + will fail. + + VAULTS: sqrt_price_x64/tick_current only change the pool's quoted price; they do + not move token_vault_0/token_vault_1 balances. A swap that would trade at the new + price is still bounded by what the vaults actually hold, so fund the vaults (or + accept that only small trades succeed) when the override should support a real + swap at depth. + + FINDING A POOL: the PancakeSwap CLMM program is + HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq. A live PoolState account is 1544 + bytes and starts with the 8-byte discriminator [247, 237, 227, 245, 215, 195, + 222, 70]. Three known pools: 1Piz3kL4v9fcS8GRkArpskfDG9BeSVc5eHMRjnvSfoX, + DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ (SOL/USDC, the deepest), + 14qfdHrPWhduozgCkwosL9AC3DnKY12GySXP9bz3BJ6F. Browse pools at + https://solana.pancakeswap.finance/liquidity-pools/. + address: + type: pubkey + + - id: pancakeswap-clmm-amm-config + name: Override CLMM Fee Tier (AmmConfig) + description: | + Override an AmmConfig fee tier for PancakeSwap CLMM. The address is a PDA derived + from ["amm_config", index.to_be_bytes()]. Every pool created with this config + index shares these fee rates. + idl_account_name: AmmConfig + properties: + - path: trade_fee_rate + label: Trade Fee Rate + description: Fee on the input amount, parts per million (2500 = 0.25%); below 1,000,000 + - path: protocol_fee_rate + label: Protocol Fee Rate + description: Protocol treasury's share of the collected trade fee, parts per million + - path: fund_fee_rate + label: Fund Fee Rate + description: Fund owner's share of the collected trade fee, parts per million + - path: config_index + type: constant_ref + label: Fee Tier Index + constant: amm_config_index + description: Fee tier whose AmmConfig account is overridden. The address derives from this index. + llm_context: | + Set fetchBeforeUse: true so the live account is forked first and every field you + don't override (owner, fund_owner, tick_spacing, bump) keeps its live value; set + it to false only for a later override that builds on state an earlier override in + the same scenario already prepared. + + BLAST RADIUS: this AmmConfig is shared by every pool created with the same index + - overriding it changes fees for all of them at once, not one pool. To change a + single pool's price instead, use pancakeswap-clmm-pool-state or + pancakeswap-clmm-custom. + + UNITS AND DENOMINATOR (all three fields use FEE_RATE_DENOMINATOR_VALUE = 1,000,000): + - trade_fee_rate is a fraction of TRADE VOLUME: fee = amount_in * trade_fee_rate + / 1,000,000. E.g. 2500 = 0.25% (25 bps). The program requires trade_fee_rate to + stay strictly below 1,000,000. + - protocol_fee_rate and fund_fee_rate are fractions of the FEE trade_fee_rate + ALREADY COLLECTED, not of trade volume: protocol_cut = trade_fee * + protocol_fee_rate / 1,000,000 (and likewise for fund_fee_rate). E.g. 160000 + means 16% of the trade fee goes to the protocol treasury, not 16% of the trade. + The program requires protocol_fee_rate + fund_fee_rate to stay at or below + 1,000,000. + + This template has no sqrt_price_x64/tick_current or mint fields of its own; for + an actual price or tick override on a specific pool use + pancakeswap-clmm-pool-state or pancakeswap-clmm-custom, and keep this config's + fee-rate change and that pool's price change in the same scenario when both need + to move together. + address: + type: pda + program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq + seeds: + - type: string + value: amm_config + - type: u16_be_ref + value: config_index diff --git a/crates/core/src/scenarios/registry.rs b/crates/core/src/scenarios/registry.rs index edef806d0..9afae2fa7 100644 --- a/crates/core/src/scenarios/registry.rs +++ b/crates/core/src/scenarios/registry.rs @@ -68,6 +68,10 @@ pub const PHOENIX_ETERNAL_IDL_CONTENT: &str = pub const PHOENIX_ETERNAL_OVERRIDES_CONTENT: &str = include_str!("./protocols/phoenix-eternal/v1/overrides.yaml"); +pub const PANCAKESWAP_V1_IDL_CONTENT: &str = include_str!("./protocols/pancakeswap/v1/idl.json"); +pub const PANCAKESWAP_V1_OVERRIDES_CONTENT: &str = + include_str!("./protocols/pancakeswap/v1/overrides.yaml"); + /// Registry for managing override templates loaded from YAML files #[derive(Clone, Debug, Default)] pub struct TemplateRegistry { @@ -117,6 +121,7 @@ impl TemplateRegistry { default.load_spl_token_overrides(); default.load_pump_overrides(); default.load_phoenix_overrides(); + default.load_pancakeswap_overrides(); default } @@ -224,6 +229,14 @@ impl TemplateRegistry { ); } + pub fn load_pancakeswap_overrides(&mut self) { + self.load_protocol_overrides( + PANCAKESWAP_V1_IDL_CONTENT, + PANCAKESWAP_V1_OVERRIDES_CONTENT, + "pancakeswap", + ); + } + fn load_protocol_overrides( &mut self, idl_content: &str, @@ -520,6 +533,76 @@ mod tests { ); } + #[test] + fn pancakeswap_amm_config_options_derive_their_documented_address() { + let registry = TemplateRegistry::new(); + let template = registry + .get("pancakeswap-clmm-amm-config") + .expect("template"); + let custom = registry.get("pancakeswap-clmm-custom").expect("template"); + + let options = &custom + .constants + .get("amm_config_index") + .expect("amm_config_index constant") + .options; + assert_eq!(options.len(), 22, "22 live AmmConfig accounts"); + + for option in options { + let expected = option + .metadata + .get("derived_address") + .and_then(|address| address.as_str()) + .map(|address| Pubkey::from_str(address).expect("a valid address")) + .unwrap_or_else(|| panic!("option {} documents no derived_address", option.id)); + + let values = HashMap::from([( + "config_index".to_string(), + serde_json::Value::String(option.value.clone()), + )]); + + assert_eq!( + template + .address + .resolve(Some(&values)) + .unwrap_or_else(|| panic!("option {} did not resolve", option.id)), + expected, + "option {}", + option.id + ); + } + } + + #[test] + fn pancakeswap_template_derives_a_live_pool() { + let registry = TemplateRegistry::new(); + let template = registry.get("pancakeswap-clmm-custom").expect("template"); + + let values = HashMap::from([ + ( + "config_index".to_string(), + serde_json::Value::String("0".to_string()), + ), + ( + "token_mint_0".to_string(), + serde_json::Value::String( + "CGiwPp7bzmpYkUChduemtXKMZsUB54hB82tuFR7euJ8R".to_string(), + ), + ), + ( + "token_mint_1".to_string(), + serde_json::Value::String( + "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".to_string(), + ), + ), + ]); + + assert_eq!( + template.address.resolve(Some(&values)).expect("resolves"), + Pubkey::from_str("1Piz3kL4v9fcS8GRkArpskfDG9BeSVc5eHMRjnvSfoX").expect("address"), + ); + } + /// Both singleton addresses are documented in pump-public-docs: the Pump Global /// account at 4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf and the PumpSwap /// GlobalConfig at ADyA8hdefvWN2dbGGWFotbzWxrAvLW83WG6QCVXvJKqw. @@ -606,11 +689,12 @@ mod tests { // Pyth (1) + Jupiter (1) + Raydium CLMM (1) + Raydium AMM v4 (4) + Drift (4) + Meteora (2) // + Kamino (Lend 17, Scope 3, Farms 5, Swap 2, Vault 5, Liquidity 4 = 36) - // + Whirlpool (6) + SPL Token (2) + Pump (2) + PumpSwap (3) + Phoenix Eternal (8) = 70 + // + Whirlpool (6) + SPL Token (2) + Pump (2) + PumpSwap (3) + Phoenix Eternal (8) + // + PancakeSwap CLMM (3) = 73 assert_eq!( registry.count(), - 70, - "Registry should load 70 templates total" + 73, + "Registry should load 73 templates total" ); assert!(registry.contains("pyth-price-feed-v2")); @@ -684,6 +768,10 @@ mod tests { assert!(registry.contains("phoenix-trader-collateral-stress")); assert!(registry.contains("phoenix-direct-mark-risk-shock")); + + assert!(registry.contains("pancakeswap-clmm-custom")); + assert!(registry.contains("pancakeswap-clmm-pool-state")); + assert!(registry.contains("pancakeswap-clmm-amm-config")); } #[test] @@ -1016,6 +1104,13 @@ templates: [] 8, "Should have 8 Phoenix Eternal templates" ); + + let pancakeswap_templates = registry.by_protocol("PancakeSwap"); + assert_eq!( + pancakeswap_templates.len(), + 3, + "Should have 3 PancakeSwap templates" + ); } #[test] diff --git a/crates/core/src/tests/mod.rs b/crates/core/src/tests/mod.rs index f43607e64..d7aad5dd3 100644 --- a/crates/core/src/tests/mod.rs +++ b/crates/core/src/tests/mod.rs @@ -3,6 +3,8 @@ pub mod integration; #[cfg(feature = "integration-tests")] pub mod kamino; #[cfg(feature = "integration-tests")] +pub mod pancakeswap; +#[cfg(feature = "integration-tests")] pub mod phoenix; pub mod plugin; #[cfg(feature = "integration-tests")] diff --git a/crates/core/src/tests/pancakeswap/mod.rs b/crates/core/src/tests/pancakeswap/mod.rs new file mode 100644 index 000000000..cf25c97fa --- /dev/null +++ b/crates/core/src/tests/pancakeswap/mod.rs @@ -0,0 +1,247 @@ +//! PancakeSwap CLMM integration tests. They fetch real mainnet accounts, so they need a network +//! connection and `--features integration-tests`. `SURFPOOL_TEST_RPC_URL` overrides the endpoint. + +use std::collections::HashMap; + +use solana_account::Account; +use solana_commitment_config::CommitmentConfig; +use solana_pubkey::Pubkey; +use surfpool_types::{AccountAddress, OverrideInstance, Scenario}; + +use crate::{ + scenarios::TemplateRegistry, + surfnet::{ + GetAccountResult, locker::SurfnetSvmLocker, remote::SurfnetRemoteClient, svm::SurfnetSvm, + }, +}; + +const RPC_URL_ENV: &str = "SURFPOOL_TEST_RPC_URL"; +const DEFAULT_RPC_URL: &str = "https://api.mainnet-beta.solana.com"; + +const POOL_STATE_TEMPLATE: &str = "pancakeswap-clmm-pool-state"; + +const SOL_USDC_POOL: Pubkey = + Pubkey::from_str_const("DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ"); + +const LIQUIDITY_RANGE: std::ops::Range = 237..253; +const TICK_CURRENT_RANGE: std::ops::Range = 269..273; +const STATUS_OFFSET: usize = 389; + +const TRADE_FEE_RATE_OFFSET: usize = 47; +const TICK_SPACING_OFFSET: usize = 51; +const AMM_CONFIG_LEN: usize = 117; + +/// Fetches the accounts in one request, so every account returned is from the same slot. +async fn fetch(addresses: &[Pubkey]) -> Vec { + let client = SurfnetRemoteClient::new( + std::env::var(RPC_URL_ENV).unwrap_or_else(|_| DEFAULT_RPC_URL.to_string()), + ); + client + .get_multiple_accounts(addresses, CommitmentConfig::confirmed()) + .await + .unwrap_or_else(|e| panic!("failed to fetch {addresses:?} from mainnet: {e}")) + .into_iter() + .zip(addresses) + .map(|(result, address)| match result { + GetAccountResult::FoundAccount(_, account, _) + | GetAccountResult::FoundCoupledAccount((_, account), _, _) => account, + GetAccountResult::None(_) => { + panic!("{address} no longer exists on mainnet; the test needs a new address") + } + }) + .collect() +} + +fn diff_indices(a: &[u8], b: &[u8]) -> Vec { + a.iter() + .zip(b.iter()) + .enumerate() + .filter(|(_, (x, y))| x != y) + .map(|(i, _)| i) + .collect() +} + +#[tokio::test] +async fn real_mainnet_pool_round_trips_unchanged() { + let data = fetch(&[SOL_USDC_POOL]).await.remove(0).data; + + let (surfnet_svm, _simnet_events_rx, _geyser_events_rx) = SurfnetSvm::default(); + let registry = TemplateRegistry::new(); + let template = registry + .get(POOL_STATE_TEMPLATE) + .expect("pool state template should exist"); + + let forged = surfnet_svm + .get_forged_account_data(&Pubkey::new_unique(), &data, &template.idl, &HashMap::new()) + .unwrap_or_else(|e| panic!("live mainnet PoolState failed to decode/re-encode: {e}")); + assert_eq!( + forged, data, + "live mainnet PoolState was altered by a no-op round-trip" + ); +} + +#[tokio::test] +async fn every_amm_config_index_option_is_a_live_amm_config_account() { + let registry = TemplateRegistry::new(); + let template = registry + .get("pancakeswap-clmm-amm-config") + .expect("template pancakeswap-clmm-amm-config should exist"); + let amm_config_index = template + .constants + .get("amm_config_index") + .expect("amm_config_index constant should exist"); + assert!( + !amm_config_index.options.is_empty(), + "the fee tiers are the fixture here" + ); + + let account_def = template + .idl + .accounts + .iter() + .find(|a| a.name == "AmmConfig") + .expect("AmmConfig not in the IDL"); + + let addresses: Vec = amm_config_index + .options + .iter() + .map(|option| { + let address = option + .metadata + .get("derived_address") + .and_then(|v| v.as_str()) + .unwrap_or_else(|| panic!("option {} documents no derived_address", option.id)); + Pubkey::from_str_const(address) + }) + .collect(); + let accounts = fetch(&addresses).await; + + for (option, account) in amm_config_index.options.iter().zip(&accounts) { + let data = &account.data; + assert_eq!( + data.len(), + AMM_CONFIG_LEN, + "AmmConfig for option {} has the wrong size live", + option.id + ); + assert_eq!( + &data[..8], + account_def.discriminator.as_slice(), + "AmmConfig for option {} has the wrong discriminator live", + option.id + ); + + let tick_spacing = u16::from_le_bytes( + data[TICK_SPACING_OFFSET..TICK_SPACING_OFFSET + 2] + .try_into() + .unwrap(), + ); + let trade_fee_rate = u32::from_le_bytes( + data[TRADE_FEE_RATE_OFFSET..TRADE_FEE_RATE_OFFSET + 4] + .try_into() + .unwrap(), + ); + + let expect_u64 = |field: &str| -> u64 { + option + .metadata + .get(field) + .and_then(|v| v.as_u64()) + .unwrap_or_else(|| panic!("option {} documents no {field} metadata", option.id)) + }; + + assert_eq!( + tick_spacing as u64, + expect_u64("tick_spacing"), + "option {} tick_spacing metadata disagrees with the live AmmConfig", + option.id + ); + assert_eq!( + trade_fee_rate as u64, + expect_u64("fee_rate_bps") * 100, + "option {} live trade_fee_rate should be fee_rate_bps * 100", + option.id + ); + } +} + +#[tokio::test(flavor = "multi_thread")] +async fn overrides_through_materializer_touch_only_their_own_bytes() { + let before = fetch(&[SOL_USDC_POOL]).await.remove(0); + + let new_status: u8 = if before.data[STATUS_OFFSET] == 0 { + 31 + } else { + 0 + }; + let new_liquidity = u128::from_le_bytes(before.data[LIQUIDITY_RANGE].try_into().unwrap()) ^ 1; + let new_tick = i32::from_le_bytes(before.data[TICK_CURRENT_RANGE].try_into().unwrap()) - 1000; + + let (mut surfnet_svm, _simnet_events_rx, _geyser_events_rx) = SurfnetSvm::default(); + surfnet_svm + .set_account(&SOL_USDC_POOL, before.clone()) + .unwrap(); + let locker = SurfnetSvmLocker::new(surfnet_svm); + + let registry = TemplateRegistry::new(); + let template = registry + .get(POOL_STATE_TEMPLATE) + .expect("pool state template should exist"); + + let pool_override = OverrideInstance::new( + template.id.clone(), + 1, + AccountAddress::Pubkey(SOL_USDC_POOL.to_string()), + ) + .with_values(HashMap::from([ + ("status".to_string(), serde_json::json!(new_status)), + ( + "liquidity".to_string(), + serde_json::json!(new_liquidity.to_string()), + ), + ("tick_current".to_string(), serde_json::json!(new_tick)), + ])) + .with_label("PancakeSwap CLMM pool override".to_string()); + + let mut scenario = Scenario::new( + "PancakeSwap CLMM Pool Override".to_string(), + "Change a live PoolState's status, liquidity and tick through the materializer." + .to_string(), + ); + scenario.add_override(pool_override); + locker.register_scenario(scenario, Some(0)).unwrap(); + locker + .materialize_overrides_for_slot(&None, 1) + .await + .unwrap(); + + let after = locker + .with_svm_reader(|svm| svm.get_account(&SOL_USDC_POOL)) + .unwrap() + .expect("account should still exist after materialization"); + + assert_eq!( + after.data.len(), + before.data.len(), + "override changed account size" + ); + let outside: Vec = diff_indices(&before.data, &after.data) + .into_iter() + .filter(|i| { + *i != STATUS_OFFSET && !LIQUIDITY_RANGE.contains(i) && !TICK_CURRENT_RANGE.contains(i) + }) + .collect(); + assert!( + outside.is_empty(), + "bytes outside the overridden fields changed: {outside:?}" + ); + assert_eq!(after.data[STATUS_OFFSET], new_status); + assert_eq!( + u128::from_le_bytes(after.data[LIQUIDITY_RANGE].try_into().unwrap()), + new_liquidity + ); + assert_eq!( + i32::from_le_bytes(after.data[TICK_CURRENT_RANGE].try_into().unwrap()), + new_tick + ); +} From 1ef5c2b2be5e4305a8b03bf0fe1b677745146ef3 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 29 Sep 2026 14:09:43 +0300 Subject: [PATCH 02/20] docs(scenarios): document the PancakeSwap liquidity rule for price shocks --- .../scenarios/protocols/pancakeswap/README.md | 18 ++++++++++++------ .../protocols/pancakeswap/v1/overrides.yaml | 14 ++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index 37c56ba0e..9e2b8a2f0 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -77,15 +77,21 @@ only. The pool's price moves between reads, so recompute both fields from its cu Multiplying the price by `f` means `sqrt_price_x64' = round(sqrt_price_x64 * sqrt(f))`, bounded to `[4295048016, 79226673521066979257578248091)`, and `tick_current' = floor(2 * ln(sqrt_price_x64' / 2^64) / ln(1.0001))`, bounded to -`[-443636, 443636]`. Set both fields in one `pancakeswap-clmm-pool-state` override with -`fetchBeforeUse: true`. +`[-443636, 443636]`. The active liquidity must follow the price: +`liquidity' = liquidity + sum(liquidity_net of initialized ticks crossed)` when it rises, +`liquidity - sum(...)` when it falls. Set all three fields in one +`pancakeswap-clmm-pool-state` override with `fetchBeforeUse: true`. + +A tick `t` is crossed when `old < t <= new` going up and `new < t <= old` going down. Without +the liquidity step the pool keeps the old range's depth at the new price, so swaps succeed with +wrong amounts: on the SOL/USDC pool a +10% move left the pool about 2.5x deeper than a real swap to the +same price. A swap resumes from the tick array covering `tick_current'`: PDA `["tick_array", pool, start_index as i32 big-endian]` under the program, 60 ticks per -array, `start_index = floor(tick / (tick_spacing * 60)) * tick_spacing * 60`. A move that -stays inside the pool's current array is always safe; a larger one needs the destination -array to exist (a null `getAccountInfo` on its PDA means the swap will fail). The Studio -card computes this for you. +array, `start_index = floor(tick / (tick_spacing * 60)) * tick_spacing * 60`. The destination +array must exist (a null `getAccountInfo` on its PDA means the swap will fail). The Studio +card computes all of this for you. ## Verification diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml index 533fbc913..2e23b96a0 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml @@ -351,10 +351,16 @@ templates: TICK ARRAYS: the array covering a tick is the PDA ["tick_array", pool, start_index as i32 big-endian] under HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq, 60 ticks per array, start_index = floor(tick / (tick_spacing * 60)) * - tick_spacing * 60. A move whose new tick stays inside the array covering the - current tick is always safe. A larger move needs the destination array to exist: - check it with getAccountInfo on the derived PDA; a null result means the swap - will fail. + tick_spacing * 60. The destination array must exist: check it with getAccountInfo + on the derived PDA; a null result means the swap will fail. + + LIQUIDITY RULE: a price move must also set liquidity to the active liquidity at the + new tick. Start from the live liquidity and, for every initialized tick t the move + crosses, add its liquidity_net when the price rises (old < t <= new) and subtract it + when it falls (new < t <= old). Leaving liquidity unchanged keeps the old range's depth + at the new price, so swaps return wrong amounts without failing. The Studio price + shock computes this; without the tick arrays, keep the move between the initialized + ticks around the current one. VAULTS: sqrt_price_x64/tick_current only change the pool's quoted price; they do not move token_vault_0/token_vault_1 balances. A swap that would trade at the new From 2fe14b5fed2842c603e39a24be69e50480eb3644 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 29 Sep 2026 14:53:29 +0300 Subject: [PATCH 03/20] docs(scenarios): rewrite the PancakeSwap README as a how-to and add the liquidity rule to the custom template --- .../scenarios/protocols/pancakeswap/README.md | 203 ++++++++---------- .../protocols/pancakeswap/v1/overrides.yaml | 14 ++ 2 files changed, 102 insertions(+), 115 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index 9e2b8a2f0..251765f63 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -1,117 +1,90 @@ -# PancakeSwap CLMM (Solana) - -Declarative state-preparation templates for PancakeSwap's concentrated liquidity AMM on -Solana, a fork of Raydium CLMM (`amm_v3`) with identical `PoolState`, `AmmConfig` and -`TickArrayState` layouts and discriminators. The templates use the standard IDL override -path. For how scenarios work in general see the [scenarios README](../../README.md). - -## Program identity (verified 2026-09-21) - -| | | -| -------------------- | --------------------------------------------------------------------------------------- | -| Program ID | `HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq` | -| On-chain IDL account | `CAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf` | -| Fork of | Raydium CLMM (`CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK`) | -| Bundled IDL | `v1/idl.json`, decompressed from the on-chain IDL account 2026-09-21; `amm_v3` `0.1.0` | - -The bundled IDL keeps every account and type from the on-chain IDL and drops -`instructions`, `errors` and `events`. A later on-chain IDL with a different -`types`/`accounts` shape means the program was upgraded and this integration must be -revisited. - -## Templates - -| Template | Account | Address | Use for | -| ----------------------------- | ----------- | ------------------------------------------------------------------------- | ------------------------------------------------------- | -| `pancakeswap-clmm-custom` | `PoolState` | PDA `["pool", PDA(["amm_config", index_be]), token_mint_0, token_mint_1]` | any pool, selected by fee tier index and the two mints | -| `pancakeswap-clmm-pool-state` | `PoolState` | caller-provided pubkey | any pool by raw address | -| `pancakeswap-clmm-amm-config` | `AmmConfig` | PDA `["amm_config", index_be]` | a fee tier shared by every pool created with that index | - -`token_mint_0` must be the mint whose raw 32-byte pubkey is numerically smaller (compare -decoded bytes, not base58). Nothing checks the order: a reversed pair derives an empty -address. `amm_config_index` lists all 22 live fee tiers, each with its tick spacing, fee -and derived address. - -## Finding a pool - -- Browse pools at `https://solana.pancakeswap.finance/liquidity-pools/`. -- A pool account is owned by `HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq`, is 1544 - bytes, and starts with `PoolState`'s discriminator from `v1/idl.json`. -- Example: the deepest SOL/USDC pool (fee tier index 0, tick spacing 10) at - `DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ`. - -## Field reference - -Every field, unit and rule is the same as Raydium CLMM's; see the -[Raydium CLMM field reference](../raydium/v3/README.md#field-reference). In short: -`sqrt_price_x64` and `tick_current` must satisfy -`tick_current = floor(log((sqrt_price_x64 / 2^64)^2) / log(1.0001))`, the `status` bitmask -disables instructions (bit4 = swap), and the three `AmmConfig` rates are parts per -million. - -## Worked example: halve the SOL/USDC pool's price and disable swaps - -Starting from `sqrt_price_x64` 6213368270497578833 (tick -21765), halving the price -multiplies `sqrt_price_x64` by `sqrt(0.5)`: - -```json -{ - "templateId": "pancakeswap-clmm-pool-state", - "address": "DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ", - "values": { - "sqrt_price_x64": "4393514838078169088", - "tick_current": -28697, - "status": 16 - }, - "fetchBeforeUse": true -} +# PancakeSwap CLMM + +PancakeSwap's concentrated-liquidity AMM on Solana, a fork of Raydium CLMM with the same account +layouts. Three templates: a pool found by its mints, a pool found by its address, and a fee tier. +Units and rules match [Raydium CLMM](../raydium/v3/README.md); only the program, pools and fee +tiers differ. + +# Template index + +**PancakeSwap CLMM** · `HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq` + +| Template | Overrides | +|---|---| +| `pancakeswap-clmm-custom` | a pool's price, active liquidity and status, selected by fee tier and mints | +| `pancakeswap-clmm-pool-state` | the same fields, selected by the pool address | +| `pancakeswap-clmm-amm-config` | a fee tier, shared by every pool created on it | + +## Number formats + +| You'll see | It means | Example | +|---|---|---| +| `sqrt_price_x64` | `sqrt(price_raw) x 2^64`, as a decimal **string** | | +| `liquidity` | raw `u128`, as a decimal **string** | | +| `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% | + +`amm_config_index` lists all 22 live fee tiers with their tick spacing and fee. + +## Picking a pool + +Browse pools at `https://solana.pancakeswap.finance/liquidity-pools/`. The deepest SOL/USDC pool +is `DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ` (fee tier 0, tick spacing 10). + +**Order the mints for `pancakeswap-clmm-custom`.** `token_mint_0` is the mint whose raw 32 bytes +are numerically smaller, not the smaller base58 string. A reversed pair derives an empty address +and nothing checks it. + +**Check the owner.** The layouts match Raydium's, so a PancakeSwap template pointed at a Raydium +pool writes it without complaint. + +Set `fetchBeforeUse: true` so the live pool is forked first. + +# Recipes + +## Shock the price + +Use **Scenario presets → PancakeSwap state → CLMM price shock** in Studio. It reads the pool and +the tick arrays the move crosses, and writes all three coupled fields: + +``` +template: pancakeswap-clmm-pool-state +sqrt_price_x64: "" +tick_current: +liquidity: "" +``` + +**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 must exist.** A swap resumes from the array covering the new tick, +PDA `["tick_array", pool, start_index as i32 big-endian]` with 60 ticks of `tick_spacing` each. +Studio refuses a move onto a missing array. + +## Freeze swaps + ``` +template: pancakeswap-clmm-pool-state +status: 16 # bit 4: swaps off, liquidity still moves +``` + +## Change a fee tier + +``` +template: pancakeswap-clmm-amm-config +config_index: 0 # the SOL/USDC pool's tier +trade_fee_rate: 10000 # 1% +``` + +Every pool created with that index shares the account, so the change reaches all of them. + +# Troubleshooting -`(4393514838078169088 / 2^64)^2 = 0.056726` and `floor(log(0.056726) / log(1.0001)) = --28697`, so the pair satisfies the coupling rule. `status: 16` sets bit4 (disable swap) -only. The pool's price moves between reads, so recompute both fields from its current -`sqrt_price_x64`. - -## Price shock - -Multiplying the price by `f` means `sqrt_price_x64' = round(sqrt_price_x64 * sqrt(f))`, -bounded to `[4295048016, 79226673521066979257578248091)`, and -`tick_current' = floor(2 * ln(sqrt_price_x64' / 2^64) / ln(1.0001))`, bounded to -`[-443636, 443636]`. The active liquidity must follow the price: -`liquidity' = liquidity + sum(liquidity_net of initialized ticks crossed)` when it rises, -`liquidity - sum(...)` when it falls. Set all three fields in one -`pancakeswap-clmm-pool-state` override with `fetchBeforeUse: true`. - -A tick `t` is crossed when `old < t <= new` going up and `new < t <= old` going down. Without -the liquidity step the pool keeps the old range's depth at the new price, so swaps succeed with -wrong amounts: on the SOL/USDC pool a +10% move left the pool about 2.5x deeper than a real swap to the -same price. - -A swap resumes from the tick array covering `tick_current'`: PDA -`["tick_array", pool, start_index as i32 big-endian]` under the program, 60 ticks per -array, `start_index = floor(tick / (tick_spacing * 60)) * tick_spacing * 60`. The destination -array must exist (a null `getAccountInfo` on its PDA means the swap will fail). The Studio -card computes all of this for you. - -## Verification - -- Static: the `PoolState` and `TickArrayState` type definitions (fields, types, order) and - the `PoolState` discriminator are identical in `pancakeswap/v1/idl.json` and - `raydium/v3/idl.json`. -- Unit: `cargo test -p surfpool-core --lib pancakeswap` covers the pool PDA for a live fee - tier and mint pair and every `amm_config_index` option's derived address. -- Live fork (`cargo test -p surfpool-core --features integration-tests pancakeswap -- - --test-threads=1`, needs network; `SURFPOOL_TEST_RPC_URL` overrides the endpoint): - round-trips the live SOL/USDC `PoolState` byte-for-byte, checks every - `amm_config_index` option's live size, discriminator, `tick_spacing` and - `trade_fee_rate`, runs `status`, `liquidity` and `tick_current` through the - materializer and asserts only their bytes changed. - -## Known limitations - -- `token_mint_0`/`token_mint_1` are plain `property_ref` seeds, so the caller orders them. - Raydium CLMM has the same gap. -- No swap simulation compares baseline and shocked prices, so the evidence for a price - override is byte-level, not trade-level. -- The layouts are identical and the engine picks the IDL by account owner, so a PancakeSwap - template pointed at a Raydium CLMM pool writes the same bytes. Check the pool's owner. +| 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 | The new tick has no tick array, or `sqrt_price_x64` and `tick_current` disagree | +| `pancakeswap-clmm-custom` changed nothing | The mints are in the wrong order, so the derived address is empty | +| The swap fails on the token transfer | The paying vault holds less than the output. Fund it with `spl-token-account-balance` | diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml index 2e23b96a0..931782a22 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml @@ -278,6 +278,20 @@ templates: recomputing the other from the formula above leaves the pool in a state no real swap can trade against. + TICK ARRAYS: the array covering a tick is the PDA ["tick_array", pool, + start_index as i32 big-endian] under HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq, + 60 ticks per array, start_index = floor(tick / (tick_spacing * 60)) * + tick_spacing * 60. The destination array must exist: check it with getAccountInfo + on the derived PDA; a null result means the swap will fail. + + LIQUIDITY RULE: a price move must also set liquidity to the active liquidity at the + new tick. Start from the live liquidity and, for every initialized tick t the move + crosses, add its liquidity_net when the price rises (old < t <= new) and subtract it + when it falls (new < t <= old). Leaving liquidity unchanged keeps the old range's depth + at the new price, so swaps return wrong amounts without failing. The Studio price + shock computes this; without the tick arrays, keep the move between the initialized + ticks around the current one. + VAULTS: sqrt_price_x64/tick_current only change the pool's quoted price; they do not move token_vault_0/token_vault_1 balances. A swap that would trade at the new price is still bounded by what the vaults actually hold, so fund the vaults (or From 9d0467092d228c05a9e523d8c5626dd3d0b5a731 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 29 Sep 2026 15:07:28 +0300 Subject: [PATCH 04/20] test(scenarios): cover the PancakeSwap sqrt_price_x64 u128 write --- crates/core/src/tests/pancakeswap/mod.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/core/src/tests/pancakeswap/mod.rs b/crates/core/src/tests/pancakeswap/mod.rs index cf25c97fa..818b06329 100644 --- a/crates/core/src/tests/pancakeswap/mod.rs +++ b/crates/core/src/tests/pancakeswap/mod.rs @@ -24,6 +24,7 @@ const SOL_USDC_POOL: Pubkey = Pubkey::from_str_const("DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ"); const LIQUIDITY_RANGE: std::ops::Range = 237..253; +const SQRT_PRICE_X64_RANGE: std::ops::Range = 253..269; const TICK_CURRENT_RANGE: std::ops::Range = 269..273; const STATUS_OFFSET: usize = 389; @@ -175,6 +176,8 @@ async fn overrides_through_materializer_touch_only_their_own_bytes() { 0 }; let new_liquidity = u128::from_le_bytes(before.data[LIQUIDITY_RANGE].try_into().unwrap()) ^ 1; + let new_sqrt_price_x64 = + u128::from_le_bytes(before.data[SQRT_PRICE_X64_RANGE].try_into().unwrap()) + (1u128 << 64); let new_tick = i32::from_le_bytes(before.data[TICK_CURRENT_RANGE].try_into().unwrap()) - 1000; let (mut surfnet_svm, _simnet_events_rx, _geyser_events_rx) = SurfnetSvm::default(); @@ -199,13 +202,17 @@ async fn overrides_through_materializer_touch_only_their_own_bytes() { "liquidity".to_string(), serde_json::json!(new_liquidity.to_string()), ), + ( + "sqrt_price_x64".to_string(), + serde_json::json!(new_sqrt_price_x64.to_string()), + ), ("tick_current".to_string(), serde_json::json!(new_tick)), ])) .with_label("PancakeSwap CLMM pool override".to_string()); let mut scenario = Scenario::new( "PancakeSwap CLMM Pool Override".to_string(), - "Change a live PoolState's status, liquidity and tick through the materializer." + "Change a live PoolState's status, liquidity, price and tick through the materializer." .to_string(), ); scenario.add_override(pool_override); @@ -228,7 +235,10 @@ async fn overrides_through_materializer_touch_only_their_own_bytes() { let outside: Vec = diff_indices(&before.data, &after.data) .into_iter() .filter(|i| { - *i != STATUS_OFFSET && !LIQUIDITY_RANGE.contains(i) && !TICK_CURRENT_RANGE.contains(i) + *i != STATUS_OFFSET + && !LIQUIDITY_RANGE.contains(i) + && !SQRT_PRICE_X64_RANGE.contains(i) + && !TICK_CURRENT_RANGE.contains(i) }) .collect(); assert!( @@ -240,6 +250,10 @@ async fn overrides_through_materializer_touch_only_their_own_bytes() { u128::from_le_bytes(after.data[LIQUIDITY_RANGE].try_into().unwrap()), new_liquidity ); + assert_eq!( + u128::from_le_bytes(after.data[SQRT_PRICE_X64_RANGE].try_into().unwrap()), + new_sqrt_price_x64 + ); assert_eq!( i32::from_le_bytes(after.data[TICK_CURRENT_RANGE].try_into().unwrap()), new_tick From 88d116be01ef318b6f71225d33dd0109a74c8f1f Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Thu, 8 Oct 2026 09:47:28 +0300 Subject: [PATCH 05/20] test(pancakeswap): read the template IDL through idl() after the raw-layout merge --- crates/core/src/tests/pancakeswap/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/core/src/tests/pancakeswap/mod.rs b/crates/core/src/tests/pancakeswap/mod.rs index 818b06329..c637fabbf 100644 --- a/crates/core/src/tests/pancakeswap/mod.rs +++ b/crates/core/src/tests/pancakeswap/mod.rs @@ -73,7 +73,12 @@ async fn real_mainnet_pool_round_trips_unchanged() { .expect("pool state template should exist"); let forged = surfnet_svm - .get_forged_account_data(&Pubkey::new_unique(), &data, &template.idl, &HashMap::new()) + .get_forged_account_data( + &Pubkey::new_unique(), + &data, + template.idl(), + &HashMap::new(), + ) .unwrap_or_else(|e| panic!("live mainnet PoolState failed to decode/re-encode: {e}")); assert_eq!( forged, data, @@ -97,7 +102,7 @@ async fn every_amm_config_index_option_is_a_live_amm_config_account() { ); let account_def = template - .idl + .idl() .accounts .iter() .find(|a| a.name == "AmmConfig") From 717f81d16c5ff9f0dd3ea442da13336f2b4bdb39 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Sun, 11 Oct 2026 08:45:59 +0300 Subject: [PATCH 06/20] feat(scenarios): let an override collection share its llm_context --- crates/core/src/scenarios/registry.rs | 36 +++++++++++++++++++++++++++ crates/types/src/scenarios.rs | 9 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/crates/core/src/scenarios/registry.rs b/crates/core/src/scenarios/registry.rs index 9afae2fa7..f68180d3b 100644 --- a/crates/core/src/scenarios/registry.rs +++ b/crates/core/src/scenarios/registry.rs @@ -372,6 +372,42 @@ mod tests { use super::*; + #[test] + fn collection_llm_context_leads_every_template_context() { + let collection: YamlOverrideTemplateCollection = serde_yaml::from_str( + r#" +protocol: Example +version: v1 +raw_layout: true +llm_context: | + Shared lookup. +templates: + - id: with-own + name: With own + description: Has its own context + address: + type: pubkey + llm_context: | + Own guidance. + - id: without-own + name: Without own + description: Has no context of its own + address: + type: pubkey +"#, + ) + .unwrap(); + let templates = collection.to_override_templates(None).unwrap(); + assert_eq!( + templates[0].llm_context.as_deref(), + Some("Shared lookup.\n\nOwn guidance.\n") + ); + assert_eq!( + templates[1].llm_context.as_deref(), + Some("Shared lookup.\n") + ); + } + #[test] fn account_data_values_exclude_constant_ref_selectors() { let registry = TemplateRegistry::new(); diff --git a/crates/types/src/scenarios.rs b/crates/types/src/scenarios.rs index 00e4ecf76..bdd148228 100644 --- a/crates/types/src/scenarios.rs +++ b/crates/types/src/scenarios.rs @@ -1031,6 +1031,9 @@ pub struct YamlOverrideTemplateCollection { /// Protocol-specific constants shared by all templates in this collection #[serde(default)] pub constants: HashMap, + /// LLM context shared by all templates in this collection, placed before each template's own + #[serde(default)] + pub llm_context: Option, /// Selects offset-and-encoding writes for programs with no usable IDL. #[serde(default)] pub raw_layout: bool, @@ -1483,6 +1486,10 @@ impl YamlOverrideTemplateCollection { let account_type = entry .idl_account_name .unwrap_or_else(|| default_account_type.clone()); + let llm_context = match (&self.llm_context, entry.llm_context) { + (Some(shared), Some(own)) => Some(format!("{}\n\n{own}", shared.trim_end())), + (shared, own) => own.or_else(|| shared.clone()), + }; let properties = describe_properties_from_idl(entry.properties, idl.as_ref(), &account_type) .map_err(|e| format!("template '{}': {e}", entry.id))?; @@ -1497,7 +1504,7 @@ impl YamlOverrideTemplateCollection { account_type, constants: constants.clone(), tags: self.tags.clone(), - llm_context: entry.llm_context, + llm_context, raw_layout: self.raw_layout, }) }) From 1fd20357149d94087b7cfb5e5a37a598ffa7c6c2 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Sun, 11 Oct 2026 08:45:59 +0300 Subject: [PATCH 07/20] fix(mcp): keep call_surfnet_rpc's tagged params and explain them with an example --- crates/mcp/src/surfpool/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/mcp/src/surfpool/mod.rs b/crates/mcp/src/surfpool/mod.rs index 9e23884ce..8653ca44b 100644 --- a/crates/mcp/src/surfpool/mod.rs +++ b/crates/mcp/src/surfpool/mod.rs @@ -198,7 +198,9 @@ pub struct CallSurfnetRpcParams { A list of all the RPC methods available can be found at str:///rpc_endpoints" )] pub method: String, - #[schemars(description = "The parameters to pass to the RPC method")] + #[schemars( + description = "The parameters to pass to the RPC method. Wrap every value at every depth by its type: a string as {\"String\":\"...\"}, a whole number as {\"Number\":5}, a boolean as {\"Bool\":true}, a list as {\"Array\":[...]} and an object as {\"Object\":{\"key\":}}; object keys stay plain. Example for getProgramAccounts with a filter: [{\"String\":\"\"},{\"Object\":{\"encoding\":{\"String\":\"base64\"},\"filters\":{\"Array\":[{\"Object\":{\"memcmp\":{\"Object\":{\"offset\":{\"Number\":0},\"bytes\":{\"String\":\"\"}}}}}]}}}]" + )] pub params: Vec, } From fda7373a59d05dca7cc4a6e67cfb25929de370c3 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Mon, 12 Oct 2026 08:47:34 +0300 Subject: [PATCH 08/20] fix(scenarios): find PancakeSwap pools by pair or address and shorten their llm_context --- .../scenarios/protocols/pancakeswap/README.md | 9 +- .../protocols/pancakeswap/v1/overrides.yaml | 172 ++++-------------- 2 files changed, 39 insertions(+), 142 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index 251765f63..323faf366 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -28,8 +28,11 @@ tiers differ. ## Picking a pool -Browse pools at `https://solana.pancakeswap.finance/liquidity-pools/`. The deepest SOL/USDC pool -is `DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ` (fee tier 0, tick spacing 10). +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` (fee tier 0, tick spacing 10). Pools are also listed +at `https://solana.pancakeswap.finance/liquidity-pools/`. **Order the mints for `pancakeswap-clmm-custom`.** `token_mint_0` is the mint whose raw 32 bytes are numerically smaller, not the smaller base58 string. A reversed pair derives an empty address @@ -38,7 +41,7 @@ and nothing checks it. **Check the owner.** The layouts match Raydium's, so a PancakeSwap template pointed at a Raydium pool writes it without complaint. -Set `fetchBeforeUse: true` so the live pool is forked first. +Set `fetchBeforeUse: true` to pull the pool from upstream first. # Recipes diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml index 931782a22..cf163a50e 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml @@ -204,12 +204,29 @@ constants: description: Select a token mint address from verified tokens source: verified_tokens +llm_context: | + PancakeSwap CLMM, program HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq, a fork of Raydium CLMM. + + FIND A POOL BY PAIR: resolve both mints with get_token_address, then call getProgramAccounts on the + program with filters dataSize 1544 and memcmp of the two mints at offsets 73 and 105, once in each + order (only one returns pools). Read each pool's token_vault_0 with dataSlice {offset 137, length + 32} and encoding base58, compare the vaults with getMultipleAccounts jsonParsed and keep the pool + whose vault holds the most; name it. If neither order returns a pool, recheck the mints once, then + ask for the pool address. A pool address the user gives is used as is. + + Set fetchBeforeUse: true. + + PRICE: sqrt_price_x64 = sqrt(price_raw) x 2^64, where price_raw is token_1 per token_0 in raw units, + and tick_current = floor(log(price_raw) / log(1.0001)); set both together. A price move must also + set liquidity to the active liquidity at the new tick, and the tick array covering the new tick must + exist. The Studio price shock computes all three; prefer it to hand-computed values. + templates: - id: pancakeswap-clmm-custom - name: Override Any CLMM Pool (Custom) + name: Override CLMM Pool (By Fee Tier and Mints) description: | - Override any PancakeSwap CLMM pool by specifying the fee tier index and token - mints. Both the AMM config address AND the pool address are dynamically derived: + Override a PancakeSwap CLMM pool given its fee tier index and its two token mints. + Both the AMM config address AND the pool address are dynamically derived: - AMM Config: PDA from ["amm_config", config_index.to_be_bytes()] - Pool: PDA from ["pool", amm_config, token_mint_0, token_mint_1] idl_account_name: PoolState @@ -242,68 +259,10 @@ templates: constant: token_mint description: Second mint of the pair as the program stores it, the higher of the two by raw bytes. llm_context: | - Set fetchBeforeUse: true so the live account is forked first and every field you - don't override keeps its live value; set it to false only for a later override - that builds on state an earlier override in the same scenario already prepared. - - CRITICAL: token_mint_0 and token_mint_1 must be SPL TOKEN MINT addresses, NOT - program IDs! - - CORRECT examples of token mints: - - SOL (wrapped): So11111111111111111111111111111111111111112 - - USDC: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v - - WRONG - these are PROGRAM IDs, not token mints: - - HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq (PancakeSwap CLMM) - - CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK (Raydium CLMM) - - Always use get_token_address tool to look up token mints by symbol (e.g., "SOL", - "USDC"). - - MINT ORDER: token_mint_0 must be the mint whose raw 32-byte pubkey is numerically - smaller than token_mint_1's (compare the decoded bytes, not the base58 string). - The pool PDA is ["pool", amm_config, token_mint_0, token_mint_1] in that exact - order, so swapping the two mints derives a different, almost certainly empty, - address. token_mint_0/token_mint_1 are plain property_ref seeds here and the - caller is responsible for the ordering. - - PRICE / TICK COUPLING (sqrt_price_x64 and tick_current must agree): - - raw price = (sqrt_price_x64 / 2^64)^2, a token_1-per-token_0 ratio in raw - (undecimaled) units; multiply by 10^(mint_decimals_0 - mint_decimals_1) for a - human-readable price - - tick_current = floor(log(raw price) / log(1.0001)) - - a swap walks TickArrayState accounts starting from tick_current; if - tick_current doesn't match sqrt_price_x64, or the tick array covering it was - never initialized, the swap fails. Overriding one of the pair without - recomputing the other from the formula above leaves the pool in a state no - real swap can trade against. - - TICK ARRAYS: the array covering a tick is the PDA ["tick_array", pool, - start_index as i32 big-endian] under HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq, - 60 ticks per array, start_index = floor(tick / (tick_spacing * 60)) * - tick_spacing * 60. The destination array must exist: check it with getAccountInfo - on the derived PDA; a null result means the swap will fail. - - LIQUIDITY RULE: a price move must also set liquidity to the active liquidity at the - new tick. Start from the live liquidity and, for every initialized tick t the move - crosses, add its liquidity_net when the price rises (old < t <= new) and subtract it - when it falls (new < t <= old). Leaving liquidity unchanged keeps the old range's depth - at the new price, so swaps return wrong amounts without failing. The Studio price - shock computes this; without the tick arrays, keep the move between the initialized - ticks around the current one. - - VAULTS: sqrt_price_x64/tick_current only change the pool's quoted price; they do - not move token_vault_0/token_vault_1 balances. A swap that would trade at the new - price is still bounded by what the vaults actually hold, so fund the vaults (or - accept that only small trades succeed) when the override should support a real - swap at depth. - - FINDING A POOL: the PancakeSwap CLMM program is - HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq. A live PoolState account is 1544 - bytes and starts with the 8-byte discriminator [247, 237, 227, 245, 215, 195, - 222, 70]. The deepest SOL/USDC pool is DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ - (fee tier index 0, tick spacing 10). Browse pools at - https://solana.pancakeswap.finance/liquidity-pools/. + Derives the pool from config_index and the two mints, from get_token_address (never program ids). + token_mint_0 must be the mint whose raw 32 bytes are smaller (SOL before USDC); reversed mints + derive an empty address and nothing checks it. For a pool found by address, use + pancakeswap-clmm-pool-state. address: type: pda program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq @@ -324,10 +283,8 @@ templates: value: token_mint_1 - id: pancakeswap-clmm-pool-state - name: Override CLMM Pool State (By Address) - description: | - Override any PancakeSwap CLMM pool by its own address, for a pubkey the caller - already has (no mint/config lookup). + name: Override CLMM Pool State + description: Override a PancakeSwap CLMM pool found by pair or by address idl_account_name: PoolState properties: - path: liquidity @@ -343,52 +300,9 @@ templates: label: Pool Status description: "Disable bitmask (u8): bit0 open/increase liquidity, bit1 decrease liquidity, bit2 collect fee, bit3 collect reward, bit4 swap; 0 = all enabled" llm_context: | - Set fetchBeforeUse: true so the live account is forked first and every field you - don't override keeps its live value; set it to false only for a later override - that builds on state an earlier override in the same scenario already prepared. - - This template takes the pool's own address directly (no PDA derivation): supply a - pubkey you already have. If you only have the fee tier index and the two mints, - use pancakeswap-clmm-custom instead, which derives the address for you. - - PRICE / TICK COUPLING (sqrt_price_x64 and tick_current must agree): - - raw price = (sqrt_price_x64 / 2^64)^2, a token_1-per-token_0 ratio in raw - (undecimaled) units; multiply by 10^(mint_decimals_0 - mint_decimals_1) for a - human-readable price - - tick_current = floor(log(raw price) / log(1.0001)) - - a swap walks TickArrayState accounts starting from tick_current; if - tick_current doesn't match sqrt_price_x64, or the tick array covering it was - never initialized, the swap fails. Overriding one of the pair without - recomputing the other from the formula above leaves the pool in a state no - real swap can trade against. + Put the pool in the override's account as {"pubkey":""}, never in values. - TICK ARRAYS: the array covering a tick is the PDA ["tick_array", pool, - start_index as i32 big-endian] under HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq, - 60 ticks per array, start_index = floor(tick / (tick_spacing * 60)) * - tick_spacing * 60. The destination array must exist: check it with getAccountInfo - on the derived PDA; a null result means the swap will fail. - - LIQUIDITY RULE: a price move must also set liquidity to the active liquidity at the - new tick. Start from the live liquidity and, for every initialized tick t the move - crosses, add its liquidity_net when the price rises (old < t <= new) and subtract it - when it falls (new < t <= old). Leaving liquidity unchanged keeps the old range's depth - at the new price, so swaps return wrong amounts without failing. The Studio price - shock computes this; without the tick arrays, keep the move between the initialized - ticks around the current one. - - VAULTS: sqrt_price_x64/tick_current only change the pool's quoted price; they do - not move token_vault_0/token_vault_1 balances. A swap that would trade at the new - price is still bounded by what the vaults actually hold, so fund the vaults (or - accept that only small trades succeed) when the override should support a real - swap at depth. - - FINDING A POOL: the PancakeSwap CLMM program is - HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq. A live PoolState account is 1544 - bytes and starts with the 8-byte discriminator [247, 237, 227, 245, 215, 195, - 222, 70]. Three known pools: 1Piz3kL4v9fcS8GRkArpskfDG9BeSVc5eHMRjnvSfoX, - DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ (SOL/USDC, the deepest), - 14qfdHrPWhduozgCkwosL9AC3DnKY12GySXP9bz3BJ6F. Browse pools at - https://solana.pancakeswap.finance/liquidity-pools/. + status is a bitmask of disabled operations: 16 disables swaps, 0 enables everything. address: type: pubkey @@ -415,32 +329,12 @@ templates: constant: amm_config_index description: Fee tier whose AmmConfig account is overridden. The address derives from this index. llm_context: | - Set fetchBeforeUse: true so the live account is forked first and every field you - don't override (owner, fund_owner, tick_spacing, bump) keeps its live value; set - it to false only for a later override that builds on state an earlier override in - the same scenario already prepared. - - BLAST RADIUS: this AmmConfig is shared by every pool created with the same index - - overriding it changes fees for all of them at once, not one pool. To change a - single pool's price instead, use pancakeswap-clmm-pool-state or - pancakeswap-clmm-custom. - - UNITS AND DENOMINATOR (all three fields use FEE_RATE_DENOMINATOR_VALUE = 1,000,000): - - trade_fee_rate is a fraction of TRADE VOLUME: fee = amount_in * trade_fee_rate - / 1,000,000. E.g. 2500 = 0.25% (25 bps). The program requires trade_fee_rate to - stay strictly below 1,000,000. - - protocol_fee_rate and fund_fee_rate are fractions of the FEE trade_fee_rate - ALREADY COLLECTED, not of trade volume: protocol_cut = trade_fee * - protocol_fee_rate / 1,000,000 (and likewise for fund_fee_rate). E.g. 160000 - means 16% of the trade fee goes to the protocol treasury, not 16% of the trade. - The program requires protocol_fee_rate + fund_fee_rate to stay at or below - 1,000,000. + To change the fees of a pool's tier, read the pool's amm_config with getAccountInfo, dataSlice + {offset 9, length 32} and encoding base58, and pick the config_index option whose derived_address + matches. Every pool on the tier shares the account. - This template has no sqrt_price_x64/tick_current or mint fields of its own; for - an actual price or tick override on a specific pool use - pancakeswap-clmm-pool-state or pancakeswap-clmm-custom, and keep this config's - fee-rate change and that pool's price change in the same scenario when both need - to move together. + Rates are parts per million: trade_fee_rate of the input (2500 = 0.25%, below 1,000,000); + protocol_fee_rate and fund_fee_rate of the collected fee, together at most 1,000,000. address: type: pda program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq From 981dd8507da5ddd28b7f3e5b39b6ce04264ed656 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Mon, 12 Oct 2026 08:47:35 +0300 Subject: [PATCH 09/20] ci: add the Claude Code 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 22d02476b402e2d307f74a75812dafe4fb2c3459 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 13 Oct 2026 08:49:21 +0300 Subject: [PATCH 10/20] fix(scenarios): address the PancakeSwap fee tier by its pool's AmmConfig instead of a catalog --- .../scenarios/protocols/pancakeswap/README.md | 36 ++- .../protocols/pancakeswap/v1/overrides.yaml | 287 +----------------- crates/core/src/scenarios/registry.rs | 81 +---- crates/core/src/tests/pancakeswap/mod.rs | 156 +++++----- 4 files changed, 107 insertions(+), 453 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index 323faf366..d2af30834 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -1,9 +1,8 @@ # PancakeSwap CLMM PancakeSwap's concentrated-liquidity AMM on Solana, a fork of Raydium CLMM with the same account -layouts. Three templates: a pool found by its mints, a pool found by its address, and a fee tier. -Units and rules match [Raydium CLMM](../raydium/v3/README.md); only the program, pools and fee -tiers differ. +layouts. Two templates: a pool, and the fee tier a pool points to. Units and rules match +[Raydium CLMM](../raydium/v3/README.md); only the program, pools and fee tiers differ. # Template index @@ -11,33 +10,26 @@ tiers differ. | Template | Overrides | |---|---| -| `pancakeswap-clmm-custom` | a pool's price, active liquidity and status, selected by fee tier and mints | -| `pancakeswap-clmm-pool-state` | the same fields, selected by the pool address | -| `pancakeswap-clmm-amm-config` | a fee tier, shared by every pool created on it | +| `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** | | -| `liquidity` | raw `u128`, as a decimal **string** | | +| `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% | -`amm_config_index` lists all 22 live fee tiers with their tick spacing and fee. - ## 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` (fee tier 0, tick spacing 10). Pools are also listed +`DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ` (0.01% fee, tick spacing 10). Pools are also listed at `https://solana.pancakeswap.finance/liquidity-pools/`. -**Order the mints for `pancakeswap-clmm-custom`.** `token_mint_0` is the mint whose raw 32 bytes -are numerically smaller, not the smaller base58 string. A reversed pair derives an empty address -and nothing checks it. - **Check the owner.** The layouts match Raydium's, so a PancakeSwap template pointed at a Raydium pool writes it without complaint. @@ -57,6 +49,9 @@ tick_current: liquidity: "" ``` +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; @@ -73,15 +68,19 @@ template: pancakeswap-clmm-pool-state status: 16 # bit 4: swaps off, liquidity still moves ``` -## Change a fee tier +## 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 -config_index: 0 # the SOL/USDC pool's tier +account: {"pubkey": ""} trade_fee_rate: 10000 # 1% ``` -Every pool created with that index shares the account, so the change reaches all of them. +Every pool on that tier shares the account, so the change reaches all of them. # Troubleshooting @@ -89,5 +88,4 @@ Every pool created with that index shares the account, so the change reaches all |---|---| | 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 | The new tick has no tick array, or `sqrt_price_x64` and `tick_current` disagree | -| `pancakeswap-clmm-custom` changed nothing | The mints are in the wrong order, so the derived address is empty | | The swap fails on the token transfer | The paying vault holds less than the output. Fund it with `spl-token-account-balance` | diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml index cf163a50e..3a5bb6464 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml @@ -8,202 +8,6 @@ tags: - concentrated-liquidity - defi -# Protocol-specific constants that can be referenced by templates -constants: - # PancakeSwap CLMM AMM Config index (for dynamic derivation) - # The AMM config PDA is derived as: ["amm_config", index.to_be_bytes()] - # Captured 2026-09-21 from all 22 live AmmConfig accounts on mainnet - # (getProgramAccounts, dataSize 117, AmmConfig discriminator memcmp). - amm_config_index: - label: Fee Tier (by index) - description: | - AMM config index for dynamic PDA derivation, captured live 2026-09-21 from all - 22 AmmConfig accounts owned by the PancakeSwap program. - The config address is derived from ["amm_config", index.to_be_bytes()]. - options: - - id: index_0 - label: "Fee tier 0.01% (tick spacing 10)" - description: AMM config index 0, trade fee 100 / 1,000,000 - value: "0" - metadata: - tick_spacing: 10 - fee_rate_bps: 1 - derived_address: HZzqEWHEvSiqYt6PxxLs7zXETmqGuryqfmvggjAkqisp - - id: index_1 - label: "Fee tier 0.25% (tick spacing 60)" - description: AMM config index 1, trade fee 2500 / 1,000,000 - value: "1" - metadata: - tick_spacing: 60 - fee_rate_bps: 25 - derived_address: He4brjK7TRKiqJ8szpRmhuueDwC4837BFRRBmWfmjo14 - - id: index_2 - label: "Fee tier 0.05% (tick spacing 10)" - description: AMM config index 2, trade fee 500 / 1,000,000 - value: "2" - metadata: - tick_spacing: 10 - fee_rate_bps: 5 - derived_address: GUNzSDNbhcWpS6Ymj7kgyYmhgHimwfzpRdhJnbKDAi9K - - id: index_3 - label: "Fee tier 1% (tick spacing 120)" - description: AMM config index 3, trade fee 10000 / 1,000,000 - value: "3" - metadata: - tick_spacing: 120 - fee_rate_bps: 100 - derived_address: EtgcyD5Yk6Kuqf1fahAjTrsRCDgoUmgeZ7xJDS3giaE - - id: index_4 - label: "Fee tier 0.01% (tick spacing 1)" - description: AMM config index 4, trade fee 100 / 1,000,000 - value: "4" - metadata: - tick_spacing: 1 - fee_rate_bps: 1 - derived_address: EvKEMSRSdxJUcpVTaB2isqMyF5G4yETvMbQxbfwSuwZa - - id: index_5 - label: "Fee tier 0.05% (tick spacing 1)" - description: AMM config index 5, trade fee 500 / 1,000,000 - value: "5" - metadata: - tick_spacing: 1 - fee_rate_bps: 5 - derived_address: 2cc6jRdZgmN7uG3PxbuVEkYwQNPS7qQinKYYCwG53cpr - - id: index_6 - label: "Fee tier 0.02% (tick spacing 1)" - description: AMM config index 6, trade fee 200 / 1,000,000 - value: "6" - metadata: - tick_spacing: 1 - fee_rate_bps: 2 - derived_address: GcJVsj5MxokA4eRMUkB4cJHuZ6o9Y8MooXBViN5F1mYW - - id: index_7 - label: "Fee tier 0.03% (tick spacing 1)" - description: AMM config index 7, trade fee 300 / 1,000,000 - value: "7" - metadata: - tick_spacing: 1 - fee_rate_bps: 3 - derived_address: 2zmg7259ahZkrSn6M3PEM7eFvEfBU8obgfVHT3AL9Qwu - - id: index_8 - label: "Fee tier 0.04% (tick spacing 1)" - description: AMM config index 8, trade fee 400 / 1,000,000 - value: "8" - metadata: - tick_spacing: 1 - fee_rate_bps: 4 - derived_address: 5kosJrgZ6rHyqqweWGpp11nNqdwPTHbyXVczvzPM9h7M - - id: index_9 - label: "Fee tier 2% (tick spacing 120)" - description: AMM config index 9, trade fee 20000 / 1,000,000 - value: "9" - metadata: - tick_spacing: 120 - fee_rate_bps: 200 - derived_address: 2W1ToXSAUDwRQtZdgCjgXmFfiSvPmGDPx3CijKpVKArw - - id: index_10 - label: "Fee tier 0.1% (tick spacing 10)" - description: AMM config index 10, trade fee 1000 / 1,000,000 - value: "10" - metadata: - tick_spacing: 10 - fee_rate_bps: 10 - derived_address: 5szFcjKA7UU93nhgb3fE1o1cfcurwpFQEzywZyb2qAYF - - id: index_11 - label: "Fee tier 0.15% (tick spacing 10)" - description: AMM config index 11, trade fee 1500 / 1,000,000 - value: "11" - metadata: - tick_spacing: 10 - fee_rate_bps: 15 - derived_address: J1SzfvdJ3p4ixWdyhoHmVpnixfjUBcEZiJ3M66JHGTKz - - id: index_12 - label: "Fee tier 0.16% (tick spacing 10)" - description: AMM config index 12, trade fee 1600 / 1,000,000 - value: "12" - metadata: - tick_spacing: 10 - fee_rate_bps: 16 - derived_address: 5B9wMiyqe7maHxAKACrTiGYwTeSX3ZmpmxRgALUMTcdZ - - id: index_13 - label: "Fee tier 0.18% (tick spacing 10)" - description: AMM config index 13, trade fee 1800 / 1,000,000 - value: "13" - metadata: - tick_spacing: 10 - fee_rate_bps: 18 - derived_address: 5tbvQTWV2btAgX5NwzCbd8aFwTfDWeCZANRQUcWuKRan - - id: index_14 - label: "Fee tier 0.2% (tick spacing 10)" - description: AMM config index 14, trade fee 2000 / 1,000,000 - value: "14" - metadata: - tick_spacing: 10 - fee_rate_bps: 20 - derived_address: G3BrCQzNu93v1acayMA23CmCMH8tf6iAFb3PYUHUHtcg - - id: index_15 - label: "Fee tier 0.4% (tick spacing 60)" - description: AMM config index 15, trade fee 4000 / 1,000,000 - value: "15" - metadata: - tick_spacing: 60 - fee_rate_bps: 40 - derived_address: 2G7HZiydoxtDqQU5SPsyc66nCGRUaP6H85FRKunKpmPs - - id: index_16 - label: "Fee tier 0.6% (tick spacing 60)" - description: AMM config index 16, trade fee 6000 / 1,000,000 - value: "16" - metadata: - tick_spacing: 60 - fee_rate_bps: 60 - derived_address: A3qKMAUV2JsBUeRssKeLm2xJr9w9PKFNWGxPfSV6E7vu - - id: index_17 - label: "Fee tier 0.8% (tick spacing 60)" - description: AMM config index 17, trade fee 8000 / 1,000,000 - value: "17" - metadata: - tick_spacing: 60 - fee_rate_bps: 80 - derived_address: GaWZjVasTQLCNmag5n34eyhhD4T56TN39ckNcuUmu7x4 - - id: index_18 - label: "Fee tier 3% (tick spacing 120)" - description: AMM config index 18, trade fee 30000 / 1,000,000 - value: "18" - metadata: - tick_spacing: 120 - fee_rate_bps: 300 - derived_address: 3EKNN4mNKSzBnfB5gC9q4eeL7WMWBrnuaoagMQVCL2vq - - id: index_19 - label: "Fee tier 4% (tick spacing 120)" - description: AMM config index 19, trade fee 40000 / 1,000,000 - value: "19" - metadata: - tick_spacing: 120 - fee_rate_bps: 400 - derived_address: GeNe8uDSMpCip17DmToci8XNhTgwJJ4QdXP3HNrZbA21 - - id: index_20 - label: "Fee tier 0.3% (tick spacing 60)" - description: AMM config index 20, trade fee 3000 / 1,000,000 - value: "20" - metadata: - tick_spacing: 60 - fee_rate_bps: 30 - derived_address: 4LTiLQbjodjCy8dFWqgUx6fzQ93Pq37c5jWGX9jRsRtC - - id: index_21 - label: "Fee tier 0.08% (tick spacing 1)" - description: AMM config index 21, trade fee 800 / 1,000,000 - value: "21" - metadata: - tick_spacing: 1 - fee_rate_bps: 8 - derived_address: 9rrh2c8w15HExZnLFzcEgkvHg846TBBFEPUuFG7RMGmm - - # Token mints loaded from verified tokens registry - token_mint: - label: Token - description: Select a token mint address from verified tokens - source: verified_tokens - llm_context: | PancakeSwap CLMM, program HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq, a fork of Raydium CLMM. @@ -216,72 +20,11 @@ llm_context: | Set fetchBeforeUse: true. - PRICE: sqrt_price_x64 = sqrt(price_raw) x 2^64, where price_raw is token_1 per token_0 in raw units, - and tick_current = floor(log(price_raw) / log(1.0001)); set both together. A price move must also - set liquidity to the active liquidity at the new tick, and the tick array covering the new tick must - exist. The Studio price shock computes all three; prefer it to hand-computed values. + PRICE: do not move a pool's price by hand. sqrt_price_x64, tick_current and liquidity must change + together, and the new liquidity comes from the pool's tick arrays; tell the user to use the Studio + price shock instead. templates: - - id: pancakeswap-clmm-custom - name: Override CLMM Pool (By Fee Tier and Mints) - description: | - Override a PancakeSwap CLMM pool given its fee tier index and its two token mints. - Both the AMM config address AND the pool address are dynamically derived: - - AMM Config: PDA from ["amm_config", config_index.to_be_bytes()] - - Pool: PDA from ["pool", amm_config, token_mint_0, token_mint_1] - idl_account_name: PoolState - properties: - - path: liquidity - label: Liquidity - description: Total liquidity in the current tick range (raw u128, no decimals) - - path: sqrt_price_x64 - label: Square Root Price (Q64.64) - description: sqrt(token_1/token_0) in Q64.64 fixed point (raw u128); must agree with tick_current - - path: tick_current - label: Current Tick - description: Tick index of the current price (i32); must agree with sqrt_price_x64 - - path: status - label: Pool Status - description: "Disable bitmask (u8): bit0 open/increase liquidity, bit1 decrease liquidity, bit2 collect fee, bit3 collect reward, bit4 swap; 0 = all enabled" - - path: config_index - type: constant_ref - label: Fee Tier - constant: amm_config_index - description: Fee tier of the pool. Together with the two mints it selects the pool address. - - path: token_mint_0 - type: constant_ref - label: Token 0 Mint - constant: token_mint - description: First mint of the pair as the program stores it, the lower of the two by raw bytes. - - path: token_mint_1 - type: constant_ref - label: Token 1 Mint - constant: token_mint - description: Second mint of the pair as the program stores it, the higher of the two by raw bytes. - llm_context: | - Derives the pool from config_index and the two mints, from get_token_address (never program ids). - token_mint_0 must be the mint whose raw 32 bytes are smaller (SOL before USDC); reversed mints - derive an empty address and nothing checks it. For a pool found by address, use - pancakeswap-clmm-pool-state. - address: - type: pda - program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq - seeds: - - type: string - value: pool - # Dynamically derive the AMM config PDA from the index - - type: derived_pda - program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq - seeds: - - type: string - value: amm_config - - type: u16_be_ref - value: config_index - - type: property_ref - value: token_mint_0 - - type: property_ref - value: token_mint_1 - - id: pancakeswap-clmm-pool-state name: Override CLMM Pool State description: Override a PancakeSwap CLMM pool found by pair or by address @@ -309,9 +52,8 @@ templates: - id: pancakeswap-clmm-amm-config name: Override CLMM Fee Tier (AmmConfig) description: | - Override an AmmConfig fee tier for PancakeSwap CLMM. The address is a PDA derived - from ["amm_config", index.to_be_bytes()]. Every pool created with this config - index shares these fee rates. + Override the fee tier (AmmConfig) a PancakeSwap CLMM pool points to. Every pool on the + tier shares it. idl_account_name: AmmConfig properties: - path: trade_fee_rate @@ -323,23 +65,12 @@ templates: - path: fund_fee_rate label: Fund Fee Rate description: Fund owner's share of the collected trade fee, parts per million - - path: config_index - type: constant_ref - label: Fee Tier Index - constant: amm_config_index - description: Fee tier whose AmmConfig account is overridden. The address derives from this index. llm_context: | - To change the fees of a pool's tier, read the pool's amm_config with getAccountInfo, dataSlice - {offset 9, length 32} and encoding base58, and pick the config_index option whose derived_address - matches. Every pool on the tier shares the account. + Put the tier's AmmConfig in the override's account as {"pubkey":""}: read a pool's + amm_config with getAccountInfo, dataSlice {offset 9, length 32} and encoding base58. Every pool + on the tier shares the account. Rates are parts per million: trade_fee_rate of the input (2500 = 0.25%, below 1,000,000); protocol_fee_rate and fund_fee_rate of the collected fee, together at most 1,000,000. address: - type: pda - program_id: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq - seeds: - - type: string - value: amm_config - - type: u16_be_ref - value: config_index + type: pubkey diff --git a/crates/core/src/scenarios/registry.rs b/crates/core/src/scenarios/registry.rs index f68180d3b..3fba7c1e7 100644 --- a/crates/core/src/scenarios/registry.rs +++ b/crates/core/src/scenarios/registry.rs @@ -569,76 +569,6 @@ templates: ); } - #[test] - fn pancakeswap_amm_config_options_derive_their_documented_address() { - let registry = TemplateRegistry::new(); - let template = registry - .get("pancakeswap-clmm-amm-config") - .expect("template"); - let custom = registry.get("pancakeswap-clmm-custom").expect("template"); - - let options = &custom - .constants - .get("amm_config_index") - .expect("amm_config_index constant") - .options; - assert_eq!(options.len(), 22, "22 live AmmConfig accounts"); - - for option in options { - let expected = option - .metadata - .get("derived_address") - .and_then(|address| address.as_str()) - .map(|address| Pubkey::from_str(address).expect("a valid address")) - .unwrap_or_else(|| panic!("option {} documents no derived_address", option.id)); - - let values = HashMap::from([( - "config_index".to_string(), - serde_json::Value::String(option.value.clone()), - )]); - - assert_eq!( - template - .address - .resolve(Some(&values)) - .unwrap_or_else(|| panic!("option {} did not resolve", option.id)), - expected, - "option {}", - option.id - ); - } - } - - #[test] - fn pancakeswap_template_derives_a_live_pool() { - let registry = TemplateRegistry::new(); - let template = registry.get("pancakeswap-clmm-custom").expect("template"); - - let values = HashMap::from([ - ( - "config_index".to_string(), - serde_json::Value::String("0".to_string()), - ), - ( - "token_mint_0".to_string(), - serde_json::Value::String( - "CGiwPp7bzmpYkUChduemtXKMZsUB54hB82tuFR7euJ8R".to_string(), - ), - ), - ( - "token_mint_1".to_string(), - serde_json::Value::String( - "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".to_string(), - ), - ), - ]); - - assert_eq!( - template.address.resolve(Some(&values)).expect("resolves"), - Pubkey::from_str("1Piz3kL4v9fcS8GRkArpskfDG9BeSVc5eHMRjnvSfoX").expect("address"), - ); - } - /// Both singleton addresses are documented in pump-public-docs: the Pump Global /// account at 4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf and the PumpSwap /// GlobalConfig at ADyA8hdefvWN2dbGGWFotbzWxrAvLW83WG6QCVXvJKqw. @@ -726,11 +656,11 @@ templates: // Pyth (1) + Jupiter (1) + Raydium CLMM (1) + Raydium AMM v4 (4) + Drift (4) + Meteora (2) // + Kamino (Lend 17, Scope 3, Farms 5, Swap 2, Vault 5, Liquidity 4 = 36) // + Whirlpool (6) + SPL Token (2) + Pump (2) + PumpSwap (3) + Phoenix Eternal (8) - // + PancakeSwap CLMM (3) = 73 + // + PancakeSwap CLMM (2) = 72 assert_eq!( registry.count(), - 73, - "Registry should load 73 templates total" + 72, + "Registry should load 72 templates total" ); assert!(registry.contains("pyth-price-feed-v2")); @@ -805,7 +735,6 @@ templates: assert!(registry.contains("phoenix-trader-collateral-stress")); assert!(registry.contains("phoenix-direct-mark-risk-shock")); - assert!(registry.contains("pancakeswap-clmm-custom")); assert!(registry.contains("pancakeswap-clmm-pool-state")); assert!(registry.contains("pancakeswap-clmm-amm-config")); } @@ -1144,8 +1073,8 @@ templates: [] let pancakeswap_templates = registry.by_protocol("PancakeSwap"); assert_eq!( pancakeswap_templates.len(), - 3, - "Should have 3 PancakeSwap templates" + 2, + "Should have 2 PancakeSwap templates" ); } diff --git a/crates/core/src/tests/pancakeswap/mod.rs b/crates/core/src/tests/pancakeswap/mod.rs index c637fabbf..fc95dd112 100644 --- a/crates/core/src/tests/pancakeswap/mod.rs +++ b/crates/core/src/tests/pancakeswap/mod.rs @@ -19,17 +19,20 @@ const RPC_URL_ENV: &str = "SURFPOOL_TEST_RPC_URL"; const DEFAULT_RPC_URL: &str = "https://api.mainnet-beta.solana.com"; const POOL_STATE_TEMPLATE: &str = "pancakeswap-clmm-pool-state"; +const AMM_CONFIG_TEMPLATE: &str = "pancakeswap-clmm-amm-config"; +const PANCAKESWAP_CLMM_PROGRAM: Pubkey = + Pubkey::from_str_const("HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq"); const SOL_USDC_POOL: Pubkey = Pubkey::from_str_const("DJNtGuBGEQiUCWE8F981M2C3ZghZt2XLD8f2sQdZ6rsZ"); +const AMM_CONFIG_RANGE: std::ops::Range = 9..41; const LIQUIDITY_RANGE: std::ops::Range = 237..253; const SQRT_PRICE_X64_RANGE: std::ops::Range = 253..269; const TICK_CURRENT_RANGE: std::ops::Range = 269..273; const STATUS_OFFSET: usize = 389; -const TRADE_FEE_RATE_OFFSET: usize = 47; -const TICK_SPACING_OFFSET: usize = 51; +const POOL_STATE_LEN: usize = 1544; const AMM_CONFIG_LEN: usize = 117; /// Fetches the accounts in one request, so every account returned is from the same slot. @@ -71,6 +74,22 @@ async fn real_mainnet_pool_round_trips_unchanged() { let template = registry .get(POOL_STATE_TEMPLATE) .expect("pool state template should exist"); + let account_def = template + .idl() + .accounts + .iter() + .find(|a| a.name == "PoolState") + .expect("PoolState not in the IDL"); + assert_eq!( + data.len(), + POOL_STATE_LEN, + "the SOL/USDC pool has the wrong size live" + ); + assert_eq!( + &data[..8], + account_def.discriminator.as_slice(), + "the SOL/USDC pool has the wrong discriminator live" + ); let forged = surfnet_svm .get_forged_account_data( @@ -87,94 +106,76 @@ async fn real_mainnet_pool_round_trips_unchanged() { } #[tokio::test] -async fn every_amm_config_index_option_is_a_live_amm_config_account() { +async fn pool_amm_config_at_offset_9_is_a_live_amm_config_that_round_trips() { + let pool = fetch(&[SOL_USDC_POOL]).await.remove(0).data; + let config_address = Pubkey::try_from(&pool[AMM_CONFIG_RANGE]).expect("32 bytes"); + let config = fetch(&[config_address]).await.remove(0); + + let (surfnet_svm, _simnet_events_rx, _geyser_events_rx) = SurfnetSvm::default(); let registry = TemplateRegistry::new(); let template = registry - .get("pancakeswap-clmm-amm-config") - .expect("template pancakeswap-clmm-amm-config should exist"); - let amm_config_index = template - .constants - .get("amm_config_index") - .expect("amm_config_index constant should exist"); - assert!( - !amm_config_index.options.is_empty(), - "the fee tiers are the fixture here" - ); - + .get(AMM_CONFIG_TEMPLATE) + .expect("amm config template should exist"); let account_def = template .idl() .accounts .iter() .find(|a| a.name == "AmmConfig") .expect("AmmConfig not in the IDL"); + assert_eq!( + config.owner, PANCAKESWAP_CLMM_PROGRAM, + "the SOL/USDC pool's AmmConfig has the wrong owner live" + ); + assert_eq!( + config.data.len(), + AMM_CONFIG_LEN, + "the SOL/USDC pool's AmmConfig has the wrong size live" + ); + assert_eq!( + &config.data[..8], + account_def.discriminator.as_slice(), + "the SOL/USDC pool's AmmConfig has the wrong discriminator live" + ); - let addresses: Vec = amm_config_index - .options - .iter() - .map(|option| { - let address = option - .metadata - .get("derived_address") - .and_then(|v| v.as_str()) - .unwrap_or_else(|| panic!("option {} documents no derived_address", option.id)); - Pubkey::from_str_const(address) - }) - .collect(); - let accounts = fetch(&addresses).await; - - for (option, account) in amm_config_index.options.iter().zip(&accounts) { - let data = &account.data; - assert_eq!( - data.len(), - AMM_CONFIG_LEN, - "AmmConfig for option {} has the wrong size live", - option.id - ); - assert_eq!( - &data[..8], - account_def.discriminator.as_slice(), - "AmmConfig for option {} has the wrong discriminator live", - option.id - ); - - let tick_spacing = u16::from_le_bytes( - data[TICK_SPACING_OFFSET..TICK_SPACING_OFFSET + 2] - .try_into() - .unwrap(), - ); - let trade_fee_rate = u32::from_le_bytes( - data[TRADE_FEE_RATE_OFFSET..TRADE_FEE_RATE_OFFSET + 4] - .try_into() - .unwrap(), - ); - - let expect_u64 = |field: &str| -> u64 { - option - .metadata - .get(field) - .and_then(|v| v.as_u64()) - .unwrap_or_else(|| panic!("option {} documents no {field} metadata", option.id)) - }; - - assert_eq!( - tick_spacing as u64, - expect_u64("tick_spacing"), - "option {} tick_spacing metadata disagrees with the live AmmConfig", - option.id - ); - assert_eq!( - trade_fee_rate as u64, - expect_u64("fee_rate_bps") * 100, - "option {} live trade_fee_rate should be fee_rate_bps * 100", - option.id - ); - } + let forged = surfnet_svm + .get_forged_account_data( + &config_address, + &config.data, + template.idl(), + &HashMap::new(), + ) + .unwrap_or_else(|e| panic!("live mainnet AmmConfig failed to decode/re-encode: {e}")); + assert_eq!( + forged, config.data, + "live mainnet AmmConfig was altered by a no-op round-trip" + ); } #[tokio::test(flavor = "multi_thread")] async fn overrides_through_materializer_touch_only_their_own_bytes() { let before = fetch(&[SOL_USDC_POOL]).await.remove(0); + let registry = TemplateRegistry::new(); + let template = registry + .get(POOL_STATE_TEMPLATE) + .expect("pool state template should exist"); + let account_def = template + .idl() + .accounts + .iter() + .find(|a| a.name == "PoolState") + .expect("PoolState not in the IDL"); + assert_eq!( + before.data.len(), + POOL_STATE_LEN, + "the SOL/USDC pool has the wrong size live" + ); + assert_eq!( + &before.data[..8], + account_def.discriminator.as_slice(), + "the SOL/USDC pool has the wrong discriminator live" + ); + let new_status: u8 = if before.data[STATUS_OFFSET] == 0 { 31 } else { @@ -191,11 +192,6 @@ async fn overrides_through_materializer_touch_only_their_own_bytes() { .unwrap(); let locker = SurfnetSvmLocker::new(surfnet_svm); - let registry = TemplateRegistry::new(); - let template = registry - .get(POOL_STATE_TEMPLATE) - .expect("pool state template should exist"); - let pool_override = OverrideInstance::new( template.id.clone(), 1, From a3d965e6c59317fb7454f6ff7b40936ce1f59932 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 13 Oct 2026 08:49:21 +0300 Subject: [PATCH 11/20] test: share diff_indices through tests/helpers --- crates/core/src/tests/helpers.rs | 10 ++++++++++ crates/core/src/tests/kamino/mod.rs | 11 +---------- crates/core/src/tests/pancakeswap/mod.rs | 10 +--------- crates/core/src/tests/pump/mod.rs | 12 +----------- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/crates/core/src/tests/helpers.rs b/crates/core/src/tests/helpers.rs index 7e20538aa..17dfabdb4 100644 --- a/crates/core/src/tests/helpers.rs +++ b/crates/core/src/tests/helpers.rs @@ -12,6 +12,16 @@ use crate::{ surfnet::{PluginCommand, locker::SurfnetSvmLocker, svm::SurfnetSvm}, }; +/// Returns the byte indices whose values differ between two buffers. +pub(super) fn diff_indices(left: &[u8], right: &[u8]) -> Vec { + left.iter() + .zip(right.iter()) + .enumerate() + .filter(|(_, (left, right))| left != right) + .map(|(index, _)| index) + .collect() +} + pub fn get_free_port() -> Result { let listener = TcpListener::bind("127.0.0.1:0").map_err(|e| format!("Failed to bind to port 0: {}", e))?; diff --git a/crates/core/src/tests/kamino/mod.rs b/crates/core/src/tests/kamino/mod.rs index aef2ba25e..dccfa1def 100644 --- a/crates/core/src/tests/kamino/mod.rs +++ b/crates/core/src/tests/kamino/mod.rs @@ -22,6 +22,7 @@ use solana_pubkey::Pubkey; use crate::{ scenarios::TemplateRegistry, surfnet::{GetAccountResult, remote::SurfnetRemoteClient, svm::SurfnetSvm}, + tests::helpers::diff_indices, }; const RPC_URL_ENV: &str = "SURFPOOL_TEST_RPC_URL"; @@ -68,16 +69,6 @@ async fn fetch(addresses: &[&str]) -> Vec> { .collect() } -/// Byte indices at which two buffers differ. -fn diff_indices(a: &[u8], b: &[u8]) -> Vec { - a.iter() - .zip(b.iter()) - .enumerate() - .filter(|(_, (x, y))| x != y) - .map(|(i, _)| i) - .collect() -} - /// A failure here means a bundled IDL disagrees with the live on-chain layout. #[tokio::test] async fn real_mainnet_accounts_round_trip_unchanged() { diff --git a/crates/core/src/tests/pancakeswap/mod.rs b/crates/core/src/tests/pancakeswap/mod.rs index fc95dd112..6d1c4aaa2 100644 --- a/crates/core/src/tests/pancakeswap/mod.rs +++ b/crates/core/src/tests/pancakeswap/mod.rs @@ -13,6 +13,7 @@ use crate::{ surfnet::{ GetAccountResult, locker::SurfnetSvmLocker, remote::SurfnetRemoteClient, svm::SurfnetSvm, }, + tests::helpers::diff_indices, }; const RPC_URL_ENV: &str = "SURFPOOL_TEST_RPC_URL"; @@ -56,15 +57,6 @@ async fn fetch(addresses: &[Pubkey]) -> Vec { .collect() } -fn diff_indices(a: &[u8], b: &[u8]) -> Vec { - a.iter() - .zip(b.iter()) - .enumerate() - .filter(|(_, (x, y))| x != y) - .map(|(i, _)| i) - .collect() -} - #[tokio::test] async fn real_mainnet_pool_round_trips_unchanged() { let data = fetch(&[SOL_USDC_POOL]).await.remove(0).data; diff --git a/crates/core/src/tests/pump/mod.rs b/crates/core/src/tests/pump/mod.rs index 650662766..70dd91dd3 100644 --- a/crates/core/src/tests/pump/mod.rs +++ b/crates/core/src/tests/pump/mod.rs @@ -49,7 +49,7 @@ use crate::{ GetAccountResult, locker::SurfnetSvmLocker, remote::SurfnetRemoteClient, svm::SurfnetSvm, }, tests::{ - helpers::get_free_port, + helpers::{diff_indices, get_free_port}, integration::{RunloopGuard, spawn_runloop, wait_for_ready_and_connected}, }, }; @@ -125,16 +125,6 @@ async fn fetch(addresses: &[Pubkey]) -> Vec { .collect() } -/// Byte indices at which two buffers differ. -fn diff_indices(a: &[u8], b: &[u8]) -> Vec { - a.iter() - .zip(b.iter()) - .enumerate() - .filter(|(_, (x, y))| x != y) - .map(|(i, _)| i) - .collect() -} - /// A failure here means a bundled IDL disagrees with the live on-chain layout. #[tokio::test] async fn real_mainnet_accounts_round_trip_unchanged() { From dc0dbc7016dd948c335aa165ddb096282260f350 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 13 Oct 2026 11:11:39 +0300 Subject: [PATCH 12/20] docs(scenarios): drop the PancakeSwap README link to the Raydium README --- crates/core/src/scenarios/protocols/pancakeswap/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index d2af30834..b72edbc5f 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -1,8 +1,8 @@ # 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](../raydium/v3/README.md); only the program, pools and fee tiers differ. +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 From 8f0f065b951ef1a35c02309985d5f5e51127448a Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Fri, 30 Oct 2026 11:34:01 +0200 Subject: [PATCH 13/20] fix(scenarios): use the PancakeSwap IDL published on chain --- .../scenarios/protocols/pancakeswap/README.md | 6 + .../protocols/pancakeswap/v1/idl.json | 1855 +---------------- 2 files changed, 7 insertions(+), 1854 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index b72edbc5f..bf943b467 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -89,3 +89,9 @@ Every pool on that tier shares the account, so the change reaches all of them. | 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 | The new tick has no tick array, or `sqrt_price_x64` and `tick_current` disagree | | 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`, unchanged (sha256 +`661eb632c441b2adb681ecd547fd8cea18e836be2305064e84b14bb90d7efb4c`), as written in slot 348011868. diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json b/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json index 6661fa4b1..ca82772b4 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json @@ -1,1854 +1 @@ -{ - "address": "HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq", - "metadata": { - "name": "amm_v3", - "version": "0.1.0", - "spec": "0.1.0", - "description": "Anchor client and source for Pancake concentrated liquidity AMM" - }, - "instructions": [], - "accounts": [ - { - "name": "AmmConfig", - "discriminator": [ - 218, - 244, - 33, - 104, - 203, - 203, - 43, - 111 - ] - }, - { - "name": "ObservationState", - "discriminator": [ - 122, - 174, - 197, - 53, - 129, - 9, - 165, - 132 - ] - }, - { - "name": "OperationState", - "discriminator": [ - 19, - 236, - 58, - 237, - 81, - 222, - 183, - 252 - ] - }, - { - "name": "PermissionlessFarmSwitch", - "discriminator": [ - 37, - 92, - 147, - 78, - 250, - 100, - 147, - 137 - ] - }, - { - "name": "PersonalPositionState", - "discriminator": [ - 70, - 111, - 150, - 126, - 230, - 15, - 25, - 117 - ] - }, - { - "name": "PoolState", - "discriminator": [ - 247, - 237, - 227, - 245, - 215, - 195, - 222, - 70 - ] - }, - { - "name": "ProtocolPositionState", - "discriminator": [ - 100, - 226, - 145, - 99, - 146, - 218, - 160, - 106 - ] - }, - { - "name": "SupportMintAssociated", - "discriminator": [ - 134, - 40, - 183, - 79, - 12, - 112, - 162, - 53 - ] - }, - { - "name": "TickArrayBitmapExtension", - "discriminator": [ - 60, - 150, - 36, - 219, - 97, - 128, - 139, - 153 - ] - }, - { - "name": "TickArrayState", - "discriminator": [ - 192, - 155, - 85, - 205, - 49, - 249, - 129, - 42 - ] - } - ], - "types": [ - { - "name": "AmmConfig", - "docs": [ - "Holds the current owner of the factory" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "docs": [ - "Bump to identify PDA" - ], - "type": "u8" - }, - { - "name": "index", - "type": "u16" - }, - { - "name": "owner", - "docs": [ - "Address of the protocol owner" - ], - "type": "pubkey" - }, - { - "name": "protocol_fee_rate", - "docs": [ - "The protocol fee" - ], - "type": "u32" - }, - { - "name": "trade_fee_rate", - "docs": [ - "The trade fee, denominated in hundredths of a bip (10^-6)" - ], - "type": "u32" - }, - { - "name": "tick_spacing", - "docs": [ - "The tick spacing" - ], - "type": "u16" - }, - { - "name": "fund_fee_rate", - "docs": [ - "The fund fee, denominated in hundredths of a bip (10^-6)" - ], - "type": "u32" - }, - { - "name": "padding_u32", - "type": "u32" - }, - { - "name": "fund_owner", - "type": "pubkey" - }, - { - "name": "padding", - "type": { - "array": [ - "u64", - 3 - ] - } - } - ] - } - }, - { - "name": "CollectPersonalFeeEvent", - "docs": [ - "Emitted when tokens are collected for a position" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "position_nft_mint", - "docs": [ - "The ID of the token for which underlying tokens were collected" - ], - "type": "pubkey" - }, - { - "name": "recipient_token_account_0", - "docs": [ - "The token account that received the collected token_0 tokens" - ], - "type": "pubkey" - }, - { - "name": "recipient_token_account_1", - "docs": [ - "The token account that received the collected token_1 tokens" - ], - "type": "pubkey" - }, - { - "name": "amount_0", - "docs": [ - "The amount of token_0 owed to the position that was collected" - ], - "type": "u64" - }, - { - "name": "amount_1", - "docs": [ - "The amount of token_1 owed to the position that was collected" - ], - "type": "u64" - } - ] - } - }, - { - "name": "CollectProtocolFeeEvent", - "docs": [ - "Emitted when the collected protocol fees are withdrawn by the factory owner" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "pool_state", - "docs": [ - "The pool whose protocol fee is collected" - ], - "type": "pubkey" - }, - { - "name": "recipient_token_account_0", - "docs": [ - "The address that receives the collected token_0 protocol fees" - ], - "type": "pubkey" - }, - { - "name": "recipient_token_account_1", - "docs": [ - "The address that receives the collected token_1 protocol fees" - ], - "type": "pubkey" - }, - { - "name": "amount_0", - "docs": [ - "The amount of token_0 protocol fees that is withdrawn" - ], - "type": "u64" - }, - { - "name": "amount_1", - "docs": [ - "The amount of token_0 protocol fees that is withdrawn" - ], - "type": "u64" - } - ] - } - }, - { - "name": "ConfigChangeEvent", - "docs": [ - "Emitted when create or update a config" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "index", - "type": "u16" - }, - { - "name": "owner", - "type": "pubkey" - }, - { - "name": "protocol_fee_rate", - "type": "u32" - }, - { - "name": "trade_fee_rate", - "type": "u32" - }, - { - "name": "tick_spacing", - "type": "u16" - }, - { - "name": "fund_fee_rate", - "type": "u32" - }, - { - "name": "fund_owner", - "type": "pubkey" - } - ] - } - }, - { - "name": "CreatePersonalPositionEvent", - "docs": [ - "Emitted when create a new position" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "pool_state", - "docs": [ - "The pool for which liquidity was added" - ], - "type": "pubkey" - }, - { - "name": "minter", - "docs": [ - "The address that create the position" - ], - "type": "pubkey" - }, - { - "name": "nft_owner", - "docs": [ - "The owner of the position and recipient of any minted liquidity" - ], - "type": "pubkey" - }, - { - "name": "tick_lower_index", - "docs": [ - "The lower tick of the position" - ], - "type": "i32" - }, - { - "name": "tick_upper_index", - "docs": [ - "The upper tick of the position" - ], - "type": "i32" - }, - { - "name": "liquidity", - "docs": [ - "The amount of liquidity minted to the position range" - ], - "type": "u128" - }, - { - "name": "deposit_amount_0", - "docs": [ - "The amount of token_0 was deposit for the liquidity" - ], - "type": "u64" - }, - { - "name": "deposit_amount_1", - "docs": [ - "The amount of token_1 was deposit for the liquidity" - ], - "type": "u64" - }, - { - "name": "deposit_amount_0_transfer_fee", - "docs": [ - "The token transfer fee for deposit_amount_0" - ], - "type": "u64" - }, - { - "name": "deposit_amount_1_transfer_fee", - "docs": [ - "The token transfer fee for deposit_amount_1" - ], - "type": "u64" - } - ] - } - }, - { - "name": "DecreaseLiquidityEvent", - "docs": [ - "Emitted when liquidity is decreased." - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "position_nft_mint", - "docs": [ - "The ID of the token for which liquidity was decreased" - ], - "type": "pubkey" - }, - { - "name": "liquidity", - "docs": [ - "The amount by which liquidity for the position was decreased" - ], - "type": "u128" - }, - { - "name": "decrease_amount_0", - "docs": [ - "The amount of token_0 that was paid for the decrease in liquidity" - ], - "type": "u64" - }, - { - "name": "decrease_amount_1", - "docs": [ - "The amount of token_1 that was paid for the decrease in liquidity" - ], - "type": "u64" - }, - { - "name": "fee_amount_0", - "type": "u64" - }, - { - "name": "fee_amount_1", - "docs": [ - "The amount of token_1 fee" - ], - "type": "u64" - }, - { - "name": "reward_amounts", - "docs": [ - "The amount of rewards" - ], - "type": { - "array": [ - "u64", - 3 - ] - } - }, - { - "name": "transfer_fee_0", - "docs": [ - "The amount of token_0 transfer fee" - ], - "type": "u64" - }, - { - "name": "transfer_fee_1", - "docs": [ - "The amount of token_1 transfer fee" - ], - "type": "u64" - } - ] - } - }, - { - "name": "IncreaseLiquidityEvent", - "docs": [ - "Emitted when liquidity is increased." - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "position_nft_mint", - "docs": [ - "The ID of the token for which liquidity was increased" - ], - "type": "pubkey" - }, - { - "name": "liquidity", - "docs": [ - "The amount by which liquidity for the NFT position was increased" - ], - "type": "u128" - }, - { - "name": "amount_0", - "docs": [ - "The amount of token_0 that was paid for the increase in liquidity" - ], - "type": "u64" - }, - { - "name": "amount_1", - "docs": [ - "The amount of token_1 that was paid for the increase in liquidity" - ], - "type": "u64" - }, - { - "name": "amount_0_transfer_fee", - "docs": [ - "The token transfer fee for amount_0" - ], - "type": "u64" - }, - { - "name": "amount_1_transfer_fee", - "docs": [ - "The token transfer fee for amount_1" - ], - "type": "u64" - } - ] - } - }, - { - "name": "InitializeRewardParam", - "type": { - "kind": "struct", - "fields": [ - { - "name": "open_time", - "docs": [ - "Reward open time" - ], - "type": "u64" - }, - { - "name": "end_time", - "docs": [ - "Reward end time" - ], - "type": "u64" - }, - { - "name": "emissions_per_second_x64", - "docs": [ - "Token reward per second are earned per unit of liquidity" - ], - "type": "u128" - } - ] - } - }, - { - "name": "LiquidityCalculateEvent", - "docs": [ - "Emitted when liquidity decreased or increase." - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "pool_liquidity", - "docs": [ - "The pool liquidity before decrease or increase" - ], - "type": "u128" - }, - { - "name": "pool_sqrt_price_x64", - "docs": [ - "The pool price when decrease or increase in liquidity" - ], - "type": "u128" - }, - { - "name": "pool_tick", - "docs": [ - "The pool tick when decrease or increase in liquidity" - ], - "type": "i32" - }, - { - "name": "calc_amount_0", - "docs": [ - "The amount of token_0 that was calculated for the decrease or increase in liquidity" - ], - "type": "u64" - }, - { - "name": "calc_amount_1", - "docs": [ - "The amount of token_1 that was calculated for the decrease or increase in liquidity" - ], - "type": "u64" - }, - { - "name": "trade_fee_owed_0", - "type": "u64" - }, - { - "name": "trade_fee_owed_1", - "docs": [ - "The amount of token_1 fee" - ], - "type": "u64" - }, - { - "name": "transfer_fee_0", - "docs": [ - "The amount of token_0 transfer fee without trade_fee_amount_0" - ], - "type": "u64" - }, - { - "name": "transfer_fee_1", - "docs": [ - "The amount of token_1 transfer fee without trade_fee_amount_0" - ], - "type": "u64" - } - ] - } - }, - { - "name": "LiquidityChangeEvent", - "docs": [ - "Emitted pool liquidity change when increase and decrease liquidity" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "pool_state", - "docs": [ - "The pool for swap" - ], - "type": "pubkey" - }, - { - "name": "tick", - "docs": [ - "The tick of the pool" - ], - "type": "i32" - }, - { - "name": "tick_lower", - "docs": [ - "The tick lower of position" - ], - "type": "i32" - }, - { - "name": "tick_upper", - "docs": [ - "The tick lower of position" - ], - "type": "i32" - }, - { - "name": "liquidity_before", - "docs": [ - "The liquidity of the pool before liquidity change" - ], - "type": "u128" - }, - { - "name": "liquidity_after", - "docs": [ - "The liquidity of the pool after liquidity change" - ], - "type": "u128" - } - ] - } - }, - { - "name": "Observation", - "docs": [ - "The element of observations in ObservationState" - ], - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "block_timestamp", - "docs": [ - "The block timestamp of the observation" - ], - "type": "u32" - }, - { - "name": "tick_cumulative", - "docs": [ - "the cumulative of tick during the duration time" - ], - "type": "i64" - }, - { - "name": "padding", - "docs": [ - "padding for feature update" - ], - "type": { - "array": [ - "u64", - 4 - ] - } - } - ] - } - }, - { - "name": "ObservationState", - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "initialized", - "docs": [ - "Whether the ObservationState is initialized" - ], - "type": "bool" - }, - { - "name": "recent_epoch", - "docs": [ - "recent update epoch" - ], - "type": "u64" - }, - { - "name": "observation_index", - "docs": [ - "the most-recently updated index of the observations array" - ], - "type": "u16" - }, - { - "name": "pool_id", - "docs": [ - "belongs to which pool" - ], - "type": "pubkey" - }, - { - "name": "observations", - "docs": [ - "observation array" - ], - "type": { - "array": [ - { - "defined": { - "name": "Observation" - } - }, - 100 - ] - } - }, - { - "name": "padding", - "docs": [ - "padding for feature update" - ], - "type": { - "array": [ - "u64", - 4 - ] - } - } - ] - } - }, - { - "name": "OperationState", - "docs": [ - "Holds the current owner of the factory" - ], - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "docs": [ - "Bump to identify PDA" - ], - "type": "u8" - }, - { - "name": "operation_owners", - "docs": [ - "Address of the operation owner" - ], - "type": { - "array": [ - "pubkey", - 10 - ] - } - }, - { - "name": "whitelist_mints", - "docs": [ - "The mint address of whitelist to emit reward" - ], - "type": { - "array": [ - "pubkey", - 100 - ] - } - } - ] - } - }, - { - "name": "PermissionlessFarmSwitch", - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "docs": [ - "Bump to identify PDA" - ], - "type": "u8" - }, - { - "name": "is_on", - "docs": [ - "Is the permissionless farm allowed or not" - ], - "type": "bool" - } - ] - } - }, - { - "name": "PersonalPositionState", - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "docs": [ - "Bump to identify PDA" - ], - "type": { - "array": [ - "u8", - 1 - ] - } - }, - { - "name": "nft_mint", - "docs": [ - "Mint address of the tokenized position" - ], - "type": "pubkey" - }, - { - "name": "pool_id", - "docs": [ - "The ID of the pool with which this token is connected" - ], - "type": "pubkey" - }, - { - "name": "tick_lower_index", - "docs": [ - "The lower bound tick of the position" - ], - "type": "i32" - }, - { - "name": "tick_upper_index", - "docs": [ - "The upper bound tick of the position" - ], - "type": "i32" - }, - { - "name": "liquidity", - "docs": [ - "The amount of liquidity owned by this position" - ], - "type": "u128" - }, - { - "name": "fee_growth_inside_0_last_x64", - "docs": [ - "The token_0 fee growth of the aggregate position as of the last action on the individual position" - ], - "type": "u128" - }, - { - "name": "fee_growth_inside_1_last_x64", - "docs": [ - "The token_1 fee growth of the aggregate position as of the last action on the individual position" - ], - "type": "u128" - }, - { - "name": "token_fees_owed_0", - "docs": [ - "The fees owed to the position owner in token_0, as of the last computation" - ], - "type": "u64" - }, - { - "name": "token_fees_owed_1", - "docs": [ - "The fees owed to the position owner in token_1, as of the last computation" - ], - "type": "u64" - }, - { - "name": "reward_infos", - "type": { - "array": [ - { - "defined": { - "name": "PositionRewardInfo" - } - }, - 3 - ] - } - }, - { - "name": "recent_epoch", - "type": "u64" - }, - { - "name": "padding", - "type": { - "array": [ - "u64", - 7 - ] - } - } - ] - } - }, - { - "name": "PoolCreatedEvent", - "docs": [ - "Emitted when a pool is created and initialized with a starting price", - "" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "token_mint_0", - "docs": [ - "The first token of the pool by address sort order" - ], - "type": "pubkey" - }, - { - "name": "token_mint_1", - "docs": [ - "The second token of the pool by address sort order" - ], - "type": "pubkey" - }, - { - "name": "tick_spacing", - "docs": [ - "The minimum number of ticks between initialized ticks" - ], - "type": "u16" - }, - { - "name": "pool_state", - "docs": [ - "The address of the created pool" - ], - "type": "pubkey" - }, - { - "name": "sqrt_price_x64", - "docs": [ - "The initial sqrt price of the pool, as a Q64.64" - ], - "type": "u128" - }, - { - "name": "tick", - "docs": [ - "The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool" - ], - "type": "i32" - }, - { - "name": "token_vault_0", - "docs": [ - "Vault of token_0" - ], - "type": "pubkey" - }, - { - "name": "token_vault_1", - "docs": [ - "Vault of token_1" - ], - "type": "pubkey" - } - ] - } - }, - { - "name": "PoolState", - "docs": [ - "The pool state", - "", - "PDA of `[POOL_SEED, config, token_mint_0, token_mint_1]`", - "" - ], - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "docs": [ - "Bump to identify PDA" - ], - "type": { - "array": [ - "u8", - 1 - ] - } - }, - { - "name": "amm_config", - "type": "pubkey" - }, - { - "name": "owner", - "type": "pubkey" - }, - { - "name": "token_mint_0", - "docs": [ - "Token pair of the pool, where token_mint_0 address < token_mint_1 address" - ], - "type": "pubkey" - }, - { - "name": "token_mint_1", - "type": "pubkey" - }, - { - "name": "token_vault_0", - "docs": [ - "Token pair vault" - ], - "type": "pubkey" - }, - { - "name": "token_vault_1", - "type": "pubkey" - }, - { - "name": "observation_key", - "docs": [ - "observation account key" - ], - "type": "pubkey" - }, - { - "name": "mint_decimals_0", - "docs": [ - "mint0 and mint1 decimals" - ], - "type": "u8" - }, - { - "name": "mint_decimals_1", - "type": "u8" - }, - { - "name": "tick_spacing", - "docs": [ - "The minimum number of ticks between initialized ticks" - ], - "type": "u16" - }, - { - "name": "liquidity", - "docs": [ - "The currently in range liquidity available to the pool." - ], - "type": "u128" - }, - { - "name": "sqrt_price_x64", - "docs": [ - "The current price of the pool as a sqrt(token_1/token_0) Q64.64 value" - ], - "type": "u128" - }, - { - "name": "tick_current", - "docs": [ - "The current tick of the pool, i.e. according to the last tick transition that was run." - ], - "type": "i32" - }, - { - "name": "padding3", - "type": "u16" - }, - { - "name": "padding4", - "type": "u16" - }, - { - "name": "fee_growth_global_0_x64", - "docs": [ - "The fee growth as a Q64.64 number, i.e. fees of token_0 and token_1 collected per", - "unit of liquidity for the entire life of the pool." - ], - "type": "u128" - }, - { - "name": "fee_growth_global_1_x64", - "type": "u128" - }, - { - "name": "protocol_fees_token_0", - "docs": [ - "The amounts of token_0 and token_1 that are owed to the protocol." - ], - "type": "u64" - }, - { - "name": "protocol_fees_token_1", - "type": "u64" - }, - { - "name": "swap_in_amount_token_0", - "docs": [ - "The amounts in and out of swap token_0 and token_1" - ], - "type": "u128" - }, - { - "name": "swap_out_amount_token_1", - "type": "u128" - }, - { - "name": "swap_in_amount_token_1", - "type": "u128" - }, - { - "name": "swap_out_amount_token_0", - "type": "u128" - }, - { - "name": "status", - "docs": [ - "Bitwise representation of the state of the pool", - "bit0, 1: disable open position and increase liquidity, 0: normal", - "bit1, 1: disable decrease liquidity, 0: normal", - "bit2, 1: disable collect fee, 0: normal", - "bit3, 1: disable collect reward, 0: normal", - "bit4, 1: disable swap, 0: normal" - ], - "type": "u8" - }, - { - "name": "padding", - "docs": [ - "Leave blank for future use" - ], - "type": { - "array": [ - "u8", - 7 - ] - } - }, - { - "name": "reward_infos", - "type": { - "array": [ - { - "defined": { - "name": "RewardInfo" - } - }, - 3 - ] - } - }, - { - "name": "tick_array_bitmap", - "docs": [ - "Packed initialized tick array state" - ], - "type": { - "array": [ - "u64", - 16 - ] - } - }, - { - "name": "total_fees_token_0", - "docs": [ - "except protocol_fee and fund_fee" - ], - "type": "u64" - }, - { - "name": "total_fees_claimed_token_0", - "docs": [ - "except protocol_fee and fund_fee" - ], - "type": "u64" - }, - { - "name": "total_fees_token_1", - "type": "u64" - }, - { - "name": "total_fees_claimed_token_1", - "type": "u64" - }, - { - "name": "fund_fees_token_0", - "type": "u64" - }, - { - "name": "fund_fees_token_1", - "type": "u64" - }, - { - "name": "open_time", - "type": "u64" - }, - { - "name": "recent_epoch", - "type": "u64" - }, - { - "name": "padding1", - "type": { - "array": [ - "u64", - 24 - ] - } - }, - { - "name": "padding2", - "type": { - "array": [ - "u64", - 32 - ] - } - } - ] - } - }, - { - "name": "PositionRewardInfo", - "type": { - "kind": "struct", - "fields": [ - { - "name": "growth_inside_last_x64", - "type": "u128" - }, - { - "name": "reward_amount_owed", - "type": "u64" - } - ] - } - }, - { - "name": "ProtocolPositionState", - "docs": [ - "Info stored for each user's position" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "docs": [ - "Bump to identify PDA" - ], - "type": "u8" - }, - { - "name": "pool_id", - "docs": [ - "The ID of the pool with which this token is connected" - ], - "type": "pubkey" - }, - { - "name": "tick_lower_index", - "docs": [ - "The lower bound tick of the position" - ], - "type": "i32" - }, - { - "name": "tick_upper_index", - "docs": [ - "The upper bound tick of the position" - ], - "type": "i32" - }, - { - "name": "liquidity", - "docs": [ - "The amount of liquidity owned by this position" - ], - "type": "u128" - }, - { - "name": "fee_growth_inside_0_last_x64", - "docs": [ - "The token_0 fee growth per unit of liquidity as of the last update to liquidity or fees owed" - ], - "type": "u128" - }, - { - "name": "fee_growth_inside_1_last_x64", - "docs": [ - "The token_1 fee growth per unit of liquidity as of the last update to liquidity or fees owed" - ], - "type": "u128" - }, - { - "name": "token_fees_owed_0", - "docs": [ - "The fees owed to the position owner in token_0" - ], - "type": "u64" - }, - { - "name": "token_fees_owed_1", - "docs": [ - "The fees owed to the position owner in token_1" - ], - "type": "u64" - }, - { - "name": "reward_growth_inside", - "docs": [ - "The reward growth per unit of liquidity as of the last update to liquidity" - ], - "type": { - "array": [ - "u128", - 3 - ] - } - }, - { - "name": "recent_epoch", - "type": "u64" - }, - { - "name": "padding", - "type": { - "array": [ - "u64", - 7 - ] - } - } - ] - } - }, - { - "name": "RewardInfo", - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "reward_state", - "docs": [ - "Reward state" - ], - "type": "u8" - }, - { - "name": "open_time", - "docs": [ - "Reward open time" - ], - "type": "u64" - }, - { - "name": "end_time", - "docs": [ - "Reward end time" - ], - "type": "u64" - }, - { - "name": "last_update_time", - "docs": [ - "Reward last update time" - ], - "type": "u64" - }, - { - "name": "emissions_per_second_x64", - "docs": [ - "Q64.64 number indicates how many tokens per second are earned per unit of liquidity." - ], - "type": "u128" - }, - { - "name": "reward_total_emissioned", - "docs": [ - "The total amount of reward emissioned" - ], - "type": "u64" - }, - { - "name": "reward_claimed", - "docs": [ - "The total amount of claimed reward" - ], - "type": "u64" - }, - { - "name": "token_mint", - "docs": [ - "Reward token mint." - ], - "type": "pubkey" - }, - { - "name": "token_vault", - "docs": [ - "Reward vault token account." - ], - "type": "pubkey" - }, - { - "name": "authority", - "docs": [ - "The owner that has permission to set reward param" - ], - "type": "pubkey" - }, - { - "name": "reward_growth_global_x64", - "docs": [ - "Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward", - "emissions were turned on." - ], - "type": "u128" - } - ] - } - }, - { - "name": "SupportMintAssociated", - "docs": [ - "Holds the current owner of the factory" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "docs": [ - "Bump to identify PDA" - ], - "type": "u8" - }, - { - "name": "mint", - "docs": [ - "Address of the supported token22 mint" - ], - "type": "pubkey" - }, - { - "name": "padding", - "type": { - "array": [ - "u64", - 8 - ] - } - } - ] - } - }, - { - "name": "SwapEvent", - "docs": [ - "Emitted by when a swap is performed for a pool" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "pool_state", - "docs": [ - "The pool for which token_0 and token_1 were swapped" - ], - "type": "pubkey" - }, - { - "name": "sender", - "docs": [ - "The address that initiated the swap call, and that received the callback" - ], - "type": "pubkey" - }, - { - "name": "token_account_0", - "docs": [ - "The payer token account in zero for one swaps, or the recipient token account", - "in one for zero swaps" - ], - "type": "pubkey" - }, - { - "name": "token_account_1", - "docs": [ - "The payer token account in one for zero swaps, or the recipient token account", - "in zero for one swaps" - ], - "type": "pubkey" - }, - { - "name": "amount_0", - "docs": [ - "The real delta amount of the token_0 of the pool or user" - ], - "type": "u64" - }, - { - "name": "transfer_fee_0", - "docs": [ - "The transfer fee charged by the withheld_amount of the token_0" - ], - "type": "u64" - }, - { - "name": "amount_1", - "docs": [ - "The real delta of the token_1 of the pool or user" - ], - "type": "u64" - }, - { - "name": "transfer_fee_1", - "docs": [ - "The transfer fee charged by the withheld_amount of the token_1" - ], - "type": "u64" - }, - { - "name": "zero_for_one", - "docs": [ - "if true, amount_0 is negtive and amount_1 is positive" - ], - "type": "bool" - }, - { - "name": "sqrt_price_x64", - "docs": [ - "The sqrt(price) of the pool after the swap, as a Q64.64" - ], - "type": "u128" - }, - { - "name": "liquidity", - "docs": [ - "The liquidity of the pool after the swap" - ], - "type": "u128" - }, - { - "name": "tick", - "docs": [ - "The log base 1.0001 of price of the pool after the swap" - ], - "type": "i32" - } - ] - } - }, - { - "name": "TickArrayBitmapExtension", - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "pool_id", - "type": "pubkey" - }, - { - "name": "positive_tick_array_bitmap", - "docs": [ - "Packed initialized tick array state for start_tick_index is positive" - ], - "type": { - "array": [ - { - "array": [ - "u64", - 8 - ] - }, - 14 - ] - } - }, - { - "name": "negative_tick_array_bitmap", - "docs": [ - "Packed initialized tick array state for start_tick_index is negitive" - ], - "type": { - "array": [ - { - "array": [ - "u64", - 8 - ] - }, - 14 - ] - } - } - ] - } - }, - { - "name": "TickArrayState", - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "pool_id", - "type": "pubkey" - }, - { - "name": "start_tick_index", - "type": "i32" - }, - { - "name": "ticks", - "type": { - "array": [ - { - "defined": { - "name": "TickState" - } - }, - 60 - ] - } - }, - { - "name": "initialized_tick_count", - "type": "u8" - }, - { - "name": "recent_epoch", - "type": "u64" - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 107 - ] - } - } - ] - } - }, - { - "name": "TickState", - "serialization": "bytemuckunsafe", - "repr": { - "kind": "c", - "packed": true - }, - "type": { - "kind": "struct", - "fields": [ - { - "name": "tick", - "type": "i32" - }, - { - "name": "liquidity_net", - "docs": [ - "Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)" - ], - "type": "i128" - }, - { - "name": "liquidity_gross", - "docs": [ - "The total position liquidity that references this tick" - ], - "type": "u128" - }, - { - "name": "fee_growth_outside_0_x64", - "docs": [ - "Fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)", - "only has relative meaning, not absolute \u2014 the value depends on when the tick is initialized" - ], - "type": "u128" - }, - { - "name": "fee_growth_outside_1_x64", - "type": "u128" - }, - { - "name": "reward_growths_outside_x64", - "type": { - "array": [ - "u128", - 3 - ] - } - }, - { - "name": "padding", - "type": { - "array": [ - "u32", - 13 - ] - } - } - ] - } - }, - { - "name": "UpdateRewardInfosEvent", - "docs": [ - "Emitted when Reward are updated for a pool" - ], - "type": { - "kind": "struct", - "fields": [ - { - "name": "reward_growth_global_x64", - "docs": [ - "Reward info" - ], - "type": { - "array": [ - "u128", - 3 - ] - } - } - ] - } - } - ] -} +{"address":"HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq","metadata":{"name":"amm_v3","version":"0.1.0","spec":"0.1.0","description":"Anchor client and source for Pancake concentrated liquidity AMM"},"instructions":[{"name":"close_position","docs":["Close the user's position and NFT account. If the NFT mint belongs to token2022, it will also be closed and the funds returned to the NFT owner.","","# Arguments","","* `ctx` - The context of accounts",""],"discriminator":[123,134,81,0,49,68,98,98],"accounts":[{"name":"nft_owner","docs":["The position nft owner"],"writable":true,"signer":true},{"name":"position_nft_mint","docs":["Mint address bound to the personal position."],"writable":true},{"name":"position_nft_account","docs":["User token account where position NFT be minted to"],"writable":true},{"name":"personal_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"system_program","docs":["System program to close the position state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Token/Token2022 program to close token/mint account"]}],"args":[]},{"name":"collect_fund_fee","docs":["Collect the fund fee accrued to the pool","","# Arguments","","* `ctx` - The context of accounts","* `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1","* `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0",""],"discriminator":[167,138,78,149,223,194,6,126],"accounts":[{"name":"owner","docs":["Only admin or fund_owner can collect fee now"],"signer":true},{"name":"pool_state","docs":["Pool state stores accumulated protocol fee amount"],"writable":true},{"name":"amm_config","docs":["Amm config account stores fund_owner"]},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]},{"name":"recipient_token_account_0","docs":["The address that receives the collected token_0 protocol fees"],"writable":true},{"name":"recipient_token_account_1","docs":["The address that receives the collected token_1 protocol fees"],"writable":true},{"name":"token_program","docs":["The SPL program to perform token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["The SPL program 2022 to perform token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"}],"args":[{"name":"amount_0_requested","type":"u64"},{"name":"amount_1_requested","type":"u64"}]},{"name":"collect_protocol_fee","docs":["Collect the protocol fee accrued to the pool","","# Arguments","","* `ctx` - The context of accounts","* `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1","* `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0",""],"discriminator":[136,136,252,221,194,66,126,89],"accounts":[{"name":"owner","docs":["Only admin or config owner can collect fee now"],"signer":true},{"name":"pool_state","docs":["Pool state stores accumulated protocol fee amount"],"writable":true},{"name":"amm_config","docs":["Amm config account stores owner"]},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]},{"name":"recipient_token_account_0","docs":["The address that receives the collected token_0 protocol fees"],"writable":true},{"name":"recipient_token_account_1","docs":["The address that receives the collected token_1 protocol fees"],"writable":true},{"name":"token_program","docs":["The SPL program to perform token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["The SPL program 2022 to perform token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"}],"args":[{"name":"amount_0_requested","type":"u64"},{"name":"amount_1_requested","type":"u64"}]},{"name":"collect_remaining_rewards","docs":["Collect remaining reward token for reward founder","","# Arguments","","* `ctx`- The context of accounts","* `reward_index` - the index to reward info",""],"discriminator":[18,237,166,197,34,16,213,144],"accounts":[{"name":"reward_funder","docs":["The founder who init reward info previously"],"signer":true},{"name":"funder_token_account","docs":["The funder's reward token account"],"writable":true},{"name":"pool_state","docs":["Set reward for this pool"],"writable":true},{"name":"reward_token_vault","docs":["Reward vault transfer remaining token to founder token account"]},{"name":"reward_vault_mint","docs":["The mint of reward token vault"]},{"name":"token_program","address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"}],"args":[{"name":"reward_index","type":"u8"}]},{"name":"create_amm_config","docs":["# Arguments","","* `ctx`- The accounts needed by instruction.","* `index` - The index of amm config, there may be multiple config.","* `tick_spacing` - The tickspacing binding with config, cannot be changed.","* `trade_fee_rate` - Trade fee rate, can be changed.","* `protocol_fee_rate` - The rate of protocol fee within trade fee.","* `fund_fee_rate` - The rate of fund fee within trade fee.",""],"discriminator":[137,52,237,212,215,117,108,104],"accounts":[{"name":"owner","docs":["Address to be set as protocol owner."],"writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"amm_config","docs":["Initialize config state account to store protocol owner address and fee rates."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[97,109,109,95,99,111,110,102,105,103]},{"kind":"arg","path":"index"}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[{"name":"index","type":"u16"},{"name":"tick_spacing","type":"u16"},{"name":"trade_fee_rate","type":"u32"},{"name":"protocol_fee_rate","type":"u32"},{"name":"fund_fee_rate","type":"u32"}]},{"name":"create_operation_account","docs":["Creates an operation account for the program","","# Arguments","","* `ctx`- The context of accounts",""],"discriminator":[63,87,148,33,109,35,8,104],"accounts":[{"name":"owner","docs":["Address to be set as operation account owner."],"writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"operation_state","docs":["Initialize operation state account to store operation owner address and white list mint."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[]},{"name":"create_permissionless_farm_switch","docs":["Creates a permissionless farm switch account for the program","","# Arguments","","* `ctx`- The context of accounts",""],"discriminator":[88,242,198,70,241,6,196,251],"accounts":[{"name":"owner","writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"permissionless_farm_switch","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,101,114,109,105,115,115,105,111,110,108,101,115,115,95,102,97,114,109,95,115,119,105,116,99,104]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[]},{"name":"create_pool","docs":["Creates a pool for the given token pair and the initial price","","# Arguments","","* `ctx`- The context of accounts","* `sqrt_price_x64` - the initial sqrt price (amount_token_1 / amount_token_0) of the pool as a Q64.64","Note: The open_time must be smaller than the current block_timestamp on chain."],"discriminator":[233,146,209,142,207,104,64,188],"accounts":[{"name":"pool_creator","docs":["Address paying to create the pool. Can be anyone"],"writable":true,"signer":true},{"name":"amm_config","docs":["Which config the pool belongs to."]},{"name":"pool_state","docs":["Initialize an account to store the pool state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108]},{"kind":"account","path":"amm_config"},{"kind":"account","path":"token_mint_0"},{"kind":"account","path":"token_mint_1"}]}},{"name":"token_mint_0","docs":["Token_0 mint, the key must be smaller then token_1 mint."]},{"name":"token_mint_1","docs":["Token_1 mint"]},{"name":"token_vault_0","docs":["Token_0 vault for the pool"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,118,97,117,108,116]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"token_mint_0"}]}},{"name":"token_vault_1","docs":["Token_1 vault for the pool"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,118,97,117,108,116]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"token_mint_1"}]}},{"name":"observation_state","docs":["Initialize an account to store oracle observations"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[111,98,115,101,114,118,97,116,105,111,110]},{"kind":"account","path":"pool_state"}]}},{"name":"tick_array_bitmap","docs":["Initialize an account to store if a tick array is initialized."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,116,105,99,107,95,97,114,114,97,121,95,98,105,116,109,97,112,95,101,120,116,101,110,115,105,111,110]},{"kind":"account","path":"pool_state"}]}},{"name":"token_program_0","docs":["Spl token program or token program 2022"]},{"name":"token_program_1","docs":["Spl token program or token program 2022"]},{"name":"system_program","docs":["To create a new program account"],"address":"11111111111111111111111111111111"},{"name":"rent","docs":["Sysvar for program account"],"address":"SysvarRent111111111111111111111111111111111"}],"args":[{"name":"sqrt_price_x64","type":"u128"},{"name":"open_time","type":"u64"}]},{"name":"create_support_mint_associated","docs":["Create support token22 mint account which can create pool and send rewards with ignoring the not support extensions."],"discriminator":[17,251,65,92,136,242,14,169],"accounts":[{"name":"owner","docs":["Address to be set as protocol owner."],"writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"token_mint","docs":["Support token mint"]},{"name":"support_mint_associated","docs":["Initialize support mint state account to store support mint address and bump."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[115,117,112,112,111,114,116,95,109,105,110,116]},{"kind":"account","path":"token_mint"}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[]},{"name":"decrease_liquidity","docs":["#[deprecated(note = \"Use `decrease_liquidity_v2` instead.\")]","Decreases liquidity for an existing position","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The amount by which liquidity will be decreased","* `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity","* `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity",""],"discriminator":[160,38,208,111,104,91,44,1],"accounts":[{"name":"nft_owner","docs":["The position owner or delegated authority"],"signer":true},{"name":"nft_account","docs":["The token account for the tokenized position"]},{"name":"personal_position","docs":["Decrease liquidity for this position"],"writable":true},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"token_vault_0","docs":["Token_0 vault"],"writable":true},{"name":"token_vault_1","docs":["Token_1 vault"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"recipient_token_account_0","docs":["The destination token account for receive amount_0"],"writable":true},{"name":"recipient_token_account_1","docs":["The destination token account for receive amount_1"],"writable":true},{"name":"token_program","docs":["SPL program to transfer out tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_min","type":"u64"},{"name":"amount_1_min","type":"u64"}]},{"name":"decrease_liquidity_v2","docs":["Decreases liquidity for an existing position, support Token2022","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The amount by which liquidity will be decreased","* `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity","* `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity",""],"discriminator":[58,127,188,62,79,82,196,96],"accounts":[{"name":"nft_owner","docs":["The position owner or delegated authority"],"signer":true},{"name":"nft_account","docs":["The token account for the tokenized position"]},{"name":"personal_position","docs":["Decrease liquidity for this position"],"writable":true},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"token_vault_0","docs":["Token_0 vault"],"writable":true},{"name":"token_vault_1","docs":["Token_1 vault"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"recipient_token_account_0","docs":["The destination token account for receive amount_0"],"writable":true},{"name":"recipient_token_account_1","docs":["The destination token account for receive amount_1"],"writable":true},{"name":"token_program","docs":["SPL program to transfer out tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_min","type":"u64"},{"name":"amount_1_min","type":"u64"}]},{"name":"increase_liquidity","docs":["#[deprecated(note = \"Use `increase_liquidity_v2` instead.\")]","Increases liquidity for an existing position, with amount paid by `payer`","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The desired liquidity to be added, can't be zero","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check",""],"discriminator":[46,156,243,118,13,205,251,178],"accounts":[{"name":"nft_owner","docs":["Pays to mint the position"],"signer":true},{"name":"nft_account","docs":["The token account for nft"]},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"personal_position","docs":["Increase liquidity for this position"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"token_account_0","docs":["The payer's token account for token_0"],"writable":true},{"name":"token_account_1","docs":["The token account spending token_1 to mint the position"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"}]},{"name":"increase_liquidity_v2","docs":["Increases liquidity for an existing position, with amount paid by `payer`, support Token2022","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The desired liquidity to be added, if zero, calculate liquidity base amount_0 or amount_1 according base_flag","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check","* `base_flag` - must be specified if liquidity is zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max",""],"discriminator":[133,29,89,223,69,238,176,10],"accounts":[{"name":"nft_owner","docs":["Pays to mint the position"],"signer":true},{"name":"nft_account","docs":["The token account for nft"]},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"personal_position","docs":["Increase liquidity for this position"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"token_account_0","docs":["The payer's token account for token_0"],"writable":true},{"name":"token_account_1","docs":["The token account spending token_1 to mint the position"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"},{"name":"base_flag","type":{"option":"bool"}}]},{"name":"initialize_reward","docs":["Initialize a reward info for a given pool and reward index","","# Arguments","","* `ctx`- The context of accounts","* `reward_index` - the index to reward info","* `open_time` - reward open timestamp","* `end_time` - reward end timestamp","* `emissions_per_second_x64` - Token reward per second are earned per unit of liquidity.",""],"discriminator":[95,135,192,196,242,129,230,68],"accounts":[{"name":"reward_funder","docs":["The founder deposit reward token to vault"],"writable":true,"signer":true},{"name":"funder_token_account","writable":true},{"name":"amm_config","docs":["For check the reward_funder authority"]},{"name":"pool_state","docs":["Set reward for this pool"],"writable":true},{"name":"operation_state","docs":["load info from the account to judge reward permission"],"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"permissionless_farm_switch","pda":{"seeds":[{"kind":"const","value":[112,101,114,109,105,115,115,105,111,110,108,101,115,115,95,102,97,114,109,95,115,119,105,116,99,104]}]}},{"name":"reward_token_mint","docs":["Reward mint"]},{"name":"reward_token_vault","docs":["A pda, reward vault"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,114,101,119,97,114,100,95,118,97,117,108,116]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"reward_token_mint"}]}},{"name":"reward_token_program"},{"name":"system_program","address":"11111111111111111111111111111111"},{"name":"rent","address":"SysvarRent111111111111111111111111111111111"}],"args":[{"name":"param","type":{"defined":{"name":"InitializeRewardParam"}}}]},{"name":"open_position","docs":["#[deprecated(note = \"Use `open_position_with_token22_nft` instead.\")]","Creates a new position wrapped in a NFT","","# Arguments","","* `ctx` - The context of accounts","* `tick_lower_index` - The low boundary of market","* `tick_upper_index` - The upper boundary of market","* `tick_array_lower_start_index` - The start index of tick array which include tick low","* `tick_array_upper_start_index` - The start index of tick array which include tick upper","* `liquidity` - The liquidity to be added","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check",""],"discriminator":[135,128,47,77,15,152,240,49],"accounts":[{"name":"payer","docs":["Pays to mint the position"],"writable":true,"signer":true},{"name":"position_nft_owner"},{"name":"position_nft_mint","docs":["Unique token mint address"],"writable":true,"signer":true},{"name":"position_nft_account","docs":["Token account where position NFT will be minted","This account created in the contract by cpi to avoid large stack variables"],"writable":true,"pda":{"seeds":[{"kind":"account","path":"position_nft_owner"},{"kind":"const","value":[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{"kind":"account","path":"position_nft_mint"}],"program":{"kind":"const","value":[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{"name":"metadata_account","docs":["To store metaplex metadata"],"writable":true},{"name":"pool_state","docs":["Add liquidity for this pool"],"writable":true},{"name":"protocol_position","docs":["Store the information of market marking in range"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_lower_index"},{"kind":"arg","path":"tick_upper_index"}]}},{"name":"tick_array_lower","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_lower_start_index"}]}},{"name":"tick_array_upper","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_upper_start_index"}]}},{"name":"personal_position","docs":["personal position state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"token_account_0","docs":["The token_0 account deposit token to the pool"],"writable":true},{"name":"token_account_1","docs":["The token_1 account deposit token to the pool"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"rent","docs":["Sysvar for token mint and ATA creation"],"address":"SysvarRent111111111111111111111111111111111"},{"name":"system_program","docs":["Program to create the position manager state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"associated_token_program","docs":["Program to create an ATA for receiving position NFT"],"address":"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{"name":"metadata_program","docs":["Program to create NFT metadata"],"address":"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"}],"args":[{"name":"tick_lower_index","type":"i32"},{"name":"tick_upper_index","type":"i32"},{"name":"tick_array_lower_start_index","type":"i32"},{"name":"tick_array_upper_start_index","type":"i32"},{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"}]},{"name":"open_position_v2","docs":["#[deprecated(note = \"Use `open_position_with_token22_nft` instead.\")]","Creates a new position wrapped in a NFT, support Token2022","","# Arguments","","* `ctx` - The context of accounts","* `tick_lower_index` - The low boundary of market","* `tick_upper_index` - The upper boundary of market","* `tick_array_lower_start_index` - The start index of tick array which include tick low","* `tick_array_upper_start_index` - The start index of tick array which include tick upper","* `liquidity` - The liquidity to be added, if zero, and the base_flag is specified, calculate liquidity base amount_0_max or amount_1_max according base_flag, otherwise open position with zero liquidity","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check","* `with_metadata` - The flag indicating whether to create NFT mint metadata","* `base_flag` - if the liquidity specified as zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max",""],"discriminator":[77,184,74,214,112,86,241,199],"accounts":[{"name":"payer","docs":["Pays to mint the position"],"writable":true,"signer":true},{"name":"position_nft_owner"},{"name":"position_nft_mint","docs":["Unique token mint address"],"writable":true,"signer":true},{"name":"position_nft_account","docs":["Token account where position NFT will be minted"],"writable":true,"pda":{"seeds":[{"kind":"account","path":"position_nft_owner"},{"kind":"const","value":[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{"kind":"account","path":"position_nft_mint"}],"program":{"kind":"const","value":[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{"name":"metadata_account","docs":["To store metaplex metadata"],"writable":true},{"name":"pool_state","docs":["Add liquidity for this pool"],"writable":true},{"name":"protocol_position","docs":["Store the information of market marking in range"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_lower_index"},{"kind":"arg","path":"tick_upper_index"}]}},{"name":"tick_array_lower","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_lower_start_index"}]}},{"name":"tick_array_upper","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_upper_start_index"}]}},{"name":"personal_position","docs":["personal position state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"token_account_0","docs":["The token_0 account deposit token to the pool"],"writable":true},{"name":"token_account_1","docs":["The token_1 account deposit token to the pool"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"rent","docs":["Sysvar for token mint and ATA creation"],"address":"SysvarRent111111111111111111111111111111111"},{"name":"system_program","docs":["Program to create the position manager state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"associated_token_program","docs":["Program to create an ATA for receiving position NFT"],"address":"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{"name":"metadata_program","docs":["Program to create NFT metadata"],"address":"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"},{"name":"token_program_2022","docs":["Program to create mint account and mint tokens"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"tick_lower_index","type":"i32"},{"name":"tick_upper_index","type":"i32"},{"name":"tick_array_lower_start_index","type":"i32"},{"name":"tick_array_upper_start_index","type":"i32"},{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"},{"name":"with_metadata","type":"bool"},{"name":"base_flag","type":{"option":"bool"}}]},{"name":"open_position_with_token22_nft","docs":["Creates a new position wrapped in a Token2022 NFT without relying on metadata_program and metadata_account, reduce the cost for user to create a personal position.","","# Arguments","","* `ctx` - The context of accounts","* `tick_lower_index` - The low boundary of market","* `tick_upper_index` - The upper boundary of market","* `tick_array_lower_start_index` - The start index of tick array which include tick low","* `tick_array_upper_start_index` - The start index of tick array which include tick upper","* `liquidity` - The liquidity to be added, if zero, and the base_flag is specified, calculate liquidity base amount_0_max or amount_1_max according base_flag, otherwise open position with zero liquidity","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check","* `with_metadata` - The flag indicating whether to create NFT mint metadata","* `base_flag` - if the liquidity specified as zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max",""],"discriminator":[77,255,174,82,125,29,201,46],"accounts":[{"name":"payer","docs":["Pays to mint the position"],"writable":true,"signer":true},{"name":"position_nft_owner"},{"name":"position_nft_mint","docs":["Unique token mint address, initialize in contract"],"writable":true,"signer":true},{"name":"position_nft_account","writable":true},{"name":"pool_state","docs":["Add liquidity for this pool"],"writable":true},{"name":"protocol_position","docs":["Store the information of market marking in range"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_lower_index"},{"kind":"arg","path":"tick_upper_index"}]}},{"name":"tick_array_lower","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_lower_start_index"}]}},{"name":"tick_array_upper","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_upper_start_index"}]}},{"name":"personal_position","docs":["personal position state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"token_account_0","docs":["The token_0 account deposit token to the pool"],"writable":true},{"name":"token_account_1","docs":["The token_1 account deposit token to the pool"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"rent","docs":["Sysvar for token mint and ATA creation"],"address":"SysvarRent111111111111111111111111111111111"},{"name":"system_program","docs":["Program to create the position manager state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Program to transfer for token account"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"associated_token_program","docs":["Program to create an ATA for receiving position NFT"],"address":"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{"name":"token_program_2022","docs":["Program to create NFT mint/token account and transfer for token22 account"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"tick_lower_index","type":"i32"},{"name":"tick_upper_index","type":"i32"},{"name":"tick_array_lower_start_index","type":"i32"},{"name":"tick_array_upper_start_index","type":"i32"},{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"},{"name":"with_metadata","type":"bool"},{"name":"base_flag","type":{"option":"bool"}}]},{"name":"set_reward_params","docs":["Reset reward param, start a new reward cycle or extend the current cycle.","","# Arguments","","* `ctx` - The context of accounts","* `reward_index` - The index of reward token in the pool.","* `emissions_per_second_x64` - The per second emission reward, when extend the current cycle,","new value can't be less than old value","* `open_time` - reward open timestamp, must be set when starting a new cycle","* `end_time` - reward end timestamp",""],"discriminator":[112,52,167,75,32,201,211,137],"accounts":[{"name":"authority","docs":["Address to be set as protocol owner. It pays to create factory state account."],"signer":true},{"name":"amm_config"},{"name":"pool_state","writable":true},{"name":"operation_state","docs":["load info from the account to judge reward permission"],"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"token_program","docs":["Token program"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"}],"args":[{"name":"reward_index","type":"u8"},{"name":"emissions_per_second_x64","type":"u128"},{"name":"open_time","type":"u64"},{"name":"end_time","type":"u64"}]},{"name":"swap","docs":["#[deprecated(note = \"Use `swap_v2` instead.\")]","Swaps one token for as much as possible of another token across a single pool","","# Arguments","","* `ctx` - The context of accounts","* `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum)","* `other_amount_threshold` - For slippage check","* `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot","* `is_base_input` - swap base input or swap base output",""],"discriminator":[248,198,158,145,225,117,135,200],"accounts":[{"name":"payer","docs":["The user performing the swap"],"signer":true},{"name":"amm_config","docs":["The factory state to read protocol fees"]},{"name":"pool_state","docs":["The program account of the pool in which the swap will be performed"],"writable":true},{"name":"input_token_account","docs":["The user token account for input token"],"writable":true},{"name":"output_token_account","docs":["The user token account for output token"],"writable":true},{"name":"input_vault","docs":["The vault token account for input token"],"writable":true},{"name":"output_vault","docs":["The vault token account for output token"],"writable":true},{"name":"observation_state","docs":["The program account for the most recent oracle observation"],"writable":true},{"name":"token_program","docs":["SPL program for token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"tick_array","writable":true}],"args":[{"name":"amount","type":"u64"},{"name":"other_amount_threshold","type":"u64"},{"name":"sqrt_price_limit_x64","type":"u128"},{"name":"is_base_input","type":"bool"}]},{"name":"swap_router_base_in","docs":["Swap token for as much as possible of another token across the path provided, base input","","# Arguments","","* `ctx` - The context of accounts","* `amount_in` - Token amount to be swapped in","* `amount_out_minimum` - Panic if output amount is below minimum amount. For slippage.",""],"discriminator":[69,125,115,218,245,186,242,196],"accounts":[{"name":"payer","docs":["The user performing the swap"],"signer":true},{"name":"input_token_account","docs":["The token account that pays input tokens for the swap"],"writable":true},{"name":"input_token_mint","docs":["The mint of input token"],"writable":true},{"name":"token_program","docs":["SPL program for token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["SPL program 2022 for token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["Memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"}],"args":[{"name":"amount_in","type":"u64"},{"name":"amount_out_minimum","type":"u64"}]},{"name":"swap_v2","docs":["Swaps one token for as much as possible of another token across a single pool, support token program 2022","","# Arguments","","* `ctx` - The context of accounts","* `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum)","* `other_amount_threshold` - For slippage check","* `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot","* `is_base_input` - swap base input or swap base output",""],"discriminator":[43,4,237,11,26,201,30,98],"accounts":[{"name":"payer","docs":["The user performing the swap"],"signer":true},{"name":"amm_config","docs":["The factory state to read protocol fees"]},{"name":"pool_state","docs":["The program account of the pool in which the swap will be performed"],"writable":true},{"name":"input_token_account","docs":["The user token account for input token"],"writable":true},{"name":"output_token_account","docs":["The user token account for output token"],"writable":true},{"name":"input_vault","docs":["The vault token account for input token"],"writable":true},{"name":"output_vault","docs":["The vault token account for output token"],"writable":true},{"name":"observation_state","docs":["The program account for the most recent oracle observation"],"writable":true},{"name":"token_program","docs":["SPL program for token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["SPL program 2022 for token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["Memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"},{"name":"input_vault_mint","docs":["The mint of token vault 0"]},{"name":"output_vault_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"amount","type":"u64"},{"name":"other_amount_threshold","type":"u64"},{"name":"sqrt_price_limit_x64","type":"u128"},{"name":"is_base_input","type":"bool"}]},{"name":"toggle_permissionless_farm_switch","docs":["Toggle the permissionless farm switch account","","# Arguments","","* `ctx`- The context of accounts","* `is_on`- Is the permissionless farm allowed or not",""],"discriminator":[150,112,54,233,238,161,7,86],"accounts":[{"name":"owner","writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"permissionless_farm_switch","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,101,114,109,105,115,115,105,111,110,108,101,115,115,95,102,97,114,109,95,115,119,105,116,99,104]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[{"name":"is_on","type":"bool"}]},{"name":"transfer_reward_owner","docs":["Transfer reward owner","","# Arguments","","* `ctx`- The context of accounts","* `new_owner`- new owner pubkey",""],"discriminator":[7,22,12,83,242,43,48,121],"accounts":[{"name":"authority","docs":["Address to be set as operation account owner."],"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"pool_state","writable":true}],"args":[{"name":"new_owner","type":"pubkey"}]},{"name":"update_amm_config","docs":["Updates the owner of the amm config","Must be called by the current owner or admin","","# Arguments","","* `ctx`- The context of accounts","* `trade_fee_rate`- The new trade fee rate of amm config, be set when `param` is 0","* `protocol_fee_rate`- The new protocol fee rate of amm config, be set when `param` is 1","* `fund_fee_rate`- The new fund fee rate of amm config, be set when `param` is 2","* `new_owner`- The config's new owner, be set when `param` is 3","* `new_fund_owner`- The config's new fund owner, be set when `param` is 4","* `param`- The value can be 0 | 1 | 2 | 3 | 4, otherwise will report a error",""],"discriminator":[49,60,174,136,154,28,116,200],"accounts":[{"name":"owner","docs":["The amm config owner or admin"],"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"amm_config","docs":["Amm config account to be changed"],"writable":true}],"args":[{"name":"param","type":"u8"},{"name":"value","type":"u32"}]},{"name":"update_operation_account","docs":["Update the operation account","","# Arguments","","* `ctx`- The context of accounts","* `param`- The value can be 0 | 1 | 2 | 3, otherwise will report a error","* `keys`- update operation owner when the `param` is 0","remove operation owner when the `param` is 1","update whitelist mint when the `param` is 2","remove whitelist mint when the `param` is 3",""],"discriminator":[127,70,119,40,188,227,61,7],"accounts":[{"name":"owner","docs":["Address to be set as operation account owner."],"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"operation_state","docs":["Initialize operation state account to store operation owner address and white list mint."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[{"name":"param","type":"u8"},{"name":"keys","type":{"vec":"pubkey"}}]},{"name":"update_pool_status","docs":["Update pool status for given value","","# Arguments","","* `ctx`- The context of accounts","* `status` - The value of status",""],"discriminator":[130,87,108,6,46,224,117,123],"accounts":[{"name":"authority","signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"pool_state","writable":true}],"args":[{"name":"status","type":"u8"}]},{"name":"update_reward_infos","docs":["Update rewards info of the given pool, can be called for everyone","","# Arguments","","* `ctx`- The context of accounts",""],"discriminator":[163,172,224,52,11,154,106,223],"accounts":[{"name":"pool_state","docs":["The liquidity pool for which reward info to update"],"writable":true}],"args":[]}],"accounts":[{"name":"AmmConfig","discriminator":[218,244,33,104,203,203,43,111]},{"name":"ObservationState","discriminator":[122,174,197,53,129,9,165,132]},{"name":"OperationState","discriminator":[19,236,58,237,81,222,183,252]},{"name":"PermissionlessFarmSwitch","discriminator":[37,92,147,78,250,100,147,137]},{"name":"PersonalPositionState","discriminator":[70,111,150,126,230,15,25,117]},{"name":"PoolState","discriminator":[247,237,227,245,215,195,222,70]},{"name":"ProtocolPositionState","discriminator":[100,226,145,99,146,218,160,106]},{"name":"SupportMintAssociated","discriminator":[134,40,183,79,12,112,162,53]},{"name":"TickArrayBitmapExtension","discriminator":[60,150,36,219,97,128,139,153]},{"name":"TickArrayState","discriminator":[192,155,85,205,49,249,129,42]}],"events":[{"name":"CollectPersonalFeeEvent","discriminator":[166,174,105,192,81,161,83,105]},{"name":"CollectProtocolFeeEvent","discriminator":[206,87,17,79,45,41,213,61]},{"name":"ConfigChangeEvent","discriminator":[247,189,7,119,106,112,95,151]},{"name":"CreatePersonalPositionEvent","discriminator":[100,30,87,249,196,223,154,206]},{"name":"DecreaseLiquidityEvent","discriminator":[58,222,86,58,68,50,85,56]},{"name":"IncreaseLiquidityEvent","discriminator":[49,79,105,212,32,34,30,84]},{"name":"LiquidityCalculateEvent","discriminator":[237,112,148,230,57,84,180,162]},{"name":"LiquidityChangeEvent","discriminator":[126,240,175,206,158,88,153,107]},{"name":"PoolCreatedEvent","discriminator":[25,94,75,47,112,99,53,63]},{"name":"SwapEvent","discriminator":[64,198,205,232,38,8,113,226]},{"name":"UpdateRewardInfosEvent","discriminator":[109,127,186,78,114,65,37,236]}],"errors":[{"code":6000,"name":"LOK","msg":"LOK"},{"code":6001,"name":"NotApproved","msg":"Not approved"},{"code":6002,"name":"InvalidUpdateConfigFlag","msg":"invalid update amm config flag"},{"code":6003,"name":"AccountLack","msg":"Account lack"},{"code":6004,"name":"ClosePositionErr","msg":"Remove liquitity, collect fees owed and reward then you can close position account"},{"code":6005,"name":"ZeroMintAmount","msg":"Minting amount should be greater than 0"},{"code":6006,"name":"InvalidTickIndex","msg":"Tick out of range"},{"code":6007,"name":"TickInvalidOrder","msg":"The lower tick must be below the upper tick"},{"code":6008,"name":"TickLowerOverflow","msg":"The tick must be greater, or equal to the minimum tick(-443636)"},{"code":6009,"name":"TickUpperOverflow","msg":"The tick must be lesser than, or equal to the maximum tick(443636)"},{"code":6010,"name":"TickAndSpacingNotMatch","msg":"tick % tick_spacing must be zero"},{"code":6011,"name":"InvalidTickArray","msg":"Invalid tick array account"},{"code":6012,"name":"InvalidTickArrayBoundary","msg":"Invalid tick array boundary"},{"code":6013,"name":"SqrtPriceLimitOverflow","msg":"Square root price limit overflow"},{"code":6014,"name":"SqrtPriceX64","msg":"sqrt_price_x64 out of range"},{"code":6015,"name":"LiquiditySubValueErr","msg":"Liquidity sub delta L must be smaller than before"},{"code":6016,"name":"LiquidityAddValueErr","msg":"Liquidity add delta L must be greater, or equal to before"},{"code":6017,"name":"InvalidLiquidity","msg":"Invalid liquidity when update position"},{"code":6018,"name":"ForbidBothZeroForSupplyLiquidity","msg":"Both token amount must not be zero while supply liquidity"},{"code":6019,"name":"LiquidityInsufficient","msg":"Liquidity insufficient"},{"code":6020,"name":"TransactionTooOld","msg":"Transaction too old"},{"code":6021,"name":"PriceSlippageCheck","msg":"Price slippage check"},{"code":6022,"name":"TooLittleOutputReceived","msg":"Too little output received"},{"code":6023,"name":"TooMuchInputPaid","msg":"Too much input paid"},{"code":6024,"name":"ZeroAmountSpecified","msg":"Swap special amount can not be zero"},{"code":6025,"name":"InvalidInputPoolVault","msg":"Input pool vault is invalid"},{"code":6026,"name":"TooSmallInputOrOutputAmount","msg":"Swap input or output amount is too small"},{"code":6027,"name":"NotEnoughTickArrayAccount","msg":"Not enought tick array account"},{"code":6028,"name":"InvalidFirstTickArrayAccount","msg":"Invalid first tick array account"},{"code":6029,"name":"InvalidRewardIndex","msg":"Invalid reward index"},{"code":6030,"name":"FullRewardInfo","msg":"The init reward token reach to the max"},{"code":6031,"name":"RewardTokenAlreadyInUse","msg":"The init reward token already in use"},{"code":6032,"name":"ExceptRewardMint","msg":"The reward tokens must contain one of pool vault mint except the last reward"},{"code":6033,"name":"InvalidRewardInitParam","msg":"Invalid reward init param"},{"code":6034,"name":"InvalidRewardDesiredAmount","msg":"Invalid collect reward desired amount"},{"code":6035,"name":"InvalidRewardInputAccountNumber","msg":"Invalid collect reward input account number"},{"code":6036,"name":"InvalidRewardPeriod","msg":"Invalid reward period"},{"code":6037,"name":"NotApproveUpdateRewardEmissiones","msg":"Modification of emissiones is allowed within 72 hours from the end of the previous cycle"},{"code":6038,"name":"UnInitializedRewardInfo","msg":"uninitialized reward info"},{"code":6039,"name":"NotSupportMint","msg":"Not support token_2022 mint extension"},{"code":6040,"name":"MissingTickArrayBitmapExtensionAccount","msg":"Missing tickarray bitmap extension account"},{"code":6041,"name":"InsufficientLiquidityForDirection","msg":"Insufficient liquidity for this direction"},{"code":6042,"name":"MaxTokenOverflow","msg":"Max token overflow"},{"code":6043,"name":"CalculateOverflow","msg":"Calculate overflow"},{"code":6044,"name":"TransferFeeCalculateNotMatch","msg":"TransferFee calculate not match"}],"types":[{"name":"AmmConfig","docs":["Holds the current owner of the factory"],"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"index","type":"u16"},{"name":"owner","docs":["Address of the protocol owner"],"type":"pubkey"},{"name":"protocol_fee_rate","docs":["The protocol fee"],"type":"u32"},{"name":"trade_fee_rate","docs":["The trade fee, denominated in hundredths of a bip (10^-6)"],"type":"u32"},{"name":"tick_spacing","docs":["The tick spacing"],"type":"u16"},{"name":"fund_fee_rate","docs":["The fund fee, denominated in hundredths of a bip (10^-6)"],"type":"u32"},{"name":"padding_u32","type":"u32"},{"name":"fund_owner","type":"pubkey"},{"name":"padding","type":{"array":["u64",3]}}]}},{"name":"CollectPersonalFeeEvent","docs":["Emitted when tokens are collected for a position"],"type":{"kind":"struct","fields":[{"name":"position_nft_mint","docs":["The ID of the token for which underlying tokens were collected"],"type":"pubkey"},{"name":"recipient_token_account_0","docs":["The token account that received the collected token_0 tokens"],"type":"pubkey"},{"name":"recipient_token_account_1","docs":["The token account that received the collected token_1 tokens"],"type":"pubkey"},{"name":"amount_0","docs":["The amount of token_0 owed to the position that was collected"],"type":"u64"},{"name":"amount_1","docs":["The amount of token_1 owed to the position that was collected"],"type":"u64"}]}},{"name":"CollectProtocolFeeEvent","docs":["Emitted when the collected protocol fees are withdrawn by the factory owner"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool whose protocol fee is collected"],"type":"pubkey"},{"name":"recipient_token_account_0","docs":["The address that receives the collected token_0 protocol fees"],"type":"pubkey"},{"name":"recipient_token_account_1","docs":["The address that receives the collected token_1 protocol fees"],"type":"pubkey"},{"name":"amount_0","docs":["The amount of token_0 protocol fees that is withdrawn"],"type":"u64"},{"name":"amount_1","docs":["The amount of token_0 protocol fees that is withdrawn"],"type":"u64"}]}},{"name":"ConfigChangeEvent","docs":["Emitted when create or update a config"],"type":{"kind":"struct","fields":[{"name":"index","type":"u16"},{"name":"owner","type":"pubkey"},{"name":"protocol_fee_rate","type":"u32"},{"name":"trade_fee_rate","type":"u32"},{"name":"tick_spacing","type":"u16"},{"name":"fund_fee_rate","type":"u32"},{"name":"fund_owner","type":"pubkey"}]}},{"name":"CreatePersonalPositionEvent","docs":["Emitted when create a new position"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool for which liquidity was added"],"type":"pubkey"},{"name":"minter","docs":["The address that create the position"],"type":"pubkey"},{"name":"nft_owner","docs":["The owner of the position and recipient of any minted liquidity"],"type":"pubkey"},{"name":"tick_lower_index","docs":["The lower tick of the position"],"type":"i32"},{"name":"tick_upper_index","docs":["The upper tick of the position"],"type":"i32"},{"name":"liquidity","docs":["The amount of liquidity minted to the position range"],"type":"u128"},{"name":"deposit_amount_0","docs":["The amount of token_0 was deposit for the liquidity"],"type":"u64"},{"name":"deposit_amount_1","docs":["The amount of token_1 was deposit for the liquidity"],"type":"u64"},{"name":"deposit_amount_0_transfer_fee","docs":["The token transfer fee for deposit_amount_0"],"type":"u64"},{"name":"deposit_amount_1_transfer_fee","docs":["The token transfer fee for deposit_amount_1"],"type":"u64"}]}},{"name":"DecreaseLiquidityEvent","docs":["Emitted when liquidity is decreased."],"type":{"kind":"struct","fields":[{"name":"position_nft_mint","docs":["The ID of the token for which liquidity was decreased"],"type":"pubkey"},{"name":"liquidity","docs":["The amount by which liquidity for the position was decreased"],"type":"u128"},{"name":"decrease_amount_0","docs":["The amount of token_0 that was paid for the decrease in liquidity"],"type":"u64"},{"name":"decrease_amount_1","docs":["The amount of token_1 that was paid for the decrease in liquidity"],"type":"u64"},{"name":"fee_amount_0","type":"u64"},{"name":"fee_amount_1","docs":["The amount of token_1 fee"],"type":"u64"},{"name":"reward_amounts","docs":["The amount of rewards"],"type":{"array":["u64",3]}},{"name":"transfer_fee_0","docs":["The amount of token_0 transfer fee"],"type":"u64"},{"name":"transfer_fee_1","docs":["The amount of token_1 transfer fee"],"type":"u64"}]}},{"name":"IncreaseLiquidityEvent","docs":["Emitted when liquidity is increased."],"type":{"kind":"struct","fields":[{"name":"position_nft_mint","docs":["The ID of the token for which liquidity was increased"],"type":"pubkey"},{"name":"liquidity","docs":["The amount by which liquidity for the NFT position was increased"],"type":"u128"},{"name":"amount_0","docs":["The amount of token_0 that was paid for the increase in liquidity"],"type":"u64"},{"name":"amount_1","docs":["The amount of token_1 that was paid for the increase in liquidity"],"type":"u64"},{"name":"amount_0_transfer_fee","docs":["The token transfer fee for amount_0"],"type":"u64"},{"name":"amount_1_transfer_fee","docs":["The token transfer fee for amount_1"],"type":"u64"}]}},{"name":"InitializeRewardParam","type":{"kind":"struct","fields":[{"name":"open_time","docs":["Reward open time"],"type":"u64"},{"name":"end_time","docs":["Reward end time"],"type":"u64"},{"name":"emissions_per_second_x64","docs":["Token reward per second are earned per unit of liquidity"],"type":"u128"}]}},{"name":"LiquidityCalculateEvent","docs":["Emitted when liquidity decreased or increase."],"type":{"kind":"struct","fields":[{"name":"pool_liquidity","docs":["The pool liquidity before decrease or increase"],"type":"u128"},{"name":"pool_sqrt_price_x64","docs":["The pool price when decrease or increase in liquidity"],"type":"u128"},{"name":"pool_tick","docs":["The pool tick when decrease or increase in liquidity"],"type":"i32"},{"name":"calc_amount_0","docs":["The amount of token_0 that was calculated for the decrease or increase in liquidity"],"type":"u64"},{"name":"calc_amount_1","docs":["The amount of token_1 that was calculated for the decrease or increase in liquidity"],"type":"u64"},{"name":"trade_fee_owed_0","type":"u64"},{"name":"trade_fee_owed_1","docs":["The amount of token_1 fee"],"type":"u64"},{"name":"transfer_fee_0","docs":["The amount of token_0 transfer fee without trade_fee_amount_0"],"type":"u64"},{"name":"transfer_fee_1","docs":["The amount of token_1 transfer fee without trade_fee_amount_0"],"type":"u64"}]}},{"name":"LiquidityChangeEvent","docs":["Emitted pool liquidity change when increase and decrease liquidity"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool for swap"],"type":"pubkey"},{"name":"tick","docs":["The tick of the pool"],"type":"i32"},{"name":"tick_lower","docs":["The tick lower of position"],"type":"i32"},{"name":"tick_upper","docs":["The tick lower of position"],"type":"i32"},{"name":"liquidity_before","docs":["The liquidity of the pool before liquidity change"],"type":"u128"},{"name":"liquidity_after","docs":["The liquidity of the pool after liquidity change"],"type":"u128"}]}},{"name":"Observation","docs":["The element of observations in ObservationState"],"serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"block_timestamp","docs":["The block timestamp of the observation"],"type":"u32"},{"name":"tick_cumulative","docs":["the cumulative of tick during the duration time"],"type":"i64"},{"name":"padding","docs":["padding for feature update"],"type":{"array":["u64",4]}}]}},{"name":"ObservationState","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"initialized","docs":["Whether the ObservationState is initialized"],"type":"bool"},{"name":"recent_epoch","docs":["recent update epoch"],"type":"u64"},{"name":"observation_index","docs":["the most-recently updated index of the observations array"],"type":"u16"},{"name":"pool_id","docs":["belongs to which pool"],"type":"pubkey"},{"name":"observations","docs":["observation array"],"type":{"array":[{"defined":{"name":"Observation"}},100]}},{"name":"padding","docs":["padding for feature update"],"type":{"array":["u64",4]}}]}},{"name":"OperationState","docs":["Holds the current owner of the factory"],"serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"operation_owners","docs":["Address of the operation owner"],"type":{"array":["pubkey",10]}},{"name":"whitelist_mints","docs":["The mint address of whitelist to emit reward"],"type":{"array":["pubkey",100]}}]}},{"name":"PermissionlessFarmSwitch","type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"is_on","docs":["Is the permissionless farm allowed or not"],"type":"bool"}]}},{"name":"PersonalPositionState","type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":{"array":["u8",1]}},{"name":"nft_mint","docs":["Mint address of the tokenized position"],"type":"pubkey"},{"name":"pool_id","docs":["The ID of the pool with which this token is connected"],"type":"pubkey"},{"name":"tick_lower_index","docs":["The lower bound tick of the position"],"type":"i32"},{"name":"tick_upper_index","docs":["The upper bound tick of the position"],"type":"i32"},{"name":"liquidity","docs":["The amount of liquidity owned by this position"],"type":"u128"},{"name":"fee_growth_inside_0_last_x64","docs":["The token_0 fee growth of the aggregate position as of the last action on the individual position"],"type":"u128"},{"name":"fee_growth_inside_1_last_x64","docs":["The token_1 fee growth of the aggregate position as of the last action on the individual position"],"type":"u128"},{"name":"token_fees_owed_0","docs":["The fees owed to the position owner in token_0, as of the last computation"],"type":"u64"},{"name":"token_fees_owed_1","docs":["The fees owed to the position owner in token_1, as of the last computation"],"type":"u64"},{"name":"reward_infos","type":{"array":[{"defined":{"name":"PositionRewardInfo"}},3]}},{"name":"recent_epoch","type":"u64"},{"name":"padding","type":{"array":["u64",7]}}]}},{"name":"PoolCreatedEvent","docs":["Emitted when a pool is created and initialized with a starting price",""],"type":{"kind":"struct","fields":[{"name":"token_mint_0","docs":["The first token of the pool by address sort order"],"type":"pubkey"},{"name":"token_mint_1","docs":["The second token of the pool by address sort order"],"type":"pubkey"},{"name":"tick_spacing","docs":["The minimum number of ticks between initialized ticks"],"type":"u16"},{"name":"pool_state","docs":["The address of the created pool"],"type":"pubkey"},{"name":"sqrt_price_x64","docs":["The initial sqrt price of the pool, as a Q64.64"],"type":"u128"},{"name":"tick","docs":["The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool"],"type":"i32"},{"name":"token_vault_0","docs":["Vault of token_0"],"type":"pubkey"},{"name":"token_vault_1","docs":["Vault of token_1"],"type":"pubkey"}]}},{"name":"PoolState","docs":["The pool state","","PDA of `[POOL_SEED, config, token_mint_0, token_mint_1]`",""],"serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":{"array":["u8",1]}},{"name":"amm_config","type":"pubkey"},{"name":"owner","type":"pubkey"},{"name":"token_mint_0","docs":["Token pair of the pool, where token_mint_0 address < token_mint_1 address"],"type":"pubkey"},{"name":"token_mint_1","type":"pubkey"},{"name":"token_vault_0","docs":["Token pair vault"],"type":"pubkey"},{"name":"token_vault_1","type":"pubkey"},{"name":"observation_key","docs":["observation account key"],"type":"pubkey"},{"name":"mint_decimals_0","docs":["mint0 and mint1 decimals"],"type":"u8"},{"name":"mint_decimals_1","type":"u8"},{"name":"tick_spacing","docs":["The minimum number of ticks between initialized ticks"],"type":"u16"},{"name":"liquidity","docs":["The currently in range liquidity available to the pool."],"type":"u128"},{"name":"sqrt_price_x64","docs":["The current price of the pool as a sqrt(token_1/token_0) Q64.64 value"],"type":"u128"},{"name":"tick_current","docs":["The current tick of the pool, i.e. according to the last tick transition that was run."],"type":"i32"},{"name":"padding3","type":"u16"},{"name":"padding4","type":"u16"},{"name":"fee_growth_global_0_x64","docs":["The fee growth as a Q64.64 number, i.e. fees of token_0 and token_1 collected per","unit of liquidity for the entire life of the pool."],"type":"u128"},{"name":"fee_growth_global_1_x64","type":"u128"},{"name":"protocol_fees_token_0","docs":["The amounts of token_0 and token_1 that are owed to the protocol."],"type":"u64"},{"name":"protocol_fees_token_1","type":"u64"},{"name":"swap_in_amount_token_0","docs":["The amounts in and out of swap token_0 and token_1"],"type":"u128"},{"name":"swap_out_amount_token_1","type":"u128"},{"name":"swap_in_amount_token_1","type":"u128"},{"name":"swap_out_amount_token_0","type":"u128"},{"name":"status","docs":["Bitwise representation of the state of the pool","bit0, 1: disable open position and increase liquidity, 0: normal","bit1, 1: disable decrease liquidity, 0: normal","bit2, 1: disable collect fee, 0: normal","bit3, 1: disable collect reward, 0: normal","bit4, 1: disable swap, 0: normal"],"type":"u8"},{"name":"padding","docs":["Leave blank for future use"],"type":{"array":["u8",7]}},{"name":"reward_infos","type":{"array":[{"defined":{"name":"RewardInfo"}},3]}},{"name":"tick_array_bitmap","docs":["Packed initialized tick array state"],"type":{"array":["u64",16]}},{"name":"total_fees_token_0","docs":["except protocol_fee and fund_fee"],"type":"u64"},{"name":"total_fees_claimed_token_0","docs":["except protocol_fee and fund_fee"],"type":"u64"},{"name":"total_fees_token_1","type":"u64"},{"name":"total_fees_claimed_token_1","type":"u64"},{"name":"fund_fees_token_0","type":"u64"},{"name":"fund_fees_token_1","type":"u64"},{"name":"open_time","type":"u64"},{"name":"recent_epoch","type":"u64"},{"name":"padding1","type":{"array":["u64",24]}},{"name":"padding2","type":{"array":["u64",32]}}]}},{"name":"PositionRewardInfo","type":{"kind":"struct","fields":[{"name":"growth_inside_last_x64","type":"u128"},{"name":"reward_amount_owed","type":"u64"}]}},{"name":"ProtocolPositionState","docs":["Info stored for each user's position"],"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"pool_id","docs":["The ID of the pool with which this token is connected"],"type":"pubkey"},{"name":"tick_lower_index","docs":["The lower bound tick of the position"],"type":"i32"},{"name":"tick_upper_index","docs":["The upper bound tick of the position"],"type":"i32"},{"name":"liquidity","docs":["The amount of liquidity owned by this position"],"type":"u128"},{"name":"fee_growth_inside_0_last_x64","docs":["The token_0 fee growth per unit of liquidity as of the last update to liquidity or fees owed"],"type":"u128"},{"name":"fee_growth_inside_1_last_x64","docs":["The token_1 fee growth per unit of liquidity as of the last update to liquidity or fees owed"],"type":"u128"},{"name":"token_fees_owed_0","docs":["The fees owed to the position owner in token_0"],"type":"u64"},{"name":"token_fees_owed_1","docs":["The fees owed to the position owner in token_1"],"type":"u64"},{"name":"reward_growth_inside","docs":["The reward growth per unit of liquidity as of the last update to liquidity"],"type":{"array":["u128",3]}},{"name":"recent_epoch","type":"u64"},{"name":"padding","type":{"array":["u64",7]}}]}},{"name":"RewardInfo","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"reward_state","docs":["Reward state"],"type":"u8"},{"name":"open_time","docs":["Reward open time"],"type":"u64"},{"name":"end_time","docs":["Reward end time"],"type":"u64"},{"name":"last_update_time","docs":["Reward last update time"],"type":"u64"},{"name":"emissions_per_second_x64","docs":["Q64.64 number indicates how many tokens per second are earned per unit of liquidity."],"type":"u128"},{"name":"reward_total_emissioned","docs":["The total amount of reward emissioned"],"type":"u64"},{"name":"reward_claimed","docs":["The total amount of claimed reward"],"type":"u64"},{"name":"token_mint","docs":["Reward token mint."],"type":"pubkey"},{"name":"token_vault","docs":["Reward vault token account."],"type":"pubkey"},{"name":"authority","docs":["The owner that has permission to set reward param"],"type":"pubkey"},{"name":"reward_growth_global_x64","docs":["Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward","emissions were turned on."],"type":"u128"}]}},{"name":"SupportMintAssociated","docs":["Holds the current owner of the factory"],"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"mint","docs":["Address of the supported token22 mint"],"type":"pubkey"},{"name":"padding","type":{"array":["u64",8]}}]}},{"name":"SwapEvent","docs":["Emitted by when a swap is performed for a pool"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool for which token_0 and token_1 were swapped"],"type":"pubkey"},{"name":"sender","docs":["The address that initiated the swap call, and that received the callback"],"type":"pubkey"},{"name":"token_account_0","docs":["The payer token account in zero for one swaps, or the recipient token account","in one for zero swaps"],"type":"pubkey"},{"name":"token_account_1","docs":["The payer token account in one for zero swaps, or the recipient token account","in zero for one swaps"],"type":"pubkey"},{"name":"amount_0","docs":["The real delta amount of the token_0 of the pool or user"],"type":"u64"},{"name":"transfer_fee_0","docs":["The transfer fee charged by the withheld_amount of the token_0"],"type":"u64"},{"name":"amount_1","docs":["The real delta of the token_1 of the pool or user"],"type":"u64"},{"name":"transfer_fee_1","docs":["The transfer fee charged by the withheld_amount of the token_1"],"type":"u64"},{"name":"zero_for_one","docs":["if true, amount_0 is negtive and amount_1 is positive"],"type":"bool"},{"name":"sqrt_price_x64","docs":["The sqrt(price) of the pool after the swap, as a Q64.64"],"type":"u128"},{"name":"liquidity","docs":["The liquidity of the pool after the swap"],"type":"u128"},{"name":"tick","docs":["The log base 1.0001 of price of the pool after the swap"],"type":"i32"}]}},{"name":"TickArrayBitmapExtension","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"pool_id","type":"pubkey"},{"name":"positive_tick_array_bitmap","docs":["Packed initialized tick array state for start_tick_index is positive"],"type":{"array":[{"array":["u64",8]},14]}},{"name":"negative_tick_array_bitmap","docs":["Packed initialized tick array state for start_tick_index is negitive"],"type":{"array":[{"array":["u64",8]},14]}}]}},{"name":"TickArrayState","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"pool_id","type":"pubkey"},{"name":"start_tick_index","type":"i32"},{"name":"ticks","type":{"array":[{"defined":{"name":"TickState"}},60]}},{"name":"initialized_tick_count","type":"u8"},{"name":"recent_epoch","type":"u64"},{"name":"padding","type":{"array":["u8",107]}}]}},{"name":"TickState","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"tick","type":"i32"},{"name":"liquidity_net","docs":["Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)"],"type":"i128"},{"name":"liquidity_gross","docs":["The total position liquidity that references this tick"],"type":"u128"},{"name":"fee_growth_outside_0_x64","docs":["Fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)","only has relative meaning, not absolute — the value depends on when the tick is initialized"],"type":"u128"},{"name":"fee_growth_outside_1_x64","type":"u128"},{"name":"reward_growths_outside_x64","type":{"array":["u128",3]}},{"name":"padding","type":{"array":["u32",13]}}]}},{"name":"UpdateRewardInfosEvent","docs":["Emitted when Reward are updated for a pool"],"type":{"kind":"struct","fields":[{"name":"reward_growth_global_x64","docs":["Reward info"],"type":{"array":["u128",3]}}]}}]} \ No newline at end of file From a83937624365dcc0465a1bdac20b70f414892680 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Fri, 6 Nov 2026 14:55:02 +0200 Subject: [PATCH 14/20] chore(scenarios): indent the PancakeSwap IDL like the other bundled IDLs --- .../scenarios/protocols/pancakeswap/README.md | 10 +- .../protocols/pancakeswap/v1/idl.json | 5834 ++++++++++++++++- 2 files changed, 5841 insertions(+), 3 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index bf943b467..a88c2c7b5 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -93,5 +93,11 @@ Every pool on that tier shares the account, so the change reaches all of them. # IDL `v1/idl.json` is the IDL PancakeSwap publishes on chain in its Anchor IDL account -`CAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf`, unchanged (sha256 -`661eb632c441b2adb681ecd547fd8cea18e836be2305064e84b14bb90d7efb4c`), as written in slot 348011868. +`CAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf`, as written in slot 348011868, 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` | diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json b/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json index ca82772b4..97990f8f1 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/idl.json @@ -1 +1,5833 @@ -{"address":"HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq","metadata":{"name":"amm_v3","version":"0.1.0","spec":"0.1.0","description":"Anchor client and source for Pancake concentrated liquidity AMM"},"instructions":[{"name":"close_position","docs":["Close the user's position and NFT account. If the NFT mint belongs to token2022, it will also be closed and the funds returned to the NFT owner.","","# Arguments","","* `ctx` - The context of accounts",""],"discriminator":[123,134,81,0,49,68,98,98],"accounts":[{"name":"nft_owner","docs":["The position nft owner"],"writable":true,"signer":true},{"name":"position_nft_mint","docs":["Mint address bound to the personal position."],"writable":true},{"name":"position_nft_account","docs":["User token account where position NFT be minted to"],"writable":true},{"name":"personal_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"system_program","docs":["System program to close the position state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Token/Token2022 program to close token/mint account"]}],"args":[]},{"name":"collect_fund_fee","docs":["Collect the fund fee accrued to the pool","","# Arguments","","* `ctx` - The context of accounts","* `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1","* `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0",""],"discriminator":[167,138,78,149,223,194,6,126],"accounts":[{"name":"owner","docs":["Only admin or fund_owner can collect fee now"],"signer":true},{"name":"pool_state","docs":["Pool state stores accumulated protocol fee amount"],"writable":true},{"name":"amm_config","docs":["Amm config account stores fund_owner"]},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]},{"name":"recipient_token_account_0","docs":["The address that receives the collected token_0 protocol fees"],"writable":true},{"name":"recipient_token_account_1","docs":["The address that receives the collected token_1 protocol fees"],"writable":true},{"name":"token_program","docs":["The SPL program to perform token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["The SPL program 2022 to perform token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"}],"args":[{"name":"amount_0_requested","type":"u64"},{"name":"amount_1_requested","type":"u64"}]},{"name":"collect_protocol_fee","docs":["Collect the protocol fee accrued to the pool","","# Arguments","","* `ctx` - The context of accounts","* `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1","* `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0",""],"discriminator":[136,136,252,221,194,66,126,89],"accounts":[{"name":"owner","docs":["Only admin or config owner can collect fee now"],"signer":true},{"name":"pool_state","docs":["Pool state stores accumulated protocol fee amount"],"writable":true},{"name":"amm_config","docs":["Amm config account stores owner"]},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]},{"name":"recipient_token_account_0","docs":["The address that receives the collected token_0 protocol fees"],"writable":true},{"name":"recipient_token_account_1","docs":["The address that receives the collected token_1 protocol fees"],"writable":true},{"name":"token_program","docs":["The SPL program to perform token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["The SPL program 2022 to perform token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"}],"args":[{"name":"amount_0_requested","type":"u64"},{"name":"amount_1_requested","type":"u64"}]},{"name":"collect_remaining_rewards","docs":["Collect remaining reward token for reward founder","","# Arguments","","* `ctx`- The context of accounts","* `reward_index` - the index to reward info",""],"discriminator":[18,237,166,197,34,16,213,144],"accounts":[{"name":"reward_funder","docs":["The founder who init reward info previously"],"signer":true},{"name":"funder_token_account","docs":["The funder's reward token account"],"writable":true},{"name":"pool_state","docs":["Set reward for this pool"],"writable":true},{"name":"reward_token_vault","docs":["Reward vault transfer remaining token to founder token account"]},{"name":"reward_vault_mint","docs":["The mint of reward token vault"]},{"name":"token_program","address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"}],"args":[{"name":"reward_index","type":"u8"}]},{"name":"create_amm_config","docs":["# Arguments","","* `ctx`- The accounts needed by instruction.","* `index` - The index of amm config, there may be multiple config.","* `tick_spacing` - The tickspacing binding with config, cannot be changed.","* `trade_fee_rate` - Trade fee rate, can be changed.","* `protocol_fee_rate` - The rate of protocol fee within trade fee.","* `fund_fee_rate` - The rate of fund fee within trade fee.",""],"discriminator":[137,52,237,212,215,117,108,104],"accounts":[{"name":"owner","docs":["Address to be set as protocol owner."],"writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"amm_config","docs":["Initialize config state account to store protocol owner address and fee rates."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[97,109,109,95,99,111,110,102,105,103]},{"kind":"arg","path":"index"}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[{"name":"index","type":"u16"},{"name":"tick_spacing","type":"u16"},{"name":"trade_fee_rate","type":"u32"},{"name":"protocol_fee_rate","type":"u32"},{"name":"fund_fee_rate","type":"u32"}]},{"name":"create_operation_account","docs":["Creates an operation account for the program","","# Arguments","","* `ctx`- The context of accounts",""],"discriminator":[63,87,148,33,109,35,8,104],"accounts":[{"name":"owner","docs":["Address to be set as operation account owner."],"writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"operation_state","docs":["Initialize operation state account to store operation owner address and white list mint."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[]},{"name":"create_permissionless_farm_switch","docs":["Creates a permissionless farm switch account for the program","","# Arguments","","* `ctx`- The context of accounts",""],"discriminator":[88,242,198,70,241,6,196,251],"accounts":[{"name":"owner","writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"permissionless_farm_switch","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,101,114,109,105,115,115,105,111,110,108,101,115,115,95,102,97,114,109,95,115,119,105,116,99,104]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[]},{"name":"create_pool","docs":["Creates a pool for the given token pair and the initial price","","# Arguments","","* `ctx`- The context of accounts","* `sqrt_price_x64` - the initial sqrt price (amount_token_1 / amount_token_0) of the pool as a Q64.64","Note: The open_time must be smaller than the current block_timestamp on chain."],"discriminator":[233,146,209,142,207,104,64,188],"accounts":[{"name":"pool_creator","docs":["Address paying to create the pool. Can be anyone"],"writable":true,"signer":true},{"name":"amm_config","docs":["Which config the pool belongs to."]},{"name":"pool_state","docs":["Initialize an account to store the pool state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108]},{"kind":"account","path":"amm_config"},{"kind":"account","path":"token_mint_0"},{"kind":"account","path":"token_mint_1"}]}},{"name":"token_mint_0","docs":["Token_0 mint, the key must be smaller then token_1 mint."]},{"name":"token_mint_1","docs":["Token_1 mint"]},{"name":"token_vault_0","docs":["Token_0 vault for the pool"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,118,97,117,108,116]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"token_mint_0"}]}},{"name":"token_vault_1","docs":["Token_1 vault for the pool"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,118,97,117,108,116]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"token_mint_1"}]}},{"name":"observation_state","docs":["Initialize an account to store oracle observations"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[111,98,115,101,114,118,97,116,105,111,110]},{"kind":"account","path":"pool_state"}]}},{"name":"tick_array_bitmap","docs":["Initialize an account to store if a tick array is initialized."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,116,105,99,107,95,97,114,114,97,121,95,98,105,116,109,97,112,95,101,120,116,101,110,115,105,111,110]},{"kind":"account","path":"pool_state"}]}},{"name":"token_program_0","docs":["Spl token program or token program 2022"]},{"name":"token_program_1","docs":["Spl token program or token program 2022"]},{"name":"system_program","docs":["To create a new program account"],"address":"11111111111111111111111111111111"},{"name":"rent","docs":["Sysvar for program account"],"address":"SysvarRent111111111111111111111111111111111"}],"args":[{"name":"sqrt_price_x64","type":"u128"},{"name":"open_time","type":"u64"}]},{"name":"create_support_mint_associated","docs":["Create support token22 mint account which can create pool and send rewards with ignoring the not support extensions."],"discriminator":[17,251,65,92,136,242,14,169],"accounts":[{"name":"owner","docs":["Address to be set as protocol owner."],"writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"token_mint","docs":["Support token mint"]},{"name":"support_mint_associated","docs":["Initialize support mint state account to store support mint address and bump."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[115,117,112,112,111,114,116,95,109,105,110,116]},{"kind":"account","path":"token_mint"}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[]},{"name":"decrease_liquidity","docs":["#[deprecated(note = \"Use `decrease_liquidity_v2` instead.\")]","Decreases liquidity for an existing position","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The amount by which liquidity will be decreased","* `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity","* `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity",""],"discriminator":[160,38,208,111,104,91,44,1],"accounts":[{"name":"nft_owner","docs":["The position owner or delegated authority"],"signer":true},{"name":"nft_account","docs":["The token account for the tokenized position"]},{"name":"personal_position","docs":["Decrease liquidity for this position"],"writable":true},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"token_vault_0","docs":["Token_0 vault"],"writable":true},{"name":"token_vault_1","docs":["Token_1 vault"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"recipient_token_account_0","docs":["The destination token account for receive amount_0"],"writable":true},{"name":"recipient_token_account_1","docs":["The destination token account for receive amount_1"],"writable":true},{"name":"token_program","docs":["SPL program to transfer out tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_min","type":"u64"},{"name":"amount_1_min","type":"u64"}]},{"name":"decrease_liquidity_v2","docs":["Decreases liquidity for an existing position, support Token2022","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The amount by which liquidity will be decreased","* `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity","* `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity",""],"discriminator":[58,127,188,62,79,82,196,96],"accounts":[{"name":"nft_owner","docs":["The position owner or delegated authority"],"signer":true},{"name":"nft_account","docs":["The token account for the tokenized position"]},{"name":"personal_position","docs":["Decrease liquidity for this position"],"writable":true},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"token_vault_0","docs":["Token_0 vault"],"writable":true},{"name":"token_vault_1","docs":["Token_1 vault"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"recipient_token_account_0","docs":["The destination token account for receive amount_0"],"writable":true},{"name":"recipient_token_account_1","docs":["The destination token account for receive amount_1"],"writable":true},{"name":"token_program","docs":["SPL program to transfer out tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_min","type":"u64"},{"name":"amount_1_min","type":"u64"}]},{"name":"increase_liquidity","docs":["#[deprecated(note = \"Use `increase_liquidity_v2` instead.\")]","Increases liquidity for an existing position, with amount paid by `payer`","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The desired liquidity to be added, can't be zero","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check",""],"discriminator":[46,156,243,118,13,205,251,178],"accounts":[{"name":"nft_owner","docs":["Pays to mint the position"],"signer":true},{"name":"nft_account","docs":["The token account for nft"]},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"personal_position","docs":["Increase liquidity for this position"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"token_account_0","docs":["The payer's token account for token_0"],"writable":true},{"name":"token_account_1","docs":["The token account spending token_1 to mint the position"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"}]},{"name":"increase_liquidity_v2","docs":["Increases liquidity for an existing position, with amount paid by `payer`, support Token2022","","# Arguments","","* `ctx` - The context of accounts","* `liquidity` - The desired liquidity to be added, if zero, calculate liquidity base amount_0 or amount_1 according base_flag","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check","* `base_flag` - must be specified if liquidity is zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max",""],"discriminator":[133,29,89,223,69,238,176,10],"accounts":[{"name":"nft_owner","docs":["Pays to mint the position"],"signer":true},{"name":"nft_account","docs":["The token account for nft"]},{"name":"pool_state","writable":true},{"name":"protocol_position","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"personal_position.tick_lower_index","account":"PersonalPositionState"},{"kind":"account","path":"personal_position.tick_upper_index","account":"PersonalPositionState"}]}},{"name":"personal_position","docs":["Increase liquidity for this position"],"writable":true},{"name":"tick_array_lower","docs":["Stores init state for the lower tick"],"writable":true},{"name":"tick_array_upper","docs":["Stores init state for the upper tick"],"writable":true},{"name":"token_account_0","docs":["The payer's token account for token_0"],"writable":true},{"name":"token_account_1","docs":["The token account spending token_1 to mint the position"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"},{"name":"base_flag","type":{"option":"bool"}}]},{"name":"initialize_reward","docs":["Initialize a reward info for a given pool and reward index","","# Arguments","","* `ctx`- The context of accounts","* `reward_index` - the index to reward info","* `open_time` - reward open timestamp","* `end_time` - reward end timestamp","* `emissions_per_second_x64` - Token reward per second are earned per unit of liquidity.",""],"discriminator":[95,135,192,196,242,129,230,68],"accounts":[{"name":"reward_funder","docs":["The founder deposit reward token to vault"],"writable":true,"signer":true},{"name":"funder_token_account","writable":true},{"name":"amm_config","docs":["For check the reward_funder authority"]},{"name":"pool_state","docs":["Set reward for this pool"],"writable":true},{"name":"operation_state","docs":["load info from the account to judge reward permission"],"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"permissionless_farm_switch","pda":{"seeds":[{"kind":"const","value":[112,101,114,109,105,115,115,105,111,110,108,101,115,115,95,102,97,114,109,95,115,119,105,116,99,104]}]}},{"name":"reward_token_mint","docs":["Reward mint"]},{"name":"reward_token_vault","docs":["A pda, reward vault"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,111,108,95,114,101,119,97,114,100,95,118,97,117,108,116]},{"kind":"account","path":"pool_state"},{"kind":"account","path":"reward_token_mint"}]}},{"name":"reward_token_program"},{"name":"system_program","address":"11111111111111111111111111111111"},{"name":"rent","address":"SysvarRent111111111111111111111111111111111"}],"args":[{"name":"param","type":{"defined":{"name":"InitializeRewardParam"}}}]},{"name":"open_position","docs":["#[deprecated(note = \"Use `open_position_with_token22_nft` instead.\")]","Creates a new position wrapped in a NFT","","# Arguments","","* `ctx` - The context of accounts","* `tick_lower_index` - The low boundary of market","* `tick_upper_index` - The upper boundary of market","* `tick_array_lower_start_index` - The start index of tick array which include tick low","* `tick_array_upper_start_index` - The start index of tick array which include tick upper","* `liquidity` - The liquidity to be added","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check",""],"discriminator":[135,128,47,77,15,152,240,49],"accounts":[{"name":"payer","docs":["Pays to mint the position"],"writable":true,"signer":true},{"name":"position_nft_owner"},{"name":"position_nft_mint","docs":["Unique token mint address"],"writable":true,"signer":true},{"name":"position_nft_account","docs":["Token account where position NFT will be minted","This account created in the contract by cpi to avoid large stack variables"],"writable":true,"pda":{"seeds":[{"kind":"account","path":"position_nft_owner"},{"kind":"const","value":[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{"kind":"account","path":"position_nft_mint"}],"program":{"kind":"const","value":[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{"name":"metadata_account","docs":["To store metaplex metadata"],"writable":true},{"name":"pool_state","docs":["Add liquidity for this pool"],"writable":true},{"name":"protocol_position","docs":["Store the information of market marking in range"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_lower_index"},{"kind":"arg","path":"tick_upper_index"}]}},{"name":"tick_array_lower","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_lower_start_index"}]}},{"name":"tick_array_upper","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_upper_start_index"}]}},{"name":"personal_position","docs":["personal position state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"token_account_0","docs":["The token_0 account deposit token to the pool"],"writable":true},{"name":"token_account_1","docs":["The token_1 account deposit token to the pool"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"rent","docs":["Sysvar for token mint and ATA creation"],"address":"SysvarRent111111111111111111111111111111111"},{"name":"system_program","docs":["Program to create the position manager state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"associated_token_program","docs":["Program to create an ATA for receiving position NFT"],"address":"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{"name":"metadata_program","docs":["Program to create NFT metadata"],"address":"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"}],"args":[{"name":"tick_lower_index","type":"i32"},{"name":"tick_upper_index","type":"i32"},{"name":"tick_array_lower_start_index","type":"i32"},{"name":"tick_array_upper_start_index","type":"i32"},{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"}]},{"name":"open_position_v2","docs":["#[deprecated(note = \"Use `open_position_with_token22_nft` instead.\")]","Creates a new position wrapped in a NFT, support Token2022","","# Arguments","","* `ctx` - The context of accounts","* `tick_lower_index` - The low boundary of market","* `tick_upper_index` - The upper boundary of market","* `tick_array_lower_start_index` - The start index of tick array which include tick low","* `tick_array_upper_start_index` - The start index of tick array which include tick upper","* `liquidity` - The liquidity to be added, if zero, and the base_flag is specified, calculate liquidity base amount_0_max or amount_1_max according base_flag, otherwise open position with zero liquidity","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check","* `with_metadata` - The flag indicating whether to create NFT mint metadata","* `base_flag` - if the liquidity specified as zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max",""],"discriminator":[77,184,74,214,112,86,241,199],"accounts":[{"name":"payer","docs":["Pays to mint the position"],"writable":true,"signer":true},{"name":"position_nft_owner"},{"name":"position_nft_mint","docs":["Unique token mint address"],"writable":true,"signer":true},{"name":"position_nft_account","docs":["Token account where position NFT will be minted"],"writable":true,"pda":{"seeds":[{"kind":"account","path":"position_nft_owner"},{"kind":"const","value":[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{"kind":"account","path":"position_nft_mint"}],"program":{"kind":"const","value":[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{"name":"metadata_account","docs":["To store metaplex metadata"],"writable":true},{"name":"pool_state","docs":["Add liquidity for this pool"],"writable":true},{"name":"protocol_position","docs":["Store the information of market marking in range"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_lower_index"},{"kind":"arg","path":"tick_upper_index"}]}},{"name":"tick_array_lower","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_lower_start_index"}]}},{"name":"tick_array_upper","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_upper_start_index"}]}},{"name":"personal_position","docs":["personal position state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"token_account_0","docs":["The token_0 account deposit token to the pool"],"writable":true},{"name":"token_account_1","docs":["The token_1 account deposit token to the pool"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"rent","docs":["Sysvar for token mint and ATA creation"],"address":"SysvarRent111111111111111111111111111111111"},{"name":"system_program","docs":["Program to create the position manager state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Program to create mint account and mint tokens"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"associated_token_program","docs":["Program to create an ATA for receiving position NFT"],"address":"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{"name":"metadata_program","docs":["Program to create NFT metadata"],"address":"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"},{"name":"token_program_2022","docs":["Program to create mint account and mint tokens"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"tick_lower_index","type":"i32"},{"name":"tick_upper_index","type":"i32"},{"name":"tick_array_lower_start_index","type":"i32"},{"name":"tick_array_upper_start_index","type":"i32"},{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"},{"name":"with_metadata","type":"bool"},{"name":"base_flag","type":{"option":"bool"}}]},{"name":"open_position_with_token22_nft","docs":["Creates a new position wrapped in a Token2022 NFT without relying on metadata_program and metadata_account, reduce the cost for user to create a personal position.","","# Arguments","","* `ctx` - The context of accounts","* `tick_lower_index` - The low boundary of market","* `tick_upper_index` - The upper boundary of market","* `tick_array_lower_start_index` - The start index of tick array which include tick low","* `tick_array_upper_start_index` - The start index of tick array which include tick upper","* `liquidity` - The liquidity to be added, if zero, and the base_flag is specified, calculate liquidity base amount_0_max or amount_1_max according base_flag, otherwise open position with zero liquidity","* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check","* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check","* `with_metadata` - The flag indicating whether to create NFT mint metadata","* `base_flag` - if the liquidity specified as zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max",""],"discriminator":[77,255,174,82,125,29,201,46],"accounts":[{"name":"payer","docs":["Pays to mint the position"],"writable":true,"signer":true},{"name":"position_nft_owner"},{"name":"position_nft_mint","docs":["Unique token mint address, initialize in contract"],"writable":true,"signer":true},{"name":"position_nft_account","writable":true},{"name":"pool_state","docs":["Add liquidity for this pool"],"writable":true},{"name":"protocol_position","docs":["Store the information of market marking in range"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_lower_index"},{"kind":"arg","path":"tick_upper_index"}]}},{"name":"tick_array_lower","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_lower_start_index"}]}},{"name":"tick_array_upper","writable":true,"pda":{"seeds":[{"kind":"const","value":[116,105,99,107,95,97,114,114,97,121]},{"kind":"account","path":"pool_state"},{"kind":"arg","path":"tick_array_upper_start_index"}]}},{"name":"personal_position","docs":["personal position state"],"writable":true,"pda":{"seeds":[{"kind":"const","value":[112,111,115,105,116,105,111,110]},{"kind":"account","path":"position_nft_mint"}]}},{"name":"token_account_0","docs":["The token_0 account deposit token to the pool"],"writable":true},{"name":"token_account_1","docs":["The token_1 account deposit token to the pool"],"writable":true},{"name":"token_vault_0","docs":["The address that holds pool tokens for token_0"],"writable":true},{"name":"token_vault_1","docs":["The address that holds pool tokens for token_1"],"writable":true},{"name":"rent","docs":["Sysvar for token mint and ATA creation"],"address":"SysvarRent111111111111111111111111111111111"},{"name":"system_program","docs":["Program to create the position manager state account"],"address":"11111111111111111111111111111111"},{"name":"token_program","docs":["Program to transfer for token account"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"associated_token_program","docs":["Program to create an ATA for receiving position NFT"],"address":"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{"name":"token_program_2022","docs":["Program to create NFT mint/token account and transfer for token22 account"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"vault_0_mint","docs":["The mint of token vault 0"]},{"name":"vault_1_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"tick_lower_index","type":"i32"},{"name":"tick_upper_index","type":"i32"},{"name":"tick_array_lower_start_index","type":"i32"},{"name":"tick_array_upper_start_index","type":"i32"},{"name":"liquidity","type":"u128"},{"name":"amount_0_max","type":"u64"},{"name":"amount_1_max","type":"u64"},{"name":"with_metadata","type":"bool"},{"name":"base_flag","type":{"option":"bool"}}]},{"name":"set_reward_params","docs":["Reset reward param, start a new reward cycle or extend the current cycle.","","# Arguments","","* `ctx` - The context of accounts","* `reward_index` - The index of reward token in the pool.","* `emissions_per_second_x64` - The per second emission reward, when extend the current cycle,","new value can't be less than old value","* `open_time` - reward open timestamp, must be set when starting a new cycle","* `end_time` - reward end timestamp",""],"discriminator":[112,52,167,75,32,201,211,137],"accounts":[{"name":"authority","docs":["Address to be set as protocol owner. It pays to create factory state account."],"signer":true},{"name":"amm_config"},{"name":"pool_state","writable":true},{"name":"operation_state","docs":["load info from the account to judge reward permission"],"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"token_program","docs":["Token program"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["Token program 2022"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"}],"args":[{"name":"reward_index","type":"u8"},{"name":"emissions_per_second_x64","type":"u128"},{"name":"open_time","type":"u64"},{"name":"end_time","type":"u64"}]},{"name":"swap","docs":["#[deprecated(note = \"Use `swap_v2` instead.\")]","Swaps one token for as much as possible of another token across a single pool","","# Arguments","","* `ctx` - The context of accounts","* `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum)","* `other_amount_threshold` - For slippage check","* `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot","* `is_base_input` - swap base input or swap base output",""],"discriminator":[248,198,158,145,225,117,135,200],"accounts":[{"name":"payer","docs":["The user performing the swap"],"signer":true},{"name":"amm_config","docs":["The factory state to read protocol fees"]},{"name":"pool_state","docs":["The program account of the pool in which the swap will be performed"],"writable":true},{"name":"input_token_account","docs":["The user token account for input token"],"writable":true},{"name":"output_token_account","docs":["The user token account for output token"],"writable":true},{"name":"input_vault","docs":["The vault token account for input token"],"writable":true},{"name":"output_vault","docs":["The vault token account for output token"],"writable":true},{"name":"observation_state","docs":["The program account for the most recent oracle observation"],"writable":true},{"name":"token_program","docs":["SPL program for token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"tick_array","writable":true}],"args":[{"name":"amount","type":"u64"},{"name":"other_amount_threshold","type":"u64"},{"name":"sqrt_price_limit_x64","type":"u128"},{"name":"is_base_input","type":"bool"}]},{"name":"swap_router_base_in","docs":["Swap token for as much as possible of another token across the path provided, base input","","# Arguments","","* `ctx` - The context of accounts","* `amount_in` - Token amount to be swapped in","* `amount_out_minimum` - Panic if output amount is below minimum amount. For slippage.",""],"discriminator":[69,125,115,218,245,186,242,196],"accounts":[{"name":"payer","docs":["The user performing the swap"],"signer":true},{"name":"input_token_account","docs":["The token account that pays input tokens for the swap"],"writable":true},{"name":"input_token_mint","docs":["The mint of input token"],"writable":true},{"name":"token_program","docs":["SPL program for token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["SPL program 2022 for token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["Memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"}],"args":[{"name":"amount_in","type":"u64"},{"name":"amount_out_minimum","type":"u64"}]},{"name":"swap_v2","docs":["Swaps one token for as much as possible of another token across a single pool, support token program 2022","","# Arguments","","* `ctx` - The context of accounts","* `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum)","* `other_amount_threshold` - For slippage check","* `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot","* `is_base_input` - swap base input or swap base output",""],"discriminator":[43,4,237,11,26,201,30,98],"accounts":[{"name":"payer","docs":["The user performing the swap"],"signer":true},{"name":"amm_config","docs":["The factory state to read protocol fees"]},{"name":"pool_state","docs":["The program account of the pool in which the swap will be performed"],"writable":true},{"name":"input_token_account","docs":["The user token account for input token"],"writable":true},{"name":"output_token_account","docs":["The user token account for output token"],"writable":true},{"name":"input_vault","docs":["The vault token account for input token"],"writable":true},{"name":"output_vault","docs":["The vault token account for output token"],"writable":true},{"name":"observation_state","docs":["The program account for the most recent oracle observation"],"writable":true},{"name":"token_program","docs":["SPL program for token transfers"],"address":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"name":"token_program_2022","docs":["SPL program 2022 for token transfers"],"address":"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"},{"name":"memo_program","docs":["Memo program"],"address":"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"},{"name":"input_vault_mint","docs":["The mint of token vault 0"]},{"name":"output_vault_mint","docs":["The mint of token vault 1"]}],"args":[{"name":"amount","type":"u64"},{"name":"other_amount_threshold","type":"u64"},{"name":"sqrt_price_limit_x64","type":"u128"},{"name":"is_base_input","type":"bool"}]},{"name":"toggle_permissionless_farm_switch","docs":["Toggle the permissionless farm switch account","","# Arguments","","* `ctx`- The context of accounts","* `is_on`- Is the permissionless farm allowed or not",""],"discriminator":[150,112,54,233,238,161,7,86],"accounts":[{"name":"owner","writable":true,"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"permissionless_farm_switch","writable":true,"pda":{"seeds":[{"kind":"const","value":[112,101,114,109,105,115,115,105,111,110,108,101,115,115,95,102,97,114,109,95,115,119,105,116,99,104]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[{"name":"is_on","type":"bool"}]},{"name":"transfer_reward_owner","docs":["Transfer reward owner","","# Arguments","","* `ctx`- The context of accounts","* `new_owner`- new owner pubkey",""],"discriminator":[7,22,12,83,242,43,48,121],"accounts":[{"name":"authority","docs":["Address to be set as operation account owner."],"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"pool_state","writable":true}],"args":[{"name":"new_owner","type":"pubkey"}]},{"name":"update_amm_config","docs":["Updates the owner of the amm config","Must be called by the current owner or admin","","# Arguments","","* `ctx`- The context of accounts","* `trade_fee_rate`- The new trade fee rate of amm config, be set when `param` is 0","* `protocol_fee_rate`- The new protocol fee rate of amm config, be set when `param` is 1","* `fund_fee_rate`- The new fund fee rate of amm config, be set when `param` is 2","* `new_owner`- The config's new owner, be set when `param` is 3","* `new_fund_owner`- The config's new fund owner, be set when `param` is 4","* `param`- The value can be 0 | 1 | 2 | 3 | 4, otherwise will report a error",""],"discriminator":[49,60,174,136,154,28,116,200],"accounts":[{"name":"owner","docs":["The amm config owner or admin"],"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"amm_config","docs":["Amm config account to be changed"],"writable":true}],"args":[{"name":"param","type":"u8"},{"name":"value","type":"u32"}]},{"name":"update_operation_account","docs":["Update the operation account","","# Arguments","","* `ctx`- The context of accounts","* `param`- The value can be 0 | 1 | 2 | 3, otherwise will report a error","* `keys`- update operation owner when the `param` is 0","remove operation owner when the `param` is 1","update whitelist mint when the `param` is 2","remove whitelist mint when the `param` is 3",""],"discriminator":[127,70,119,40,188,227,61,7],"accounts":[{"name":"owner","docs":["Address to be set as operation account owner."],"signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"operation_state","docs":["Initialize operation state account to store operation owner address and white list mint."],"writable":true,"pda":{"seeds":[{"kind":"const","value":[111,112,101,114,97,116,105,111,110]}]}},{"name":"system_program","address":"11111111111111111111111111111111"}],"args":[{"name":"param","type":"u8"},{"name":"keys","type":{"vec":"pubkey"}}]},{"name":"update_pool_status","docs":["Update pool status for given value","","# Arguments","","* `ctx`- The context of accounts","* `status` - The value of status",""],"discriminator":[130,87,108,6,46,224,117,123],"accounts":[{"name":"authority","signer":true,"address":"DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV"},{"name":"pool_state","writable":true}],"args":[{"name":"status","type":"u8"}]},{"name":"update_reward_infos","docs":["Update rewards info of the given pool, can be called for everyone","","# Arguments","","* `ctx`- The context of accounts",""],"discriminator":[163,172,224,52,11,154,106,223],"accounts":[{"name":"pool_state","docs":["The liquidity pool for which reward info to update"],"writable":true}],"args":[]}],"accounts":[{"name":"AmmConfig","discriminator":[218,244,33,104,203,203,43,111]},{"name":"ObservationState","discriminator":[122,174,197,53,129,9,165,132]},{"name":"OperationState","discriminator":[19,236,58,237,81,222,183,252]},{"name":"PermissionlessFarmSwitch","discriminator":[37,92,147,78,250,100,147,137]},{"name":"PersonalPositionState","discriminator":[70,111,150,126,230,15,25,117]},{"name":"PoolState","discriminator":[247,237,227,245,215,195,222,70]},{"name":"ProtocolPositionState","discriminator":[100,226,145,99,146,218,160,106]},{"name":"SupportMintAssociated","discriminator":[134,40,183,79,12,112,162,53]},{"name":"TickArrayBitmapExtension","discriminator":[60,150,36,219,97,128,139,153]},{"name":"TickArrayState","discriminator":[192,155,85,205,49,249,129,42]}],"events":[{"name":"CollectPersonalFeeEvent","discriminator":[166,174,105,192,81,161,83,105]},{"name":"CollectProtocolFeeEvent","discriminator":[206,87,17,79,45,41,213,61]},{"name":"ConfigChangeEvent","discriminator":[247,189,7,119,106,112,95,151]},{"name":"CreatePersonalPositionEvent","discriminator":[100,30,87,249,196,223,154,206]},{"name":"DecreaseLiquidityEvent","discriminator":[58,222,86,58,68,50,85,56]},{"name":"IncreaseLiquidityEvent","discriminator":[49,79,105,212,32,34,30,84]},{"name":"LiquidityCalculateEvent","discriminator":[237,112,148,230,57,84,180,162]},{"name":"LiquidityChangeEvent","discriminator":[126,240,175,206,158,88,153,107]},{"name":"PoolCreatedEvent","discriminator":[25,94,75,47,112,99,53,63]},{"name":"SwapEvent","discriminator":[64,198,205,232,38,8,113,226]},{"name":"UpdateRewardInfosEvent","discriminator":[109,127,186,78,114,65,37,236]}],"errors":[{"code":6000,"name":"LOK","msg":"LOK"},{"code":6001,"name":"NotApproved","msg":"Not approved"},{"code":6002,"name":"InvalidUpdateConfigFlag","msg":"invalid update amm config flag"},{"code":6003,"name":"AccountLack","msg":"Account lack"},{"code":6004,"name":"ClosePositionErr","msg":"Remove liquitity, collect fees owed and reward then you can close position account"},{"code":6005,"name":"ZeroMintAmount","msg":"Minting amount should be greater than 0"},{"code":6006,"name":"InvalidTickIndex","msg":"Tick out of range"},{"code":6007,"name":"TickInvalidOrder","msg":"The lower tick must be below the upper tick"},{"code":6008,"name":"TickLowerOverflow","msg":"The tick must be greater, or equal to the minimum tick(-443636)"},{"code":6009,"name":"TickUpperOverflow","msg":"The tick must be lesser than, or equal to the maximum tick(443636)"},{"code":6010,"name":"TickAndSpacingNotMatch","msg":"tick % tick_spacing must be zero"},{"code":6011,"name":"InvalidTickArray","msg":"Invalid tick array account"},{"code":6012,"name":"InvalidTickArrayBoundary","msg":"Invalid tick array boundary"},{"code":6013,"name":"SqrtPriceLimitOverflow","msg":"Square root price limit overflow"},{"code":6014,"name":"SqrtPriceX64","msg":"sqrt_price_x64 out of range"},{"code":6015,"name":"LiquiditySubValueErr","msg":"Liquidity sub delta L must be smaller than before"},{"code":6016,"name":"LiquidityAddValueErr","msg":"Liquidity add delta L must be greater, or equal to before"},{"code":6017,"name":"InvalidLiquidity","msg":"Invalid liquidity when update position"},{"code":6018,"name":"ForbidBothZeroForSupplyLiquidity","msg":"Both token amount must not be zero while supply liquidity"},{"code":6019,"name":"LiquidityInsufficient","msg":"Liquidity insufficient"},{"code":6020,"name":"TransactionTooOld","msg":"Transaction too old"},{"code":6021,"name":"PriceSlippageCheck","msg":"Price slippage check"},{"code":6022,"name":"TooLittleOutputReceived","msg":"Too little output received"},{"code":6023,"name":"TooMuchInputPaid","msg":"Too much input paid"},{"code":6024,"name":"ZeroAmountSpecified","msg":"Swap special amount can not be zero"},{"code":6025,"name":"InvalidInputPoolVault","msg":"Input pool vault is invalid"},{"code":6026,"name":"TooSmallInputOrOutputAmount","msg":"Swap input or output amount is too small"},{"code":6027,"name":"NotEnoughTickArrayAccount","msg":"Not enought tick array account"},{"code":6028,"name":"InvalidFirstTickArrayAccount","msg":"Invalid first tick array account"},{"code":6029,"name":"InvalidRewardIndex","msg":"Invalid reward index"},{"code":6030,"name":"FullRewardInfo","msg":"The init reward token reach to the max"},{"code":6031,"name":"RewardTokenAlreadyInUse","msg":"The init reward token already in use"},{"code":6032,"name":"ExceptRewardMint","msg":"The reward tokens must contain one of pool vault mint except the last reward"},{"code":6033,"name":"InvalidRewardInitParam","msg":"Invalid reward init param"},{"code":6034,"name":"InvalidRewardDesiredAmount","msg":"Invalid collect reward desired amount"},{"code":6035,"name":"InvalidRewardInputAccountNumber","msg":"Invalid collect reward input account number"},{"code":6036,"name":"InvalidRewardPeriod","msg":"Invalid reward period"},{"code":6037,"name":"NotApproveUpdateRewardEmissiones","msg":"Modification of emissiones is allowed within 72 hours from the end of the previous cycle"},{"code":6038,"name":"UnInitializedRewardInfo","msg":"uninitialized reward info"},{"code":6039,"name":"NotSupportMint","msg":"Not support token_2022 mint extension"},{"code":6040,"name":"MissingTickArrayBitmapExtensionAccount","msg":"Missing tickarray bitmap extension account"},{"code":6041,"name":"InsufficientLiquidityForDirection","msg":"Insufficient liquidity for this direction"},{"code":6042,"name":"MaxTokenOverflow","msg":"Max token overflow"},{"code":6043,"name":"CalculateOverflow","msg":"Calculate overflow"},{"code":6044,"name":"TransferFeeCalculateNotMatch","msg":"TransferFee calculate not match"}],"types":[{"name":"AmmConfig","docs":["Holds the current owner of the factory"],"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"index","type":"u16"},{"name":"owner","docs":["Address of the protocol owner"],"type":"pubkey"},{"name":"protocol_fee_rate","docs":["The protocol fee"],"type":"u32"},{"name":"trade_fee_rate","docs":["The trade fee, denominated in hundredths of a bip (10^-6)"],"type":"u32"},{"name":"tick_spacing","docs":["The tick spacing"],"type":"u16"},{"name":"fund_fee_rate","docs":["The fund fee, denominated in hundredths of a bip (10^-6)"],"type":"u32"},{"name":"padding_u32","type":"u32"},{"name":"fund_owner","type":"pubkey"},{"name":"padding","type":{"array":["u64",3]}}]}},{"name":"CollectPersonalFeeEvent","docs":["Emitted when tokens are collected for a position"],"type":{"kind":"struct","fields":[{"name":"position_nft_mint","docs":["The ID of the token for which underlying tokens were collected"],"type":"pubkey"},{"name":"recipient_token_account_0","docs":["The token account that received the collected token_0 tokens"],"type":"pubkey"},{"name":"recipient_token_account_1","docs":["The token account that received the collected token_1 tokens"],"type":"pubkey"},{"name":"amount_0","docs":["The amount of token_0 owed to the position that was collected"],"type":"u64"},{"name":"amount_1","docs":["The amount of token_1 owed to the position that was collected"],"type":"u64"}]}},{"name":"CollectProtocolFeeEvent","docs":["Emitted when the collected protocol fees are withdrawn by the factory owner"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool whose protocol fee is collected"],"type":"pubkey"},{"name":"recipient_token_account_0","docs":["The address that receives the collected token_0 protocol fees"],"type":"pubkey"},{"name":"recipient_token_account_1","docs":["The address that receives the collected token_1 protocol fees"],"type":"pubkey"},{"name":"amount_0","docs":["The amount of token_0 protocol fees that is withdrawn"],"type":"u64"},{"name":"amount_1","docs":["The amount of token_0 protocol fees that is withdrawn"],"type":"u64"}]}},{"name":"ConfigChangeEvent","docs":["Emitted when create or update a config"],"type":{"kind":"struct","fields":[{"name":"index","type":"u16"},{"name":"owner","type":"pubkey"},{"name":"protocol_fee_rate","type":"u32"},{"name":"trade_fee_rate","type":"u32"},{"name":"tick_spacing","type":"u16"},{"name":"fund_fee_rate","type":"u32"},{"name":"fund_owner","type":"pubkey"}]}},{"name":"CreatePersonalPositionEvent","docs":["Emitted when create a new position"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool for which liquidity was added"],"type":"pubkey"},{"name":"minter","docs":["The address that create the position"],"type":"pubkey"},{"name":"nft_owner","docs":["The owner of the position and recipient of any minted liquidity"],"type":"pubkey"},{"name":"tick_lower_index","docs":["The lower tick of the position"],"type":"i32"},{"name":"tick_upper_index","docs":["The upper tick of the position"],"type":"i32"},{"name":"liquidity","docs":["The amount of liquidity minted to the position range"],"type":"u128"},{"name":"deposit_amount_0","docs":["The amount of token_0 was deposit for the liquidity"],"type":"u64"},{"name":"deposit_amount_1","docs":["The amount of token_1 was deposit for the liquidity"],"type":"u64"},{"name":"deposit_amount_0_transfer_fee","docs":["The token transfer fee for deposit_amount_0"],"type":"u64"},{"name":"deposit_amount_1_transfer_fee","docs":["The token transfer fee for deposit_amount_1"],"type":"u64"}]}},{"name":"DecreaseLiquidityEvent","docs":["Emitted when liquidity is decreased."],"type":{"kind":"struct","fields":[{"name":"position_nft_mint","docs":["The ID of the token for which liquidity was decreased"],"type":"pubkey"},{"name":"liquidity","docs":["The amount by which liquidity for the position was decreased"],"type":"u128"},{"name":"decrease_amount_0","docs":["The amount of token_0 that was paid for the decrease in liquidity"],"type":"u64"},{"name":"decrease_amount_1","docs":["The amount of token_1 that was paid for the decrease in liquidity"],"type":"u64"},{"name":"fee_amount_0","type":"u64"},{"name":"fee_amount_1","docs":["The amount of token_1 fee"],"type":"u64"},{"name":"reward_amounts","docs":["The amount of rewards"],"type":{"array":["u64",3]}},{"name":"transfer_fee_0","docs":["The amount of token_0 transfer fee"],"type":"u64"},{"name":"transfer_fee_1","docs":["The amount of token_1 transfer fee"],"type":"u64"}]}},{"name":"IncreaseLiquidityEvent","docs":["Emitted when liquidity is increased."],"type":{"kind":"struct","fields":[{"name":"position_nft_mint","docs":["The ID of the token for which liquidity was increased"],"type":"pubkey"},{"name":"liquidity","docs":["The amount by which liquidity for the NFT position was increased"],"type":"u128"},{"name":"amount_0","docs":["The amount of token_0 that was paid for the increase in liquidity"],"type":"u64"},{"name":"amount_1","docs":["The amount of token_1 that was paid for the increase in liquidity"],"type":"u64"},{"name":"amount_0_transfer_fee","docs":["The token transfer fee for amount_0"],"type":"u64"},{"name":"amount_1_transfer_fee","docs":["The token transfer fee for amount_1"],"type":"u64"}]}},{"name":"InitializeRewardParam","type":{"kind":"struct","fields":[{"name":"open_time","docs":["Reward open time"],"type":"u64"},{"name":"end_time","docs":["Reward end time"],"type":"u64"},{"name":"emissions_per_second_x64","docs":["Token reward per second are earned per unit of liquidity"],"type":"u128"}]}},{"name":"LiquidityCalculateEvent","docs":["Emitted when liquidity decreased or increase."],"type":{"kind":"struct","fields":[{"name":"pool_liquidity","docs":["The pool liquidity before decrease or increase"],"type":"u128"},{"name":"pool_sqrt_price_x64","docs":["The pool price when decrease or increase in liquidity"],"type":"u128"},{"name":"pool_tick","docs":["The pool tick when decrease or increase in liquidity"],"type":"i32"},{"name":"calc_amount_0","docs":["The amount of token_0 that was calculated for the decrease or increase in liquidity"],"type":"u64"},{"name":"calc_amount_1","docs":["The amount of token_1 that was calculated for the decrease or increase in liquidity"],"type":"u64"},{"name":"trade_fee_owed_0","type":"u64"},{"name":"trade_fee_owed_1","docs":["The amount of token_1 fee"],"type":"u64"},{"name":"transfer_fee_0","docs":["The amount of token_0 transfer fee without trade_fee_amount_0"],"type":"u64"},{"name":"transfer_fee_1","docs":["The amount of token_1 transfer fee without trade_fee_amount_0"],"type":"u64"}]}},{"name":"LiquidityChangeEvent","docs":["Emitted pool liquidity change when increase and decrease liquidity"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool for swap"],"type":"pubkey"},{"name":"tick","docs":["The tick of the pool"],"type":"i32"},{"name":"tick_lower","docs":["The tick lower of position"],"type":"i32"},{"name":"tick_upper","docs":["The tick lower of position"],"type":"i32"},{"name":"liquidity_before","docs":["The liquidity of the pool before liquidity change"],"type":"u128"},{"name":"liquidity_after","docs":["The liquidity of the pool after liquidity change"],"type":"u128"}]}},{"name":"Observation","docs":["The element of observations in ObservationState"],"serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"block_timestamp","docs":["The block timestamp of the observation"],"type":"u32"},{"name":"tick_cumulative","docs":["the cumulative of tick during the duration time"],"type":"i64"},{"name":"padding","docs":["padding for feature update"],"type":{"array":["u64",4]}}]}},{"name":"ObservationState","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"initialized","docs":["Whether the ObservationState is initialized"],"type":"bool"},{"name":"recent_epoch","docs":["recent update epoch"],"type":"u64"},{"name":"observation_index","docs":["the most-recently updated index of the observations array"],"type":"u16"},{"name":"pool_id","docs":["belongs to which pool"],"type":"pubkey"},{"name":"observations","docs":["observation array"],"type":{"array":[{"defined":{"name":"Observation"}},100]}},{"name":"padding","docs":["padding for feature update"],"type":{"array":["u64",4]}}]}},{"name":"OperationState","docs":["Holds the current owner of the factory"],"serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"operation_owners","docs":["Address of the operation owner"],"type":{"array":["pubkey",10]}},{"name":"whitelist_mints","docs":["The mint address of whitelist to emit reward"],"type":{"array":["pubkey",100]}}]}},{"name":"PermissionlessFarmSwitch","type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"is_on","docs":["Is the permissionless farm allowed or not"],"type":"bool"}]}},{"name":"PersonalPositionState","type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":{"array":["u8",1]}},{"name":"nft_mint","docs":["Mint address of the tokenized position"],"type":"pubkey"},{"name":"pool_id","docs":["The ID of the pool with which this token is connected"],"type":"pubkey"},{"name":"tick_lower_index","docs":["The lower bound tick of the position"],"type":"i32"},{"name":"tick_upper_index","docs":["The upper bound tick of the position"],"type":"i32"},{"name":"liquidity","docs":["The amount of liquidity owned by this position"],"type":"u128"},{"name":"fee_growth_inside_0_last_x64","docs":["The token_0 fee growth of the aggregate position as of the last action on the individual position"],"type":"u128"},{"name":"fee_growth_inside_1_last_x64","docs":["The token_1 fee growth of the aggregate position as of the last action on the individual position"],"type":"u128"},{"name":"token_fees_owed_0","docs":["The fees owed to the position owner in token_0, as of the last computation"],"type":"u64"},{"name":"token_fees_owed_1","docs":["The fees owed to the position owner in token_1, as of the last computation"],"type":"u64"},{"name":"reward_infos","type":{"array":[{"defined":{"name":"PositionRewardInfo"}},3]}},{"name":"recent_epoch","type":"u64"},{"name":"padding","type":{"array":["u64",7]}}]}},{"name":"PoolCreatedEvent","docs":["Emitted when a pool is created and initialized with a starting price",""],"type":{"kind":"struct","fields":[{"name":"token_mint_0","docs":["The first token of the pool by address sort order"],"type":"pubkey"},{"name":"token_mint_1","docs":["The second token of the pool by address sort order"],"type":"pubkey"},{"name":"tick_spacing","docs":["The minimum number of ticks between initialized ticks"],"type":"u16"},{"name":"pool_state","docs":["The address of the created pool"],"type":"pubkey"},{"name":"sqrt_price_x64","docs":["The initial sqrt price of the pool, as a Q64.64"],"type":"u128"},{"name":"tick","docs":["The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool"],"type":"i32"},{"name":"token_vault_0","docs":["Vault of token_0"],"type":"pubkey"},{"name":"token_vault_1","docs":["Vault of token_1"],"type":"pubkey"}]}},{"name":"PoolState","docs":["The pool state","","PDA of `[POOL_SEED, config, token_mint_0, token_mint_1]`",""],"serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":{"array":["u8",1]}},{"name":"amm_config","type":"pubkey"},{"name":"owner","type":"pubkey"},{"name":"token_mint_0","docs":["Token pair of the pool, where token_mint_0 address < token_mint_1 address"],"type":"pubkey"},{"name":"token_mint_1","type":"pubkey"},{"name":"token_vault_0","docs":["Token pair vault"],"type":"pubkey"},{"name":"token_vault_1","type":"pubkey"},{"name":"observation_key","docs":["observation account key"],"type":"pubkey"},{"name":"mint_decimals_0","docs":["mint0 and mint1 decimals"],"type":"u8"},{"name":"mint_decimals_1","type":"u8"},{"name":"tick_spacing","docs":["The minimum number of ticks between initialized ticks"],"type":"u16"},{"name":"liquidity","docs":["The currently in range liquidity available to the pool."],"type":"u128"},{"name":"sqrt_price_x64","docs":["The current price of the pool as a sqrt(token_1/token_0) Q64.64 value"],"type":"u128"},{"name":"tick_current","docs":["The current tick of the pool, i.e. according to the last tick transition that was run."],"type":"i32"},{"name":"padding3","type":"u16"},{"name":"padding4","type":"u16"},{"name":"fee_growth_global_0_x64","docs":["The fee growth as a Q64.64 number, i.e. fees of token_0 and token_1 collected per","unit of liquidity for the entire life of the pool."],"type":"u128"},{"name":"fee_growth_global_1_x64","type":"u128"},{"name":"protocol_fees_token_0","docs":["The amounts of token_0 and token_1 that are owed to the protocol."],"type":"u64"},{"name":"protocol_fees_token_1","type":"u64"},{"name":"swap_in_amount_token_0","docs":["The amounts in and out of swap token_0 and token_1"],"type":"u128"},{"name":"swap_out_amount_token_1","type":"u128"},{"name":"swap_in_amount_token_1","type":"u128"},{"name":"swap_out_amount_token_0","type":"u128"},{"name":"status","docs":["Bitwise representation of the state of the pool","bit0, 1: disable open position and increase liquidity, 0: normal","bit1, 1: disable decrease liquidity, 0: normal","bit2, 1: disable collect fee, 0: normal","bit3, 1: disable collect reward, 0: normal","bit4, 1: disable swap, 0: normal"],"type":"u8"},{"name":"padding","docs":["Leave blank for future use"],"type":{"array":["u8",7]}},{"name":"reward_infos","type":{"array":[{"defined":{"name":"RewardInfo"}},3]}},{"name":"tick_array_bitmap","docs":["Packed initialized tick array state"],"type":{"array":["u64",16]}},{"name":"total_fees_token_0","docs":["except protocol_fee and fund_fee"],"type":"u64"},{"name":"total_fees_claimed_token_0","docs":["except protocol_fee and fund_fee"],"type":"u64"},{"name":"total_fees_token_1","type":"u64"},{"name":"total_fees_claimed_token_1","type":"u64"},{"name":"fund_fees_token_0","type":"u64"},{"name":"fund_fees_token_1","type":"u64"},{"name":"open_time","type":"u64"},{"name":"recent_epoch","type":"u64"},{"name":"padding1","type":{"array":["u64",24]}},{"name":"padding2","type":{"array":["u64",32]}}]}},{"name":"PositionRewardInfo","type":{"kind":"struct","fields":[{"name":"growth_inside_last_x64","type":"u128"},{"name":"reward_amount_owed","type":"u64"}]}},{"name":"ProtocolPositionState","docs":["Info stored for each user's position"],"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"pool_id","docs":["The ID of the pool with which this token is connected"],"type":"pubkey"},{"name":"tick_lower_index","docs":["The lower bound tick of the position"],"type":"i32"},{"name":"tick_upper_index","docs":["The upper bound tick of the position"],"type":"i32"},{"name":"liquidity","docs":["The amount of liquidity owned by this position"],"type":"u128"},{"name":"fee_growth_inside_0_last_x64","docs":["The token_0 fee growth per unit of liquidity as of the last update to liquidity or fees owed"],"type":"u128"},{"name":"fee_growth_inside_1_last_x64","docs":["The token_1 fee growth per unit of liquidity as of the last update to liquidity or fees owed"],"type":"u128"},{"name":"token_fees_owed_0","docs":["The fees owed to the position owner in token_0"],"type":"u64"},{"name":"token_fees_owed_1","docs":["The fees owed to the position owner in token_1"],"type":"u64"},{"name":"reward_growth_inside","docs":["The reward growth per unit of liquidity as of the last update to liquidity"],"type":{"array":["u128",3]}},{"name":"recent_epoch","type":"u64"},{"name":"padding","type":{"array":["u64",7]}}]}},{"name":"RewardInfo","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"reward_state","docs":["Reward state"],"type":"u8"},{"name":"open_time","docs":["Reward open time"],"type":"u64"},{"name":"end_time","docs":["Reward end time"],"type":"u64"},{"name":"last_update_time","docs":["Reward last update time"],"type":"u64"},{"name":"emissions_per_second_x64","docs":["Q64.64 number indicates how many tokens per second are earned per unit of liquidity."],"type":"u128"},{"name":"reward_total_emissioned","docs":["The total amount of reward emissioned"],"type":"u64"},{"name":"reward_claimed","docs":["The total amount of claimed reward"],"type":"u64"},{"name":"token_mint","docs":["Reward token mint."],"type":"pubkey"},{"name":"token_vault","docs":["Reward vault token account."],"type":"pubkey"},{"name":"authority","docs":["The owner that has permission to set reward param"],"type":"pubkey"},{"name":"reward_growth_global_x64","docs":["Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward","emissions were turned on."],"type":"u128"}]}},{"name":"SupportMintAssociated","docs":["Holds the current owner of the factory"],"type":{"kind":"struct","fields":[{"name":"bump","docs":["Bump to identify PDA"],"type":"u8"},{"name":"mint","docs":["Address of the supported token22 mint"],"type":"pubkey"},{"name":"padding","type":{"array":["u64",8]}}]}},{"name":"SwapEvent","docs":["Emitted by when a swap is performed for a pool"],"type":{"kind":"struct","fields":[{"name":"pool_state","docs":["The pool for which token_0 and token_1 were swapped"],"type":"pubkey"},{"name":"sender","docs":["The address that initiated the swap call, and that received the callback"],"type":"pubkey"},{"name":"token_account_0","docs":["The payer token account in zero for one swaps, or the recipient token account","in one for zero swaps"],"type":"pubkey"},{"name":"token_account_1","docs":["The payer token account in one for zero swaps, or the recipient token account","in zero for one swaps"],"type":"pubkey"},{"name":"amount_0","docs":["The real delta amount of the token_0 of the pool or user"],"type":"u64"},{"name":"transfer_fee_0","docs":["The transfer fee charged by the withheld_amount of the token_0"],"type":"u64"},{"name":"amount_1","docs":["The real delta of the token_1 of the pool or user"],"type":"u64"},{"name":"transfer_fee_1","docs":["The transfer fee charged by the withheld_amount of the token_1"],"type":"u64"},{"name":"zero_for_one","docs":["if true, amount_0 is negtive and amount_1 is positive"],"type":"bool"},{"name":"sqrt_price_x64","docs":["The sqrt(price) of the pool after the swap, as a Q64.64"],"type":"u128"},{"name":"liquidity","docs":["The liquidity of the pool after the swap"],"type":"u128"},{"name":"tick","docs":["The log base 1.0001 of price of the pool after the swap"],"type":"i32"}]}},{"name":"TickArrayBitmapExtension","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"pool_id","type":"pubkey"},{"name":"positive_tick_array_bitmap","docs":["Packed initialized tick array state for start_tick_index is positive"],"type":{"array":[{"array":["u64",8]},14]}},{"name":"negative_tick_array_bitmap","docs":["Packed initialized tick array state for start_tick_index is negitive"],"type":{"array":[{"array":["u64",8]},14]}}]}},{"name":"TickArrayState","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"pool_id","type":"pubkey"},{"name":"start_tick_index","type":"i32"},{"name":"ticks","type":{"array":[{"defined":{"name":"TickState"}},60]}},{"name":"initialized_tick_count","type":"u8"},{"name":"recent_epoch","type":"u64"},{"name":"padding","type":{"array":["u8",107]}}]}},{"name":"TickState","serialization":"bytemuckunsafe","repr":{"kind":"c","packed":true},"type":{"kind":"struct","fields":[{"name":"tick","type":"i32"},{"name":"liquidity_net","docs":["Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)"],"type":"i128"},{"name":"liquidity_gross","docs":["The total position liquidity that references this tick"],"type":"u128"},{"name":"fee_growth_outside_0_x64","docs":["Fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)","only has relative meaning, not absolute — the value depends on when the tick is initialized"],"type":"u128"},{"name":"fee_growth_outside_1_x64","type":"u128"},{"name":"reward_growths_outside_x64","type":{"array":["u128",3]}},{"name":"padding","type":{"array":["u32",13]}}]}},{"name":"UpdateRewardInfosEvent","docs":["Emitted when Reward are updated for a pool"],"type":{"kind":"struct","fields":[{"name":"reward_growth_global_x64","docs":["Reward info"],"type":{"array":["u128",3]}}]}}]} \ No newline at end of file +{ + "address": "HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq", + "metadata": { + "name": "amm_v3", + "version": "0.1.0", + "spec": "0.1.0", + "description": "Anchor client and source for Pancake concentrated liquidity AMM" + }, + "instructions": [ + { + "name": "close_position", + "docs": [ + "Close the user's position and NFT account. If the NFT mint belongs to token2022, it will also be closed and the funds returned to the NFT owner.", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "" + ], + "discriminator": [ + 123, + 134, + 81, + 0, + 49, + 68, + 98, + 98 + ], + "accounts": [ + { + "name": "nft_owner", + "docs": [ + "The position nft owner" + ], + "writable": true, + "signer": true + }, + { + "name": "position_nft_mint", + "docs": [ + "Mint address bound to the personal position." + ], + "writable": true + }, + { + "name": "position_nft_account", + "docs": [ + "User token account where position NFT be minted to" + ], + "writable": true + }, + { + "name": "personal_position", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "position_nft_mint" + } + ] + } + }, + { + "name": "system_program", + "docs": [ + "System program to close the position state account" + ], + "address": "11111111111111111111111111111111" + }, + { + "name": "token_program", + "docs": [ + "Token/Token2022 program to close token/mint account" + ] + } + ], + "args": [] + }, + { + "name": "collect_fund_fee", + "docs": [ + "Collect the fund fee accrued to the pool", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1", + "* `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0", + "" + ], + "discriminator": [ + 167, + 138, + 78, + 149, + 223, + 194, + 6, + 126 + ], + "accounts": [ + { + "name": "owner", + "docs": [ + "Only admin or fund_owner can collect fee now" + ], + "signer": true + }, + { + "name": "pool_state", + "docs": [ + "Pool state stores accumulated protocol fee amount" + ], + "writable": true + }, + { + "name": "amm_config", + "docs": [ + "Amm config account stores fund_owner" + ] + }, + { + "name": "token_vault_0", + "docs": [ + "The address that holds pool tokens for token_0" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "The address that holds pool tokens for token_1" + ], + "writable": true + }, + { + "name": "vault_0_mint", + "docs": [ + "The mint of token vault 0" + ] + }, + { + "name": "vault_1_mint", + "docs": [ + "The mint of token vault 1" + ] + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The address that receives the collected token_0 protocol fees" + ], + "writable": true + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The address that receives the collected token_1 protocol fees" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "The SPL program to perform token transfers" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "The SPL program 2022 to perform token transfers" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + } + ], + "args": [ + { + "name": "amount_0_requested", + "type": "u64" + }, + { + "name": "amount_1_requested", + "type": "u64" + } + ] + }, + { + "name": "collect_protocol_fee", + "docs": [ + "Collect the protocol fee accrued to the pool", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1", + "* `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0", + "" + ], + "discriminator": [ + 136, + 136, + 252, + 221, + 194, + 66, + 126, + 89 + ], + "accounts": [ + { + "name": "owner", + "docs": [ + "Only admin or config owner can collect fee now" + ], + "signer": true + }, + { + "name": "pool_state", + "docs": [ + "Pool state stores accumulated protocol fee amount" + ], + "writable": true + }, + { + "name": "amm_config", + "docs": [ + "Amm config account stores owner" + ] + }, + { + "name": "token_vault_0", + "docs": [ + "The address that holds pool tokens for token_0" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "The address that holds pool tokens for token_1" + ], + "writable": true + }, + { + "name": "vault_0_mint", + "docs": [ + "The mint of token vault 0" + ] + }, + { + "name": "vault_1_mint", + "docs": [ + "The mint of token vault 1" + ] + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The address that receives the collected token_0 protocol fees" + ], + "writable": true + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The address that receives the collected token_1 protocol fees" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "The SPL program to perform token transfers" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "The SPL program 2022 to perform token transfers" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + } + ], + "args": [ + { + "name": "amount_0_requested", + "type": "u64" + }, + { + "name": "amount_1_requested", + "type": "u64" + } + ] + }, + { + "name": "collect_remaining_rewards", + "docs": [ + "Collect remaining reward token for reward founder", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `reward_index` - the index to reward info", + "" + ], + "discriminator": [ + 18, + 237, + 166, + 197, + 34, + 16, + 213, + 144 + ], + "accounts": [ + { + "name": "reward_funder", + "docs": [ + "The founder who init reward info previously" + ], + "signer": true + }, + { + "name": "funder_token_account", + "docs": [ + "The funder's reward token account" + ], + "writable": true + }, + { + "name": "pool_state", + "docs": [ + "Set reward for this pool" + ], + "writable": true + }, + { + "name": "reward_token_vault", + "docs": [ + "Reward vault transfer remaining token to founder token account" + ] + }, + { + "name": "reward_vault_mint", + "docs": [ + "The mint of reward token vault" + ] + }, + { + "name": "token_program", + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "Token program 2022" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "memo_program", + "docs": [ + "memo program" + ], + "address": "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" + } + ], + "args": [ + { + "name": "reward_index", + "type": "u8" + } + ] + }, + { + "name": "create_amm_config", + "docs": [ + "# Arguments", + "", + "* `ctx`- The accounts needed by instruction.", + "* `index` - The index of amm config, there may be multiple config.", + "* `tick_spacing` - The tickspacing binding with config, cannot be changed.", + "* `trade_fee_rate` - Trade fee rate, can be changed.", + "* `protocol_fee_rate` - The rate of protocol fee within trade fee.", + "* `fund_fee_rate` - The rate of fund fee within trade fee.", + "" + ], + "discriminator": [ + 137, + 52, + 237, + 212, + 215, + 117, + 108, + 104 + ], + "accounts": [ + { + "name": "owner", + "docs": [ + "Address to be set as protocol owner." + ], + "writable": true, + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "amm_config", + "docs": [ + "Initialize config state account to store protocol owner address and fee rates." + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + }, + { + "kind": "arg", + "path": "index" + } + ] + } + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "index", + "type": "u16" + }, + { + "name": "tick_spacing", + "type": "u16" + }, + { + "name": "trade_fee_rate", + "type": "u32" + }, + { + "name": "protocol_fee_rate", + "type": "u32" + }, + { + "name": "fund_fee_rate", + "type": "u32" + } + ] + }, + { + "name": "create_operation_account", + "docs": [ + "Creates an operation account for the program", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "" + ], + "discriminator": [ + 63, + 87, + 148, + 33, + 109, + 35, + 8, + 104 + ], + "accounts": [ + { + "name": "owner", + "docs": [ + "Address to be set as operation account owner." + ], + "writable": true, + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "operation_state", + "docs": [ + "Initialize operation state account to store operation owner address and white list mint." + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 111, + 112, + 101, + 114, + 97, + 116, + 105, + 111, + 110 + ] + } + ] + } + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [] + }, + { + "name": "create_permissionless_farm_switch", + "docs": [ + "Creates a permissionless farm switch account for the program", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "" + ], + "discriminator": [ + 88, + 242, + 198, + 70, + 241, + 6, + 196, + 251 + ], + "accounts": [ + { + "name": "owner", + "writable": true, + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "permissionless_farm_switch", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 101, + 114, + 109, + 105, + 115, + 115, + 105, + 111, + 110, + 108, + 101, + 115, + 115, + 95, + 102, + 97, + 114, + 109, + 95, + 115, + 119, + 105, + 116, + 99, + 104 + ] + } + ] + } + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [] + }, + { + "name": "create_pool", + "docs": [ + "Creates a pool for the given token pair and the initial price", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `sqrt_price_x64` - the initial sqrt price (amount_token_1 / amount_token_0) of the pool as a Q64.64", + "Note: The open_time must be smaller than the current block_timestamp on chain." + ], + "discriminator": [ + 233, + 146, + 209, + 142, + 207, + 104, + 64, + 188 + ], + "accounts": [ + { + "name": "pool_creator", + "docs": [ + "Address paying to create the pool. Can be anyone" + ], + "writable": true, + "signer": true + }, + { + "name": "amm_config", + "docs": [ + "Which config the pool belongs to." + ] + }, + { + "name": "pool_state", + "docs": [ + "Initialize an account to store the pool state" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 111, + 108 + ] + }, + { + "kind": "account", + "path": "amm_config" + }, + { + "kind": "account", + "path": "token_mint_0" + }, + { + "kind": "account", + "path": "token_mint_1" + } + ] + } + }, + { + "name": "token_mint_0", + "docs": [ + "Token_0 mint, the key must be smaller then token_1 mint." + ] + }, + { + "name": "token_mint_1", + "docs": [ + "Token_1 mint" + ] + }, + { + "name": "token_vault_0", + "docs": [ + "Token_0 vault for the pool" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 111, + 108, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "account", + "path": "token_mint_0" + } + ] + } + }, + { + "name": "token_vault_1", + "docs": [ + "Token_1 vault for the pool" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 111, + 108, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "account", + "path": "token_mint_1" + } + ] + } + }, + { + "name": "observation_state", + "docs": [ + "Initialize an account to store oracle observations" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 111, + 98, + 115, + 101, + 114, + 118, + 97, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + } + ] + } + }, + { + "name": "tick_array_bitmap", + "docs": [ + "Initialize an account to store if a tick array is initialized." + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 111, + 108, + 95, + 116, + 105, + 99, + 107, + 95, + 97, + 114, + 114, + 97, + 121, + 95, + 98, + 105, + 116, + 109, + 97, + 112, + 95, + 101, + 120, + 116, + 101, + 110, + 115, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + } + ] + } + }, + { + "name": "token_program_0", + "docs": [ + "Spl token program or token program 2022" + ] + }, + { + "name": "token_program_1", + "docs": [ + "Spl token program or token program 2022" + ] + }, + { + "name": "system_program", + "docs": [ + "To create a new program account" + ], + "address": "11111111111111111111111111111111" + }, + { + "name": "rent", + "docs": [ + "Sysvar for program account" + ], + "address": "SysvarRent111111111111111111111111111111111" + } + ], + "args": [ + { + "name": "sqrt_price_x64", + "type": "u128" + }, + { + "name": "open_time", + "type": "u64" + } + ] + }, + { + "name": "create_support_mint_associated", + "docs": [ + "Create support token22 mint account which can create pool and send rewards with ignoring the not support extensions." + ], + "discriminator": [ + 17, + 251, + 65, + 92, + 136, + 242, + 14, + 169 + ], + "accounts": [ + { + "name": "owner", + "docs": [ + "Address to be set as protocol owner." + ], + "writable": true, + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "token_mint", + "docs": [ + "Support token mint" + ] + }, + { + "name": "support_mint_associated", + "docs": [ + "Initialize support mint state account to store support mint address and bump." + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 117, + 112, + 112, + 111, + 114, + 116, + 95, + 109, + 105, + 110, + 116 + ] + }, + { + "kind": "account", + "path": "token_mint" + } + ] + } + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [] + }, + { + "name": "decrease_liquidity", + "docs": [ + "#[deprecated(note = \"Use `decrease_liquidity_v2` instead.\")]", + "Decreases liquidity for an existing position", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `liquidity` - The amount by which liquidity will be decreased", + "* `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity", + "* `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity", + "" + ], + "discriminator": [ + 160, + 38, + 208, + 111, + 104, + 91, + 44, + 1 + ], + "accounts": [ + { + "name": "nft_owner", + "docs": [ + "The position owner or delegated authority" + ], + "signer": true + }, + { + "name": "nft_account", + "docs": [ + "The token account for the tokenized position" + ] + }, + { + "name": "personal_position", + "docs": [ + "Decrease liquidity for this position" + ], + "writable": true + }, + { + "name": "pool_state", + "writable": true + }, + { + "name": "protocol_position", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "account", + "path": "personal_position.tick_lower_index", + "account": "PersonalPositionState" + }, + { + "kind": "account", + "path": "personal_position.tick_upper_index", + "account": "PersonalPositionState" + } + ] + } + }, + { + "name": "token_vault_0", + "docs": [ + "Token_0 vault" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "Token_1 vault" + ], + "writable": true + }, + { + "name": "tick_array_lower", + "docs": [ + "Stores init state for the lower tick" + ], + "writable": true + }, + { + "name": "tick_array_upper", + "docs": [ + "Stores init state for the upper tick" + ], + "writable": true + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The destination token account for receive amount_0" + ], + "writable": true + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The destination token account for receive amount_1" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "SPL program to transfer out tokens" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + } + ], + "args": [ + { + "name": "liquidity", + "type": "u128" + }, + { + "name": "amount_0_min", + "type": "u64" + }, + { + "name": "amount_1_min", + "type": "u64" + } + ] + }, + { + "name": "decrease_liquidity_v2", + "docs": [ + "Decreases liquidity for an existing position, support Token2022", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `liquidity` - The amount by which liquidity will be decreased", + "* `amount_0_min` - The minimum amount of token_0 that should be accounted for the burned liquidity", + "* `amount_1_min` - The minimum amount of token_1 that should be accounted for the burned liquidity", + "" + ], + "discriminator": [ + 58, + 127, + 188, + 62, + 79, + 82, + 196, + 96 + ], + "accounts": [ + { + "name": "nft_owner", + "docs": [ + "The position owner or delegated authority" + ], + "signer": true + }, + { + "name": "nft_account", + "docs": [ + "The token account for the tokenized position" + ] + }, + { + "name": "personal_position", + "docs": [ + "Decrease liquidity for this position" + ], + "writable": true + }, + { + "name": "pool_state", + "writable": true + }, + { + "name": "protocol_position", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "account", + "path": "personal_position.tick_lower_index", + "account": "PersonalPositionState" + }, + { + "kind": "account", + "path": "personal_position.tick_upper_index", + "account": "PersonalPositionState" + } + ] + } + }, + { + "name": "token_vault_0", + "docs": [ + "Token_0 vault" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "Token_1 vault" + ], + "writable": true + }, + { + "name": "tick_array_lower", + "docs": [ + "Stores init state for the lower tick" + ], + "writable": true + }, + { + "name": "tick_array_upper", + "docs": [ + "Stores init state for the upper tick" + ], + "writable": true + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The destination token account for receive amount_0" + ], + "writable": true + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The destination token account for receive amount_1" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "SPL program to transfer out tokens" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "Token program 2022" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "memo_program", + "docs": [ + "memo program" + ], + "address": "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" + }, + { + "name": "vault_0_mint", + "docs": [ + "The mint of token vault 0" + ] + }, + { + "name": "vault_1_mint", + "docs": [ + "The mint of token vault 1" + ] + } + ], + "args": [ + { + "name": "liquidity", + "type": "u128" + }, + { + "name": "amount_0_min", + "type": "u64" + }, + { + "name": "amount_1_min", + "type": "u64" + } + ] + }, + { + "name": "increase_liquidity", + "docs": [ + "#[deprecated(note = \"Use `increase_liquidity_v2` instead.\")]", + "Increases liquidity for an existing position, with amount paid by `payer`", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `liquidity` - The desired liquidity to be added, can't be zero", + "* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check", + "* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check", + "" + ], + "discriminator": [ + 46, + 156, + 243, + 118, + 13, + 205, + 251, + 178 + ], + "accounts": [ + { + "name": "nft_owner", + "docs": [ + "Pays to mint the position" + ], + "signer": true + }, + { + "name": "nft_account", + "docs": [ + "The token account for nft" + ] + }, + { + "name": "pool_state", + "writable": true + }, + { + "name": "protocol_position", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "account", + "path": "personal_position.tick_lower_index", + "account": "PersonalPositionState" + }, + { + "kind": "account", + "path": "personal_position.tick_upper_index", + "account": "PersonalPositionState" + } + ] + } + }, + { + "name": "personal_position", + "docs": [ + "Increase liquidity for this position" + ], + "writable": true + }, + { + "name": "tick_array_lower", + "docs": [ + "Stores init state for the lower tick" + ], + "writable": true + }, + { + "name": "tick_array_upper", + "docs": [ + "Stores init state for the upper tick" + ], + "writable": true + }, + { + "name": "token_account_0", + "docs": [ + "The payer's token account for token_0" + ], + "writable": true + }, + { + "name": "token_account_1", + "docs": [ + "The token account spending token_1 to mint the position" + ], + "writable": true + }, + { + "name": "token_vault_0", + "docs": [ + "The address that holds pool tokens for token_0" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "The address that holds pool tokens for token_1" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "Program to create mint account and mint tokens" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + } + ], + "args": [ + { + "name": "liquidity", + "type": "u128" + }, + { + "name": "amount_0_max", + "type": "u64" + }, + { + "name": "amount_1_max", + "type": "u64" + } + ] + }, + { + "name": "increase_liquidity_v2", + "docs": [ + "Increases liquidity for an existing position, with amount paid by `payer`, support Token2022", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `liquidity` - The desired liquidity to be added, if zero, calculate liquidity base amount_0 or amount_1 according base_flag", + "* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check", + "* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check", + "* `base_flag` - must be specified if liquidity is zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max", + "" + ], + "discriminator": [ + 133, + 29, + 89, + 223, + 69, + 238, + 176, + 10 + ], + "accounts": [ + { + "name": "nft_owner", + "docs": [ + "Pays to mint the position" + ], + "signer": true + }, + { + "name": "nft_account", + "docs": [ + "The token account for nft" + ] + }, + { + "name": "pool_state", + "writable": true + }, + { + "name": "protocol_position", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "account", + "path": "personal_position.tick_lower_index", + "account": "PersonalPositionState" + }, + { + "kind": "account", + "path": "personal_position.tick_upper_index", + "account": "PersonalPositionState" + } + ] + } + }, + { + "name": "personal_position", + "docs": [ + "Increase liquidity for this position" + ], + "writable": true + }, + { + "name": "tick_array_lower", + "docs": [ + "Stores init state for the lower tick" + ], + "writable": true + }, + { + "name": "tick_array_upper", + "docs": [ + "Stores init state for the upper tick" + ], + "writable": true + }, + { + "name": "token_account_0", + "docs": [ + "The payer's token account for token_0" + ], + "writable": true + }, + { + "name": "token_account_1", + "docs": [ + "The token account spending token_1 to mint the position" + ], + "writable": true + }, + { + "name": "token_vault_0", + "docs": [ + "The address that holds pool tokens for token_0" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "The address that holds pool tokens for token_1" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "Program to create mint account and mint tokens" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "Token program 2022" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "vault_0_mint", + "docs": [ + "The mint of token vault 0" + ] + }, + { + "name": "vault_1_mint", + "docs": [ + "The mint of token vault 1" + ] + } + ], + "args": [ + { + "name": "liquidity", + "type": "u128" + }, + { + "name": "amount_0_max", + "type": "u64" + }, + { + "name": "amount_1_max", + "type": "u64" + }, + { + "name": "base_flag", + "type": { + "option": "bool" + } + } + ] + }, + { + "name": "initialize_reward", + "docs": [ + "Initialize a reward info for a given pool and reward index", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `reward_index` - the index to reward info", + "* `open_time` - reward open timestamp", + "* `end_time` - reward end timestamp", + "* `emissions_per_second_x64` - Token reward per second are earned per unit of liquidity.", + "" + ], + "discriminator": [ + 95, + 135, + 192, + 196, + 242, + 129, + 230, + 68 + ], + "accounts": [ + { + "name": "reward_funder", + "docs": [ + "The founder deposit reward token to vault" + ], + "writable": true, + "signer": true + }, + { + "name": "funder_token_account", + "writable": true + }, + { + "name": "amm_config", + "docs": [ + "For check the reward_funder authority" + ] + }, + { + "name": "pool_state", + "docs": [ + "Set reward for this pool" + ], + "writable": true + }, + { + "name": "operation_state", + "docs": [ + "load info from the account to judge reward permission" + ], + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 111, + 112, + 101, + 114, + 97, + 116, + 105, + 111, + 110 + ] + } + ] + } + }, + { + "name": "permissionless_farm_switch", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 101, + 114, + 109, + 105, + 115, + 115, + 105, + 111, + 110, + 108, + 101, + 115, + 115, + 95, + 102, + 97, + 114, + 109, + 95, + 115, + 119, + 105, + 116, + 99, + 104 + ] + } + ] + } + }, + { + "name": "reward_token_mint", + "docs": [ + "Reward mint" + ] + }, + { + "name": "reward_token_vault", + "docs": [ + "A pda, reward vault" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 111, + 108, + 95, + 114, + 101, + 119, + 97, + 114, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "account", + "path": "reward_token_mint" + } + ] + } + }, + { + "name": "reward_token_program" + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + }, + { + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" + } + ], + "args": [ + { + "name": "param", + "type": { + "defined": { + "name": "InitializeRewardParam" + } + } + } + ] + }, + { + "name": "open_position", + "docs": [ + "#[deprecated(note = \"Use `open_position_with_token22_nft` instead.\")]", + "Creates a new position wrapped in a NFT", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `tick_lower_index` - The low boundary of market", + "* `tick_upper_index` - The upper boundary of market", + "* `tick_array_lower_start_index` - The start index of tick array which include tick low", + "* `tick_array_upper_start_index` - The start index of tick array which include tick upper", + "* `liquidity` - The liquidity to be added", + "* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check", + "* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check", + "" + ], + "discriminator": [ + 135, + 128, + 47, + 77, + 15, + 152, + 240, + 49 + ], + "accounts": [ + { + "name": "payer", + "docs": [ + "Pays to mint the position" + ], + "writable": true, + "signer": true + }, + { + "name": "position_nft_owner" + }, + { + "name": "position_nft_mint", + "docs": [ + "Unique token mint address" + ], + "writable": true, + "signer": true + }, + { + "name": "position_nft_account", + "docs": [ + "Token account where position NFT will be minted", + "This account created in the contract by cpi to avoid large stack variables" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "account", + "path": "position_nft_owner" + }, + { + "kind": "const", + "value": [ + 6, + 221, + 246, + 225, + 215, + 101, + 161, + 147, + 217, + 203, + 225, + 70, + 206, + 235, + 121, + 172, + 28, + 180, + 133, + 237, + 95, + 91, + 55, + 145, + 58, + 140, + 245, + 133, + 126, + 255, + 0, + 169 + ] + }, + { + "kind": "account", + "path": "position_nft_mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, + 151, + 37, + 143, + 78, + 36, + 137, + 241, + 187, + 61, + 16, + 41, + 20, + 142, + 13, + 131, + 11, + 90, + 19, + 153, + 218, + 255, + 16, + 132, + 4, + 142, + 123, + 216, + 219, + 233, + 248, + 89 + ] + } + } + }, + { + "name": "metadata_account", + "docs": [ + "To store metaplex metadata" + ], + "writable": true + }, + { + "name": "pool_state", + "docs": [ + "Add liquidity for this pool" + ], + "writable": true + }, + { + "name": "protocol_position", + "docs": [ + "Store the information of market marking in range" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_lower_index" + }, + { + "kind": "arg", + "path": "tick_upper_index" + } + ] + } + }, + { + "name": "tick_array_lower", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 116, + 105, + 99, + 107, + 95, + 97, + 114, + 114, + 97, + 121 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_array_lower_start_index" + } + ] + } + }, + { + "name": "tick_array_upper", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 116, + 105, + 99, + 107, + 95, + 97, + 114, + 114, + 97, + 121 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_array_upper_start_index" + } + ] + } + }, + { + "name": "personal_position", + "docs": [ + "personal position state" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "position_nft_mint" + } + ] + } + }, + { + "name": "token_account_0", + "docs": [ + "The token_0 account deposit token to the pool" + ], + "writable": true + }, + { + "name": "token_account_1", + "docs": [ + "The token_1 account deposit token to the pool" + ], + "writable": true + }, + { + "name": "token_vault_0", + "docs": [ + "The address that holds pool tokens for token_0" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "The address that holds pool tokens for token_1" + ], + "writable": true + }, + { + "name": "rent", + "docs": [ + "Sysvar for token mint and ATA creation" + ], + "address": "SysvarRent111111111111111111111111111111111" + }, + { + "name": "system_program", + "docs": [ + "Program to create the position manager state account" + ], + "address": "11111111111111111111111111111111" + }, + { + "name": "token_program", + "docs": [ + "Program to create mint account and mint tokens" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "associated_token_program", + "docs": [ + "Program to create an ATA for receiving position NFT" + ], + "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" + }, + { + "name": "metadata_program", + "docs": [ + "Program to create NFT metadata" + ], + "address": "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" + } + ], + "args": [ + { + "name": "tick_lower_index", + "type": "i32" + }, + { + "name": "tick_upper_index", + "type": "i32" + }, + { + "name": "tick_array_lower_start_index", + "type": "i32" + }, + { + "name": "tick_array_upper_start_index", + "type": "i32" + }, + { + "name": "liquidity", + "type": "u128" + }, + { + "name": "amount_0_max", + "type": "u64" + }, + { + "name": "amount_1_max", + "type": "u64" + } + ] + }, + { + "name": "open_position_v2", + "docs": [ + "#[deprecated(note = \"Use `open_position_with_token22_nft` instead.\")]", + "Creates a new position wrapped in a NFT, support Token2022", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `tick_lower_index` - The low boundary of market", + "* `tick_upper_index` - The upper boundary of market", + "* `tick_array_lower_start_index` - The start index of tick array which include tick low", + "* `tick_array_upper_start_index` - The start index of tick array which include tick upper", + "* `liquidity` - The liquidity to be added, if zero, and the base_flag is specified, calculate liquidity base amount_0_max or amount_1_max according base_flag, otherwise open position with zero liquidity", + "* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check", + "* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check", + "* `with_metadata` - The flag indicating whether to create NFT mint metadata", + "* `base_flag` - if the liquidity specified as zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max", + "" + ], + "discriminator": [ + 77, + 184, + 74, + 214, + 112, + 86, + 241, + 199 + ], + "accounts": [ + { + "name": "payer", + "docs": [ + "Pays to mint the position" + ], + "writable": true, + "signer": true + }, + { + "name": "position_nft_owner" + }, + { + "name": "position_nft_mint", + "docs": [ + "Unique token mint address" + ], + "writable": true, + "signer": true + }, + { + "name": "position_nft_account", + "docs": [ + "Token account where position NFT will be minted" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "account", + "path": "position_nft_owner" + }, + { + "kind": "const", + "value": [ + 6, + 221, + 246, + 225, + 215, + 101, + 161, + 147, + 217, + 203, + 225, + 70, + 206, + 235, + 121, + 172, + 28, + 180, + 133, + 237, + 95, + 91, + 55, + 145, + 58, + 140, + 245, + 133, + 126, + 255, + 0, + 169 + ] + }, + { + "kind": "account", + "path": "position_nft_mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, + 151, + 37, + 143, + 78, + 36, + 137, + 241, + 187, + 61, + 16, + 41, + 20, + 142, + 13, + 131, + 11, + 90, + 19, + 153, + 218, + 255, + 16, + 132, + 4, + 142, + 123, + 216, + 219, + 233, + 248, + 89 + ] + } + } + }, + { + "name": "metadata_account", + "docs": [ + "To store metaplex metadata" + ], + "writable": true + }, + { + "name": "pool_state", + "docs": [ + "Add liquidity for this pool" + ], + "writable": true + }, + { + "name": "protocol_position", + "docs": [ + "Store the information of market marking in range" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_lower_index" + }, + { + "kind": "arg", + "path": "tick_upper_index" + } + ] + } + }, + { + "name": "tick_array_lower", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 116, + 105, + 99, + 107, + 95, + 97, + 114, + 114, + 97, + 121 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_array_lower_start_index" + } + ] + } + }, + { + "name": "tick_array_upper", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 116, + 105, + 99, + 107, + 95, + 97, + 114, + 114, + 97, + 121 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_array_upper_start_index" + } + ] + } + }, + { + "name": "personal_position", + "docs": [ + "personal position state" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "position_nft_mint" + } + ] + } + }, + { + "name": "token_account_0", + "docs": [ + "The token_0 account deposit token to the pool" + ], + "writable": true + }, + { + "name": "token_account_1", + "docs": [ + "The token_1 account deposit token to the pool" + ], + "writable": true + }, + { + "name": "token_vault_0", + "docs": [ + "The address that holds pool tokens for token_0" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "The address that holds pool tokens for token_1" + ], + "writable": true + }, + { + "name": "rent", + "docs": [ + "Sysvar for token mint and ATA creation" + ], + "address": "SysvarRent111111111111111111111111111111111" + }, + { + "name": "system_program", + "docs": [ + "Program to create the position manager state account" + ], + "address": "11111111111111111111111111111111" + }, + { + "name": "token_program", + "docs": [ + "Program to create mint account and mint tokens" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "associated_token_program", + "docs": [ + "Program to create an ATA for receiving position NFT" + ], + "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" + }, + { + "name": "metadata_program", + "docs": [ + "Program to create NFT metadata" + ], + "address": "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" + }, + { + "name": "token_program_2022", + "docs": [ + "Program to create mint account and mint tokens" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "vault_0_mint", + "docs": [ + "The mint of token vault 0" + ] + }, + { + "name": "vault_1_mint", + "docs": [ + "The mint of token vault 1" + ] + } + ], + "args": [ + { + "name": "tick_lower_index", + "type": "i32" + }, + { + "name": "tick_upper_index", + "type": "i32" + }, + { + "name": "tick_array_lower_start_index", + "type": "i32" + }, + { + "name": "tick_array_upper_start_index", + "type": "i32" + }, + { + "name": "liquidity", + "type": "u128" + }, + { + "name": "amount_0_max", + "type": "u64" + }, + { + "name": "amount_1_max", + "type": "u64" + }, + { + "name": "with_metadata", + "type": "bool" + }, + { + "name": "base_flag", + "type": { + "option": "bool" + } + } + ] + }, + { + "name": "open_position_with_token22_nft", + "docs": [ + "Creates a new position wrapped in a Token2022 NFT without relying on metadata_program and metadata_account, reduce the cost for user to create a personal position.", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `tick_lower_index` - The low boundary of market", + "* `tick_upper_index` - The upper boundary of market", + "* `tick_array_lower_start_index` - The start index of tick array which include tick low", + "* `tick_array_upper_start_index` - The start index of tick array which include tick upper", + "* `liquidity` - The liquidity to be added, if zero, and the base_flag is specified, calculate liquidity base amount_0_max or amount_1_max according base_flag, otherwise open position with zero liquidity", + "* `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check", + "* `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check", + "* `with_metadata` - The flag indicating whether to create NFT mint metadata", + "* `base_flag` - if the liquidity specified as zero, true: calculate liquidity base amount_0_max otherwise base amount_1_max", + "" + ], + "discriminator": [ + 77, + 255, + 174, + 82, + 125, + 29, + 201, + 46 + ], + "accounts": [ + { + "name": "payer", + "docs": [ + "Pays to mint the position" + ], + "writable": true, + "signer": true + }, + { + "name": "position_nft_owner" + }, + { + "name": "position_nft_mint", + "docs": [ + "Unique token mint address, initialize in contract" + ], + "writable": true, + "signer": true + }, + { + "name": "position_nft_account", + "writable": true + }, + { + "name": "pool_state", + "docs": [ + "Add liquidity for this pool" + ], + "writable": true + }, + { + "name": "protocol_position", + "docs": [ + "Store the information of market marking in range" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_lower_index" + }, + { + "kind": "arg", + "path": "tick_upper_index" + } + ] + } + }, + { + "name": "tick_array_lower", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 116, + 105, + 99, + 107, + 95, + 97, + 114, + 114, + 97, + 121 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_array_lower_start_index" + } + ] + } + }, + { + "name": "tick_array_upper", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 116, + 105, + 99, + 107, + 95, + 97, + 114, + 114, + 97, + 121 + ] + }, + { + "kind": "account", + "path": "pool_state" + }, + { + "kind": "arg", + "path": "tick_array_upper_start_index" + } + ] + } + }, + { + "name": "personal_position", + "docs": [ + "personal position state" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 111, + 115, + 105, + 116, + 105, + 111, + 110 + ] + }, + { + "kind": "account", + "path": "position_nft_mint" + } + ] + } + }, + { + "name": "token_account_0", + "docs": [ + "The token_0 account deposit token to the pool" + ], + "writable": true + }, + { + "name": "token_account_1", + "docs": [ + "The token_1 account deposit token to the pool" + ], + "writable": true + }, + { + "name": "token_vault_0", + "docs": [ + "The address that holds pool tokens for token_0" + ], + "writable": true + }, + { + "name": "token_vault_1", + "docs": [ + "The address that holds pool tokens for token_1" + ], + "writable": true + }, + { + "name": "rent", + "docs": [ + "Sysvar for token mint and ATA creation" + ], + "address": "SysvarRent111111111111111111111111111111111" + }, + { + "name": "system_program", + "docs": [ + "Program to create the position manager state account" + ], + "address": "11111111111111111111111111111111" + }, + { + "name": "token_program", + "docs": [ + "Program to transfer for token account" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "associated_token_program", + "docs": [ + "Program to create an ATA for receiving position NFT" + ], + "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" + }, + { + "name": "token_program_2022", + "docs": [ + "Program to create NFT mint/token account and transfer for token22 account" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "vault_0_mint", + "docs": [ + "The mint of token vault 0" + ] + }, + { + "name": "vault_1_mint", + "docs": [ + "The mint of token vault 1" + ] + } + ], + "args": [ + { + "name": "tick_lower_index", + "type": "i32" + }, + { + "name": "tick_upper_index", + "type": "i32" + }, + { + "name": "tick_array_lower_start_index", + "type": "i32" + }, + { + "name": "tick_array_upper_start_index", + "type": "i32" + }, + { + "name": "liquidity", + "type": "u128" + }, + { + "name": "amount_0_max", + "type": "u64" + }, + { + "name": "amount_1_max", + "type": "u64" + }, + { + "name": "with_metadata", + "type": "bool" + }, + { + "name": "base_flag", + "type": { + "option": "bool" + } + } + ] + }, + { + "name": "set_reward_params", + "docs": [ + "Reset reward param, start a new reward cycle or extend the current cycle.", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `reward_index` - The index of reward token in the pool.", + "* `emissions_per_second_x64` - The per second emission reward, when extend the current cycle,", + "new value can't be less than old value", + "* `open_time` - reward open timestamp, must be set when starting a new cycle", + "* `end_time` - reward end timestamp", + "" + ], + "discriminator": [ + 112, + 52, + 167, + 75, + 32, + 201, + 211, + 137 + ], + "accounts": [ + { + "name": "authority", + "docs": [ + "Address to be set as protocol owner. It pays to create factory state account." + ], + "signer": true + }, + { + "name": "amm_config" + }, + { + "name": "pool_state", + "writable": true + }, + { + "name": "operation_state", + "docs": [ + "load info from the account to judge reward permission" + ], + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 111, + 112, + 101, + 114, + 97, + 116, + 105, + 111, + 110 + ] + } + ] + } + }, + { + "name": "token_program", + "docs": [ + "Token program" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "Token program 2022" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + } + ], + "args": [ + { + "name": "reward_index", + "type": "u8" + }, + { + "name": "emissions_per_second_x64", + "type": "u128" + }, + { + "name": "open_time", + "type": "u64" + }, + { + "name": "end_time", + "type": "u64" + } + ] + }, + { + "name": "swap", + "docs": [ + "#[deprecated(note = \"Use `swap_v2` instead.\")]", + "Swaps one token for as much as possible of another token across a single pool", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum)", + "* `other_amount_threshold` - For slippage check", + "* `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot", + "* `is_base_input` - swap base input or swap base output", + "" + ], + "discriminator": [ + 248, + 198, + 158, + 145, + 225, + 117, + 135, + 200 + ], + "accounts": [ + { + "name": "payer", + "docs": [ + "The user performing the swap" + ], + "signer": true + }, + { + "name": "amm_config", + "docs": [ + "The factory state to read protocol fees" + ] + }, + { + "name": "pool_state", + "docs": [ + "The program account of the pool in which the swap will be performed" + ], + "writable": true + }, + { + "name": "input_token_account", + "docs": [ + "The user token account for input token" + ], + "writable": true + }, + { + "name": "output_token_account", + "docs": [ + "The user token account for output token" + ], + "writable": true + }, + { + "name": "input_vault", + "docs": [ + "The vault token account for input token" + ], + "writable": true + }, + { + "name": "output_vault", + "docs": [ + "The vault token account for output token" + ], + "writable": true + }, + { + "name": "observation_state", + "docs": [ + "The program account for the most recent oracle observation" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "SPL program for token transfers" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "tick_array", + "writable": true + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "other_amount_threshold", + "type": "u64" + }, + { + "name": "sqrt_price_limit_x64", + "type": "u128" + }, + { + "name": "is_base_input", + "type": "bool" + } + ] + }, + { + "name": "swap_router_base_in", + "docs": [ + "Swap token for as much as possible of another token across the path provided, base input", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `amount_in` - Token amount to be swapped in", + "* `amount_out_minimum` - Panic if output amount is below minimum amount. For slippage.", + "" + ], + "discriminator": [ + 69, + 125, + 115, + 218, + 245, + 186, + 242, + 196 + ], + "accounts": [ + { + "name": "payer", + "docs": [ + "The user performing the swap" + ], + "signer": true + }, + { + "name": "input_token_account", + "docs": [ + "The token account that pays input tokens for the swap" + ], + "writable": true + }, + { + "name": "input_token_mint", + "docs": [ + "The mint of input token" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "SPL program for token transfers" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "SPL program 2022 for token transfers" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "memo_program", + "docs": [ + "Memo program" + ], + "address": "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" + } + ], + "args": [ + { + "name": "amount_in", + "type": "u64" + }, + { + "name": "amount_out_minimum", + "type": "u64" + } + ] + }, + { + "name": "swap_v2", + "docs": [ + "Swaps one token for as much as possible of another token across a single pool, support token program 2022", + "", + "# Arguments", + "", + "* `ctx` - The context of accounts", + "* `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum)", + "* `other_amount_threshold` - For slippage check", + "* `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot", + "* `is_base_input` - swap base input or swap base output", + "" + ], + "discriminator": [ + 43, + 4, + 237, + 11, + 26, + 201, + 30, + 98 + ], + "accounts": [ + { + "name": "payer", + "docs": [ + "The user performing the swap" + ], + "signer": true + }, + { + "name": "amm_config", + "docs": [ + "The factory state to read protocol fees" + ] + }, + { + "name": "pool_state", + "docs": [ + "The program account of the pool in which the swap will be performed" + ], + "writable": true + }, + { + "name": "input_token_account", + "docs": [ + "The user token account for input token" + ], + "writable": true + }, + { + "name": "output_token_account", + "docs": [ + "The user token account for output token" + ], + "writable": true + }, + { + "name": "input_vault", + "docs": [ + "The vault token account for input token" + ], + "writable": true + }, + { + "name": "output_vault", + "docs": [ + "The vault token account for output token" + ], + "writable": true + }, + { + "name": "observation_state", + "docs": [ + "The program account for the most recent oracle observation" + ], + "writable": true + }, + { + "name": "token_program", + "docs": [ + "SPL program for token transfers" + ], + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + }, + { + "name": "token_program_2022", + "docs": [ + "SPL program 2022 for token transfers" + ], + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "memo_program", + "docs": [ + "Memo program" + ], + "address": "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" + }, + { + "name": "input_vault_mint", + "docs": [ + "The mint of token vault 0" + ] + }, + { + "name": "output_vault_mint", + "docs": [ + "The mint of token vault 1" + ] + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "other_amount_threshold", + "type": "u64" + }, + { + "name": "sqrt_price_limit_x64", + "type": "u128" + }, + { + "name": "is_base_input", + "type": "bool" + } + ] + }, + { + "name": "toggle_permissionless_farm_switch", + "docs": [ + "Toggle the permissionless farm switch account", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `is_on`- Is the permissionless farm allowed or not", + "" + ], + "discriminator": [ + 150, + 112, + 54, + 233, + 238, + 161, + 7, + 86 + ], + "accounts": [ + { + "name": "owner", + "writable": true, + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "permissionless_farm_switch", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 101, + 114, + 109, + 105, + 115, + 115, + 105, + 111, + 110, + 108, + 101, + 115, + 115, + 95, + 102, + 97, + 114, + 109, + 95, + 115, + 119, + 105, + 116, + 99, + 104 + ] + } + ] + } + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "is_on", + "type": "bool" + } + ] + }, + { + "name": "transfer_reward_owner", + "docs": [ + "Transfer reward owner", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `new_owner`- new owner pubkey", + "" + ], + "discriminator": [ + 7, + 22, + 12, + 83, + 242, + 43, + 48, + 121 + ], + "accounts": [ + { + "name": "authority", + "docs": [ + "Address to be set as operation account owner." + ], + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "pool_state", + "writable": true + } + ], + "args": [ + { + "name": "new_owner", + "type": "pubkey" + } + ] + }, + { + "name": "update_amm_config", + "docs": [ + "Updates the owner of the amm config", + "Must be called by the current owner or admin", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `trade_fee_rate`- The new trade fee rate of amm config, be set when `param` is 0", + "* `protocol_fee_rate`- The new protocol fee rate of amm config, be set when `param` is 1", + "* `fund_fee_rate`- The new fund fee rate of amm config, be set when `param` is 2", + "* `new_owner`- The config's new owner, be set when `param` is 3", + "* `new_fund_owner`- The config's new fund owner, be set when `param` is 4", + "* `param`- The value can be 0 | 1 | 2 | 3 | 4, otherwise will report a error", + "" + ], + "discriminator": [ + 49, + 60, + 174, + 136, + 154, + 28, + 116, + 200 + ], + "accounts": [ + { + "name": "owner", + "docs": [ + "The amm config owner or admin" + ], + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "amm_config", + "docs": [ + "Amm config account to be changed" + ], + "writable": true + } + ], + "args": [ + { + "name": "param", + "type": "u8" + }, + { + "name": "value", + "type": "u32" + } + ] + }, + { + "name": "update_operation_account", + "docs": [ + "Update the operation account", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `param`- The value can be 0 | 1 | 2 | 3, otherwise will report a error", + "* `keys`- update operation owner when the `param` is 0", + "remove operation owner when the `param` is 1", + "update whitelist mint when the `param` is 2", + "remove whitelist mint when the `param` is 3", + "" + ], + "discriminator": [ + 127, + 70, + 119, + 40, + 188, + 227, + 61, + 7 + ], + "accounts": [ + { + "name": "owner", + "docs": [ + "Address to be set as operation account owner." + ], + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "operation_state", + "docs": [ + "Initialize operation state account to store operation owner address and white list mint." + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 111, + 112, + 101, + 114, + 97, + 116, + 105, + 111, + 110 + ] + } + ] + } + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "param", + "type": "u8" + }, + { + "name": "keys", + "type": { + "vec": "pubkey" + } + } + ] + }, + { + "name": "update_pool_status", + "docs": [ + "Update pool status for given value", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "* `status` - The value of status", + "" + ], + "discriminator": [ + 130, + 87, + 108, + 6, + 46, + 224, + 117, + 123 + ], + "accounts": [ + { + "name": "authority", + "signer": true, + "address": "DmwXqqK5Zuj619au6q2Jx3TMr9ZV1837uxJcEwyvXVtV" + }, + { + "name": "pool_state", + "writable": true + } + ], + "args": [ + { + "name": "status", + "type": "u8" + } + ] + }, + { + "name": "update_reward_infos", + "docs": [ + "Update rewards info of the given pool, can be called for everyone", + "", + "# Arguments", + "", + "* `ctx`- The context of accounts", + "" + ], + "discriminator": [ + 163, + 172, + 224, + 52, + 11, + 154, + 106, + 223 + ], + "accounts": [ + { + "name": "pool_state", + "docs": [ + "The liquidity pool for which reward info to update" + ], + "writable": true + } + ], + "args": [] + } + ], + "accounts": [ + { + "name": "AmmConfig", + "discriminator": [ + 218, + 244, + 33, + 104, + 203, + 203, + 43, + 111 + ] + }, + { + "name": "ObservationState", + "discriminator": [ + 122, + 174, + 197, + 53, + 129, + 9, + 165, + 132 + ] + }, + { + "name": "OperationState", + "discriminator": [ + 19, + 236, + 58, + 237, + 81, + 222, + 183, + 252 + ] + }, + { + "name": "PermissionlessFarmSwitch", + "discriminator": [ + 37, + 92, + 147, + 78, + 250, + 100, + 147, + 137 + ] + }, + { + "name": "PersonalPositionState", + "discriminator": [ + 70, + 111, + 150, + 126, + 230, + 15, + 25, + 117 + ] + }, + { + "name": "PoolState", + "discriminator": [ + 247, + 237, + 227, + 245, + 215, + 195, + 222, + 70 + ] + }, + { + "name": "ProtocolPositionState", + "discriminator": [ + 100, + 226, + 145, + 99, + 146, + 218, + 160, + 106 + ] + }, + { + "name": "SupportMintAssociated", + "discriminator": [ + 134, + 40, + 183, + 79, + 12, + 112, + 162, + 53 + ] + }, + { + "name": "TickArrayBitmapExtension", + "discriminator": [ + 60, + 150, + 36, + 219, + 97, + 128, + 139, + 153 + ] + }, + { + "name": "TickArrayState", + "discriminator": [ + 192, + 155, + 85, + 205, + 49, + 249, + 129, + 42 + ] + } + ], + "events": [ + { + "name": "CollectPersonalFeeEvent", + "discriminator": [ + 166, + 174, + 105, + 192, + 81, + 161, + 83, + 105 + ] + }, + { + "name": "CollectProtocolFeeEvent", + "discriminator": [ + 206, + 87, + 17, + 79, + 45, + 41, + 213, + 61 + ] + }, + { + "name": "ConfigChangeEvent", + "discriminator": [ + 247, + 189, + 7, + 119, + 106, + 112, + 95, + 151 + ] + }, + { + "name": "CreatePersonalPositionEvent", + "discriminator": [ + 100, + 30, + 87, + 249, + 196, + 223, + 154, + 206 + ] + }, + { + "name": "DecreaseLiquidityEvent", + "discriminator": [ + 58, + 222, + 86, + 58, + 68, + 50, + 85, + 56 + ] + }, + { + "name": "IncreaseLiquidityEvent", + "discriminator": [ + 49, + 79, + 105, + 212, + 32, + 34, + 30, + 84 + ] + }, + { + "name": "LiquidityCalculateEvent", + "discriminator": [ + 237, + 112, + 148, + 230, + 57, + 84, + 180, + 162 + ] + }, + { + "name": "LiquidityChangeEvent", + "discriminator": [ + 126, + 240, + 175, + 206, + 158, + 88, + 153, + 107 + ] + }, + { + "name": "PoolCreatedEvent", + "discriminator": [ + 25, + 94, + 75, + 47, + 112, + 99, + 53, + 63 + ] + }, + { + "name": "SwapEvent", + "discriminator": [ + 64, + 198, + 205, + 232, + 38, + 8, + 113, + 226 + ] + }, + { + "name": "UpdateRewardInfosEvent", + "discriminator": [ + 109, + 127, + 186, + 78, + 114, + 65, + 37, + 236 + ] + } + ], + "errors": [ + { + "code": 6000, + "name": "LOK", + "msg": "LOK" + }, + { + "code": 6001, + "name": "NotApproved", + "msg": "Not approved" + }, + { + "code": 6002, + "name": "InvalidUpdateConfigFlag", + "msg": "invalid update amm config flag" + }, + { + "code": 6003, + "name": "AccountLack", + "msg": "Account lack" + }, + { + "code": 6004, + "name": "ClosePositionErr", + "msg": "Remove liquitity, collect fees owed and reward then you can close position account" + }, + { + "code": 6005, + "name": "ZeroMintAmount", + "msg": "Minting amount should be greater than 0" + }, + { + "code": 6006, + "name": "InvalidTickIndex", + "msg": "Tick out of range" + }, + { + "code": 6007, + "name": "TickInvalidOrder", + "msg": "The lower tick must be below the upper tick" + }, + { + "code": 6008, + "name": "TickLowerOverflow", + "msg": "The tick must be greater, or equal to the minimum tick(-443636)" + }, + { + "code": 6009, + "name": "TickUpperOverflow", + "msg": "The tick must be lesser than, or equal to the maximum tick(443636)" + }, + { + "code": 6010, + "name": "TickAndSpacingNotMatch", + "msg": "tick % tick_spacing must be zero" + }, + { + "code": 6011, + "name": "InvalidTickArray", + "msg": "Invalid tick array account" + }, + { + "code": 6012, + "name": "InvalidTickArrayBoundary", + "msg": "Invalid tick array boundary" + }, + { + "code": 6013, + "name": "SqrtPriceLimitOverflow", + "msg": "Square root price limit overflow" + }, + { + "code": 6014, + "name": "SqrtPriceX64", + "msg": "sqrt_price_x64 out of range" + }, + { + "code": 6015, + "name": "LiquiditySubValueErr", + "msg": "Liquidity sub delta L must be smaller than before" + }, + { + "code": 6016, + "name": "LiquidityAddValueErr", + "msg": "Liquidity add delta L must be greater, or equal to before" + }, + { + "code": 6017, + "name": "InvalidLiquidity", + "msg": "Invalid liquidity when update position" + }, + { + "code": 6018, + "name": "ForbidBothZeroForSupplyLiquidity", + "msg": "Both token amount must not be zero while supply liquidity" + }, + { + "code": 6019, + "name": "LiquidityInsufficient", + "msg": "Liquidity insufficient" + }, + { + "code": 6020, + "name": "TransactionTooOld", + "msg": "Transaction too old" + }, + { + "code": 6021, + "name": "PriceSlippageCheck", + "msg": "Price slippage check" + }, + { + "code": 6022, + "name": "TooLittleOutputReceived", + "msg": "Too little output received" + }, + { + "code": 6023, + "name": "TooMuchInputPaid", + "msg": "Too much input paid" + }, + { + "code": 6024, + "name": "ZeroAmountSpecified", + "msg": "Swap special amount can not be zero" + }, + { + "code": 6025, + "name": "InvalidInputPoolVault", + "msg": "Input pool vault is invalid" + }, + { + "code": 6026, + "name": "TooSmallInputOrOutputAmount", + "msg": "Swap input or output amount is too small" + }, + { + "code": 6027, + "name": "NotEnoughTickArrayAccount", + "msg": "Not enought tick array account" + }, + { + "code": 6028, + "name": "InvalidFirstTickArrayAccount", + "msg": "Invalid first tick array account" + }, + { + "code": 6029, + "name": "InvalidRewardIndex", + "msg": "Invalid reward index" + }, + { + "code": 6030, + "name": "FullRewardInfo", + "msg": "The init reward token reach to the max" + }, + { + "code": 6031, + "name": "RewardTokenAlreadyInUse", + "msg": "The init reward token already in use" + }, + { + "code": 6032, + "name": "ExceptRewardMint", + "msg": "The reward tokens must contain one of pool vault mint except the last reward" + }, + { + "code": 6033, + "name": "InvalidRewardInitParam", + "msg": "Invalid reward init param" + }, + { + "code": 6034, + "name": "InvalidRewardDesiredAmount", + "msg": "Invalid collect reward desired amount" + }, + { + "code": 6035, + "name": "InvalidRewardInputAccountNumber", + "msg": "Invalid collect reward input account number" + }, + { + "code": 6036, + "name": "InvalidRewardPeriod", + "msg": "Invalid reward period" + }, + { + "code": 6037, + "name": "NotApproveUpdateRewardEmissiones", + "msg": "Modification of emissiones is allowed within 72 hours from the end of the previous cycle" + }, + { + "code": 6038, + "name": "UnInitializedRewardInfo", + "msg": "uninitialized reward info" + }, + { + "code": 6039, + "name": "NotSupportMint", + "msg": "Not support token_2022 mint extension" + }, + { + "code": 6040, + "name": "MissingTickArrayBitmapExtensionAccount", + "msg": "Missing tickarray bitmap extension account" + }, + { + "code": 6041, + "name": "InsufficientLiquidityForDirection", + "msg": "Insufficient liquidity for this direction" + }, + { + "code": 6042, + "name": "MaxTokenOverflow", + "msg": "Max token overflow" + }, + { + "code": 6043, + "name": "CalculateOverflow", + "msg": "Calculate overflow" + }, + { + "code": 6044, + "name": "TransferFeeCalculateNotMatch", + "msg": "TransferFee calculate not match" + } + ], + "types": [ + { + "name": "AmmConfig", + "docs": [ + "Holds the current owner of the factory" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "index", + "type": "u16" + }, + { + "name": "owner", + "docs": [ + "Address of the protocol owner" + ], + "type": "pubkey" + }, + { + "name": "protocol_fee_rate", + "docs": [ + "The protocol fee" + ], + "type": "u32" + }, + { + "name": "trade_fee_rate", + "docs": [ + "The trade fee, denominated in hundredths of a bip (10^-6)" + ], + "type": "u32" + }, + { + "name": "tick_spacing", + "docs": [ + "The tick spacing" + ], + "type": "u16" + }, + { + "name": "fund_fee_rate", + "docs": [ + "The fund fee, denominated in hundredths of a bip (10^-6)" + ], + "type": "u32" + }, + { + "name": "padding_u32", + "type": "u32" + }, + { + "name": "fund_owner", + "type": "pubkey" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 3 + ] + } + } + ] + } + }, + { + "name": "CollectPersonalFeeEvent", + "docs": [ + "Emitted when tokens are collected for a position" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "position_nft_mint", + "docs": [ + "The ID of the token for which underlying tokens were collected" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The token account that received the collected token_0 tokens" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The token account that received the collected token_1 tokens" + ], + "type": "pubkey" + }, + { + "name": "amount_0", + "docs": [ + "The amount of token_0 owed to the position that was collected" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The amount of token_1 owed to the position that was collected" + ], + "type": "u64" + } + ] + } + }, + { + "name": "CollectProtocolFeeEvent", + "docs": [ + "Emitted when the collected protocol fees are withdrawn by the factory owner" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool whose protocol fee is collected" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_0", + "docs": [ + "The address that receives the collected token_0 protocol fees" + ], + "type": "pubkey" + }, + { + "name": "recipient_token_account_1", + "docs": [ + "The address that receives the collected token_1 protocol fees" + ], + "type": "pubkey" + }, + { + "name": "amount_0", + "docs": [ + "The amount of token_0 protocol fees that is withdrawn" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The amount of token_0 protocol fees that is withdrawn" + ], + "type": "u64" + } + ] + } + }, + { + "name": "ConfigChangeEvent", + "docs": [ + "Emitted when create or update a config" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "index", + "type": "u16" + }, + { + "name": "owner", + "type": "pubkey" + }, + { + "name": "protocol_fee_rate", + "type": "u32" + }, + { + "name": "trade_fee_rate", + "type": "u32" + }, + { + "name": "tick_spacing", + "type": "u16" + }, + { + "name": "fund_fee_rate", + "type": "u32" + }, + { + "name": "fund_owner", + "type": "pubkey" + } + ] + } + }, + { + "name": "CreatePersonalPositionEvent", + "docs": [ + "Emitted when create a new position" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool for which liquidity was added" + ], + "type": "pubkey" + }, + { + "name": "minter", + "docs": [ + "The address that create the position" + ], + "type": "pubkey" + }, + { + "name": "nft_owner", + "docs": [ + "The owner of the position and recipient of any minted liquidity" + ], + "type": "pubkey" + }, + { + "name": "tick_lower_index", + "docs": [ + "The lower tick of the position" + ], + "type": "i32" + }, + { + "name": "tick_upper_index", + "docs": [ + "The upper tick of the position" + ], + "type": "i32" + }, + { + "name": "liquidity", + "docs": [ + "The amount of liquidity minted to the position range" + ], + "type": "u128" + }, + { + "name": "deposit_amount_0", + "docs": [ + "The amount of token_0 was deposit for the liquidity" + ], + "type": "u64" + }, + { + "name": "deposit_amount_1", + "docs": [ + "The amount of token_1 was deposit for the liquidity" + ], + "type": "u64" + }, + { + "name": "deposit_amount_0_transfer_fee", + "docs": [ + "The token transfer fee for deposit_amount_0" + ], + "type": "u64" + }, + { + "name": "deposit_amount_1_transfer_fee", + "docs": [ + "The token transfer fee for deposit_amount_1" + ], + "type": "u64" + } + ] + } + }, + { + "name": "DecreaseLiquidityEvent", + "docs": [ + "Emitted when liquidity is decreased." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "position_nft_mint", + "docs": [ + "The ID of the token for which liquidity was decreased" + ], + "type": "pubkey" + }, + { + "name": "liquidity", + "docs": [ + "The amount by which liquidity for the position was decreased" + ], + "type": "u128" + }, + { + "name": "decrease_amount_0", + "docs": [ + "The amount of token_0 that was paid for the decrease in liquidity" + ], + "type": "u64" + }, + { + "name": "decrease_amount_1", + "docs": [ + "The amount of token_1 that was paid for the decrease in liquidity" + ], + "type": "u64" + }, + { + "name": "fee_amount_0", + "type": "u64" + }, + { + "name": "fee_amount_1", + "docs": [ + "The amount of token_1 fee" + ], + "type": "u64" + }, + { + "name": "reward_amounts", + "docs": [ + "The amount of rewards" + ], + "type": { + "array": [ + "u64", + 3 + ] + } + }, + { + "name": "transfer_fee_0", + "docs": [ + "The amount of token_0 transfer fee" + ], + "type": "u64" + }, + { + "name": "transfer_fee_1", + "docs": [ + "The amount of token_1 transfer fee" + ], + "type": "u64" + } + ] + } + }, + { + "name": "IncreaseLiquidityEvent", + "docs": [ + "Emitted when liquidity is increased." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "position_nft_mint", + "docs": [ + "The ID of the token for which liquidity was increased" + ], + "type": "pubkey" + }, + { + "name": "liquidity", + "docs": [ + "The amount by which liquidity for the NFT position was increased" + ], + "type": "u128" + }, + { + "name": "amount_0", + "docs": [ + "The amount of token_0 that was paid for the increase in liquidity" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The amount of token_1 that was paid for the increase in liquidity" + ], + "type": "u64" + }, + { + "name": "amount_0_transfer_fee", + "docs": [ + "The token transfer fee for amount_0" + ], + "type": "u64" + }, + { + "name": "amount_1_transfer_fee", + "docs": [ + "The token transfer fee for amount_1" + ], + "type": "u64" + } + ] + } + }, + { + "name": "InitializeRewardParam", + "type": { + "kind": "struct", + "fields": [ + { + "name": "open_time", + "docs": [ + "Reward open time" + ], + "type": "u64" + }, + { + "name": "end_time", + "docs": [ + "Reward end time" + ], + "type": "u64" + }, + { + "name": "emissions_per_second_x64", + "docs": [ + "Token reward per second are earned per unit of liquidity" + ], + "type": "u128" + } + ] + } + }, + { + "name": "LiquidityCalculateEvent", + "docs": [ + "Emitted when liquidity decreased or increase." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_liquidity", + "docs": [ + "The pool liquidity before decrease or increase" + ], + "type": "u128" + }, + { + "name": "pool_sqrt_price_x64", + "docs": [ + "The pool price when decrease or increase in liquidity" + ], + "type": "u128" + }, + { + "name": "pool_tick", + "docs": [ + "The pool tick when decrease or increase in liquidity" + ], + "type": "i32" + }, + { + "name": "calc_amount_0", + "docs": [ + "The amount of token_0 that was calculated for the decrease or increase in liquidity" + ], + "type": "u64" + }, + { + "name": "calc_amount_1", + "docs": [ + "The amount of token_1 that was calculated for the decrease or increase in liquidity" + ], + "type": "u64" + }, + { + "name": "trade_fee_owed_0", + "type": "u64" + }, + { + "name": "trade_fee_owed_1", + "docs": [ + "The amount of token_1 fee" + ], + "type": "u64" + }, + { + "name": "transfer_fee_0", + "docs": [ + "The amount of token_0 transfer fee without trade_fee_amount_0" + ], + "type": "u64" + }, + { + "name": "transfer_fee_1", + "docs": [ + "The amount of token_1 transfer fee without trade_fee_amount_0" + ], + "type": "u64" + } + ] + } + }, + { + "name": "LiquidityChangeEvent", + "docs": [ + "Emitted pool liquidity change when increase and decrease liquidity" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool for swap" + ], + "type": "pubkey" + }, + { + "name": "tick", + "docs": [ + "The tick of the pool" + ], + "type": "i32" + }, + { + "name": "tick_lower", + "docs": [ + "The tick lower of position" + ], + "type": "i32" + }, + { + "name": "tick_upper", + "docs": [ + "The tick lower of position" + ], + "type": "i32" + }, + { + "name": "liquidity_before", + "docs": [ + "The liquidity of the pool before liquidity change" + ], + "type": "u128" + }, + { + "name": "liquidity_after", + "docs": [ + "The liquidity of the pool after liquidity change" + ], + "type": "u128" + } + ] + } + }, + { + "name": "Observation", + "docs": [ + "The element of observations in ObservationState" + ], + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "block_timestamp", + "docs": [ + "The block timestamp of the observation" + ], + "type": "u32" + }, + { + "name": "tick_cumulative", + "docs": [ + "the cumulative of tick during the duration time" + ], + "type": "i64" + }, + { + "name": "padding", + "docs": [ + "padding for feature update" + ], + "type": { + "array": [ + "u64", + 4 + ] + } + } + ] + } + }, + { + "name": "ObservationState", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "initialized", + "docs": [ + "Whether the ObservationState is initialized" + ], + "type": "bool" + }, + { + "name": "recent_epoch", + "docs": [ + "recent update epoch" + ], + "type": "u64" + }, + { + "name": "observation_index", + "docs": [ + "the most-recently updated index of the observations array" + ], + "type": "u16" + }, + { + "name": "pool_id", + "docs": [ + "belongs to which pool" + ], + "type": "pubkey" + }, + { + "name": "observations", + "docs": [ + "observation array" + ], + "type": { + "array": [ + { + "defined": { + "name": "Observation" + } + }, + 100 + ] + } + }, + { + "name": "padding", + "docs": [ + "padding for feature update" + ], + "type": { + "array": [ + "u64", + 4 + ] + } + } + ] + } + }, + { + "name": "OperationState", + "docs": [ + "Holds the current owner of the factory" + ], + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "operation_owners", + "docs": [ + "Address of the operation owner" + ], + "type": { + "array": [ + "pubkey", + 10 + ] + } + }, + { + "name": "whitelist_mints", + "docs": [ + "The mint address of whitelist to emit reward" + ], + "type": { + "array": [ + "pubkey", + 100 + ] + } + } + ] + } + }, + { + "name": "PermissionlessFarmSwitch", + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "is_on", + "docs": [ + "Is the permissionless farm allowed or not" + ], + "type": "bool" + } + ] + } + }, + { + "name": "PersonalPositionState", + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": { + "array": [ + "u8", + 1 + ] + } + }, + { + "name": "nft_mint", + "docs": [ + "Mint address of the tokenized position" + ], + "type": "pubkey" + }, + { + "name": "pool_id", + "docs": [ + "The ID of the pool with which this token is connected" + ], + "type": "pubkey" + }, + { + "name": "tick_lower_index", + "docs": [ + "The lower bound tick of the position" + ], + "type": "i32" + }, + { + "name": "tick_upper_index", + "docs": [ + "The upper bound tick of the position" + ], + "type": "i32" + }, + { + "name": "liquidity", + "docs": [ + "The amount of liquidity owned by this position" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_0_last_x64", + "docs": [ + "The token_0 fee growth of the aggregate position as of the last action on the individual position" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_1_last_x64", + "docs": [ + "The token_1 fee growth of the aggregate position as of the last action on the individual position" + ], + "type": "u128" + }, + { + "name": "token_fees_owed_0", + "docs": [ + "The fees owed to the position owner in token_0, as of the last computation" + ], + "type": "u64" + }, + { + "name": "token_fees_owed_1", + "docs": [ + "The fees owed to the position owner in token_1, as of the last computation" + ], + "type": "u64" + }, + { + "name": "reward_infos", + "type": { + "array": [ + { + "defined": { + "name": "PositionRewardInfo" + } + }, + 3 + ] + } + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 7 + ] + } + } + ] + } + }, + { + "name": "PoolCreatedEvent", + "docs": [ + "Emitted when a pool is created and initialized with a starting price", + "" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "token_mint_0", + "docs": [ + "The first token of the pool by address sort order" + ], + "type": "pubkey" + }, + { + "name": "token_mint_1", + "docs": [ + "The second token of the pool by address sort order" + ], + "type": "pubkey" + }, + { + "name": "tick_spacing", + "docs": [ + "The minimum number of ticks between initialized ticks" + ], + "type": "u16" + }, + { + "name": "pool_state", + "docs": [ + "The address of the created pool" + ], + "type": "pubkey" + }, + { + "name": "sqrt_price_x64", + "docs": [ + "The initial sqrt price of the pool, as a Q64.64" + ], + "type": "u128" + }, + { + "name": "tick", + "docs": [ + "The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool" + ], + "type": "i32" + }, + { + "name": "token_vault_0", + "docs": [ + "Vault of token_0" + ], + "type": "pubkey" + }, + { + "name": "token_vault_1", + "docs": [ + "Vault of token_1" + ], + "type": "pubkey" + } + ] + } + }, + { + "name": "PoolState", + "docs": [ + "The pool state", + "", + "PDA of `[POOL_SEED, config, token_mint_0, token_mint_1]`", + "" + ], + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": { + "array": [ + "u8", + 1 + ] + } + }, + { + "name": "amm_config", + "type": "pubkey" + }, + { + "name": "owner", + "type": "pubkey" + }, + { + "name": "token_mint_0", + "docs": [ + "Token pair of the pool, where token_mint_0 address < token_mint_1 address" + ], + "type": "pubkey" + }, + { + "name": "token_mint_1", + "type": "pubkey" + }, + { + "name": "token_vault_0", + "docs": [ + "Token pair vault" + ], + "type": "pubkey" + }, + { + "name": "token_vault_1", + "type": "pubkey" + }, + { + "name": "observation_key", + "docs": [ + "observation account key" + ], + "type": "pubkey" + }, + { + "name": "mint_decimals_0", + "docs": [ + "mint0 and mint1 decimals" + ], + "type": "u8" + }, + { + "name": "mint_decimals_1", + "type": "u8" + }, + { + "name": "tick_spacing", + "docs": [ + "The minimum number of ticks between initialized ticks" + ], + "type": "u16" + }, + { + "name": "liquidity", + "docs": [ + "The currently in range liquidity available to the pool." + ], + "type": "u128" + }, + { + "name": "sqrt_price_x64", + "docs": [ + "The current price of the pool as a sqrt(token_1/token_0) Q64.64 value" + ], + "type": "u128" + }, + { + "name": "tick_current", + "docs": [ + "The current tick of the pool, i.e. according to the last tick transition that was run." + ], + "type": "i32" + }, + { + "name": "padding3", + "type": "u16" + }, + { + "name": "padding4", + "type": "u16" + }, + { + "name": "fee_growth_global_0_x64", + "docs": [ + "The fee growth as a Q64.64 number, i.e. fees of token_0 and token_1 collected per", + "unit of liquidity for the entire life of the pool." + ], + "type": "u128" + }, + { + "name": "fee_growth_global_1_x64", + "type": "u128" + }, + { + "name": "protocol_fees_token_0", + "docs": [ + "The amounts of token_0 and token_1 that are owed to the protocol." + ], + "type": "u64" + }, + { + "name": "protocol_fees_token_1", + "type": "u64" + }, + { + "name": "swap_in_amount_token_0", + "docs": [ + "The amounts in and out of swap token_0 and token_1" + ], + "type": "u128" + }, + { + "name": "swap_out_amount_token_1", + "type": "u128" + }, + { + "name": "swap_in_amount_token_1", + "type": "u128" + }, + { + "name": "swap_out_amount_token_0", + "type": "u128" + }, + { + "name": "status", + "docs": [ + "Bitwise representation of the state of the pool", + "bit0, 1: disable open position and increase liquidity, 0: normal", + "bit1, 1: disable decrease liquidity, 0: normal", + "bit2, 1: disable collect fee, 0: normal", + "bit3, 1: disable collect reward, 0: normal", + "bit4, 1: disable swap, 0: normal" + ], + "type": "u8" + }, + { + "name": "padding", + "docs": [ + "Leave blank for future use" + ], + "type": { + "array": [ + "u8", + 7 + ] + } + }, + { + "name": "reward_infos", + "type": { + "array": [ + { + "defined": { + "name": "RewardInfo" + } + }, + 3 + ] + } + }, + { + "name": "tick_array_bitmap", + "docs": [ + "Packed initialized tick array state" + ], + "type": { + "array": [ + "u64", + 16 + ] + } + }, + { + "name": "total_fees_token_0", + "docs": [ + "except protocol_fee and fund_fee" + ], + "type": "u64" + }, + { + "name": "total_fees_claimed_token_0", + "docs": [ + "except protocol_fee and fund_fee" + ], + "type": "u64" + }, + { + "name": "total_fees_token_1", + "type": "u64" + }, + { + "name": "total_fees_claimed_token_1", + "type": "u64" + }, + { + "name": "fund_fees_token_0", + "type": "u64" + }, + { + "name": "fund_fees_token_1", + "type": "u64" + }, + { + "name": "open_time", + "type": "u64" + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding1", + "type": { + "array": [ + "u64", + 24 + ] + } + }, + { + "name": "padding2", + "type": { + "array": [ + "u64", + 32 + ] + } + } + ] + } + }, + { + "name": "PositionRewardInfo", + "type": { + "kind": "struct", + "fields": [ + { + "name": "growth_inside_last_x64", + "type": "u128" + }, + { + "name": "reward_amount_owed", + "type": "u64" + } + ] + } + }, + { + "name": "ProtocolPositionState", + "docs": [ + "Info stored for each user's position" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "pool_id", + "docs": [ + "The ID of the pool with which this token is connected" + ], + "type": "pubkey" + }, + { + "name": "tick_lower_index", + "docs": [ + "The lower bound tick of the position" + ], + "type": "i32" + }, + { + "name": "tick_upper_index", + "docs": [ + "The upper bound tick of the position" + ], + "type": "i32" + }, + { + "name": "liquidity", + "docs": [ + "The amount of liquidity owned by this position" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_0_last_x64", + "docs": [ + "The token_0 fee growth per unit of liquidity as of the last update to liquidity or fees owed" + ], + "type": "u128" + }, + { + "name": "fee_growth_inside_1_last_x64", + "docs": [ + "The token_1 fee growth per unit of liquidity as of the last update to liquidity or fees owed" + ], + "type": "u128" + }, + { + "name": "token_fees_owed_0", + "docs": [ + "The fees owed to the position owner in token_0" + ], + "type": "u64" + }, + { + "name": "token_fees_owed_1", + "docs": [ + "The fees owed to the position owner in token_1" + ], + "type": "u64" + }, + { + "name": "reward_growth_inside", + "docs": [ + "The reward growth per unit of liquidity as of the last update to liquidity" + ], + "type": { + "array": [ + "u128", + 3 + ] + } + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 7 + ] + } + } + ] + } + }, + { + "name": "RewardInfo", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "reward_state", + "docs": [ + "Reward state" + ], + "type": "u8" + }, + { + "name": "open_time", + "docs": [ + "Reward open time" + ], + "type": "u64" + }, + { + "name": "end_time", + "docs": [ + "Reward end time" + ], + "type": "u64" + }, + { + "name": "last_update_time", + "docs": [ + "Reward last update time" + ], + "type": "u64" + }, + { + "name": "emissions_per_second_x64", + "docs": [ + "Q64.64 number indicates how many tokens per second are earned per unit of liquidity." + ], + "type": "u128" + }, + { + "name": "reward_total_emissioned", + "docs": [ + "The total amount of reward emissioned" + ], + "type": "u64" + }, + { + "name": "reward_claimed", + "docs": [ + "The total amount of claimed reward" + ], + "type": "u64" + }, + { + "name": "token_mint", + "docs": [ + "Reward token mint." + ], + "type": "pubkey" + }, + { + "name": "token_vault", + "docs": [ + "Reward vault token account." + ], + "type": "pubkey" + }, + { + "name": "authority", + "docs": [ + "The owner that has permission to set reward param" + ], + "type": "pubkey" + }, + { + "name": "reward_growth_global_x64", + "docs": [ + "Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward", + "emissions were turned on." + ], + "type": "u128" + } + ] + } + }, + { + "name": "SupportMintAssociated", + "docs": [ + "Holds the current owner of the factory" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "docs": [ + "Bump to identify PDA" + ], + "type": "u8" + }, + { + "name": "mint", + "docs": [ + "Address of the supported token22 mint" + ], + "type": "pubkey" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 8 + ] + } + } + ] + } + }, + { + "name": "SwapEvent", + "docs": [ + "Emitted by when a swap is performed for a pool" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_state", + "docs": [ + "The pool for which token_0 and token_1 were swapped" + ], + "type": "pubkey" + }, + { + "name": "sender", + "docs": [ + "The address that initiated the swap call, and that received the callback" + ], + "type": "pubkey" + }, + { + "name": "token_account_0", + "docs": [ + "The payer token account in zero for one swaps, or the recipient token account", + "in one for zero swaps" + ], + "type": "pubkey" + }, + { + "name": "token_account_1", + "docs": [ + "The payer token account in one for zero swaps, or the recipient token account", + "in zero for one swaps" + ], + "type": "pubkey" + }, + { + "name": "amount_0", + "docs": [ + "The real delta amount of the token_0 of the pool or user" + ], + "type": "u64" + }, + { + "name": "transfer_fee_0", + "docs": [ + "The transfer fee charged by the withheld_amount of the token_0" + ], + "type": "u64" + }, + { + "name": "amount_1", + "docs": [ + "The real delta of the token_1 of the pool or user" + ], + "type": "u64" + }, + { + "name": "transfer_fee_1", + "docs": [ + "The transfer fee charged by the withheld_amount of the token_1" + ], + "type": "u64" + }, + { + "name": "zero_for_one", + "docs": [ + "if true, amount_0 is negtive and amount_1 is positive" + ], + "type": "bool" + }, + { + "name": "sqrt_price_x64", + "docs": [ + "The sqrt(price) of the pool after the swap, as a Q64.64" + ], + "type": "u128" + }, + { + "name": "liquidity", + "docs": [ + "The liquidity of the pool after the swap" + ], + "type": "u128" + }, + { + "name": "tick", + "docs": [ + "The log base 1.0001 of price of the pool after the swap" + ], + "type": "i32" + } + ] + } + }, + { + "name": "TickArrayBitmapExtension", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_id", + "type": "pubkey" + }, + { + "name": "positive_tick_array_bitmap", + "docs": [ + "Packed initialized tick array state for start_tick_index is positive" + ], + "type": { + "array": [ + { + "array": [ + "u64", + 8 + ] + }, + 14 + ] + } + }, + { + "name": "negative_tick_array_bitmap", + "docs": [ + "Packed initialized tick array state for start_tick_index is negitive" + ], + "type": { + "array": [ + { + "array": [ + "u64", + 8 + ] + }, + 14 + ] + } + } + ] + } + }, + { + "name": "TickArrayState", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "pool_id", + "type": "pubkey" + }, + { + "name": "start_tick_index", + "type": "i32" + }, + { + "name": "ticks", + "type": { + "array": [ + { + "defined": { + "name": "TickState" + } + }, + 60 + ] + } + }, + { + "name": "initialized_tick_count", + "type": "u8" + }, + { + "name": "recent_epoch", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 107 + ] + } + } + ] + } + }, + { + "name": "TickState", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "tick", + "type": "i32" + }, + { + "name": "liquidity_net", + "docs": [ + "Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)" + ], + "type": "i128" + }, + { + "name": "liquidity_gross", + "docs": [ + "The total position liquidity that references this tick" + ], + "type": "u128" + }, + { + "name": "fee_growth_outside_0_x64", + "docs": [ + "Fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)", + "only has relative meaning, not absolute — the value depends on when the tick is initialized" + ], + "type": "u128" + }, + { + "name": "fee_growth_outside_1_x64", + "type": "u128" + }, + { + "name": "reward_growths_outside_x64", + "type": { + "array": [ + "u128", + 3 + ] + } + }, + { + "name": "padding", + "type": { + "array": [ + "u32", + 13 + ] + } + } + ] + } + }, + { + "name": "UpdateRewardInfosEvent", + "docs": [ + "Emitted when Reward are updated for a pool" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "reward_growth_global_x64", + "docs": [ + "Reward info" + ], + "type": { + "array": [ + "u128", + 3 + ] + } + } + ] + } + } + ] +} From 3d5d43bb73d0096be790bc9e72255dea57a69941 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Tue, 17 Nov 2026 08:55:15 +0200 Subject: [PATCH 15/20] test(pancakeswap): register the scenario at the next slot --- crates/core/src/tests/pancakeswap/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/core/src/tests/pancakeswap/mod.rs b/crates/core/src/tests/pancakeswap/mod.rs index 6d1c4aaa2..96daeaf80 100644 --- a/crates/core/src/tests/pancakeswap/mod.rs +++ b/crates/core/src/tests/pancakeswap/mod.rs @@ -209,9 +209,10 @@ async fn overrides_through_materializer_touch_only_their_own_bytes() { .to_string(), ); scenario.add_override(pool_override); - locker.register_scenario(scenario, Some(0)).unwrap(); + let next_slot = locker.get_latest_absolute_slot() + 1; + locker.register_scenario(scenario, Some(next_slot)).unwrap(); locker - .materialize_overrides_for_slot(&None, 1) + .materialize_overrides_for_slot(&None, next_slot + 1) .await .unwrap(); From d80767f831c8a63ae35854b2b4300c717a600e64 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Fri, 20 Nov 2026 14:03:28 +0200 Subject: [PATCH 16/20] fix(scenarios): check the owner of a PancakeSwap pool the user gives --- crates/core/src/scenarios/protocols/pancakeswap/README.md | 3 ++- .../core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index a88c2c7b5..b5b23261f 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -31,7 +31,8 @@ most is usually the one you want. For SOL/USDC that is at `https://solana.pancakeswap.finance/liquidity-pools/`. **Check the owner.** The layouts match Raydium's, so a PancakeSwap template pointed at a Raydium -pool writes it without complaint. +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. diff --git a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml index 3a5bb6464..2bb9b6cce 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml +++ b/crates/core/src/scenarios/protocols/pancakeswap/v1/overrides.yaml @@ -16,7 +16,8 @@ llm_context: | order (only one returns pools). Read each pool's token_vault_0 with dataSlice {offset 137, length 32} and encoding base58, compare the vaults with getMultipleAccounts jsonParsed and keep the pool whose vault holds the most; name it. If neither order returns a pool, recheck the mints once, then - ask for the pool address. A pool address the user gives is used as is. + ask for the pool address. Before you use a pool address the user gives, check with getAccountInfo + that the program above owns it; if it does not, stop and tell the user. Set fetchBeforeUse: true. From 3cf6cad6a3131ba4682a48d32b7b8a63af6fd5b1 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Fri, 20 Nov 2026 14:03:28 +0200 Subject: [PATCH 17/20] test(scenarios): move the PancakeSwap tests to tests/protocols with their own diff_indices --- crates/core/src/tests/helpers.rs | 10 ---------- crates/core/src/tests/kamino/mod.rs | 11 ++++++++++- crates/core/src/tests/mod.rs | 4 ++-- crates/core/src/tests/protocols/mod.rs | 11 +++++++++++ .../src/tests/{ => protocols}/pancakeswap/mod.rs | 11 ++++++++++- crates/core/src/tests/pump/mod.rs | 12 +++++++++++- 6 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 crates/core/src/tests/protocols/mod.rs rename crates/core/src/tests/{ => protocols}/pancakeswap/mod.rs (97%) diff --git a/crates/core/src/tests/helpers.rs b/crates/core/src/tests/helpers.rs index b42958ec0..8c70bcd62 100644 --- a/crates/core/src/tests/helpers.rs +++ b/crates/core/src/tests/helpers.rs @@ -26,16 +26,6 @@ use crate::{ }, }; -/// Returns the byte indices whose values differ between two buffers. -pub(super) fn diff_indices(left: &[u8], right: &[u8]) -> Vec { - left.iter() - .zip(right.iter()) - .enumerate() - .filter(|(_, (left, right))| left != right) - .map(|(index, _)| index) - .collect() -} - pub fn get_free_port() -> Result { let listener = TcpListener::bind("127.0.0.1:0").map_err(|e| format!("Failed to bind to port 0: {}", e))?; diff --git a/crates/core/src/tests/kamino/mod.rs b/crates/core/src/tests/kamino/mod.rs index dccfa1def..aef2ba25e 100644 --- a/crates/core/src/tests/kamino/mod.rs +++ b/crates/core/src/tests/kamino/mod.rs @@ -22,7 +22,6 @@ use solana_pubkey::Pubkey; use crate::{ scenarios::TemplateRegistry, surfnet::{GetAccountResult, remote::SurfnetRemoteClient, svm::SurfnetSvm}, - tests::helpers::diff_indices, }; const RPC_URL_ENV: &str = "SURFPOOL_TEST_RPC_URL"; @@ -69,6 +68,16 @@ async fn fetch(addresses: &[&str]) -> Vec> { .collect() } +/// Byte indices at which two buffers differ. +fn diff_indices(a: &[u8], b: &[u8]) -> Vec { + a.iter() + .zip(b.iter()) + .enumerate() + .filter(|(_, (x, y))| x != y) + .map(|(i, _)| i) + .collect() +} + /// A failure here means a bundled IDL disagrees with the live on-chain layout. #[tokio::test] async fn real_mainnet_accounts_round_trip_unchanged() { diff --git a/crates/core/src/tests/mod.rs b/crates/core/src/tests/mod.rs index d7aad5dd3..28233e7f3 100644 --- a/crates/core/src/tests/mod.rs +++ b/crates/core/src/tests/mod.rs @@ -3,10 +3,10 @@ pub mod integration; #[cfg(feature = "integration-tests")] pub mod kamino; #[cfg(feature = "integration-tests")] -pub mod pancakeswap; -#[cfg(feature = "integration-tests")] pub mod phoenix; pub mod plugin; #[cfg(feature = "integration-tests")] +pub mod protocols; +#[cfg(feature = "integration-tests")] pub mod pump; pub mod simnet_events; diff --git a/crates/core/src/tests/protocols/mod.rs b/crates/core/src/tests/protocols/mod.rs new file mode 100644 index 000000000..fd045e224 --- /dev/null +++ b/crates/core/src/tests/protocols/mod.rs @@ -0,0 +1,11 @@ +//! Tests against live mainnet state, one module per integrated protocol. +//! +//! They need a network, so they are compiled only behind a feature. One filter runs them all: +//! +//! ```text +//! cargo test -p surfpool-core --features integration-tests tests::protocols:: +//! ``` +//! +//! A protocol's module is declared here and nowhere else; the filter above then covers it. + +pub mod pancakeswap; diff --git a/crates/core/src/tests/pancakeswap/mod.rs b/crates/core/src/tests/protocols/pancakeswap/mod.rs similarity index 97% rename from crates/core/src/tests/pancakeswap/mod.rs rename to crates/core/src/tests/protocols/pancakeswap/mod.rs index 96daeaf80..e10cb1ad0 100644 --- a/crates/core/src/tests/pancakeswap/mod.rs +++ b/crates/core/src/tests/protocols/pancakeswap/mod.rs @@ -13,7 +13,6 @@ use crate::{ surfnet::{ GetAccountResult, locker::SurfnetSvmLocker, remote::SurfnetRemoteClient, svm::SurfnetSvm, }, - tests::helpers::diff_indices, }; const RPC_URL_ENV: &str = "SURFPOOL_TEST_RPC_URL"; @@ -57,6 +56,16 @@ async fn fetch(addresses: &[Pubkey]) -> Vec { .collect() } +/// Byte indices at which two buffers differ. +fn diff_indices(a: &[u8], b: &[u8]) -> Vec { + a.iter() + .zip(b.iter()) + .enumerate() + .filter(|(_, (x, y))| x != y) + .map(|(i, _)| i) + .collect() +} + #[tokio::test] async fn real_mainnet_pool_round_trips_unchanged() { let data = fetch(&[SOL_USDC_POOL]).await.remove(0).data; diff --git a/crates/core/src/tests/pump/mod.rs b/crates/core/src/tests/pump/mod.rs index c09a8cbdb..91248d1f9 100644 --- a/crates/core/src/tests/pump/mod.rs +++ b/crates/core/src/tests/pump/mod.rs @@ -49,7 +49,7 @@ use crate::{ GetAccountResult, locker::SurfnetSvmLocker, remote::SurfnetRemoteClient, svm::SurfnetSvm, }, tests::{ - helpers::{diff_indices, get_free_port}, + helpers::get_free_port, integration::{RunloopGuard, spawn_runloop, wait_for_ready_and_connected}, }, }; @@ -125,6 +125,16 @@ async fn fetch(addresses: &[Pubkey]) -> Vec { .collect() } +/// Byte indices at which two buffers differ. +fn diff_indices(a: &[u8], b: &[u8]) -> Vec { + a.iter() + .zip(b.iter()) + .enumerate() + .filter(|(_, (x, y))| x != y) + .map(|(i, _)| i) + .collect() +} + /// A failure here means a bundled IDL disagrees with the live on-chain layout. #[tokio::test] async fn real_mainnet_accounts_round_trip_unchanged() { From 373d7007d267dba46e3daf6bc9782a6015914517 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Wed, 2 Dec 2026 10:33:15 +0200 Subject: [PATCH 18/20] ci: remove the Claude pull request review --- .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'), - }); - } From 8ce23f3e3c54eb3424466275541e05bb78053b15 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Wed, 2 Dec 2026 15:04:07 +0200 Subject: [PATCH 19/20] docs(scenarios): a PancakeSwap CLMM swap does not need the tick array of the new tick --- .../core/src/scenarios/protocols/pancakeswap/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index b5b23261f..920637690 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -58,9 +58,10 @@ price, and swaps succeed with wrong amounts: a +10% move on the SOL/USDC pool le 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 must exist.** A swap resumes from the array covering the new tick, -PDA `["tick_array", pool, start_index as i32 big-endian]` with 60 ticks of `tick_spacing` each. -Studio refuses a move onto a missing array. +**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 @@ -88,7 +89,7 @@ Every pool on that tier shares the account, so the change reaches all of them. | 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 | The new tick has no tick array, or `sqrt_price_x64` and `tick_current` disagree | +| 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 From 84df0e7330f691c01fd2d92dab184a1208de1c55 Mon Sep 17 00:00:00 2001 From: 92Infinitus92 <92georgepetroff92@gmail.com> Date: Fri, 4 Dec 2026 14:58:04 +0200 Subject: [PATCH 20/20] docs(scenarios): drop the slot number from the PancakeSwap IDL note --- crates/core/src/scenarios/protocols/pancakeswap/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/core/src/scenarios/protocols/pancakeswap/README.md b/crates/core/src/scenarios/protocols/pancakeswap/README.md index 920637690..05c302714 100644 --- a/crates/core/src/scenarios/protocols/pancakeswap/README.md +++ b/crates/core/src/scenarios/protocols/pancakeswap/README.md @@ -95,9 +95,8 @@ Every pool on that tier shares the account, so the change reaches all of them. # IDL `v1/idl.json` is the IDL PancakeSwap publishes on chain in its Anchor IDL account -`CAD7TZySgk4RkqyAkGu3bJFvf8itWsfTtpViRK8TJrKf`, as written in slot 348011868, indented with two -spaces like the other bundled IDLs. Only whitespace changed: `jq -j -c . v1/idl.json` gives back the -on-chain bytes. +`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 | |---|---|