Meteora 백서

Meteora

원문

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

unts.pool.to_account_info(), escrow: ctx.accounts.escrow.to_account_info(), source_token: ctx.accounts.source_token.to_account_info(), token_vault: ctx.accounts.token_vault.to_account_info(), token_mint: ctx.accounts.token_mint.to_account_info(), token_program: ctx.accounts.token_program.to_account_info(), owner: ctx.accounts.owner.to_account_info(), }; cpi::deposit(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 generated event authority and program accounts expected by the IDL. </Note> ## Common CPI Calls | CPI call | Account context | Parameters | Notes | | - | - | - | - | | `cpi::create_new_escrow` | `CreateNewEscrowCtx` | None | Permissionless only. Runs during the deposit window. | | `cpi::create_permissioned_escrow` | `CreatePermissionedEscrowWithMerkleProofCtx` | `max_cap`, `proof` | Verifies wallet cap proof against `MerkleRootConfig`. | | `cpi::create_permissioned_escrow_with_authority` | `CreatePermissionedEscrowWithAuthorityCtx` | `max_cap` | Payer must equal `vault_authority`. | | `cpi::deposit` | `DepositCtx` | `max_amount` | Owner signer transfers quote into the vault token account. | | `cpi::withdraw` | `WithdrawCtx` | `amount` | Pro Rata only. Can withdraw deposits or overflow depending on current time point. | | `cpi::withdraw_remaining_quote` | `WithdrawRemainingQuoteCtx` | None | Runs after the buying window and marks the escrow refunded. | | `cpi::claim_token` | `ClaimTokenCtx` | None | Runs after `start_vesting_point`. | | `cpi::close_escrow` | `CloseEscrowCtx` | None | Requires the escrow to be closable. | | `cpi::fill_dlmm` | `FillDlmmCtx` | `max_amount`, `remaining_accounts_info` | Requires DLMM bin array and transfer-hook remaining accounts when applicable. | | `cpi::fill_dynamic_amm` | `FillDynamicAmmCtx` | `max_amount` | Calls Dynamic AMM / DAMM v1. | | `cpi::fill_damm_v2` | `FillDammV2Ctx` | `max_amount` | Calls DAMM v2. | ## Account Requirements | Flow | Required signer | Important accounts | | - | - | - | | Escrow creation, permissionless | `payer` | `vault`, `pool`, escrow PDA, owner, optional treasury fee receiver. | | Escrow creation, Merkle proof | `payer` | `vault`, `pool`, escrow PDA, owner, `merkle_root_config`, optional treasury fee receiver. | | Escrow creation, authority | `payer` equal to `vault_authority` | `vault`, `pool`, escrow PDA, owner. | | User deposit | `owner` | Owner quote token source, vault quote token ATA, quote mint, token program. | | User withdraw or refund | `owner` | User quote destination, vault quote token ATA, quote mint, token program. | | User claim | `owner` | User base destination, vault base token ATA, base mint, token program. | | Fill | `cranker` | Vault quote and base token accounts, connected pool-specific accounts, optional crank whitelist, optional treasury fee receiver. | ## Remaining Accounts | Situation | Remaining accounts | | - | - | | Destination account requires Token 2022 memo transfer | Pass the memo program first for `withdraw`, `withdraw_remaining_quote`, or `claim_token`. | | DLMM fill with Token 2022 transfer hooks | Pass the transfer-hook accounts described by `RemainingAccountsInfo`, followed by writable bin array accounts. | | Dynamic AMM fill | No Alpha Vault-specific remaining accounts are read by the handler. | | DAMM v2 fill | No Alpha Vault-specific remaining accounts are read by the handler. | ## Common CPI Failures | Error area | CPI-side fix | | - | - | | Pool type mismatch | Call the fill instruction matching `vault.pool_type`. | | Time window mismatch | Read the connected pool timing and vault timing before sending CPI. | | Missing treasury | Pass the treasury as `crank_fee_receiver` or `escrow_fee_receiver` when no valid whitelist removes the fee path. | | Permission mode mismatch | Use the escrow creation instruction that matches `vault.whitelist_mode`. | | Token 2022 transfer fee | Pass max amounts in raw token units and expect credited amounts to be transfer-fee excluded. | ## Best Practices | Check | Detail | | - | - | | Prefer generated bindings | Use the local Anchor crate with the `cpi` feature or generated IDL bindings. Avoid hand-typing account order from memory. | | Compare with the SDK | Build the same flow with `@meteora-ag/alpha-vault` and compare account metas, signers, writable flags, and optional accounts. | | Read vault state first | Load `Vault` before deciding the flow. Validate `vault_mode`, `whitelist_mode`, `pool_type`, token vaults, mints, and authority from account state. | | Respect pool timing | Read the connected pool timing before deposits, fills, refunds, and claims. Alpha Vault actions are gated by both vault points and pool pre-activation points. | | Keep pool type explicit | Route fills by `vault.pool_type`: DLMM, Dynamic AMM / DAMM v1, or DAMM v2. Each path has a different account set. | | Treat Merkle caps as state | For Merkle-proof vaults, verify the proof off-chain before sending CPI and use the same `max_cap` passed to the program. | | Plan fee accounts | Permissionless escrow creation and non-whitelisted fills can require the Alpha Vault treasury. Permissioned vaults must not charge escrow fees. | | Handle once-only actions | `withdraw_remaining_quote` marks the escrow refunded. Escrow close also depends on claims, refunds, and overflow withdrawals being complete. | | Simulate Token 2022 paths | Transfer-fee mints change credited amounts, and memo-required destination accounts need the memo program in remaining accounts. DLMM transfer hooks need matching remaining-account slices. | | Test every mode you support | Pro Rata and FCFS differ in deposits, withdrawals, caps, overflow behavior, and swappable amounts. Permissionless, Merkle, and authority access also differ. | ## Testing Use the local Alpha Vault test suite as a reference for account metas and edge cases: ```bash theme={"system"} cd alpha-vault anchor build anchor test ``` Add CPI caller tests that cover at least one successful path and one expected failure path for each vault mode, whitelist mode, and pool type your integration supports. # Alpha Vault TS SDK Examples Source: https://docs.meteora.ag/developer-guides/alpha-vault/typescript-sdk/examples Explore Alpha Vault TypeScript examples for reading vault state, deposits, withdrawals, claims, fills, Merkle proofs, and authority escrows. These examples use the SDK methods exported by `@meteora-ag/alpha-vault`. The SDK returns unsigned `Transaction` objects or instructions; sign and send them with your wallet adapter, backend signer, or test keypair. ## Load A Vault ```typescript theme={"system"} import AlphaVault from "@meteora-ag/alpha-vault"; import { Connection, PublicKey } from "@solana/web3.js"; const connection = new Connection(process.env.RPC_URL!, "confirmed"); const vaultAddress = new PublicKey("ALPHA_VAULT_ADDRESS"); const alphaVault = await AlphaVault.create(connection, vaultAddress, { cluster: "mainnet-beta", }); console.log(alphaVault.vaultState); console.log(alphaVault.vaultPoint); ``` ## Read User State ```typescript theme={"system"} import AlphaVault from "@meteora-ag/alpha-vault"; import { PublicKey } from "@solana/web3.js"; const owner = new PublicKey("OWNER_ADDRESS"); const escrow = await alphaVault.getEscrow(owner); const merkleProof = await alphaVault.getMerkleProofForDeposit(owner); const state = await alphaVault.interactionState(escrow, merkleProof); console.log({ canDeposit: state.canDeposit, canClaim: state.canClaim, availableQuota: state.availableQuota.toString(), totalClaimable: state.claimInfo.totalClaimable.toString(), }); ``` ## Deposit `deposit(maxAmount, owner, merkleProof?)` creates the escrow first when needed for permissionless and Merkle-proof vaults. For `PermissionWithAuthority`, the vault authority must create the escrow before the user can deposit. ```typescript theme={"system"} import { BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; const owner = new PublicKey("OWNER_ADDRESS"); const maxAmount = new BN(1_000_000); const merkleProof = await alphaVault.getMerkleProofForDeposit(owner); const tx = await alphaVault.deposit(maxAmount, owner, merkleProof ?? undefined); tx.feePayer = owner; ``` ## Authority-Created Escrows Use this flow for `WhitelistMode.PermissionWithAuthority`. The vault authority pays rent and creates an escrow with a wallet-specific cap. ```typescript theme={"system"} import { BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; const owner = new PublicKey("USER_ADDRESS"); const vaultAuthority = new PublicKey("VAULT_AUTHORITY"); const maxCap = new BN(1_000_000); const tx = await alphaVault.createStakeEscrowByAuthority( maxCap, owner, vaultAuthority, ); ``` For batches, build instructions and place them in your own transaction: ```typescript theme={"system"} const instructions = await alphaVault.createMultipleStakeEscrowByAuthorityInstructions( [ { address: new PublicKey("USER_1"), maxAmount: new BN(1_000_000) }, { address: new PublicKey("USER_2"), maxAmount: new BN(2_000_000) }, ], vaultAuthority, ); ``` ## Withdraw During Deposit Window `withdraw` is only available for Pro Rata vaults. During the deposit window it withdraws a user's deposit share. After the join window and before the buying window ends, it can withdraw Pro Rata deposit overflow. ```typescript theme={"system"} import { BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; const owner = new PublicKey("OWNER_ADDRESS"); const maxAmount = new BN(500_000); const tx = await alphaVault.withdraw(maxAmount, owner); ``` ## Withdraw Remaining Quote After the buying window ends, users can withdraw unused quote once from their escrow. ```typescript theme={"system"} import { PublicKey } from "@solana/web3.js"; const owner = new PublicKey("OWNER_ADDRESS"); const tx = await alphaVault.withdrawRemainingQuote(owner); ``` ## Claim Bought Token Users can claim bought base tokens after the vault's `startVestingPoint`. Claims vest linearly until `endVestingPoint`. ```typescript theme={"system"} import { PublicKey } from "@solana/web3.js"; const owner = new PublicKey("OWNER_ADDRESS"); const tx = await alphaVault.claimToken(owner); ``` ## Fill The Vault `fillVault(payer)` chooses the correct pool-specific fill helper from `vault.poolType`. It returns `null` when no fill transaction should be sent, such as a fully filled vault or a DLMM quote with insufficient liquidity for a partial fill. ```typescript theme={"system"} import { PublicKey } from "@solana/web3.js"; const payer = new PublicKey("CRANKER_ADDRESS"); const tx = await alphaVault.fillVault(payer); if (tx) { tx.feePayer = payer; } ``` <Note> Fill instructions can charge the Alpha Vault crank fee unless the cranker has a `CrankFeeWhitelist` PDA. </Note> ## Merkle Proof Metadata For `PermissionWithMerkleProof`, the vault authority or admin can create an on-chain Merkle root config and optional proof URL metadata. The SDK falls back to Meteora's default proof API when metadata is missing. ```typescript theme={"system"} import { BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; const vaultCreator = new PublicKey("VAULT_AUTHORITY"); const version = new BN(0); const root = Buffer.from("MERKLE_ROOT_HEX", "hex"); const rootTx = await alphaVault.createMerkleRootConfig( root, version, vaultCreator, ); const metadataTx = await alphaVault.createMerkleProofMetadata( vaultCreator, "https://example.com/alpha-vault-proofs", ); ``` ## Build A Merkle Tree Locally The SDK exports `BalanceTree` for creating Merkle roots and proofs from wallet caps. ```typescript theme={"system"} import { BN } from "@coral-xyz/anchor"; import { BalanceTree } from "@meteora-ag/alpha-vault"; import { PublicKey } from "@solana/web3.js"; const entries = [ { account: new PublicKey("USER_1"), maxCap: new BN(1_000_000) }, { account: new PublicKey("USER_2"), maxCap: new BN(2_000_000) }, ]; const tree = new BalanceTree(entries); const root = tree.getRoot(); const proof = tree.getProof(entries[0].account, entries[0].maxCap); ``` # Alpha Vault TS SDK Getting Started Source: https://docs.meteora.ag/developer-guides/alpha-vault/typescript-sdk/getting-started Learn how to install @meteora-ag/alpha-vault, initialize an AlphaVault client, read vault state, and test the SDK. This guide shows how to install and initialize the official Alpha Vault TypeScript SDK, `@meteora-ag/alpha-vault`. Before you begin, here are the main resources: <CardGroup> <Card title="TypeScript SDK" icon="node-js" href="https://github.com/MeteoraAg/alpha-vault-sdk/tree/main/ts-client"> SDK source, IDL, transaction helpers, PDA helpers, Merkle tree helpers, and package metadata. </Card> <Card title="NPM Package" icon="npm" href="https://www.npmjs.com/package/@meteora-ag/alpha-vault"> Published package for Alpha Vault TypeScript integrations. </Card> </CardGroup> ## Installation Install the SDK and Solana dependencies: <Tabs> <Tab title="npm"> ```bash theme={"system"} npm install @meteora-ag/alpha-vault @solana/web3.js @solana/spl-token @coral-xyz/anchor bn.js ``` </Tab> <Tab title="pnpm"> ```bash theme={"system"} pnpm install @meteora-ag/alpha-vault @solana/web3.js @solana/spl-token @coral-xyz/anchor bn.js ``` </Tab> <Tab title="yarn"> ```bash theme={"system"} yarn add @meteora-ag/alpha-vault @solana/web3.js @solana/spl-token @coral-xyz/anchor bn.js ``` </Tab> <Tab title="bun"> ```bash theme={"system"} bun add @meteora-ag/alpha-vault @solana/web3.js @solana/spl-token @coral-xyz/anchor bn.js ``` </Tab> </Tabs> ## Initialization Load an existing Alpha Vault from its vault address: ```typescript theme={"system"} import AlphaVault, { VaultState } from "@meteora-ag/alpha-vault"; import { Connection, PublicKey } from "@solana/web3.js"; const connection = new Connection(process.env.RPC_URL!, "confirmed"); const vaultAddress = new PublicKey("ALPHA_VAULT_ADDRESS"); const alphaVault = await AlphaVault.create(connection, vaultAddress, { cluster: "mainnet-beta", }); console.log(alphaVault.vaultState === VaultState.DEPOSITING); console.log(alphaVault.vaultPoint); ``` The package default export is the `AlphaVault` client class. Named exports include enums, types, PDA helpers, Merkle tree helpers, fill helpers, constants, and the IDL. ## Program ID The SDK maps clusters to these Alpha Vault program IDs: | Cluster | Program ID | | - | - | | `mainnet-beta` | `vaU6kP7iNEGkbmPkLmZfGwiGxd4Mob24QQCie5R9kd2` | | `devnet` | `vaU6kP7iNEGkbmPkLmZfGwiGxd4Mob24QQCie5R9kd2` | | `localhost` | `SNPmGgnywBvvrAKMLundzG6StojyHTHDLu7T4sdhP4k` | ## First Reads Use these methods and getters before building transactions: | API | Use | | - | - | | `AlphaVault.create(connection, vaultAddress, opt?)` | Fetches vault, clock, mints, and connected pool timing into an `AlphaVault` instance. | | `alphaVault.vault` | Decoded on-chain `Vault` account. | | `alphaVault.mode` | SDK `VaultMode` value derived from `vault.vaultMode`. | | `alphaVault.vaultPoint` | First join, last join, last buying, start vesting, and end vesting points. | | `alphaVault.vaultState` | Current lifecycle state from the clock and vault timing. | | `alphaVault.getEscrow(owner)` | Fetches the owner escrow PDA or returns `null`. | | `alphaVault.interactionState(escrow, merkleProof?)` | Computes UI-ready deposit, claim, withdrawal, and whitelist booleans. | ## Reference <CardGroup> <Card title="SDK Examples" icon="bolt" href="/developer-guides/alpha-vault/typescript-sdk/examples"> Explore transaction flows for deposits, claims, fills, Merkle proofs, and authority-created escrows. </Card> <Card title="SDK Reference" icon="code" href="/developer-guides/alpha-vault/typescript-sdk/reference"> Access the SDK method map, PDA helpers, constants, enums, and exported types. </Card> </CardGroup> ## Testing The SDK The local SDK package uses `tsup` for builds and Jest for tests. ```bash theme={"system"} cd alpha-vault-sdk/ts-client npm install npm run build npm test ``` Some tests require local validator fixtures and launch-pool artifacts. For application integrations, simulate transactions and test the exact vault and pool configuration before mainnet use. ## Faucets <CardGroup> <Card title="Devnet Faucet" icon="faucet" href="https://faucet.solana.com/"> Request test SOL for devnet integration testing. </Card> </CardGroup> # Alpha Vault TS SDK Reference Source: https://docs.meteora.ag/developer-guides/alpha-vault/typescript-sdk/reference Explore Alpha Vault TypeScript SDK exports, client methods, PDA helpers, constants, enums, fill helpers, Merkle helpers, and types. The TypeScript SDK package is `@meteora-ag/alpha-vault`. The package default export is the `AlphaVault` client class. Named exports include types, enums, constants, PDA helpers, fill helpers, Merkle tree helpers, and the IDL. ```typescript theme={"system"} import AlphaVault, { BalanceTree, PoolType, VaultMode, WhitelistMode, deriveAlphaVault, deriveEscrow, } from "@meteora-ag/alpha-vault"; ``` ## Client Construction | API | Signature | Use | | - | - | - | | `AlphaVault.create` | `(connection, vaultAddress, opt?) => Promise<AlphaVault>` | Loads a vault, sysvar clock, mint accounts, and connected pool timing. | | `createProgram` | `(connection, opt?) => Program` | Creates an Anchor program client for Alpha Vault. | | `createDlmmProgram` | `(connection, opt?) => Program` | Creates a DLMM Anchor program client used for pool reads. | | `createDammProgram` | `(connection, opt?) => Program` | Creates a Dynamic AMM / DAMM v1 program client used for pool reads. | | `createCpAmmProgram` | `(connection, opt?) => Program` | Creates a DAMM v2 program client used for pool reads. | `opt.cluster` supports `mainnet-beta`, `devnet`, and `localhost`. ## Static Vault APIs | API | Use | | - | - | | `AlphaVault.createCustomizableProrataVault(connection, params, owner, opt?)` | Builds a direct Pro Rata vault initialization transaction. | | `AlphaVault.createCustomizableFcfsVault(connection, params, owner, opt?)` | Builds a direct FCFS vault initialization transaction. | | `AlphaVault.createPermissionlessVault(connection, vaultParam, owner, opt?)` | Builds a config-based permissionless vault initialization transaction. | | `AlphaVault.createPermissionedVaultWithMerkleProof(connection, vaultParam, owner, opt?)` | Builds a config-based vault initialization transaction using Merkle-proof escrow creation. | | `AlphaVault.createPermissionedVaultWithAuthorityFund(connection, vaultParam, owner, opt?)` | Builds a config-based vault initialization transaction using authority-created escrows. | | `AlphaVault.getFcfsConfigs(connection, opt?)` | Fetches all FCFS vault config accounts. | | `AlphaVault.getProrataConfigs(connection, opt?)` | Fetches all Pro Rata vault config accounts. | | `AlphaVault.getEscrowByOwner(connection, owner, opt?)` | Fetches all escrow accounts with the owner at account-data offset `40`. | ## Instance Read APIs | API | Use | | - | - | | `alphaVault.mode` | Returns `VaultMode.PRORATA` or `VaultMode.FCFS`. | | `alphaVault.vaultPoint` | Returns first join, last join, last buying, start vesting, and end vesting points. | | `alphaVault.vaultState` | Returns `PREPARING`, `DEPOSITING`, `PURCHASING`, `LOCKING`, `VESTING`, or `ENDED`. | | `refreshState(clock?)` | Refetches the vault and clock state, or uses a provided clock. | | `getEscrow(owner)` | Fetches the owner's escrow or returns `null`. | | `getClaimInfo(escrow)` | Calculates total allocated, claimed, and currently claimable base token. | | `getDepositInfo(escrow)` | Calculates total deposit, total filled, and total returned quote. | | `getAvailableDepositQuota(escrow, merkleProof?)` | Calculates current available deposit quota in raw
프로젝트로 돌아가기