bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 51쪽
orts gain. |
Use the TypeScript SDK's `VaultImpl.create(connection, tokenMint)` or `VaultImpl.createMultiple(...)` for hydrated vault clients. Low-level readers can fetch the Anchor `vault` account directly by PDA.
## LockedProfitTracker
| Field | Type | Meaning |
| - | - | - |
| `last_updated_locked_profit` | `u64` | Locked profit remaining from the last report. |
| `last_report` | `u64` | Unix timestamp of the last locked-profit update. |
| `locked_profit_degradation` | `u64` | Per-second unlock rate over `LOCKED_PROFIT_DEGRADATION_DENOMINATOR`. Default fully releases profit over 6 hours. |
`Vault.get_unlocked_amount(current_time)` returns `total_amount - current_locked_profit`. Deposits, withdrawals, virtual price, and SDK helpers use this unlocked amount rather than raw `total_amount`.
## Strategy
`Strategy` stores one external or internal strategy attached to a rebalance vault.
| Field | Type | Meaning |
| - | - | - |
| `reserve` | `Pubkey` | External reserve, market, or pool account used by the strategy handler. |
| `collateral_vault` | `Pubkey` | Vault-owned token account holding strategy collateral tokens. |
| `strategy_type` | `StrategyType` | Strategy handler enum. |
| `current_liquidity` | `u64` | Last recorded liquidity in underlying token units. |
| `bumps` | `[u8; 10]` | Strategy and downstream protocol PDA bump bytes. |
| `vault` | `Pubkey` | Parent vault account. |
| `is_disable` | `u8` | Non-zero means the strategy was disabled and cannot be re-added. |
The current program source supports `StrategyType::Vault` and `StrategyType::JupLend` handlers. Other enum variants remain in the enum for historical compatibility, but their handlers panic as unsupported in the current source.
## StrategyType
| Variant | Current source behavior |
| - | - |
| `PortFinanceWithoutLM` | Unsupported handler. |
| `PortFinanceWithLM` | Unsupported handler. |
| `SolendWithoutLM` | Unsupported handler. |
| `Mango` | Unsupported handler. |
| `SolendWithLM` | Unsupported handler. |
| `ApricotWithoutLM` | Unsupported handler. |
| `Francium` | Unsupported handler. |
| `Tulip` | Unsupported handler. |
| `Vault` | Internal vault-reserve handler and compatibility strategy. |
| `Drift` | Unsupported handler. |
| `Frakt` | Unsupported handler. |
| `Marginfi` | Unsupported handler. |
| `Kamino` | Unsupported handler in the current source. |
| `JupLend` | Jupiter Lend strategy handler in the current source. |
## Bump Types
| Type | Field | Meaning |
| - | - | - |
| `VaultBumps` | `vault_bump` | Bump for the vault PDA. |
| `VaultBumps` | `token_vault_bump` | Bump for the token-vault PDA. |
| `StrategyBumps` | `strategy_index` | Seed byte used in strategy PDA derivation. |
| `StrategyBumps` | `other_bumps` | Ten downstream bump bytes. The current `initialize_strategy` handler requires `other_bumps[0] == strategy_index` and `other_bumps[1] == strategy` PDA bump. |
## Account Reads
| Need | TypeScript SDK | Rust / Anchor |
| - | - | - |
| Vault state from token mint | `VaultImpl.create(connection, tokenMint)` | Derive `vault` PDA, then fetch `mercurial_vault::state::Vault`. |
| Vault state from vault PDA | `VaultImpl.createMultipleWithPda(connection, [vault])` | Fetch `Vault` directly by pubkey. |
| Vault LP supply | `vault.getVaultSupply()` or `getLpSupply(connection, lpMint)` | Fetch `anchor_spl::token::Mint` for `vault.lp_mint`. |
| User LP balance | `vault.getUserBalance(owner)` or `VaultImpl.fetchMultipleUserBalance(...)` | Read the owner's ATA for `vault.lp_mint`. |
| Strategies | `vault.getStrategiesState()` | Iterate non-default `vault.strategies` and fetch `Strategy`. |
## Gotchas
| Topic | Detail |
| - | - |
| Rebalance vs idle vault | Admin, operator, strategy, fee vault, and rebalance instructions require `vault.get_vault_type() == RebalanceVault`. Idle vaults cannot be rebalanced. |
| Fee vault | `initialize_strategy` fails with `FeeVaultIsNotSet` unless `fee_vault` was set to a treasury-owned LP token account. |
| Locked profit | `total_amount` can be higher than the amount available for withdrawal until locked profit has degraded. |
| Strategy slots | A vault can hold up to 30 strategy pubkeys. Removed strategies clear their slot unless removed through the advance-payment path, which also disables the strategy. |
| Source and IDL drift | The public TS IDL in `vault-sdk` is older than the current `mercurial-vault` program source. Prefer source-backed docs for low-level program behavior and SDK docs for public client behavior. |
# Dynamic Vault Program Errors
Source: https://docs.meteora.ag/developer-guides/dynamic-vault/program/errors
Understand Dynamic Vault VaultError codes, messages, source and IDL naming notes, and common integration causes.
This page lists Anchor custom errors returned by the current Dynamic Vault `vault` program source.
<Tip>
Anchor custom program errors start at `6000`. When a transaction log contains `custom program error: 0x1771`, convert the hex value to decimal and match it against the table below.
</Tip>
## Error Codes
| Code | Name | Message | Common cause |
| - | - | - | - |
| `6000` | `VaultIsDisabled` | Vault is disabled | A deposit was attempted while `vault.enabled == 0`. |
| `6001` | `ExceededSlippage` | Exceeded slippage tolerance | Minted LP or output tokens were below the caller's minimum threshold. Refresh vault state and quote. |
| `6002` | `StrategyIsNotExisted` | Strategy is not existed | The strategy account is not registered in `vault.strategies`. |
| `6003` | `UnAuthorized` | UnAuthorized | A protected flow was attempted by the wrong authority in older paths or downstream strategy code. |
| `6004` | `MathOverflow` | Math operation overflow | Checked arithmetic failed during LP math, locked-profit math, strategy accounting, or fee calculations. |
| `6005` | `ProtocolIsNotSupported` | Protocol is not supported | The selected strategy type does not have a supported handler. |
| `6006` | `UnMatchReserve` | Reserve does not support token mint | The strategy reserve does not match the vault token mint. |
| `6007` | `InvalidLockedProfitDegradation` | lockedProfitDegradation is invalid | Admin tried to set a zero or above-denominator locked-profit degradation value. |
| `6008` | `MaxStrategyReached` | Maximum number of strategies have been reached | All 30 strategy slots are already occupied. |
| `6009` | `StrategyExisted` | Strategy existed | `initialize_strategy` tried to add a strategy already registered in the vault. |
| `6010` | `InvalidUnmintAmount` | Invalid unmint amount | Direct strategy withdrawal computed an LP burn amount greater than the requested amount. |
| `6011` | `InvalidAccountsForStrategy` | Invalid accounts for strategy | Strategy remaining accounts or fee vault did not match vault or strategy state. |
| `6012` | `InvalidBump` | Invalid bump | Strategy bump args do not match the expected strategy index or PDA bump. |
| `6013` | `AmountMustGreaterThanZero` | Amount must be greater than 0 | `deposit` received `token_amount == 0`. |
| `6014` | `MangoIsNotSupportedAnymore` | Mango is not supported anymore | Historical Mango strategy path is blocked. |
| `6015` | `StrategyIsNotSupported` | Strategy is not supported | The selected strategy variant is not supported by the current source. |
| `6016` | `PayAmountIsExceeded` | Pay amount is exceeded | `remove_strategy2` required admin advance payment above `max_admin_pay_amount`. |
| `6017` | `FeeVaultIsNotSet` | Fee vault is not set | Strategy initialization was attempted before configuring a fee vault. |
| `6018` | `LendingAssertionViolation` | deposit amount in lending is not matched | Downstream lending deposit accounting did not match the expected amount. |
| `6019` | `HaveMoneyInLending` | Cannot remove strategy because we have some in lending | Strategy removal left more than the allowed residual liquidity in the lending protocol. |
| `6020` | `InvalidPrecisionLoss` | Invalid precision loss | Direct strategy withdrawal precision loss was greater than one underlying unit. |
| `6021` | `UndeterminedError` | Undetermined error | Fallback error for unexpected internal state. |
## IDL Naming Notes
| Source | Difference |
| - | - |
| Current program source | Uses `PayAmountIsExceeded` for code `6016` and includes `InvalidPrecisionLoss` plus `UndeterminedError`. |
| Checked-in TypeScript IDL | The older IDL spells code `6016` as `PayAmountIsExeeced` and stops at `HaveMoneyInLending`. |
When decoding transactions from logs, match by numeric code first. When matching SDK-generated IDL names, account for the older misspelling in the TypeScript IDL.
## Troubleshooting
| Symptom | Check |
| - | - |
| Deposit fails immediately | Confirm `vault.enabled == 1`, amount is non-zero, and the user's underlying token ATA has enough balance. |
| Withdrawal fails with slippage | Refresh vault state, LP supply, and unlocked amount. Increase `min_out_amount` tolerance only after re-quoting. |
| Strategy rebalance fails | Confirm the strategy is present in `vault.strategies`, the fee vault matches `vault.fee_vault`, and all strategy-specific remaining accounts are in handler order. |
| Strategy initialization fails | Set `fee_vault` first, verify `StrategyBumps`, and confirm the strategy type has a supported current handler. |
| Admin action fails | Confirm the vault is a rebalance vault and the signer matches `vault.admin`. |
| Operator action fails | Confirm the signer is either `vault.admin` or `vault.operator`. |
| Fee vault transfer fails | The new fee vault must be an LP token account whose owner is the treasury address. |
| `remove_strategy2` fails | The admin and vault advance-payment token accounts must cover the required underlying amount without exceeding `max_admin_pay_amount`. |
# Dynamic Vault Program Events
Source: https://docs.meteora.ag/developer-guides/dynamic-vault/program/events
Understand Dynamic Vault events emitted by deposits, withdrawals, strategy rebalances, rewards, fees, losses, and unlocked-amount reads.
The `vault` program emits Anchor events in program logs. Indexers can use these events to track user liquidity, strategy movements, rewards, performance fees, losses, and simulated unlocked amount reads.
## Event Delivery
| Item | Value |
| - | - |
| Program ID | `24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi` |
| Event source | Anchor `Program data:` logs emitted with `emit!` |
| Parser | Anchor event discriminator plus Borsh event payload |
| Rust client example | `rust-client/src/utils.rs` scans `Program data:` logs and deserializes matching event discriminators |
Unlike newer event-CPI programs, Dynamic Vault events are emitted as Anchor logs rather than through a separate event authority account.
## Liquidity Events
| Event | Emitted by | Payload | Use |
| - | - | - | - |
| `AddLiquidity` | `deposit` | `lp_mint_amount: u64`, `token_amount: u64` | Track user deposits and LP minted from the vault's unlocked accounting. |
| `RemoveLiquidity` | `withdraw`, `withdraw_directly_from_strategy` | `lp_unmint_amount: u64`, `token_amount: u64` | Track user LP burns and underlying tokens returned. |
`RemoveLiquidity.lp_unmint_amount` is the amount of LP burned. In a direct strategy withdrawal, the handler may refine the burn amount when the strategy cannot return the full desired amount.
## Strategy Events
| Event | Emitted by | Payload | Use |
| - | - | - | - |
| `StrategyDeposit` | `deposit_strategy` | `strategy_type: StrategyType`, `token_amount: u64` | Track vault reserve liquidity moved into a strategy. |
| `StrategyWithdraw` | `withdraw_strategy`, `remove_strategy`, `remove_strategy2`, `withdraw_directly_from_strategy` | `strategy_type: StrategyType`, `collateral_amount: u64`, `estimated_token_amount: u64` | Track strategy collateral redeemed and estimated underlying returned. |
For `remove_strategy`, `estimated_token_amount` is the actual increase in the vault token account after withdrawing all strategy collateral. For normal strategy withdrawal, it is the requested underlying amount.
## Reward And Fee Events
| Event | Emitted by | Payload | Use |
| - | - | - | - |
| `ClaimReward` | `claim_rewards` | `strategy_type: StrategyType`, `token_amount: u64`, `mint_account: Pubkey` | Track strategy rewards claimed to a treasury-owned token account. |
| `PerformanceFee` | Rebalance wrapper on profit | `lp_mint_more: u64` | Track performance-fee LP minted to `fee_vault`. |
| `ReportLoss` | Rebalance wrapper on loss | `strategy: Pubkey`, `loss: u64` | Track decreases in vault total amount after strategy accounting. |
The performance fee is calculated only when a rebalance reports gain. The program mints LP tokens to the configured `fee_vault` and adjusts locked profit so the fee accounting does not immediately change virtual price.
## Read Events
| Event | Emitted by | Payload | Use |
| - | - | - | - |
| `TotalAmount` | `get_unlocked_amount` | `total_amount: u64` | Read current unlocked amount through transaction simulation logs. |
The Rust client uses `get_unlocked_amount` by simulating the instruction and parsing `TotalAmount` from logs. Off-chain clients can also compute withdrawable amount locally from vault state and sysvar clock data.
## Indexing Notes
| Use case | Event |
| - | - |
| Deposit history | `AddLiquidity` |
| Withdrawal history | `RemoveLiquidity` |
| Strategy allocation movement | `StrategyDeposit`, `StrategyWithdraw` |
| Reward collection | `ClaimReward` |
| Fee accounting | `PerformanceFee` |
| Loss accounting | `ReportLoss` |
| Unlocked amount simulation | `TotalAmount` |
Events do not include the vault address in their payloads. Indexers should join the event to the transaction instruction accounts, especially the `vault`, `strategy`, and token accounts, when building vault-level analytics.
## Payload Reference
| Event | Field | Type | Meaning |
| - | - | - | - |
| `AddLiquidity` | `lp_mint_amount` | `u64` | LP tokens minted to the user's LP token account. |
| `AddLiquidity` | `token_amount` | `u64` | Underlying tokens transferred into the vault. |
| `RemoveLiquidity` | `lp_unmint_amount` | `u64` | LP tokens burned from the user's LP token account. |
| `RemoveLiquidity` | `token_amount` | `u64` | Underlying tokens transferred out to the user. |
| `StrategyDeposit` | `strategy_type` | `StrategyType` | Strategy handler used for the deposit. |
| `StrategyDeposit` | `token_amount` | `u64` | Underlying amount sent to the strategy. |
| `StrategyWithdraw` | `strategy_type` | `StrategyType` | Strategy handler used for the withdrawal. |
| `StrategyWithdraw` | `collateral_amount` | `u64` | Collateral tokens redeemed or accounted for. |
| `StrategyWithdraw` | `estimated_token_amount` | `u64` | Estimated or actual underlying amount associated with the strategy withdrawal. |
| `ClaimReward` | `strategy_type` | `StrategyType` | Strategy handler used for reward claiming. |
| `ClaimReward` | `token_amount` | `u64` | Reward tokens received by the treasury-owned reward account. |
| `ClaimReward` | `mint_account` | `Pubkey` | Reward token mint. |
| `PerformanceFee` | `lp_mint_more` | `u64` | LP tokens minted to the fee vault. |
| `ReportLoss` | `strategy` | `Pubkey` | Strategy account that reported loss through rebalance accounting. |
| `ReportLoss` | `loss` | `u64` | Loss in underlying token units. |
| `TotalAmount` | `total_amount` | `u64` | Current unlocked amount in underlying token units. |
# Dynamic Vault Program Instructions
Source: https://docs.meteora.ag/developer-guides/dynamic-vault/program/instructions
Explore Dynamic Vault instructions for initialization, deposits, withdrawals, strategy rebalancing, rewards, operators, and admins.
The `vault` program exposes user liquidity instructions, strategy rebalance instructions, and admin/operator instructions. Apps should normally use the TypeScript SDK for transaction construction. Programs using CPI should generate bindings from the IDL and cross-check account order against the current source.
<Note>
The current `mercurial-vault/programs/vault` source includes `initialize_idle_vault` and `JupLend` strategy support. The checked-in TypeScript IDL in `vault-sdk` is older in a few places, so this page follows the current program handlers.
</Note>
## User Liquidity
| Instruction | TypeScript SDK | Accounts | Args | Use |
| - | - | - | - | - |
| `deposit` | `vault.deposit(owner, amount)` | `vault`, `token_vault`, `lp_mint`, `user_token`, `user_lp`, `user`, `token_program` | `token_amount`, `minimum_lp_token_amount` | Transfer underlying tokens into the vault and mint LP tokens to the user. |
| `withdraw` | `vault.withdraw(owner, lpAmount)` when reserve liquidity is enough | Same as `deposit` | `unmint_amount`, `min_out_amount` | Burn vault LP tokens and withdraw underlying tokens from the vault reserve. |
| `withdraw_directly_from_strategy` | `vault.withdraw(owner, lpAmount)` when strategy liquidity is needed | `vault`, `strategy`, `reserve`, `strategy_program`, `collateral_vault`, `token_vault`, `lp_mint`, `fee_vault`, `user_token`, `user_lp`, `user`, `token_program` | `unmint_amount`, `min_out_amount` | Withdraw from a selected strategy first when vault reserves cannot satisfy the desired withdrawal. |
`deposit` rejects zero amounts and rejects deposits when `vault.enabled == 0`. `withdraw` does not check `enabled`, so users can still exit a disabled vault.
## Deposit Accounting
| Step | Behavior |
| - | - |
| Check amount | `token_amount` must be greater than zero. |
| Check vault status | Deposits fail with `VaultIsDisabled` when `enabled == 0`. |
| Calculate LP | Uses unlocked vault amount and current LP supply. Empty vaults mint based on unlocked amount after adding the deposit. |
| Slippage check | Fails with `ExceededSlippage` if minted LP is below `minimum_lp_token_amount`. |
| Emit event | Emits `AddLiquidity`. |
| Token movement | Transfers underlying tokens from `user_token` to `token_vault`, then mints LP to `user_lp`. |
## Withdrawal Accounting
| Step | Behavior |
| - | - |
| Calculate output | Uses `unmint_amount / lp_supply` over the current unlocked amount. |
| Slippage check | Fails with `ExceededSlippage` if output is below `min_out_amount`. |
| Reserve withdrawal | Transfers underlying tokens from `token_vault` to `user_token`. |
| LP burn | Burns `unmint_amount` from `user_lp`. |
| Strategy withdrawal | `withdraw_directly_from_strategy` can pull from a strategy first, then refines the burned LP amount if available liquidity is lower than requested. |
## Vault Initialization
| Instruction | Accounts | Args | Use |
| - | - | - | - |
| `initialize` | `vault`, `payer`, `token_vault`, `token_mint`, `lp_mint`, `rent`, `token_program`, `system_program` | none | Create a rebalance vault PDA for a token mint using `get_base_address()`. |
| `initialize_idle_vault` | Same as `initialize` | none | Create an idle vault PDA for a token mint using the default pubkey as base. |
Initialization sets `admin` and `operator` from the configured program admin, initializes the token vault and LP mint PDAs, clears all strategy slots, initializes locked profit, and enables the vault.
## Strategy Management
| Instruction | Accounts | Args | Authority | Use |
| - | - | - | - | - |
| `initialize_strategy` | `vault`, `strategy_program`, `strategy`, `reserve`, `collateral_vault`, `collateral_mint`, `admin`, `system_program`, `rent`, `token_program` | `bumps`, `strategy_type` | Admin | Initialize a strategy account, collateral vault, downstream strategy state, and add it to `vault.strategies`. |
| `add_strategy` | `vault`, `strategy`, `admin` | none | Admin | Re-add an initialized, non-disabled strategy to a vault slot. |
| `remove_strategy` | `vault`, `strategy`, `strategy_program`, `collateral_vault`, `reserve`, `token_vault`, `fee_vault`, `lp_mint`, `token_program`, `admin` | none | Admin | Withdraw all liquidity from a strategy and remove it from the vault strategy list. |
| `remove_strategy2` | Same as `remove_프로젝트로 돌아가기