bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 58쪽
nchor custom error codes, enum names, messages, and common integration causes.
</Card>
<Card title="TypeScript SDK" icon="node-js" href="/developer-guides/stake2earn/typescript-sdk/getting-started">
Transaction builders, state readers, PDA helpers, and examples from `@meteora-ag/m3m3`.
</Card>
<Card title="Rust Integration" icon="terminal" href="/developer-guides/stake2earn/rust-integration/library">
Generated Rust instruction/account interface, PDA helpers, and CPI guidance.
</Card>
<Card title="Stake2Earn API" icon="database" href="/developer-guides/stake2earn/api-reference/overview">
Indexed read-only vault discovery, analytics, filter routes, and leaderboard responses.
</Card>
<Card title="Changelog" icon="newspaper" href="/developer-guides/stake2earn/changelog">
Program, SDK, API, and source-noted release changes that affect integrations.
</Card>
</CardGroup>
## Program IDs
The public `stake_for_fee` program ID is the same on mainnet and devnet:
| Network | Program ID |
| - | - |
| Mainnet Beta | `FEESngU3neckdwib9X3KWqdL7Mjmqk9XNp3uh5JbP4KP` |
| Devnet | `FEESngU3neckdwib9X3KWqdL7Mjmqk9XNp3uh5JbP4KP` |
| Local feature build | `M5c95Zio3HQ1gvQ3pjhh8BsscrDcKnN28gxnQD1E17U` |
Related program IDs used by the SDK:
| Program | ID |
| - | - |
| DAMM v1 | `Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB` |
| Dynamic Vault | `24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi` |
<CardGroup>
<Card title="Stake2Earn Program" icon="code" href="https://github.com/MeteoraAg/stake-for-fee/tree/main/programs/stake-for-fee">
Anchor program source for `stake_for_fee`.
</Card>
<Card title="Stake2Earn IDL" icon="file-code" href="https://github.com/MeteoraAg/stake-for-fee-sdk/blob/main/ts-client/src/stake-for-fee/idls/stake_for_fee.ts">
TypeScript IDL bundled by the public SDK.
</Card>
<Card title="TypeScript SDK" icon="node-js" href="https://github.com/MeteoraAg/stake-for-fee-sdk/tree/main/ts-client">
`@meteora-ag/m3m3` SDK source for transaction builders and state helpers.
</Card>
<Card title="Rust Interface" icon="terminal" href="https://github.com/MeteoraAg/stake-for-fee-sdk/tree/main/stake_for_fee_interface">
Generated Rust instruction, account, event, and error interface.
</Card>
</CardGroup>
## Important Constants
| Constant | Public value | Use |
| - | - | - |
| `MIN_LIST_LENGTH` / `MAX_LIST_LENGTH` | `5` / `1000` | Allowed top staker list length on public builds. |
| `FULL_BALANCE_LIST_HARD_LIMIT` | `10000` | Maximum tracked full-balance entries on public builds. |
| `MIN_SECONDS_TO_FULL_UNLOCK` / `MAX_SECONDS_TO_FULL_UNLOCK` | `6 hours` / `31 days` | Allowed fee drip duration range. |
| `MIN_UNSTAKE_LOCK_DURATION` / `MAX_UNSTAKE_LOCK_DURATION` | `6 hours` / `31 days` | Allowed unstake cooldown range. |
| `MAX_JOIN_WINDOW_DURATION` | `31 days` | Maximum delay before fee distribution begins. |
| `MIN_LOCK_ESCROW_CLAIM_FEE_DURATION` | `5 minutes` | Minimum interval before another lock escrow fee claim. |
| `SCALE_OFFSET` | `64` | Fixed-point scale used for cumulative fee-per-liquidity checkpoints. |
| Quote mints | SOL, USDC | Only SOL and USDC are accepted as quote mints. |
## Commands
| Task | Command |
| - | - |
| Build TypeScript SDK | `cd stake-for-fee-sdk/ts-client && pnpm install && pnpm run build` |
| Run TypeScript SDK tests | `cd stake-for-fee-sdk/ts-client && pnpm test` |
| Build local program | `cd stake-for-fee && anchor build -p stake_for_fee -- --features local` |
| Run local program tests | `cd stake-for-fee && yarn test` |
| Check Rust interface workspace | `cd stake-for-fee-sdk && cargo check` |
# Stake2Earn Program Accounts
Source: https://docs.meteora.ag/developer-guides/stake2earn/program/accounts
Understand Stake2Earn stake_for_fee accounts, including vaults, stake escrows, unstake requests, top staker lists, full balance lists, metrics, configuration, and PDA seeds.
<Note>
This page summarizes the account model used by `stake_for_fee`. For exact binary layouts, use the Anchor IDL or the generated TypeScript and Rust types exported by `@meteora-ag/m3m3` and `stake_for_fee_interface`.
</Note>
## PDA Map
| Account | Seeds | Notes |
| - | - | - |
| `FeeVault` | `["vault", pool]` | One Stake2Earn vault per DAMM v1 pool. |
| `TopListMetadata` | `["list", vault]` | Header plus appended `StakerMetadata` entries for top stakers. |
| `FullBalanceListMetadata` | `["balance", vault]` | Header plus appended `StakerBalance` entries for tracked stakers. |
| `StakeEscrow` | `["escrow", vault, owner]` | User stake account for one vault and owner. |
| DAMM v1 `LockEscrow` | `["lock_escrow", pool, vault]` in the DAMM v1 program | Holds locked LP for the Stake2Earn vault owner PDA. |
| Event authority | `["__event_authority"]` | Anchor Event CPI authority used by generated clients. |
The SDK exports `deriveFeeVault`, `deriveTopStakerList`, `deriveFullBalanceList`, `deriveStakeEscrow`, `deriveLockEscrowPda`, and `deriveLpMint`.
## FeeVault
`FeeVault` is the root Stake2Earn account.
| Field | Meaning |
| - | - |
| `lock_escrow` | DAMM v1 lock escrow whose owner is the Stake2Earn vault PDA. |
| `stake_mint` | Pool token that users stake. Must not be SOL or USDC. |
| `quote_mint` | Quote mint. Public builds accept SOL or USDC. |
| `pool` | DAMM v1 constant-product pool linked to the vault. |
| `stake_token_vault` | Token account owned by the vault PDA for staked base tokens. |
| `quote_token_vault` | Token account owned by the vault PDA for quote fee claims. |
| `top_staker_list` | PDA storing top staker entries. |
| `full_balance_list` | PDA storing tracked staker balances. |
| `metrics` | Aggregate stake, escrow count, ongoing unstake, and fee totals. |
| `configuration` | Fee drip and unstake configuration. |
| `top_staker_info` | Top list size, effective stake, locked fees, and fee-per-liquidity checkpoints. |
| `creator` | Creator that initialized the vault. |
| `created_at` | Unix timestamp when the vault was initialized. |
| `bump` | PDA bump for vault signing. |
## Configuration
| Field | Meaning |
| - | - |
| `seconds_to_full_unlock` | Time required for locked claimed fees to drip fully to top stakers. |
| `unstake_lock_duration` | Cooldown before a requested unstake can be withdrawn. |
| `start_fee_distribute_timestamp` | Timestamp when fee distribution begins. Defaults to vault creation time when not provided. |
## Metrics
| Field | Meaning |
| - | - |
| `total_staked_amount` | Total active staked amount across stake escrows. |
| `total_stake_escrow_count` | Number of stake escrows initialized for the vault. |
| `ongoing_total_partial_unstake_amount` | Stake amount currently locked in pending unstake requests. |
| `total_fee_a_amount` / `total_fee_b_amount` | Lifetime fees claimed from the DAMM v1 lock escrow. |
| `user_total_claimed_fee_a` / `user_total_claimed_fee_b` | Lifetime fees claimed through user `claim_fee` flows. |
## TopStakerInfo
| Field | Meaning |
| - | - |
| `top_list_length` | Configured maximum number of top stakers. |
| `current_length` | Current allocated top list length used for account resizing. |
| `effective_stake_amount` | Total stake amount currently in the top list. |
| `last_claim_fee_at` | Last time the vault claimed from the DAMM v1 lock escrow. |
| `last_updated_at` | Last fee drip update timestamp. |
| `locked_fee_a` / `locked_fee_b` | Claimed fees still locked for drip release. |
| `cumulative_fee_a_per_liquidity` / `cumulative_fee_b_per_liquidity` | Fee growth checkpoints scaled by `2^64`. |
## StakeEscrow
`StakeEscrow` is the user position account for one vault.
| Field | Meaning |
| - | - |
| `owner` | Wallet that owns the stake escrow. |
| `vault` | Parent `FeeVault`. |
| `full_balance_index` | Index into the full balance list, or `FULL_BALANCE_LIST_HARD_LIMIT` when not tracked. |
| `stake_amount` | Active stake amount. |
| `in_top_list` | `1` when the escrow is currently in the top list. |
| `ongoing_total_partial_unstake_amount` | Amount reserved by open unstake requests for this escrow. |
| `created_at` | Unix timestamp when the stake escrow was initialized. |
| `fee_a_claimed_amount` / `fee_b_claimed_amount` | Lifetime user-claimed fee totals. |
| `fee_a_per_liquidity_checkpoint` / `fee_b_per_liquidity_checkpoint` | Last fee-per-liquidity checkpoints for this escrow. |
| `fee_a_pending` / `fee_b_pending` | Pending fee balances not yet claimed by the user. |
When a user calls `claim_fee`, the base/stake token side is automatically restaked. Only the quote token side is transferred to the user, capped by `max_fee`.
## Unstake
`Unstake` stores one pending withdrawal request.
| Field | Meaning |
| - | - |
| `stake_escrow` | Stake escrow that requested the unstake. |
| `unstake_amount` | Amount reserved for withdrawal. |
| `created_at` | Timestamp when the request was created. |
| `release_at` | Earliest timestamp when `withdraw` can transfer stake tokens back. |
| `owner` | Owner that can cancel or withdraw. |
| `vault` | Parent `FeeVault`. |
`request_unstake` creates this account with an arbitrary keypair supplied by the caller. `cancel_unstake` and `withdraw` close it to the owner.
## Top List Account
`TopListMetadata` is a zero-copy account header followed by `StakerMetadata` entries.
| Type | Field | Meaning |
| - | - | - |
| `TopListMetadata` | `vault` | Parent vault. |
| `StakerMetadata` | `stake_amount` | Stake amount used for ranking. |
| `StakerMetadata` | `full_balance_index` | Index in the full balance list. Negative values mark empty slots. |
| `StakerMetadata` | `owner` | Owner wallet for indexing and PDA derivation. |
Ranking uses stake amount first. For equal balances, earlier full balance indexes rank ahead of later joiners.
## Full Balance List Account
`FullBalanceListMetadata` is a zero-copy account header followed by `StakerBalance` entries.
| Type | Field | Meaning |
| - | - | - |
| `FullBalanceListMetadata` | `vault` | Parent vault. |
| `FullBalanceListMetadata` | `length` | Number of tracked entries. |
| `StakerBalance` | `balance` | Current stake amount for the owner. |
| `StakerBalance` | `owner` | Owner wallet. |
| `StakerBalance` | `is_in_top_list` | `1` when the entry is also in the top staker list. |
The public hard limit is `10000` tracked entries. If the full balance list is full, a new or returning large staker can reclaim the smallest tracked index only when the required `smallest_stake_escrow` account is provided.
# Stake2Earn Program Errors
Source: https://docs.meteora.ag/developer-guides/stake2earn/program/errors
Understand Stake2Earn stake_for_fee Anchor custom errors, numeric codes, messages, and common integration causes.
Stake2Earn uses Anchor custom errors. Numeric codes start at `6000`.
| Code | Enum | Message | Common cause |
| - | - | - | - |
| `6000` | `InvalidEscrowOwner` | Escrow owner is not vault | DAMM v1 lock escrow owner does not equal the Stake2Earn vault PDA. |
| `6001` | `InvalidTopListLength` | Invalid top list length | `top_list_length` is outside the public `5` to `1000` range. |
| `6002` | `InvalidSecondsToFullUnlock` | Invalid seconds to full unlock | Fee drip duration is outside the public `6 hours` to `31 days` range. |
| `6003` | `MustHaveQuoteTokenOrInvalidStakeMint` | Pool missing SOL/USDC token or invalid stake mint | Quote mint is not SOL/USDC or the stake mint is a quote mint. |
| `6004` | `MissingDroppedStakeEscrow` | Missing dropped stake escrow | A top-list replacement needs the dropped stake escrow account but it was not supplied. |
| `6005` | `InvalidStakeEscrow` | Invalid stake escrow | A supplied stake escrow does not match the expected vault, owner, or list index. |
| `6006` | `FullBalanceListFull` | Full balance list is full | The full balance list reached its hard limit and no valid reclaim path was supplied. |
| `6007` | `MintDoesNotBelongToPool` | Mint does not belong to the pool | `stake_mint` or `quote_mint` is not one of the DAMM v1 pool mints. |
| `6008` | `InsufficientStakeAmount` | Insufficient stake amount | `request_unstake` amount exceeds active stake amount. |
| `6009` | `CannotWithdrawUnstakeAmount` | Unstake amount release date not reached | `withdraw` was called before `unstake.release_at`. |
| `6010` | `InvalidAdmin` | Invalid admin | Admin instruction signer is not one of the hardcoded program admins. |
| `6011` | `InvalidUnstakeLockDuration` | Invalid unstake lock duration | Unstake cooldown is outside the public `6 hours` to `31 days` range. |
| `6012` | `InvalidJoinWindowDuration` | Invalid join window duration | Custom fee distribution start time is more than `31 days` after the current timestamp. |
| `6013` | `InvalidCustomStartFeeDistributeTimestamp` | Invalid custom start fee distribute timestamp | Defined in the error enum; use source/IDL to confirm when handling legacy flows. |
| `6014` | `InvalidSmallestStakeEscrow` | Invalid smallest stake escrow | The supplied `smallest_stake_escrow` does not match the expected reclaim index or vault. |
| `6015` | `MathOverflow` | MathOverflow | Checked arithmetic overflow or division failure. |
| `6016` | `TypeCastFailed` | Type casting failed | Checked numeric conversion failed. |
| `6017` | `InvalidLockEscrowRelatedAccounts` | Invalid lock escrow related accounts | DAMM v1 pool, Dynamic Vault, LP mint, LP account, or token vault accounts do not match each other. |
| `6018` | `OnlyConstantProductPool` | Only constant product pool is supported | `initialize_vault` was called for a non-constant-product DAMM v1 pool. |
| `6019` | `UndeterminedError` | Undetermined error | Internal invariant failure in list synchronization. |
| `6020` | `MissingSmallestStakeEscrow` | Missing smallest stake escrow | Reclaiming a full-balance-list index requires the smallest tracked stake escrow account. |
| `6021` | `UpdatedValueIsTheSame` | Updated value is the same as old value | Admin update supplied the current value. |
| `6022` | `InvalidFeeCrankIx` | Invalid fee crank instruction | `update_seconds_to_full_unlock` was not immediately preceded by `claim_fee_crank` for the same vault/program. |
## Debugging Checklist
| Symptom | Check |
| - | - |
| Vault initialization fails | Confirm the pool is DAMM v1 constant product, mints belong to the pool, quote mint is SOL/USDC, and the lock escrow owner is the vault PDA. |
| Stake or claim fails with account mismatch | Re-fetch the DAMM v1 pool, Dynamic Vault accounts, LP mints, token vaults, and lock escrow before building the transaction. |
| Top list sync fails | Include the SDK-provided replacement stake escrows in `remaining_accounts`; do not omit `smallest_stake_escrow` when reclaiming a full-balance entry. |
| Withdraw fails | Compare the current on-chain timestamp with `unstake.release_at`. |
| Admin drip update fails | Put `claim_fee_crank` immediately before `update_seconds_to_full_unlock` in the same transaction. |
# Stake2Earn Program Events
Source: https://docs.meteora.ag/developer-guides/stake2earn/program/events
Track Stake2Earn stake_for_fee events for vault creation, stake escrow creation, staking, fee emission, user claims, unstake flows, list movement, and admin updates.
Stake2Earn emits Anchor events with Event CPI (`emit_cpi!`) in the inspected user and admin flows. Indexers should parse inner instructions from the `stake_for_fee` program, not only log strings.
## Event Delivery
| Detail | Value |
| - | - |
| Program | `stake_for_fee` |
| Public program ID | `FEESngU3neckdwib9X3KWqdL7Mjmqk9XNp3uh5JbP4KP` |
| Delivery path | Anchor Event CPI |
| Event authority PDA | `["__event_authority"]` |
| Client requirement | Low-level transactions must include Anchor Event CPI accounts when an instruction struct uses `#[event_cpi]`. |
## Vault Lifecycle
| Event | Emitted by | Fields | Use |
| - | - | - | - |
| `VaultCreated` | `initialize_vault` | `pool`, `token_a_mint`, `token_b_mint`, `vault`, `stake_mint`, `quote_mint`, `creator`, `top_list_length`, `seconds_to_full_unlock`, `unstake_lock_duration`, `start_fee_distribute_timestamp` | Discover a new Stake2Earn vault and its launch configuration. |
| `StakeEscrowCreated` | `initialize_stake_escrow` | `pool`, `vault`, `escrow`, `owner`, `full_balance_index` | Index a user's stake escrow for one vault. |
## Fee And Stake Events
| Event | Emitted by | Fields | Use |
| - | - | - | - |
| `FeeEmission` | `stake`, `claim_fee`, `request_unstake`, `cancel_unstake`, `claim_fee_crank` | `pool`, `vault`, `token_a_claimed`, `token_b_claimed`, `token_a_released`, `token_b_released`, `cumulative_fee_a_per_liquidity`, `cumulative_fee_b_per_liquidity`, `effective_stake_amount` | Track lock escrow fee claims and drip release into top staker accounting. |
| `UserStake` | `stake`, `claim_fee` | `pool`, `vault`, `owner`, `stake_amount`, `total_stake_amount`, `fee_a_pending`, `fee_b_pending`, fee checkpoints | Track direct stakes and automatic restake of base/stake-token fee claims. |
| `ClaimFeeSucceed` | `claim_fee` | `stake_escrow`, `pool`, `vault`, `owner`, `fee_a_amount`, `fee_b_amount`, `total_fee_a_amount`, `total_fee_b_amount` | Track user fee claims. The quote side is transferred; the stake/base side is restaked. |
## Unstake Events
| Event | Emitted by | Fields | Use |
| - | - | - | - |
| `UnstakeCreated` | `request_unstake` | `unstake`, `pool`, `vault`, `owner`, `amount`, `new_stake_escrow_amount`, `new_stake_escrow_ongoing_total_unstake_amount`, pending fees, fee checkpoints, `start_at`, `end_at` | Track a new pending unstake and its release timestamp. |
| `CancelUnstakeSucceed` | `cancel_unstake` | `unstake`, `pool`, `vault`, `owner`, `amount`, `new_stake_escrow_amount`, `new_stake_escrow_ongoing_total_unstake_amount`, pending fees, fee checkpoints | Track cancellation of a pending unstake. |
| `WithdrawSucceed` | `withdraw` | `unstake`, `pool`, `vault`, `owner`, `amount`, `new_stake_escrow_ongoing_total_unstake_amount` | Track final withdrawal of released stake tokens. |
## Top List Events
| Event | Emitted by | Fields | Use |
| - | - | - | - |
| `AddNewUserToTopHolder` | `stake`, `claim_fee`, `request_unstake`, `cancel_unstake` when list sync promotes a staker | `pool`, `vault`, `owner`, `stake_amount`, pending fees, fee checkpoints | Track a staker entering the top list. |
| `RemoveUserFromTopHolder` | `stake`, `claim_fee`, `request_unstake`, `cancel_unstake` when list sync removes a staker | `pool`, `vault`, `owner`, `stake_amount`, pending fees, fee checkpoints | Track a staker leaving the top list. |
| `ReclaimIndex` | `stake`, `claim_fee`, `cancel_unstake` when the full balance list index is reclaimed | `vault`, `in_owner`, `in_owner_balance`, `out_owner`, `out_owner_balance`, `reclaim_index` | Track replacement of the smallest tracked full-balance entry. |
## Admin Events
| Event | Emitted by | Fields | Use |
| - | - | - | - |
| `UpdateUnstakeLockDuration` | `update_unstake_lock_duration` | `vault`, `old_value`, `new_value` | Track changes to the cooldown used by future unstake requests. |
| `UpdateSecondsToFullUnlock` | `update_seconds_to_full_unlock` | `vault`, `old_value`, `new_value` | Track changes to the fee drip duration. |
## Defined But Not Emitted By Current Handlers
| Event | Fields | Source note |
| - | - | - |
| `ConfigCreated` | `config`, `index`, `seconds_to_full_unlock`, `unstake_lock_duration`, `join_window_duration`, `top_list_length` | Defined in `events.rs`, but no matching active handler is exposed by the inspected `lib.rs`. |
| `ConfigClosed` | `config`, `index` | Defined in `events.rs`, but no matching active handler is exposed by the inspected `lib.rs`. |
## Indexing Notes
| Need | Recommended event |
| - | - |
| New vault discovery | `VaultCreated` |
| User stake escrow discovery | `StakeEscrowCreated` |
| Current user active stake changes | `UserStake`, `UnstakeCreated`, `CancelUnstakeSucceed`, `WithdrawSucceed` |
| Fee drip accounting | `FeeEmission` |
| User quote-claim accounting | `ClaimFeeSucceed` |
| Leaderboard movements | `AddNew프로젝트로 돌아가기