Meteora 백서

Meteora

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 26쪽

ictedFromZap` | SOL,USDC protocol fee cannot be withdrawn via zap | Restricted fee mint was used in the zap protocol-fee path. | | `6064` | `CpiDisabled` | CPI disabled | A disallowed CPI path was attempted. | | `6065` | `MissingZapOutInstruction` | Missing zap out instruction | Zap protocol-fee flow did not include the required downstream instruction. | | `6066` | `InvalidZapAccounts` | Invalid zap accounts | Zap accounts do not match the whitelisted route or expected account set. | | `6067` | `InvalidCompoundingFeeBps` | Invalid compounding fee bps | Compounding fee bps is outside allowed bounds or incompatible with collect fee mode. | | `6068` | `InvalidClaimProtocolFeeAccounts` | Invalid claim protocol fee accounts | `claim_protocol_fee2` receiver token account mint or token program does not match pool token A or token B. | | `6069` | `TransferFeeExcludedAmountIsZero` | Transfer fee excluded amount is zero | Token-2022 transfer fee would reduce the claimed protocol fee amount to zero. | | `6070` | `DelegatedAmountNonZero` | Delegated amount is not zero | Position NFT token account has a non-zero `delegated_amount` on a delegate path. | | `6071` | `DeprecatedBaseFeeMode` | Deprecated base fee mode | New config or new pool creation used `BaseFeeMode::RateLimiter`. Existing rate-limiter pools are unaffected. | | `6072` | `InvalidConfigPermission` | Invalid config permission | Non-zero `permission` was set on a public config (default `pool_creator_authority`), or permission bits are outside the defined `ConfigPermission` range. | ## Typescript SDK Validation Errors The TypeScript SDK also raises local validation errors before a transaction is built. These are JavaScript errors rather than on-chain Anchor errors. | SDK error | Common cause | | - | - | | `DepositTokenNotAcceptedError` | Deposit was attempted on the side that the current price range cannot accept. | | `SameTokenMintsError` | Pool creation or swap input uses the same mint for both sides. | | `AmountIsZeroError` | Swap, liquidity, or reward funding amount is zero before building the transaction. | | `ExceedMaxFeeBpsError` | Fee bps exceeds the pool version's maximum. | | `InvalidPriceRangeError` | Initial, minimum, or maximum price is outside DAMM v2 bounds. | | `InvalidCollectFeeModeError` | Unsupported collect fee mode or incompatible pool parameters. | | `InvalidCompoundingFeeBpsError` | Compounding fee bps is invalid or used with an incompatible collect fee mode. | | `InvalidBaseFeeModeError` | Unsupported base fee mode. | | `DeprecatedBaseFeeModeError` | New config or pool helpers received `BaseFeeMode.RateLimiter`. | | `InvalidFeeTimeSchedulerError` | Time scheduler parameters are invalid. | | `InvalidFeeRateLimiterError` | Rate limiter parameters are invalid. | | `InvalidFeeMarketCapSchedulerError` | Market-cap scheduler parameters are invalid. | | `InvalidDynamicFeeParametersError` | Dynamic fee parameters are invalid. | | `InvalidMinimumLiquidityError` | Pool creation or liquidity change does not satisfy minimum liquidity checks. | | `SwapDisabledError` | Quote helper determined swap access is disabled for the current point. | | `PriceRangeViolationError` | Quote would move outside the pool price range. | | `InvalidSplitPositionParametersError` | Split ratio or target position setup is invalid. | | `InvalidVestingInfoError` | Vesting parameters are inconsistent or outside duration limits. | | `InvalidRewardIndexError` | Reward index is not one of the two supported reward slots. | | `InvalidRewardDurationError` | Reward duration is outside program bounds. | # DAMM v2 Program Events Source: https://docs.meteora.ag/developer-guides/damm-v2/program/events Understand DAMM v2 cp-amm events emitted by pool, config, position, liquidity, lock, swap, fee, reward, and operator flows. The `cp-amm` program emits most 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 DAMM v2 pool activity. ## Event CPI | Item | Value | | - | - | | Program ID | `cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG` | | 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. | | Swap hot path | The optimized swap entrypoint emits the same Anchor event-CPI payload for `EvtSwap2`. | | Log-event exception | `EvtClaimProtocolFee2` is emitted with `emit!`, not event CPI. | Low-level builders should pass the event authority account and the `cp-amm` program account when the IDL requires them. The program signs the self-CPI with the event authority PDA internally. ## Pool And Config Events | Event | Emitted by | Payload | | - | - | - | | `EvtCreateConfig` | `create_config` | Static config fees, vault config, pool creator authority, activation type, sqrt price range, collect-fee mode, index, config address, and `permission` (`u128` bitmask). | | `EvtCreateDynamicConfig` | `create_dynamic_config` | Dynamic config address, pool creator authority, index, and `permission` (`u128` bitmask). | | `EvtCloseConfig` | `close_config` | Config address and admin. | | `EvtCreateTokenBadge` | `create_token_badge` | Token mint that received a badge. | | `EvtInitializePool` | `initialize_pool`, `initialize_pool_with_dynamic_config`, `initialize_customizable_pool` | Pool address, token mints, creator, payer, alpha vault, fee parameters, sqrt price range, activation fields, token flags, initial token amounts, initial reserves, liquidity, and pool type. | `EvtInitializePool` is the primary pool-creation event. Indexers should treat it as the source of pool metadata at creation time, then reconcile current mutable state from the pool account. ## Position Events | Event | Emitted by | Payload | | - | - | - | | `EvtCreatePosition` | Pool initialization instructions and `create_position` | Pool, owner, position account, and position NFT mint. | | `EvtClosePosition` | `close_position` | Pool, owner, position account, and position NFT mint. | | `EvtSplitPosition2` | `split_position`, `split_position2` | Deprecated compatibility event with split amounts and position snapshots without vested-liquidity fields. | | `EvtSplitPosition3` | `split_position`, `split_position2` | Current split event with owners, source and destination positions, current sqrt price, split amounts, position snapshots, and split parameters. | New indexers should use `EvtSplitPosition3`. The current split handler emits `EvtSplitPosition2` for backward compatibility, but `EvtSplitPosition3` carries the current payload shape. ## Liquidity And Lock Events | Event | Emitted by | Payload | | - | - | - | | `EvtLiquidityChange` | `add_liquidity`, `remove_liquidity`, `remove_all_liquidity` | Pool, position, owner, token A/B amounts, transfer-fee-included token amounts, reserve snapshots, liquidity delta, token amount thresholds, and `change_type`. | | `EvtLockPosition` | `lock_position`, `lock_inner_position` | Pool, position, owner, vesting account, cliff point, period frequency, cliff unlock liquidity, liquidity per period, and number of periods. | | `EvtPermanentLockPosition` | `permanent_lock_position` | Pool, position, newly locked liquidity, and total permanent locked liquidity. | `EvtLiquidityChange.change_type` is `0` for add liquidity and `1` for remove liquidity. ## Swap Events | Event | Emitted by | Payload | | - | - | - | | `EvtSwap2` | `swap`, `swap2` | Pool, trade direction, collect-fee mode, referral flag, swap parameters, swap result, transfer-fee fields, timestamp, and reserve snapshots. | `EvtSwap2` is the canonical swap event for charting and analytics. Prefer it over SPL token transfer logs because DAMM v2 swaps can include Token-2022 transfer fees, protocol fees, compounding fees, and referral fees. | Field | Meaning | | - | - | | `trade_direction` | `0` means token A to token B. `1` means token B to token A. | | `has_referral` | Whether a referral account participated in the swap. | | `params.amount_0` | Input amount for exact-in and partial-fill swaps. Desired output amount for exact-out swaps. | | `params.amount_1` | Minimum output for exact-in and partial-fill swaps. Maximum input for exact-out swaps. | | `params.swap_mode` | `0` exact in, `1` partial fill, `2` exact out. | | `swap_result.included_fee_input_amount` | Input amount including transfer fee accounting. | | `swap_result.excluded_fee_input_amount` | Input amount after excluded transfer fee accounting. | | `swap_result.amount_left` | Unused input for partial-fill or exact-out execution. | | `swap_result.output_amount` | Swap output amount before external transfer-fee effects. | | `swap_result.next_sqrt_price` | Pool sqrt price after the swap. | | `swap_result.claiming_fee` | LP fee component. | | `swap_result.protocol_fee` | Protocol fee component. | | `swap_result.compounding_fee` | Compounding fee component. | | `swap_result.referral_fee` | Referral fee component. | | `included_transfer_fee_amount_in` | Transfer fee included on input side. | | `included_transfer_fee_amount_out` | Transfer fee included on output side. | | `excluded_transfer_fee_amount_out` | Output amount excluded by transfer fee accounting. | | `reserve_a_amount`, `reserve_b_amount` | Pool reserve snapshots after execution. | ## Fee And Reward Events | Event | Emitted by | Payload | | - | - | - | | `EvtClaimPositionFee` | `claim_position_fee` | Pool, position, owner, claimed token A fee, and claimed token B fee. | | `EvtClaimProtocolFee` | Historical `claim_protocol_fee` | Pool and protocol fee amounts claimed from token A and token B. Kept for historical transactions. New claims use `claim_protocol_fee2`. | | `EvtClaimProtocolFee2` | `claim_protocol_fee2` | Pool, receiver token account, token mint, and claimed amount for one pool token. | | `EvtInitializeReward` | `initialize_reward` | Pool, reward mint, funder, creator, reward index, and reward duration. | | `EvtFundReward` | `fund_reward` | Pool, funder, reward mint, reward index, funded amount, transfer-fee-excluded input amount, reward duration end, previous reward rate, and new reward rate. | | `EvtClaimReward` | `claim_reward` | Pool, position, owner, reward mint, reward index, and claimed reward amount. | | `EvtUpdateRewardDuration` | `update_reward_duration` | Pool, reward index, old duration, and new duration. | | `EvtUpdateRewardFunder` | `update_reward_funder` | Pool, reward index, old funder, and new funder. | | `EvtWithdrawIneligibleReward` | `withdraw_ineligible_reward` | Pool, reward mint, and withdrawn amount. | Reward indexes are limited to the two DAMM v2 reward slots, `0` and `1`. ## Operator Events | Event | Emitted by | Payload | | - | - | - | | `EvtSetPoolStatus` | `set_pool_status` | Pool and status byte. | | `EvtUpdatePoolFees` | `update_pool_fees` | Pool, operator, and update parameters. | `EvtUpdatePoolFees.params.cliff_fee_numerator` is optional. `EvtUpdatePoolFees.params.dynamic_fee` is also optional; `None` skips dynamic-fee updates, while a default dynamic-fee value disables dynamic fees. ## Fee Parameter Decoding `EvtInitializePool.pool_fees.base_fee.data` uses the Borsh event format. Pool account state uses the Pod-aligned account format. | Source | Format | TypeScript decoder family | | - | - | - | | `EvtInitializePool` event | Borsh | `decodeFeeTimeSchedulerParams`, `decodeFeeRateLimiterParams`, `decodeFeeMarketCapSchedulerParams` | | Pool state account | Pod-aligned | `decodePodAlignedFeeTimeScheduler`, `decodePodAlignedFeeRateLimiter`, `decodePodAlignedFeeMarketCapScheduler` | Choose the decoder from the pool fee mode. Do not decode an event payload with a pool-state decoder, or pool account data with an event decoder. ## Indexing Notes | Use case | Event to index | | - | - | | Pool discovery | `EvtInitializePool` | | Position lifecycle | `EvtCreatePosition`, `EvtClosePosition` | | LP accounting | `EvtLiquidityChange`, `EvtClaimPositionFee` | | Protocol fees | `EvtClaimProtocolFee2`. Historical `EvtClaimProtocolFee` for older `claim_protocol_fee` transactions. | | Swap history and candles | `EvtSwap2` | | Rewards | `EvtInitializeReward`, `EvtFundReward`, `EvtClaimReward`, `EvtUpdateRewardDuration`, `EvtUpdateRewardFunder`, `EvtWithdrawIneligibleReward` | | Locks and vesting | `EvtLockPosition`, `EvtPermanentLockPosition`, `EvtSplitPosition3` | | Operator changes | `EvtSetPoolStatus`, `EvtUpdatePoolFees`, config events | Most events include `pool` and can be joined directly to pool state. Config and token-badge events do not necessarily include a pool, so index them by config address or token mint. # DAMM v2 Instructions Source: https://docs.meteora.ag/developer-guides/damm-v2/program/instructions Explore DAMM v2 cp-amm instructions for pool creation, positions, liquidity, locks, swaps, fees, rewards, operators, and admins. The `cp-amm` IDL exposes many instructions. Integrators can choose to either use the TypeScript SDK for transaction construction or build through CPI. ## Pool Creation | Instruction | TypeScript SDK | Use | | - | - | - | | `initialize_pool` | `createPool` | Create a permissionless pool from a static config. Honors `CreatePoolWithoutMintValidation` on private configs. Rejects `RateLimiter` configs. | | `initialize_pool_with_dynamic_config` | `createCustomPoolWithDynamicConfig` | Create a pool from a dynamic config where the creator supplies pool-specific parameters. Honors `CreatePoolWithoutMintValidation` on private configs. Rejects `RateLimiter`. | | `initialize_customizable_pool` | `createCustomPool` | Create a customizable launch pool without a config PDA. Always validates mints (`skip=false`). Rejects `RateLimiter`. | Pool creation initializes the pool, vaults, first position, and Token-2022 position NFT. Pool PDAs sort mints in the seed list, but transaction builders should use the canonical `token_a_mint` and `token_b_mint` fields from pool state after creation. <Note> When mint validation is not skipped, pass token badge remaining accounts at index `0` (token A) and index `1` (token B) for mints that are not permissionless-supported. `initialize_pool` and `initialize_pool_with_dynamic_config` skip those checks when the private config has `CreatePoolWithoutMintValidation`. `initialize_customizable_pool` always validates mints. Token-2022 wrapped SOL is still rejected. </Note> ## Positions | Instruction | TypeScript SDK | Use | | - | - | - | | `create_position` | `createPosition` | Mint a Token-2022 position NFT and initialize an empty position. | | `close_position` | `closePosition` | Close an empty position account and position NFT. | | `split_position` | `splitPosition` | Split liquidity, fees, rewards, and inner vesting by independent percentage fields. | | `split_position2` | `splitPosition2` | Split all supported position state by one numerator over `SPLIT_POSITION_DENOMINATOR`. | Position ownership is checked through the position NFT token account. The token account must hold exactly one NFT and be owned by the signer. ## Liquidity And Locks | Instruction | TypeScript SDK | Use | | - | - | - | | `add_liquidity` | `addLiquidity`, `createPositionAndAddLiquidity` | Add liquidity to an existing or newly created position. | | `remove_liquidity` | `removeLiquidity` | Withdraw a selected amount of unlocked liquidity. | | `remove_all_liquidity` | `removeAllLiquidity`, `removeAllLiquidityAndClosePosition`, `mergePosition` | Withdraw all currently unlocked liquidity. | | `lock_position` | `lockPosition` | Lock liquidity with an external vesting account. | | `lock_inner_position` | `lockPosition({ innerPosition: true })` | Lock liquidity using embedded `Position.inner_vesting`. | | `refresh_vesting` | `refreshVesting` | Release available vested liquidity into unlocked liquidity. | | `permanent_lock_position` | `permanentLockPosition` | Move unlocked liquidity into permanent lock. | Add and remove liquidity update pool rewards, position rewards, fees, reserves, and liquidity before transferring tokens. ## Swaps | Instruction | TypeScript SDK | Use | | - | - | - | | `swap` | `swap` | Legacy exact-in swap path. | | `swap2` | `swap2` | Current exact-in, partial-fill, and exact-out swap path. | ## Swap Modes `swap2` accepts `SwapMode`: | Mode | Parameter meaning | | - | - | | `ExactIn` | `amount_0` is input amount; `amount_1` is minimum output | | `PartialFill` | `amount_0` is input amount; `amount_1` is minimum output; execution may stop at pool bounds | | `ExactOut` | `amount_0` is desired output; `amount_1` is maximum input | New integrations should prefer `swap2` and SDK `getQuote2` because they share exact-in, partial-fill, and exact-out semantics. ## Fees And Rewards | Instruction | TypeScript SDK | Use | | - | - | - | | `claim_position_fee` | `claimPositionFee`, `claimPositionFee2` | Claim pending LP fees from a position. | | `initialize_reward` | `initializeReward`, `initializeAndFundReward` | Initialize one of the two reward slots. | | `fund_reward` | `fundReward`, `initializeAndFundReward` | Fund reward emissions. | | `claim_reward` | `claimReward` | Claim pending liquidity mining rewards. | | `withdraw_ineligible_reward` | `withdrawIneligibleReward` | Withdraw undistributable rewards after campaign constraints allow it. | | `update_reward_duration` | `updateRewardDuration` | Update reward campaign duration. | | `update_reward_funder` | `updateRewardFunder` | Update the funder authority for a reward slot. | Reward index `0` and `1` are the only supported reward slots. ## Config And Operator Instructions | Instruction | Use | | - | - | | `create_config` | Operator creates a static config. `permission` is the trailing `u128` on `StaticConfigParameters`. Non-zero permission is allowed only on private configs (non-default `pool_creator_authority`). Rejects `RateLimiter`. | | `create_dynamic_config` | Operator creates a dynamic config. `permission` is the trailing `u128` on `DynamicConfigParameters`. Same private-config permission rule. | | `create_token_badge` | Operator creates a token badge PDA for a mint that is not permissionless-supported. | | `close_token_badge` | Operator closes a token badge and returns rent. Existing pools that already use the mint keep working. | | `claim_protocol_fee2` | Protocol fee authority claims one pool token per call. Replaces the removed `claim_protocol_fee` and `zap_protocol_fee` instructions. | `permission` is set at config creation and is immutable. There is no instruction to update `Config.permission`. Public configs (default `pool_creator_authority`) must use `permission = 0`. The only defined bit today is `CreatePoolWithoutMintValidation` (`1 << 0`). `InvalidConfigPermission` (`6072`) is returned when a public config is given a non-zero permission, or when permission bits are outside the defined `ConfigPermission` range. <Warning> Token-2022 wrapped SOL is rejected during mint validation even when `CreatePoolWithoutMintValidation` is set. Use the standard wrapped SOL mint. </Warning> <Note> `claim_protocol_fee` and `zap_protocol_fee` are removed. Use `claim_protocol_fee2`. </Note> # DAMM v2 Rust Integration CPI Source: https://docs.meteora.ag/developer-guides/damm-v2/rust-integration/cpi Learn how to plan DAMM v2 Anchor CPI integrations with cp-amm accounts, remaining accounts, generated clients, failures, and tests. Use CPI when your Solana program must call DAMM v2 directly, for example to swap, add or remove liquidity, claim fees or rewards, or manage a DAMM v2 position as part of a larger protocol instruction. <Note> The stable integration contract is the public `cp-amm` program, the published IDL, and the official SDK behavior. This page is cross-checked against the `cp-amm` source so account ordering and remaining-account notes match the on-chain handlers.
프로젝트로 돌아가기