Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.meteora.ag/llms.txt

Use this file to discover all available pages before exploring further.

This page maps the public source surface of @meteora-ag/m3m3. Use the package types for exact parameter shapes when building a production integration.
import StakeForFee, {
  STAKE_FOR_FEE_PROGRAM_ID,
  DYNAMIC_AMM_PROGRAM_ID,
  DYNAMIC_VAULT_PROGRAM_ID,
  U64_MAX,
  deriveFeeVault,
  deriveStakeEscrow,
} from "@meteora-ag/m3m3";

Dependencies

PackageVersion in ts-client/package.json
@coral-xyz/anchor0.29.0
@coral-xyz/borsh^0.30.1
@solana/spl-token^0.4.8
@solana/web3.js^1.98.0
bn.js^5.2.1
decimal.js^10.4.3

Program IDs

ConstantValue
STAKE_FOR_FEE_PROGRAM_IDFEESngU3neckdwib9X3KWqdL7Mjmqk9XNp3uh5JbP4KP
DYNAMIC_AMM_PROGRAM_IDEo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB
DYNAMIC_VAULT_PROGRAM_ID24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi

Constants

ConstantValue or typeUse
MAX_COMPUTE_UNITS1_400_000Default compute unit limit helper value.
FULL_BALANCE_LIST_HARD_LIMITBN(10000)Public full-balance list hard limit.
U64_MAXBN("18446744073709551615")Common max quote-claim cap for claimFee.
VAULT_WITH_NON_PDA_BASED_LP_MINTSMap<string, PublicKey>Overrides for legacy Dynamic Vault LP mints that are not PDA-derived.
MIN_LOCK_ESCROW_CLAIM_FEE_DURATIONBN(300)Minimum lock escrow claim interval in seconds.

Core Client

MethodReturnsUse
StakeForFee.create(connection, pool, opt?)Promise<StakeForFee>Preferred client factory. Derives the vault/list/lock escrow keys and fetches all account state.
new StakeForFee(...)StakeForFeeInternal constructor used after account state has been fetched.
StakeForFee.fetchAccountStates(connection, feeVaultKey, topStakerListKey, fullBalanceListKey, pool, opt?)Promise<AccountStates>Fetch and decode FeeVault, list states, DAMM v1 pool, Dynamic Vault accounts, token accounts, mints, lock escrow, and clock.
refreshStates()Promise<AccountStates>Re-fetch current account state and return the previous cached state.
The opt object supports stakeForFeeProgramId, dynamicAmmProgramId, and dynamicVaultProgramId.

Transaction Builders

MethodReturnsUse
StakeForFee.createFeeVault(connection, pool, stakeMint, payer, param?, opt?)Promise<Transaction>Create a vault, deriving quote mint from the DAMM v1 pool. Creates the DAMM v1 lock escrow if missing.
StakeForFee.createFeeVaultWithParams(connection, pool, payer, stakeMint, quoteMint, param?, opt?)Promise<Transaction>Create a vault with explicit stake and quote mints.
StakeForFee.createFeeVaultInstructions(connection, pool, payer, stakeMint, quoteMint, param?, opt?)Promise<TransactionInstruction[]>Return raw vault-creation instructions for composition.
initializeStakeEscrow(owner)Promise<Transaction>Create the owner’s stake escrow for this vault.
stake(maxAmount, owner, replaceableTopStakerCount = 2)Promise<Transaction>Build a stake transaction, adding stake escrow initialization and top-list replacement accounts when needed.
claimFee(owner, maxFee)Promise<Transaction>Build a fee claim transaction. Only quote token is transferred to the user; base/stake token is restaked.
unstake(amount, unstakeKeypair, owner)Promise<Transaction>Build a request_unstake transaction. unstakeKeypair is a public key for a new signer account.
cancelUnstake(unstakeKey, owner)Promise<Transaction>Cancel a pending unstake and return the amount to active stake.
withdraw(unstakeKey, owner)Promise<Transaction>Withdraw released stake after the cooldown.

Account Scanners

MethodReturnsUse
StakeForFee.getAllStakedVaultByUser(connection, owner, opt?)User stake entries with vault, unstake list, unclaimed fees, and pool infoFind all stake escrows owned by a wallet.
StakeForFee.getUnstakeByUser(connection, owner, feeVault)Program account listFind open unstake records for a user and vault.
StakeForFee.getAllFeeVault(connection, programId?)Program account listFetch all FeeVault accounts for the program.

Balance And Fee Helpers

Method or helperReturnsUse
getUserStakeAndClaimBalance(user)Stake escrow plus unclaimFeeRead a user’s active stake and claimable fees using current cached vault state.
getStakeEscrowPendingFees(stakeEscrow)[BN, BN]Calculate pending token A and token B fees for a stake escrow.
StakeForFee.getFarmPendingClaimFees(args)[BN, BN]Calculate pending lock escrow fees available to claim from DAMM v1.
StakeForFee.getFarmReleasedFees(args)[BN, BN]Calculate currently released fees after applying the vault’s drip duration.
getTopStakerListEntryStakeAmount()BNMinimum stake amount needed to enter the current top list.
findLargestStakerNotInTopListFromFullBalanceList(lookupNumber)PublicKey[]Find candidate stake escrows outside the top list.
findReplaceableTopStaker(lookupNumber)PublicKey[]Find current top stakers that can be replaced.
findSmallestStakeEscrowInFullBalanceList(skipOwner)`PublicKeynull`Find the smallest tracked full-balance entry for reclaim handling.

Exported Helpers

PDA Helpers

HelperSeeds
deriveFeeVault(pool, programId)["vault", pool]
deriveTopStakerList(vault, programId)["list", vault]
deriveFullBalanceList(vault, programId)["balance", vault]
deriveStakeEscrow(vault, owner, programId)["escrow", vault, owner]
deriveLockEscrowPda(pool, owner, ammProgram)DAMM v1 ["lock_escrow", pool, owner]
deriveLpMint(poolAddress, programId)DAMM v1 ["lp_mint", poolAddress]

Program And Account Helpers

HelperUse
createStakeFeeProgram(connection, programId)Create an Anchor program for stake_for_fee.
createDynamicAmmProgram(connection, programId)Create an Anchor program for DAMM v1.
createDynamicVaultProgram(connection, programId)Create an Anchor program for Dynamic Vault.
getOrCreateStakeEscrowInstruction(connection, feeVaultKey, ownerKey, programId)Return the stake escrow PDA and an initialize instruction when absent.
getOrCreateATAInstruction(connection, tokenMint, owner, payer?, allowOwnerOffCurve?)Return an ATA and optional create instruction.
decodeFullBalanceState(program, account)Decode full balance list metadata and appended StakerBalance entries.
decodeTopStakerListState(program, feeVault, account)Decode top list metadata and appended StakerMetadata entries.

Calculation Helpers

HelperUse
findLargestStakerNotInTopListFromFullBalanceListSort and return largest non-top-list stakers from a decoded full balance list.
findReplaceableTopStakerSort and return smallest replaceable top stakers.
getTopStakerListStateEntryStakeAmountCompute minimum top-list entry amount.
calculateFeeFarmPerformanceEstimate performance between two account-state snapshots.
parseFeeVaultInfoBuild display context from two snapshots and USD rates.
parseTopStakerListStateBuild ordered top staker display rows.
getStakeEscrowEarningPerDayEstimate current daily earning for a stake escrow.
getStakeEscrowEarningPerDayAfterUnstakeEstimate daily earning after a proposed unstake.
getLockedEscrowPendingFeeCalculate pending DAMM v1 lock escrow fees.
getVirtualPriceCalculate constant-product LP virtual price.
getTokenBalancesCalculate Dynamic Vault token balances from LP shares.

Transaction Helpers

HelperUse
computeUnitIx(units?)Build a compute budget limit instruction.
getSimulationComputeUnitsSimulate a transaction to estimate compute units.
getEstimatedComputeUnitUsageWithBufferEstimate compute with a buffer.
getEstimatedComputeUnitIxWithBufferBuild a compute unit instruction from the buffered estimate.
unwrapSOLInstruction(owner)Build an instruction to close the owner’s wrapped SOL ATA.

Exported Types

TypeUse
AccountStatesCombined decoded state fetched by the SDK.
StakeForFeeProgramAnchor program type for stake_for_fee.
FeeVault, StakeEscrow, UnstakeIDL account types.
TopListMetadata, FullBalanceListMetadataList account metadata types.
StakerMetadata, StakerBalanceAppended list entry types.
Metrics, TopStakerInfoNested vault state types.
InitializeVaultParamsIDL parameter type for vault creation.
FullBalanceListState, TopStakerListStateDecoded list states with metadata and entries.
TopStakerListStateContext, FeeVaultContextDisplay/helper output types.

Integration Notes

TopicNote
Cached stateMethods use accountStates cached on the instance. Call refreshStates() after transactions or external state changes.
Claim behaviorclaimFee transfers quote token only; base/stake token fees are restaked.
Unstake keyunstake expects a new account public key and the keypair must sign the transaction.
Admin methodsThe TypeScript wrapper does not expose high-level builders for claim_fee_crank or admin update instructions. Use the bundled IDL/program helpers for those flows.
Package nameThe published package is @meteora-ag/m3m3; some source changelog entries use the older stake-for-fee naming.