bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 43쪽
low attempted to CPI into a program or path that is disabled by configuration. |
| `6101` | `MissingZapOutInstruction` | Missing zap out instruction | The instruction sysvar did not contain the expected zap-out instruction at the required position. |
| `6102` | `InvalidZapAccounts` | Invalid zap accounts | Zap accounts are missing, out of order, duplicated incorrectly, or do not match the expected pool/token accounts. |
| `6103` | `InvalidZapOutParameters` | Invalid zap out parameters | Zap-out instruction data, route parameters, amount, direction, or decoded fields are invalid. |
| `6104` | `InsufficientInAmount` | Insufficient in amount | The input amount available to a swap, bin, or zap calculation is not enough to continue the operation. |
| `6105` | `InvalidPlaceLimitOrderParameters` | Invalid place limit order parameters | Limit order placement parameters are invalid, such as inconsistent bins, side, amount, or active-bin relationship. |
| `6106` | `InvalidLimitOrderOwner` | Invalid limit order owner | The signer is not the owner allowed to create, update, or cancel the limit order account. |
| `6107` | `InvalidCancelLimitOrderParameters` | Invalid cancel limit order parameters | Cancel parameters do not match an existing order bin, side, amount, or cancellation constraints. |
| `6108` | `CannotFindLimitOrderByBinId` | Cannot find limit order by bin id | The limit order account does not contain an order entry for the requested bin ID. |
| `6109` | `CancelNonEmptyLimitOrder` | Cannot cancel non-empty limit order | A limit order close/cancel path expected the limit order to be empty, but order data remains. |
| `6110` | `InvalidCollectFeeMode` | Invalid collect fee mode | The stored collect-fee mode byte cannot be decoded into a supported collect fee mode. |
# DLMM Program Events
Source: https://docs.meteora.ag/developer-guides/dlmm/program/events
Understand DLMM lb_clmm events emitted by pool, position, liquidity, swap, fee, reward, rebalance, and limit order flows.
The `lb_clmm` program emits Anchor events through event CPI. Use this page when building indexers, analytics pipelines, charting systems, or low-level clients that need to map transactions back to DLMM pool activity.
## Event CPI
| Item | Value |
| - | - |
| Program ID | `LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo` |
| Event authority PDA seed | `__event_authority` |
| Event source | Anchor event CPI inner instructions |
| Client account planning | Event-emitting instructions include `event_authority` and the program account. SDK builders and generated clients derive these accounts. |
Low-level builders should keep the generated `event_authority` and program accounts in the exact account order expected by the IDL. If either account is missing or moved, Anchor account deserialization can fail before the handler reaches the intended operation.
## Pool Events
| Event | Emitted by | Payload |
| - | - | - |
| `LbPairCreate` | `initialize_lb_pair`, `initialize_lb_pair2`, `initialize_permission_lb_pair`, `initialize_customizable_permissionless_lb_pair`, `initialize_customizable_permissionless_lb_pair2` | LB pair address, bin step, token X mint, and token Y mint. |
`LbPairCreate` is the primary pool-discovery event. It identifies the pool and token pair, while mutable pool state such as active bin, fees, reserves, rewards, oracle, and status should be read from the `LbPair` account.
## Position Events
| Event | Emitted by | Payload |
| - | - | - |
| `PositionCreate` | `initialize_position`, `initialize_position2`, `initialize_position_pda`, `initialize_position_by_operator` | LB pair, position account, and owner. |
| `PositionClose` | `close_position`, `close_position2`, `close_position_if_empty` | Position account and owner. |
| `IncreasePositionLength` | `increase_position_length`, `increase_position_length2` | LB pair, position, owner, length added, and resize side. |
| `DecreasePositionLength` | `decrease_position_length` | LB pair, position, owner, length removed, and resize side. |
| `UpdatePositionOperator` | `update_position_operator` | Position, old operator, and new operator. |
| `SetPositionPermissionlessOperationBitsEvt` | `set_permissionless_operation_bits` | Position, owner, previous permission bits, and new permission bits. |
`IncreasePositionLength.side` and `DecreasePositionLength.side` are encoded resize-side values from the program IDL.
## Liquidity Events
| Event | Emitted by | Payload |
| - | - | - |
| `AddLiquidity` | `add_liquidity*`, `add_liquidity*2` | LB pair, sender, position, deposited token X/Y amounts, and active bin during deposit. |
| `RemoveLiquidity` | `remove_liquidity*`, `remove_liquidity*2`, `remove_all_liquidity` | LB pair, sender, position, withdrawn token X/Y amounts, and active bin during withdrawal. |
| `CompositionFee` | Add-liquidity and rebalance flows when a composition fee is charged | Sender, bin id, token X/Y composition fee amounts, and protocol fee portions. |
| `Rebalancing` | `rebalance_liquidity` | LB pair, position, owner, active bin, withdrawn amounts, added amounts, claimed fees, old and new position ranges, and claimed rewards. |
`CompositionFee` can be emitted along with an add-liquidity or rebalance event. Indexers that calculate LP cost basis should process both event types for the same transaction.
## Swap Events
| Event | Emitted by | Payload |
| - | - | - |
| `Swap` | `swap`, `swap2` | LB pair, user, start and end bin ids, input amount, output amount, direction, total fee, protocol fee, fee bps, and host fee. |
| `Swap2Evt` | `swap`, `swap2` | LB pair, user, start and end bin ids, direction, fee bps, input amount, amount left, output amount, market-maker fee, protocol fee, limit-order fee, host fee, and fee-side flags. |
`Swap2Evt` is the richer swap event for charting and analytics. New indexers should prefer it because it separates market-maker, protocol, limit-order, and host fee components.
| Field | Meaning |
| - | - |
| `swap_for_y` | `true` means token X is swapped for token Y. `false` means token Y is swapped for token X. |
| `start_bin_id` | Active bin before swap execution. |
| `end_bin_id` | Active bin after swap execution. |
| `fee_bps` | Fee rate used for the swap path. |
| `amount_in` | Total amount paid by the user. |
| `amount_left` | Unused input amount after execution. |
| `amount_out` | Total amount transferred to the user. |
| `mm_fee` | Market-maker fee component. |
| `protocol_fee` | Protocol fee component. |
| `limit_order_fee` | Limit-order fee component. |
| `host_fee` | Host or referral fee component. |
| `fees_on_input` | Whether fees were collected on the input side. |
| `fees_on_token_x` | Whether the charged fee token is token X. |
## Fee And Reward Events
| Event | Emitted by | Payload |
| - | - | - |
| `ClaimFee` | `claim_fee`, `claim_fee2` | LB pair, position, owner, claimed token X fee, and claimed token Y fee. |
| `ClaimFee2` | `claim_fee`, `claim_fee2` | `ClaimFee` payload plus active bin id. |
| `InitializeReward` | `initialize_reward` | LB pair, reward mint, funder, reward index, and reward duration. |
| `FundReward` | `fund_reward` | LB pair, funder, reward index, and funded amount. |
| `ClaimReward` | `claim_reward`, `claim_reward2` | LB pair, position, owner, reward index, and claimed reward amount. |
| `ClaimReward2` | `claim_reward`, `claim_reward2` | `ClaimReward` payload plus active bin id. |
| `UpdateRewardDuration` | `update_reward_duration` | LB pair, reward index, old duration, and new duration. |
| `UpdateRewardFunder` | `update_reward_funder` | LB pair, reward index, old funder, and new funder. |
| `WithdrawIneligibleReward` | `withdraw_ineligible_reward` | LB pair, reward mint, and withdrawn amount. |
Reward indexes are limited to the two DLMM reward slots, `0` and `1`.
New indexers should prefer `ClaimFee2` and `ClaimReward2` when active-bin context is useful. The program still emits the original `ClaimFee` and `ClaimReward` compatibility events.
## Operator And Oracle Events
| Event | Emitted by | Payload |
| - | - | - |
| `FeeParameterUpdate` | `update_base_fee` | LB pair, protocol share, base factor, and base fee power factor. |
| `DynamicFeeParameterUpdate` | `update_dynamic_fee` | LB pair, filter period, decay period, reduction factor, variable fee control, and max volatility accumulator. |
| `IncreaseObservation` | `increase_oracle_length` | Oracle account and new observation length. |
| `GoToABin` | `go_to_a_bin` | LB pair, previous bin id, and target bin id. |
Some operator and admin instructions update accounts without emitting a dedicated event. For those flows, use account-state indexing in addition to event indexing.
## Limit Order Events
| Event | Emitted by | Payload |
| - | - | - |
| `PlaceLimitOrderEvt` | `place_limit_order` | LB pair, sender, owner, limit order account, active bin id, and place-order parameters. |
| `CancelLimitOrderEvt` | `cancel_limit_order` | LB pair, sender, limit order account, withdrawn token X/Y amounts, active bin id, and removed bin ids. |
| `CloseLimitOrderEvt` | `close_limit_order_if_empty` | LB pair, owner, and limit order account. |
`PlaceLimitOrderEvt.params` includes the side, optional relative-bin settings, and bin amount list supplied to the instruction.
## Declared Event Note
`UpdatePositionLockReleasePoint` is defined in `src/events.rs`, but no current `lb_clmm` handler emits it. Treat it as a declared compatibility type, not an emitted event source, unless a future program version adds an `emit_cpi!` call for it.
## Indexing Notes
| Use case | Event to index |
| - | - |
| Pool discovery | `LbPairCreate` |
| Position lifecycle | `PositionCreate`, `PositionClose`, `IncreasePositionLength`, `DecreasePositionLength`, `UpdatePositionOperator`, `SetPositionPermissionlessOperationBitsEvt` |
| LP accounting | `AddLiquidity`, `RemoveLiquidity`, `CompositionFee`, `Rebalancing` |
| Swap history and candles | `Swap2Evt` |
| Fees | `ClaimFee2`, `FeeParameterUpdate`, `DynamicFeeParameterUpdate` |
| Rewards | `InitializeReward`, `FundReward`, `ClaimReward2`, `UpdateRewardDuration`, `UpdateRewardFunder`, `WithdrawIneligibleReward` |
| Oracle and bin movement | `IncreaseObservation`, `GoToABin` |
| Limit orders | `PlaceLimitOrderEvt`, `CancelLimitOrderEvt`, `CloseLimitOrderEvt` |
# DLMM Program Instructions
Source: https://docs.meteora.ag/developer-guides/dlmm/program/instructions
Explore DLMM lb_clmm instructions for pool creation, swaps, liquidity, positions, rewards, operators, and limit orders.
The `lb_clmm` IDL exposes many instructions. Integrators can choose to either use the TypeScript SDK for transaction construction or build through CPI.
## Pool Creation
| Instruction | Use |
| - | - |
| `initialize_lb_pair` | Legacy permissionless SPL Token pool creation. |
| `initialize_lb_pair2` | Current permissionless v2 pool creation with Token-2022 support and `PresetParameter2`. |
| `initialize_permission_lb_pair` | Operator-controlled pool creation for permissioned launches. |
| `initialize_customizable_permissionless_lb_pair` | Legacy customizable permissionless pool creation for SPL Token pools. |
| `initialize_customizable_permissionless_lb_pair2` | Current customizable permissionless pool creation with Token-2022 support. |
## Bin Arrays
| Instruction | Use |
| - | - |
| `initialize_bin_array` | Creates a bin array and initializes bin prices. |
| `initialize_bin_array_bitmap_extension` | Creates the bitmap extension for far bin array indexes. |
| `close_bin_array` | Closes an empty bin array. |
`initialize_bin_array` is compute-heavy. If you construct it manually, add a compute budget instruction.
## Positions
| Instruction | Use |
| - | - |
| `initialize_position` | Legacy position initialization. |
| `initialize_position2` | Current idempotent `PositionV2` initialization. |
| `initialize_position_pda` | Initializes a position PDA. |
| `initialize_position_by_operator` | Operator-driven position initialization. |
| `increase_position_length` / `increase_position_length2` | Expands a dynamic position. |
| `decrease_position_length` | Shrinks a dynamic position. |
| `update_position_operator` | Changes the operator authority. |
| `set_permissionless_operation_bits` | Enables selected permissionless position actions. |
| `close_position`, `close_position2`, `close_position_if_empty` | Close position accounts when eligible. |
## Liquidity
| Instruction family | Use |
| - | - |
| `add_liquidity*` | Adds liquidity by explicit bin amounts, strategy, weights, or one-sided parameters. |
| `add_liquidity*2` | v2 liquidity flows with Token-2022 and dynamic-position support. |
| `remove_liquidity*` | Removes liquidity by bin amounts, range, or all liquidity. |
| `rebalance_liquidity` | Combines add, remove, claim, resize, and shrink behavior in one flow. |
## Swaps
| Instruction | Use |
| - | - |
| `swap` | Legacy exact-in swap. |
| `swap2` | Current exact-in swap with Token-2022 account support. |
| `swap_exact_out` / `swap_exact_out2` | Exact-out swap flows. |
| `swap_with_price_impact` / `swap_with_price_impact2` | Swap with price-impact controls. |
## Fees And Rewards
| Instruction | Use |
| - | - |
| `claim_fee` / `claim_fee2` | Claims swap fees for a position. |
| `claim_reward` / `claim_reward2` | Claims one reward index for a position. |
| `initialize_reward` | Initializes a reward mint for liquidity mining pools. |
| `fund_reward` | Funds reward emissions. |
| `update_reward_duration` | Updates reward duration. |
| `update_reward_funder` | Updates reward funder. |
| `withdraw_ineligible_reward` | Withdraws undistributable rewards. |
## Limit Orders
| Instruction | Use |
| - | - |
| `place_limit_order` | Places an order at one or more bins. |
| `cancel_limit_order` | Cancels an existing order. |
| `close_limit_order_if_empty` | Closes the account after all order bins are empty. |
# DLMM Rust Integration CPI
Source: https://docs.meteora.ag/developer-guides/dlmm/rust-integration/cpi
Learn how to call DLMM lb_clmm from Rust programs with generated bindings, event CPI accounts, remaining accounts, and validation.
Use CPI when your Solana program must call DLMM directly, for example to swap,
add or remove liquidity, claim fees or rewards, or manage a DLMM position as
part of a larger protocol instruction.
<Note>
The stable integration contract is the published DLMM IDL and the official SDK
behavior. This page is cross-checked against the `lb_clmm` source so the
account ordering and remaining-account notes match the on-chain handlers.
</Note>
## Program ID
```rust theme={"system"}
pub const DLMM_PROGRAM_ID: Pubkey =
pubkey!("LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo");
```
The public program ID is the same for mainnet and devnet.
## Generated Bindings
Prefer generated CPI bindings from the DLMM IDL. The `lb_clmm` handlers use
Anchor accounts, optional accounts, generated instruction args, and `#[event_cpi]`
on many v2 instructions.
<Warning>
Do not hand-type account order from memory. Generate bindings or compare
against SDK-built instructions. Most CPI failures come from one misplaced
optional account, event authority account, bin array, or Token-2022 remaining
account.
</Warning>
If you use Anchor-generated CPI modules, the handler usually looks like:
```rust theme={"system"}
let cpi_ctx = CpiContext::new(
ctx.accounts.dlmm_program.to_account_info(),
dlmm::cpi::accounts::Swap2 {
// generated account struct fields
},
)
.with_remaining_accounts(ctx.remaining_accounts.to_vec());
dlmm::cpi::swap2(
cpi_ctx,
amount_in,
min_amount_out,
remaining_accounts_info,
)?;
```
If your integration uses raw `invoke` / `invoke_signed`, build the same
instruction data and account metas produced by the generated client.
## CPI Instruction Scope
For the full `lb_clmm` instruction-family map, see
[DLMM Program Instructions](/developer-guides/dlmm/program/instructions). This
page focuses on CPI implementation details for the v2 instructions most
integrations call: `swap2`, `swap_exact_out2`, `add_liquidity2`,
`remove_liquidity2`, `claim_fee2`, `claim_reward2`, and `rebalance_liquidity`.
New CPI integrations should prefer v2 instructions because they support SPL
Token, Token-2022, dynamic positions, and explicit remaining account metadata.
## Event CPI Accounts
Several `lb_clmm` account structs use `#[event_cpi]`, including `Swap2`,
`AddLiquidity2`, `RemoveLiquidity2`, `ClaimFee2`, and `ClaimReward2`. Generated
clients include extra event CPI accounts, commonly:
| Account | Why it appears |
| - | - |
| `program` | The DLMM program account used by Anchor event CPI emission. |
| `event_authority` | PDA derived from `b"__event_authority"` for the DLMM program. |
When you inspect an SDK or generated Rust instruction, keep these accounts in
the exact generated position. If they are missing or moved, Anchor account
deserialization can fail before the DLMM handler reaches your intended logic.
## Remaining Accounts Ordering
`lb_clmm` v2 handlers parse remaining accounts in two phases.
1. They consume Token-2022 transfer-hook account groups according to
`RemainingAccountsInfo.slices`.
2. They consume the leftover accounts as instruction-specific accounts, usually
bin arrays.
This ordering comes from `src/utils/remaining_accounts_util.rs` and calls like:
```rust theme={"system"}
let parsed_transfer_hook_accounts = parse_remaining_accounts(
&mut remaining_accounts,
&remaining_accounts_info.slices,
&[AccountsType::TransferHookX, AccountsType::TransferHookY],
)?;
// remaining_accounts now starts at the first bin array account.
```
The order of `ctx.remaining_accounts` must match the order of
`RemainingAccountsInfo.slices`.
| Slice type | Used by |
| - | - |
| `TransferHookX` | Token X transfers in swap, add liquidity, remove liquidity, claim fee. |
| `TransferHookY` | Token Y transfers in swap, add liquidity, remove liquidity, claim fee. |
| `TransferHookReward` | Single reward transfer in `claim_reward2`. |
| `TransferHookMultiReward(index)` | Multi-reward flows. |
| `TransferHookReferral` | Host/referral fee transfer in swaps. |
<Tip>
If you have no transfer-hook accounts, pass `RemainingAccountsInfo { slices:
vec![] }`, then put bin arrays first in `remaining_accounts`.
</Tip>
## Instruction Account Notes
| Instruction | Main accounts | Remaining accounts after transfer-hook slices |
| - | - | - |
| `swap2`, `swap_exact_out2`, `swap_with_price_impact2` | `lb_pair`, optional `bin_array_bitmap_extension`, reserves, user token accounts, token mints, oracle, optional `host_fee_in`, user signer, token programs, memo program, event CPI accounts. | Bin arrays for the swap route, in the order expected by the quote. |
| `add_liquidity2` | `position`, `lb_pair`, optional bitmap extension, user token X/Y, reserves, mints, sender signer, token programs, event CPI accounts. | Bin arrays covering the bins in `LiquidityParameter.amounts`. |
| `remove_liquidity2` | `position`, `lb_pair`, optional bitmap extension, user token X/Y, reserves, mints, sender signer, token programs, memo program, event CPI accounts. | Bin arrays covering the `BinLiquidityReduction` bins, in ascending bin order. |
| `claim_fee2` | `lb_pair`, `position`, sender signer, reserves, user token X/Y, mints, token programs, memo program, event CPI accounts. | Bin arrays from `min_bin_id` through `max_bin_id`. |
| `claim_reward2` | `lb_pair`, `position`, sender signer, reward vault, reward mint, user reward token account, token program, memo program, event CPI accounts. | Bin arrays from `min_bin_id` through `max_bin_id`. |
| `rebalance_liquidity` | Position, pool, token, reserve, and authority accounts for the rebalance wrapper. | Transfer-hook slices, reward accounts, bin arrays, resize accounts, and other operation-specific accounts in the order produced by SDK simulation. |
## Swap2 CPI Shape
This shape mirrors `swap2` on the program.
```rust theme={"system"}
use anchor_la프로젝트로 돌아가기