Meteora 백서

Meteora

원문

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

gram account lists. | ## Constants | Constant | Value | Meaning | | - | - | - | | `DYNAMIC_FEE_SHARING_PROGRAM_ID` | `dfsdo2UqvwfN8DuUVrMRNfQe11VaiNoKcMqLHVvDPzh` | Program ID on mainnet and devnet. | | Fee vault authority | `EYqHRdtepv1KKUkPAYMBYpSfiGfNd8sa55ZtswodTfBS` | PDA derived from `FEE_VAULT_AUTHORITY_PREFIX`. | | `MAX_USER` | `5` | Maximum number of configured shareholders. | | Minimum users | `2` | Minimum number of configured shareholders enforced during initialization. | | `PRECISION_SCALE` | `64` | Fixed-point scale used for `fee_per_share` accounting. | | `FEE_VAULT_PREFIX` | `fee_vault` | Seed prefix for PDA fee vaults. | | `FEE_VAULT_AUTHORITY_PREFIX` | `fee_vault_authority` | Seed prefix for the program token authority. | | `TOKEN_VAULT_PREFIX` | `token_vault` | Seed prefix for vault token accounts. | | `FeeVault::INIT_SPACE` | `640` bytes | Account data size before the Anchor discriminator. | | `UserFee::INIT_SPACE` | `80` bytes | Per-user fixed-size share record inside `FeeVault`. | ## FeeVault `FeeVault` is the primary zero-copy account. Padding fields are omitted from this table. | Field | Type | Use | | - | - | - | | `owner` | `Pubkey` | Owner recorded during vault initialization. The current program does not expose an owner-only management instruction. | | `token_mint` | `Pubkey` | Mint accepted by the vault and paid out to users. | | `token_vault` | `Pubkey` | Token account PDA that stores funded fees. | | `token_flag` | `u8` | Token program flag: `0` SPL Token, `1` Token 2022. | | `fee_vault_type` | `u8` | Fee vault type: `0` non-PDA account, `1` PDA account. | | `fee_vault_bump` | `u8` | PDA bump for PDA fee vaults. Non-PDA vaults store `0`. | | `total_share` | `u32` | Sum of all configured user shares. | | `total_funded_fee` | `u64` | Total token amount credited to the fee vault after transfer-fee adjustments. | | `fee_per_share` | `u128` | Accumulated Q64 fixed-point fee per share. | | `base` | `Pubkey` | Base signer used in the PDA fee vault seeds. Non-PDA vaults store the default public key. | | `users` | `[UserFee; 5]` | Fixed array of shareholder records. Unused slots remain defaulted. | ## UserFee | Field | Type | Use | | - | - | - | | `address` | `Pubkey` | Shareholder address allowed to claim at this user index. | | `share` | `u32` | Share weight for fee distribution. | | `fee_claimed` | `u64` | Total amount this user has claimed. | | `fee_per_share_checkpoint` | `u128` | User checkpoint used to calculate the next claimable amount. | ## Initialization Parameters | Type | Field | Rule | | - | - | - | | `InitializeFeeVaultParameters` | `padding: [u64; 8]` | Reserved for future use. SDK callers pass an empty array, which Anchor serializes for the fixed array. | | `InitializeFeeVaultParameters` | `users: Vec<UserShare>` | Must contain at least 2 and at most 5 users. | | `UserShare` | `address: Pubkey` | Must not be the default public key. | | `UserShare` | `share: u32` | Must be greater than zero. | <Warning> The program validates the number of users, nonzero shares, and non-default addresses. It does not enforce unique user addresses, so integrations should validate duplicate shareholder addresses before initialization. </Warning> ## Share Accounting | Step | Program behavior | | - | - | | Funding | Adds the credited token amount to `total_funded_fee`. | | Fee-per-share update | Adds `(amount << 64) / total_share` to `fee_per_share`. | | Claim calculation | Uses `share * (fee_per_share - fee_per_share_checkpoint) >> 64`. | | Claim checkpoint | Updates the user's `fee_per_share_checkpoint` to the current vault `fee_per_share`. | | Claim counter | Adds the claimed amount to `user.fee_claimed`. | Amounts are raw token units. Apply mint decimals off-chain for display. ## Token Support | Token behavior | Support | | - | - | | SPL Token | Supported. | | Token 2022 transfer fee | Supported for direct funding. The credited amount excludes the current epoch transfer fee. | | Token 2022 metadata pointer | Supported mint extension. | | Token 2022 token metadata | Supported mint extension. | | Other Token 2022 extensions | Rejected by `is_supported_mint`. | | Native SOL | Supported through wrapped SOL token accounts in the TypeScript SDK helpers. | ## Vault Type Behavior | Behavior | Non-PDA fee vault | PDA fee vault | | - | - | - | | Address | External keypair account | PDA from `base` and `token_mint`. | | Initialization signer | `fee_vault` signs. | `base` signs. | | `base` state field | Default public key. | The base signer public key. | | Direct `fund_fee` | Supported. | Supported. | | `claim_fee` | Supported. | Supported. | | `fund_by_claiming_fee` | Not supported by program validation. | Supported when the source action is whitelisted and the signer is a shareholder. | # Dynamic Fee Sharing Program Errors Source: https://docs.meteora.ag/developer-guides/dynamic-fee-sharing/program/errors Understand Dynamic Fee Sharing custom errors, codes, messages, and common causes for integration debugging. Dynamic Fee Sharing custom errors are emitted by the Anchor `FeeVaultError` enum. <Tip> Anchor custom error codes start at `6000`. When a transaction log contains a custom program error such as `0x1776`, convert the hex value to decimal to find the matching code. `0x1776` is `6006`, which maps to `ExceededUser`. </Tip> ## Error Codes | Code | Name | Message | Common cause | | - | - | - | - | | `6000` | `MathOverflow` | Math operation overflow | Checked arithmetic failed during funding, fee-per-share calculation, claim calculation, or Token 2022 transfer-fee calculation. | | `6001` | `InvalidMint` | Mint is not supported | Token 2022 mint has an unsupported extension, or mint account validation failed. | | `6002` | `InvalidFeeVaultParameters` | Fee vault parameters are invalid | A configured user share is zero. | | `6003` | `AmountIsZero` | Amount is zero | Direct funding resolved to zero after capping by the funder's token account balance. | | `6004` | `InvalidUserIndex` | Invalid user index | `claim_fee` was called with an index outside the fixed user array. | | `6005` | `InvalidUserAddress` | Invalid user address | Initialization used a default public key, or `claim_fee` signer did not match `users[index].address`. | | `6006` | `ExceededUser` | Exceeded number of users allowed | Initialization used fewer than 2 users or more than 5 users. | | `6007` | `InvalidFeeVault` | Invalid fee vault | `fund_by_claiming_fee` was called with a non-PDA fee vault. | | `6008` | `InvalidSigner` | Invalid signer | Source-program funding signer is not one of the fee vault shareholders. | | `6009` | `InvalidAction` | Invalid action | Source program, instruction discriminator, or expected token vault remaining account does not match the whitelist. | # Dynamic Fee Sharing Program Events Source: https://docs.meteora.ag/developer-guides/dynamic-fee-sharing/program/events Track Dynamic Fee Sharing event payloads for vault initialization, fee funding, and user claims. The `dynamic_fee_sharing` program emits Anchor events through event CPI. Indexers should decode these events from Dynamic Fee Sharing program logs and join them with `FeeVault` account reads when current aggregate state is needed. ## Events | Event | Fields | Emitted by | Use | | - | - | - | - | | `EvtInitializeFeeVault` | `fee_vault`, `token_mint`, `owner`, `base`, `params` | `initialize_fee_vault`, `initialize_fee_vault_pda` | Index new fee vaults, token mints, owners, PDA bases, and configured user shares. | | `EvtFundFee` | `source_program`, `fee_vault`, `funded_amount`, `fee_per_share`, `payload` | `fund_fee`, `fund_by_claiming_fee` | Track fee vault funding and the updated accumulated fee per share. | | `EvtClaimFee` | `fee_vault`, `user`, `index`, `claimed_fee` | `claim_fee` | Track user claims by configured user index. | ## Event Details ### `EvtInitializeFeeVault` | Field | Type | Notes | | - | - | - | | `fee_vault` | `Pubkey` | Created fee vault account. | | `token_mint` | `Pubkey` | Mint accepted by the vault. | | `owner` | `Pubkey` | Owner recorded in the vault state. | | `base` | `Pubkey` | PDA base for `initialize_fee_vault_pda`; default public key for non-PDA vaults. | | `params` | `InitializeFeeVaultParameters` | Includes reserved padding and configured `UserShare[]`. | ### `EvtFundFee` | Field | Type | Notes | | - | - | - | | `source_program` | `Pubkey` | Default public key for direct `fund_fee`; downstream program ID for `fund_by_claiming_fee`. | | `fee_vault` | `Pubkey` | Fee vault that received credited fees. | | `funded_amount` | `u64` | Raw token amount credited to share accounting. For Token 2022 transfer-fee mints, this excludes the transfer fee on direct funding. | | `fee_per_share` | `u128` | Vault's accumulated Q64 fixed-point fee per share after funding. | | `payload` | `Vec<u8>` | Empty for direct `fund_fee`; downstream instruction data for source-program funding. | `fund_by_claiming_fee` emits `EvtFundFee` only when the downstream invocation increases the fee vault token balance by more than zero. ### `EvtClaimFee` | Field | Type | Notes | | - | - | - | | `fee_vault` | `Pubkey` | Fee vault being claimed from. | | `user` | `Pubkey` | Claiming shareholder. | | `index` | `u8` | User index passed to `claim_fee`. | | `claimed_fee` | `u64` | Raw token amount transferred to `user_token_vault`. | `claim_fee` emits `EvtClaimFee` only when the computed claim amount is greater than zero. ## Indexing Notes | Topic | Note | | - | - | | Event CPI accounts | Generated Anchor clients add `event_authority` and `program` accounts for all event-emitting instructions. | | Amount precision | Amounts are raw token units. Apply mint decimals off-chain for display. | | Direct funding | `source_program` is the default public key and `payload` is empty. | | Source-program funding | Store `source_program` and `payload` if you need to reconstruct which whitelisted DAMM v2 or DBC action funded the vault. | | Current state | Events are append-only. Read `FeeVault` for current `total_funded_fee`, `fee_per_share`, and per-user `fee_claimed` counters. | # Dynamic Fee Sharing Program Instructions Source: https://docs.meteora.ag/developer-guides/dynamic-fee-sharing/program/instructions Explore Dynamic Fee Sharing instructions for vault initialization, direct funding, source-program funding, and user fee claims. The `dynamic_fee_sharing` program exposes the instructions below. Integrators should use the TypeScript SDK for normal transaction construction, or build through CPI. ## Instruction Summary | Instruction | Parameters | Main signers | Behavior | | - | - | - | - | | `initialize_fee_vault` | `params: InitializeFeeVaultParameters` | `fee_vault`, `payer` | Creates a non-PDA fee vault account and its token vault PDA. | | `initialize_fee_vault_pda` | `params: InitializeFeeVaultParameters` | `base`, `payer` | Creates a deterministic PDA fee vault from `base` and `token_mint`, plus its token vault PDA. | | `fund_fee` | `max_amount: u64` | `funder` | Transfers up to `max_amount` from the funder's token account into the vault and updates fee-per-share accounting. | | `fund_by_claiming_fee` | `payload: Vec<u8>` | `signer` | Invokes a whitelisted DAMM v2 or DBC instruction with the PDA fee vault as signer, then credits the token vault balance increase. | | `claim_fee` | `index: u8` | `user` | Claims the user's currently available fee amount for the configured user index. | ## Initialize Non-PDA Fee Vault | Account | Writable | Signer | Notes | | - | - | - | - | | `fee_vault` | Yes | Yes | New external account initialized with `8 + FeeVault::INIT_SPACE` bytes. | | `fee_vault_authority` | No | No | PDA from `["fee_vault_authority"]`. | | `token_vault` | Yes | No | PDA token account from `["token_vault", fee_vault]`. | | `token_mint` | No | No | Mint for the fee vault. Must be supported by the token utility. | | `owner` | No | No | Stored in the `FeeVault` account. | | `payer` | Yes | Yes | Pays rent for the new accounts. | | `token_program` | No | No | SPL Token or Token 2022 program for `token_mint`. | | `system_program` | No | No | System program. | `params.users` must contain 2 to 5 entries. Each `UserShare.address` must be non-default, and each `UserShare.share` must be greater than zero. ## Initialize PDA Fee Vault | Account | Writable | Signer | Notes | | - | - | - | - | | `fee_vault` | Yes | No | PDA from `["fee_vault", base, token_mint]`. | | `fee_vault_authority` | No | No | PDA from `["fee_vault_authority"]`. | | `token_vault` | Yes | No | PDA token account from `["token_vault", fee_vault]`. | | `token_mint` | No | No | Mint for the fee vault. | | `owner` | No | No | Stored in the `FeeVault` account. | | `base` | No | Yes | Seed signer used to derive the fee vault PDA. | | `payer` | Yes | Yes | Pays rent for the new accounts. | | `token_program` | No | No | SPL Token or Token 2022 program for `token_mint`. | | `system_program` | No | No | System program. | Use PDA fee vaults when the fee vault must sign downstream source-program instructions, such as DAMM v2 fee claims or DBC fee withdrawals. ## Direct Funding | Account | Writable | Signer | Notes | | - | - | - | - | | `fee_vault` | Yes | No | Must have `token_vault` and `token_mint` relations. | | `token_vault` | Yes | No | Fee vault token account. | | `token_mint` | No | No | Fee vault mint. | | `fund_token_vault` | Yes | No | Funder's token account. The transferred amount is capped by its balance. | | `funder` | No | Yes | Token authority for `fund_token_vault`. | | `token_program` | No | No | Token program for checked transfer. | `fund_fee` transfers `min(max_amount, fund_token_vault.amount)`. If the resulting amount is zero, the instruction returns `AmountIsZero`. For Token 2022 transfer-fee mints, the vault credits the transfer-fee excluded amount to `total_funded_fee` and `fee_per_share`. ## Source-Program Funding `fund_by_claiming_fee` is a wrapper for whitelisted source-program actions. The caller passes the downstream instruction data as `payload` and the downstream account metas as remaining accounts. | Account | Writable | Signer | Notes | | - | - | - | - | | `fee_vault` | Yes | No | Must be a PDA fee vault. Used as a signer for the downstream invocation. | | `token_vault` | Yes | No | Fee vault token account. The handler measures this balance before and after the downstream CPI. | | `signer` | No | Yes | Must be one of the configured shareholders in the fee vault. | | `source_program` | No | No | Whitelisted DAMM v2 or DBC program. | | Remaining accounts | Varies | Varies | Passed directly to the downstream instruction. One expected account must equal `token_vault`. | The first 8 bytes of `payload` must be the downstream Anchor instruction discriminator. ## Whitelisted Source Actions | Source program | Downstream instruction | Expected `token_vault` remaining-account index | SDK wrapper | | - | - | - | - | | DAMM v2 `cp_amm` | `claim_position_fee` | `4` | `fundByClaimDammV2Fee` | | DAMM v2 `cp_amm` | `claim_reward` | `5` | `fundByClaimDammV2Reward` | | DBC `dynamic_bonding_curve` | `creator_withdraw_surplus` | `3` | `fundByWithdrawDbcCreatorSurplus` | | DBC `dynamic_bonding_curve` | `claim_creator_trading_fee` | `3` | `fundByClaimDbcCreatorTradingFee` | | DBC `dynamic_bonding_curve` | `partner_withdraw_surplus` | `3` | `fundByWithdrawDbcPartnerSurplus` | | DBC `dynamic_bonding_curve` | `claim_trading_fee` | `4` | `fundByClaimDbcPartnerTradingFee` | | DBC `dynamic_bonding_curve` | `withdraw_migration_fee` | `3` | `fundByWithdrawDbcMigrationFee` | The index is zero-based within the remaining accounts passed to `fund_by_claiming_fee`. <Warning> A fee vault is designed to support a single token mint and a single token vault. `fund_by_claiming_fee` credits only the balance increase of the fee vault's `token_vault`, and the whitelist check pins exactly one token account of the downstream instruction to it. The source pool's `CollectFeeMode` must therefore collect fees only in the fee vault's token mint: `OnlyB` or `Compounding` for DAMM v2 and `QuoteToken` for DBC. </Warning> ## User Claim | Account | Writable | Signer | Notes | | - | - | - | - | | `fee_vault` | Yes | No | Must have `token_vault` and `token_mint` relations. | | `fee_vault_authority` | No | No | Must equal `EYqHRdtepv1KKUkPAYMBYpSfiGfNd8sa55ZtswodTfBS`. | | `token_vault` | Yes | No | Source token account controlled by fee vault authority. | | `token_mint` | No | No | Fee vault mint. | | `user_token_vault` | Yes | No | Destination token account. | | `user` | No | Yes | Must match `fee_vault.users[index].address`. | | `token_program` | No | No | Token program for checked transfer. | If the calculated claim amount is zero, the instruction updates no tokens and emits no claim event. ## Validation | Area | Rule | | - | - | | User count | Vault initialization requires at least 2 and at most 5 users. | | User share | Each share must be greater than zero. | | User address | Each address must be non-default. | | Mint support | SPL Token mints are supported. Token 2022 mints are supported only with transfer-fee, metadata-pointer, and token-metadata extensions. | | Direct funding | `max_amount` is capped by the funder's token account balance. | | Source funding | Only PDA fee vaults can be used, the signer must be a configured shareholder, and the downstream action must be whitelisted. | | Claims | The `index` must exist in the fixed user array and the signer must match that user entry. | # Dynamic Fee Sharing CPI Integration Source: https://docs.meteora.ag/developer-guides/dynamic-fee-sharing/rust-integration/cpi Learn how to call Dynamic Fee Sharing instructions through Rust CPI, pass required accounts, handle event-CPI accounts, and plan source-program funding. Use CPI when your Solana program must call Dynamic Fee Sharing directly, for example to create a vault, fund a vault from program-controlled token accounts, or claim fees as part of a larger protocol instruction. ## Program ID | Network | Program ID | | - | - | | Mainnet Beta | `dfsdo2UqvwfN8DuUVrMRNfQe11VaiNoKcMqLHVvDPzh` | | Devnet | `dfsdo2UqvwfN8DuUVrMRNfQe11VaiNoKcMqLHVvDPzh` | ## Generated Bindings For a Rust program in the same workspace, enable the Dynamic Fee Sharing program crate with the `cpi` feature: ```toml theme={"system"} [dependencies] dynamic-fee-sharing = { git = "https://github.com/MeteoraAg/dynamic-fee-sharing", package = "dynamic-fee-sharing", features = ["cpi"] } ``` For local development inside the program repository: ```toml theme={"system"} [dependencies] dynamic-fee-sharing = { path = "../dynamic-fee-sharing/programs/dynamic-fee-sharing", features = ["cpi"] } ``` The crate name in Rust code is `dynamic_fee_sharing`. ## CPI Pattern Anchor generates CPI helpers for the program instructions. Account structs use the same names as the instruction contexts in the Dynamic Fee Sharing source. ```rust theme={"system"} use anchor_lang::prelude::*; use dynamic_fee_sharing::cpi; use dynamic_fee_sharing::cpi::accounts::FundFeeCtx; pub fn fund_fee_via_cpi<'info>( ctx: Context<'_, '_, '_, 'info, YourFundCtx<'info>>, max_amount: u64, ) -> Result<()> { let cpi_program = ctx.accounts.dynamic_fee_sharing_program.to_account_info(); let cpi_accounts = FundFeeCtx { fee_vault: ctx.accounts.fee_vault.to_account_info(), token_vault: ctx.accounts.token_vault.to_account_info(), token_mint: ctx.accounts.token_mint.to_account_info(), fund_token_vault: ctx.accounts.fund_token_vault.to_account_info(), funder: ctx.accounts.funder.to_account_info(), token_program: ctx.accounts.token_program.to_account_info(), }; cpi::fund_fee(CpiContext::new(cpi_program, cpi_accounts), max_amount) } ``` <Note> Instructions marked with `#[event_cpi]` require the event-CPI accounts generated by Anchor. If you construct CPI calls manually, include the Dynamic Fee Sharing event authority and program accounts expecte
프로젝트로 돌아가기