Meteora 백서

Meteora

원문

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

ale-vault/access-and-states" icon="key"> Review state accounts, escrow creation paths, operator permissions, Merkle roots, lifecycle gates, and close conditions. </Card> </CardGroup> <CardGroup> <Card title="Presale Vault Formulas" href="/helper-products/presale-vault/formulas" icon="calculator"> Understand the core formulas for Q64.64 fixed price, dynamic allocation, deposit fees, refunds, creator withdrawal, and vesting. </Card> </CardGroup> ## Who Presale Vault Is For <AccordionGroup> <Accordion title="Launchpads"> Presale Vault is useful for launchpads that want repeatable presale infrastructure with configurable sale modes, permissioned access, registries, deposit fees, refunds, and vesting. </Accordion> <Accordion title="Token Creators"> Creators can run a standalone fundraising round before listing, decide who can participate, define per-buyer limits, configure unlocks, and settle raised quote tokens after the sale. </Accordion> <Accordion title="Buyers"> Buyers get an escrow account that tracks their registry, net deposit, deposit fee, personal cap, pending claim amount, claimed tokens, and remaining-quote withdrawal status. </Accordion> <Accordion title="Ecosystem Integrators"> Wallets, launch interfaces, dashboards, and indexers can follow a clear lifecycle: vault initialization, escrow creation, deposits, completion or failure, claims, refunds, and creator settlement. </Accordion> </AccordionGroup> ## Presale Vault vs Alpha Vault Presale Vault and Alpha Vault both support early token access, but they solve different launch problems. * **Presale Vault** runs a standalone token sale. Buyers deposit quote tokens into a presale vault and later claim the sold token. The creator withdraws raised quote tokens after a successful sale. * **Alpha Vault** is paired with a launch pool. Users deposit into the vault so the vault can buy from that pool before public trading starts. Use Presale Vault when the goal is a configurable fundraising round. Use Alpha Vault when the goal is first access to buy from a launch pool. <Warning> Presale Vault does not automatically create liquidity or list the token after the sale. Launch teams should plan creator withdrawal, fee collection, refunds, unsold-token handling, and any post-sale liquidity deployment before deposits open. </Warning> # Zap Compatibilities Source: https://docs.meteora.ag/helper-products/zap/compatibilities Review the instructions, routes, tokens, accounts, permissions, and constraints supported by Zap. Zap has a fixed compatibility surface in the on-chain program. Use this page to check whether a user flow maps to one of Zap's supported instructions. ## Instruction Surface | Instruction | Purpose | Main constraint | | - | - | - | | `initialize_ledger_account` | Create the user ledger PDA. | `owner` and `payer` sign. | | `set_ledger_balance` | Write token A/B or token X/Y amount into the ledger. | Ledger owner signs. | | `update_ledger_balance_after_swap` | Record a post-swap balance delta, capped by `max_transfer_amount`. | Ledger owner signs. | | `close_ledger_account` | Close the ledger and send rent to `rent_receiver`. | Ledger owner and rent receiver sign. | | `zap_in_damm_v2` | Add DAMM v2 liquidity, optionally swap surplus through DAMM v2, then add again. | Existing DAMM v2 position; owner signs. | | `zap_in_dlmm_for_uninitialized_position` | Initialize a new DLMM position and add liquidity through `rebalance_liquidity`. | Position account must be empty and sign. | | `zap_in_dlmm_for_initialized_position` | Add liquidity to an existing DLMM position through `rebalance_liquidity`. | Ledger owner signs. | | `zap_out` | Swap a percentage of a detected token balance increase. | Route must be whitelisted by program and discriminator; swap authority comes from the supplied route accounts. | ## Compatibility Matrix | Area | Supported | Important constraint | | - | - | - | | Program ID | `zapvX9M3uf5pvy4wRPAbQgdQsM1xmuiFnkfHKPvwMiz` | Same declared ID in the program. | | DAMM v2 Zap In | Yes | Swaps only through DAMM v2 `swap2` inside the Zap In flow. | | DLMM Zap In | Yes | Adds through DLMM `rebalance_liquidity`; Zap does not withdraw or claim in this instruction. | | DLMM strategies | `Spot`, `Curve`, `BidAsk` | `min_delta_id <= max_delta_id`. | | Zap Out routes | DAMM v2 swap, DLMM `swap2`, Jupiter v6 route, Jupiter v6 shared-account route | Route is checked by program ID plus 8-byte instruction discriminator. | | Zap Out percentage | `1` to `100` | Values outside this range fail. | | Ledger | User-owned PDA | Seeds are `["user_ledger", owner]`; ledger instructions require owner signature. | | Token transfer fees | Partially supported | Zap In math uses transfer-fee-excluded amounts where it calculates liquidity or strategy amounts. | ## Whitelisted Zap Out Routes Zap Out only invokes a swap if the supplied `amm_program` and the first 8 bytes of `payload_data` match one of the whitelisted pairs: | Route | Program-level check | | - | - | | DAMM v2 swap | DAMM v2 program plus DAMM v2 swap discriminator. | | DLMM swap | DLMM program plus `swap2` discriminator. | | Jupiter v6 route | Jupiter v6 program plus route discriminator. | | Jupiter v6 shared-account route | Jupiter v6 program plus shared-account route discriminator. | Unsupported Jupiter instruction variants, custom routers, or arbitrary AMM instructions are rejected with `AmmIsNotSupported`. ## Access Controls and Accounts | Action | Required authority | | - | - | | Initialize ledger | `owner` signer and `payer` signer. | | Set ledger balance | Ledger `owner` signer. | | Update ledger balance after swap | Ledger `owner` signer. | | Close ledger | Ledger `owner` signer and `rent_receiver` signer. | | DAMM v2 Zap In | Ledger `owner` signer, also used as DAMM v2 position owner. | | DLMM Zap In | Ledger `owner` signer, plus `rent_payer` signer. | | Zap Out | No owner signer is enforced by Zap itself; the invoked swap route must receive whatever signers/accounts it requires. | The ledger account has `has_one = owner` checks on mutable instructions. For uninitialized DLMM positions, the `position` account must be a signer, must be empty, and must not equal the owner or rent payer. Zap Out does not verify the token account owner; integrators should build the surrounding transaction so the route authority and token accounts are the intended user accounts. ## Flow Constraints | Flow | Constraint | | - | - | | DAMM v2 Zap In | Zap calls DAMM v2 `add_liquidity` with `token_a_amount_threshold` and `token_b_amount_threshold` set to `u64::MAX`; price protection comes from `max_sqrt_price_change_bps` around the optional balancing swap. | | DAMM v2 Zap In | If the surplus-side swap calculation fails or returns zero input/output, Zap returns successfully after the first add-liquidity attempt and leaves remaining amounts in the ledger. | | DLMM Zap In | Strategy parameters are generated from the pair's on-chain active bin at execution. The caller-supplied `active_id` is forwarded to DLMM with `max_active_bin_slippage`. | | DLMM Zap In | Zap sets `should_claim_fee = false`, `should_claim_reward = false`, `min_withdraw_x_amount = 0`, `min_withdraw_y_amount = 0`, and `removes = []`. | | Zap Out | `payload_data` must start with an 8-byte supported instruction discriminator, and `offset_amount_in` must point to the amount-in field to rewrite. | ## Token Compatibility Zap In calculates transfer-fee-excluded amounts for token mints when it needs to reason about net deposit amounts. For Token 2022 mints without a transfer fee extension, the calculation is treated like a normal token amount. <Warning> Do not assume every Token 2022 extension is compatible with every underlying DAMM v2, DLMM, or Jupiter route. Zap can coordinate supported instructions, but the downstream program still defines whether a token behavior is valid. </Warning> ## Not a Fit Use a direct integration instead of Zap when: * The target AMM is not DAMM v2 or DLMM. * The Zap Out route is not one of the four whitelisted instruction types. * The flow needs Zap In swaps through Jupiter or another external router inside the Zap instruction. * The DLMM flow needs Zap itself to withdraw liquidity, claim fees, or claim rewards. * The token behavior is unsupported by the underlying product or route. * The product copy needs to promise best execution, guaranteed output, or automatic route selection. # Zap Formulas and Limits Source: https://docs.meteora.ag/helper-products/zap/formula-and-limits Review the formulas, units, rounding behavior, and limits used by the Zap program. Zap uses integer arithmetic and delegates most AMM math to DAMM v2 or DLMM. This page covers the calculations Zap performs directly. ## Zap Out Amount Zap Out starts from the increase in the user's input token account: ```math theme={"system"} \text{balance increase} = \text{post balance} - \text{pre balance} ``` If `pre_user_token_balance >= post balance`, Zap returns successfully and does not invoke a swap. The swap amount is: ```math theme={"system"} \text{swap amount} = \min\left( \left\lfloor\frac{\text{balance increase} \times \text{percentage}}{100}\right\rfloor, \text{max swap amount} \right) ``` For `percentage = 100`, Zap uses the full balance increase before applying the max-swap cap. | Parameter | Limit | | - | - | | `percentage` | Must be `1` through `100`. | | `max_swap_amount` | Caps the calculated swap amount. | | `payload_data` | Must contain at least the first 8 discriminator bytes for the route check. | | `offset_amount_in` | Must allow 8 bytes to fit inside `payload_data`. | Zap writes the final swap amount into `payload_data` as a little-endian `u64`. ## Ledger Delta Updates When Zap updates a ledger after a balance-changing CPI, it applies the token account delta to the current ledger amount: ```math theme={"system"} \text{new ledger amount} = \text{old ledger amount} + \text{post token balance} - \text{pre token balance} ``` For `update_ledger_balance_after_swap`, the recorded amount is capped: ```math theme={"system"} \text{recorded amount} = \min(\text{post token balance} - \text{pre token balance}, \text{max transfer amount}) ``` The balance delta uses saturating subtraction, so if the current token balance is below the supplied pre-balance, the delta is `0`. ## Transfer-Fee-Excluded Amounts Zap In uses transfer-fee-excluded token amounts when calculating DAMM v2 liquidity and DLMM strategy parameters: ```math theme={"system"} \text{net amount} = \text{gross amount} - \text{transfer fee} ``` For SPL Token mints and Token 2022 mints without a transfer fee extension, the transfer fee is treated as `0`. For Token 2022 transfer-fee mints, Zap uses the current epoch's configured fee. ## DAMM v2 Price Slippage DAMM v2 Zap In checks the pool sqrt price after the optional balancing swap: ```math theme={"system"} \text{sqrt price change bps} = \left\lceil \frac{|\text{post sqrt price} - \text{pre sqrt price}| \times 10{,}000} {\text{pre sqrt price}} \right\rceil ``` The instruction fails if: ```math theme={"system"} \text{sqrt price change bps} > \text{max sqrt price change bps} ``` `max_sqrt_price_change_bps` is supplied by the caller as a `u32`. ## DAMM v2 Surplus-Side Swap DAMM v2 Zap In compares how much liquidity the ledger's token A and token B amounts can provide. The side that can provide more liquidity is considered surplus: | Comparison | Swap direction | | - | - | | `liquidity_from_a > liquidity_from_b` | Swap A to B. | | `liquidity_from_a <= liquidity_from_b` | Swap B to A. | Zap then uses a binary search of up to `20` iterations to estimate an exact-in swap amount that makes the remaining user amounts closer to the pool ratio. The search accounts for DAMM v2 fee mode, dynamic fee, reserves, compounding fee behavior, and transfer-fee-excluded token amounts. The internal DAMM v2 fee simulation supports these base fee modes: * `FeeTimeSchedulerLinear` * `FeeTimeSchedulerExponential` * `FeeMarketCapSchedulerLinear` * `FeeMarketCapSchedulerExponential` * `RateLimiter` If the calculation fails or produces a zero input or output amount, Zap skips the swap and returns successfully. ## DLMM Range DLMM Zap In receives `min_delta_id` and `max_delta_id` relative to the current active bin. The program requires: ```math theme={"system"} \text{min delta id} \le \text{max delta id} ``` For a new position, Zap initializes the DLMM position with: ```math theme={"system"} \text{lower bin id} = \text{current active id} + \text{min delta id} ``` ```math theme={"system"} \text{width} = \text{max delta id} - \text{min delta id} + 1 ``` The strategy math uses the pair's current `active_id` and `bin_step`. ## Active Bin Side Selection `favor_x_in_active_id` controls which side receives the active bin when a range crosses the active bin. | `favor_x_in_active_id` | Y-side end | X-side start | | - | - | - | | `true` | `-1` | `0` | | `false` | `0` | `1` | This matters because bins below the active area use token Y, bins above it use token X, and the active bin can be assigned to either side. ## DLMM Strategy Shapes Zap computes DLMM `AddLiquidityParams` for three strategy types: | Strategy | Program behavior | | - | - | | `Spot` | Token Y is divided evenly across Y-side bins. Token X is weighted by inverse bin price across X-side bins. | | `Curve` | Liquidity is concentrated toward the active area. The slope terms are negative on each side and integer division rounds amounts down. | | `BidAsk` | Liquidity is weighted toward the range edges. The slope terms are positive on each side, except single-bin ranges use the single-bin formula. | The computed signed parameters are stored as absolute `u64` values plus a bit flag that marks which of `x0`, `y0`, `delta_x`, or `delta_y` was negative. <Note> Zap's DLMM strategy math is parameter generation for DLMM `rebalance_liquidity`. DLMM still performs its own validation and liquidity accounting during the CPI. </Note> ## Error Conditions | Error | Common cause | | - | - | | `InvalidZapOutParameters` | Zap Out percentage is `0` or greater than `100`. | | `AmmIsNotSupported` | Zap Out program/discriminator pair is not whitelisted. | | `InvalidOffset` | `offset_amount_in + 8` exceeds payload length. | | `InvalidPosition` | New DLMM position account is already initialized or is the owner/rent payer account. | | `ExceededSlippage` | DAMM v2 sqrt price moved beyond `max_sqrt_price_change_bps`. | | `InvalidDlmmZapInParameters` | `min_delta_id > max_delta_id`. | | `UnsupportedFeeMode` | DAMM v2 fee mode cannot be handled by Zap's swap amount calculation. | # What is Zap? Source: https://docs.meteora.ag/helper-products/zap/what-is-zap Learn how Meteora Zap coordinates supported zap-in and zap-out flows for DAMM v2 and DLMM positions. ## Overview Zap is Meteora's helper program for position workflows that need token accounting, a supported swap, or a follow-up liquidity action. In practice, Zap has two jobs: * **Zap In**: use tracked token amounts to add liquidity to a supported DAMM v2 or DLMM position flow. * **Zap Out**: detect tokens received during the current flow and swap a selected percentage through a whitelisted route. <Info> Zap runs on the program `zapvX9M3uf5pvy4wRPAbQgdQsM1xmuiFnkfHKPvwMiz`. </Info> <Note> Zap is deliberately narrow. It only supports the instructions and routes described in this section; it is not a general-purpose Solana router. </Note> ## Core Features <CardGroup> <Card title="User Ledger" icon="clipboard-list"> Zap In flows use a user-owned ledger PDA to track token A/B or token X/Y amounts before and after swaps or deposits. </Card> <Card title="DAMM v2 Zap In" icon="right-to-bracket"> Zap can add DAMM v2 liquidity, optionally swap the surplus side through DAMM v2, then add remaining liquidity again. </Card> <Card title="DLMM Zap In" icon="layer-group"> Zap can initialize a new DLMM position or deposit into an existing position with Spot, Curve, or Bid-Ask distribution parameters. </Card> <Card title="Zap Out" icon="right-from-bracket"> Zap can rewrite the amount field in a prepared DAMM v2, DLMM, or Jupiter v6 swap instruction and invoke it for the detected balance increase. </Card> </CardGroup> ## What Zap Supports | Area | Supported by the Zap program | | - | - | | DAMM v2 Zap In | Add liquidity, calculate the surplus side, swap through DAMM v2 `swap2`, then add remaining liquidity. | | DLMM Zap In | New and existing positions through DLMM `rebalance_liquidity`. | | DLMM strategies | `Spot`, `Curve`, and `BidAsk`. | | Zap Out routes | DAMM v2 swap, DLMM `swap2`, Jupiter v6 route, and Jupiter v6 shared-account route. | | Ledger accounting | One PDA per owner using the `user_ledger` seed. | | Token 2022 transfer fees | Transfer-fee-aware net amount calculations in Zap In liquidity math. | ## What Zap Does Not Do Zap does not choose the user's pool, route, quote, position range, or slippage settings. Frontends and integrators still prepare those decisions before calling the program. Zap also does not guarantee the best route or exact final output. Swap execution still depends on pool liquidity, price movement, route accounts, token behavior, and the slippage checks used by the underlying program. ## How It Works ```text theme={"system"} Frontend prepares accounts, quote, range, and payload | Zap validates ownership, route type, and supplied limits | Zap updates ledger balances or detects received tokens | Zap CPIs into DAMM v2, DLMM, or a whitelisted Zap Out route ``` For Zap In, the frontend records the token amounts in a user ledger before calling the DAMM v2 or DLMM Zap In instruction. For Zap Out, the frontend supplies a prepared swap instruction payload, and Zap replaces the amount field with the percentage of tokens received during the current flow. ## Product Fit Zap is useful when a user intent maps cleanly to one of the supported flows: * Add liquidity to a DAMM v2 position using amounts already tracked in the ledger. * Create a DLMM position and deposit into a selected bin range. * Add to or reposition an existing DLMM position with a supported strategy. * Claim, withdraw, or otherwise receive tokens, then convert a selected percentage through a supported Zap Out route. For unsupported AMMs, unsupported Jupiter instructions, custom token behavior, or complex conditional execution, use the underlying program or route directly. ## Read Next <CardGroup> <Card title="Zap Compatibilities" href="/helper-products/zap/compatibilities" icon="plug"> Review supported instructions, routes, accounts, access controls, and not-fit cases. </Card> <Card title="Zap Formulas and Limits" href="/helper-products/zap/formula-and-limits" icon="calculator"> See the percentage, slippage, price, and DLMM strategy math used by the program. </Card> </CardGroup> <Warning> Zap simplifies supported workflows, but users still take AMM, route, price movement, and token behavior risk. </Warning> # Actions Source: https://docs.meteora.ag/invent/actions Run Meteora Invent CLI workflows for onchain actions across Meteora programs. <video /> Launch anything and do any onchain action on Meteora in just a few configurations and commands. Meteora Invent helps you test fast and launch fast with reusable configs and CLI actions. <Note> Using an AI agent? Install the [Meteora Agent Skill](/agents/skill) — it ships in the same repository (`skills/meteora`) and teaches agents every action on this page with dry-run and confirmation safety gates built in. </Note> # Prerequisites * Node.js >= 22.12.0 * pnpm >= 10.0.0 *If you don't have pnpm installed, you can install it by running the following command.* ```bash Terminal theme={"system"} npm install -g pnpm ``` # Steps <Steps> <Step title="Clone and Setup Meteora Invent"> Meteora Invent is a toolkit consisting of everything you need to invent inn
프로젝트로 돌아가기