waps, liquidity, pool creation, configs, locks, and lock fee claims.
These examples are based on the local `damm-v1-sdk/ts-client/src/examples` files and public SDK methods. They focus on transaction construction patterns. For the full method catalog, see the [SDK Reference](/developer-guides/damm-v1/typescript-sdk/reference).
## Setup
```typescript theme={"system"}
import AmmImpl from "@meteora-ag/dynamic-amm-sdk";
import { Connection, Keypair, PublicKey, sendAndConfirmTransaction } from "@solana/web3.js";
import BN from "bn.js";
const connection = new Connection(process.env.RPC_URL!, "confirmed");
// Replace with your wallet adapter, backend signer, or key management flow.
const user = Keypair.generate();
const poolAddress = new PublicKey("...");
```
Use devnet while testing. The DAMM v1 program ID is the same for devnet and mainnet:
```typescript theme={"system"}
// Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB
```
## Fetch Pool State
```typescript theme={"system"}
const pool = await AmmImpl.create(connection, poolAddress, {
cluster: "mainnet-beta",
});
await pool.updateState();
const lockedLpAmount = await pool.getLockedLpAmount();
const lpSupply = await pool.getLpSupply();
console.log({
pool: pool.address.toBase58(),
lpMint: pool.getPoolTokenMint().toBase58(),
tokenA: pool.tokenAMint.address.toBase58(),
tokenB: pool.tokenBMint.address.toBase58(),
tokenAAmount: pool.poolInfo.tokenAAmount.toString(),
tokenBAmount: pool.poolInfo.tokenBAmount.toString(),
virtualPriceRaw: pool.poolInfo.virtualPriceRaw.toString(),
lockedLpAmount: lockedLpAmount.toString(),
lpSupply: lpSupply.toString(),
});
```
`AmmImpl.create` reads the pool, both Dynamic Vault accounts, vault token accounts, vault LP mints, pool-held vault LP token accounts, clock, and depeg accounts when required.
## Quote And Swap
The recommended swap flow is:
1. Load the pool.
2. Quote with `getSwapQuote`.
3. Build the swap transaction with `minSwapOutAmount`.
4. Sign, simulate when appropriate, and send.
```typescript theme={"system"}
const pool = await AmmImpl.create(connection, poolAddress, {
cluster: "devnet",
});
const inTokenMint = pool.tokenAMint.address;
const inAmount = new BN(10_000_000);
const slippagePercent = 1;
const quote = pool.getSwapQuote(inTokenMint, inAmount, slippagePercent);
const tx = await pool.swap(
user.publicKey,
inTokenMint,
quote.swapInAmount,
quote.minSwapOutAmount,
);
const signature = await sendAndConfirmTransaction(connection, tx, [user]);
console.log({
signature,
outAmount: quote.swapOutAmount.toString(),
minOutAmount: quote.minSwapOutAmount.toString(),
fee: quote.fee.toString(),
priceImpact: quote.priceImpact.toString(),
});
```
Pass a `referralOwner` as the optional fifth `pool.swap` argument when routing a host fee account for referral flows.
## Deposit Liquidity
For a balanced deposit, provide one token-side amount to `getDepositQuote` with `balance = true`; the SDK computes the other side from pool state.
```typescript theme={"system"}
const pool = await AmmImpl.create(connection, poolAddress);
const tokenBInAmount = new BN(1_000_000);
const slippagePercent = 1;
const quote = pool.getDepositQuote(
new BN(0),
tokenBInAmount,
true,
slippagePercent,
);
const tx = await pool.deposit(
user.publicKey,
quote.tokenAInAmount,
quote.tokenBInAmount,
quote.minPoolTokenAmountOut,
);
const signature = await sendAndConfirmTransaction(connection, tx, [user]);
console.log(signature);
```
For stable pools, the SDK can also quote imbalanced deposits by calling `getDepositQuote(tokenAAmount, tokenBAmount, false, slippagePercent)`.
## Withdraw Liquidity
```typescript theme={"system"}
const pool = await AmmImpl.create(connection, poolAddress);
const lpTokenAmount = new BN(100_000);
const slippagePercent = 1;
const quote = pool.getWithdrawQuote(lpTokenAmount, slippagePercent);
const tx = await pool.withdraw(
user.publicKey,
quote.poolTokenAmountIn,
quote.minTokenAOutAmount,
quote.minTokenBOutAmount,
);
const signature = await sendAndConfirmTransaction(connection, tx, [user]);
console.log(signature);
```
For stable pools, pass a token mint as the third `getWithdrawQuote` argument to quote a single-sided withdrawal.
## Create A Config-Based Pool
`createPermissionlessConstantProductPoolWithConfig` returns an array of transactions because vault creation, pool creation, optional locking, and optional initial swap can require multiple transactions.
```typescript theme={"system"}
import AmmImpl, { PROGRAM_ID } from "@meteora-ag/dynamic-amm-sdk";
import { derivePoolAddressWithConfig } from "@meteora-ag/dynamic-amm-sdk/dist/cjs/src/amm/utils";
import { PublicKey } from "@solana/web3.js";
import BN from "bn.js";
const tokenAMint = new PublicKey("...");
const tokenBMint = new PublicKey("...");
const config = new PublicKey("...");
const tokenAAmount = new BN(100_000);
const tokenBAmount = new BN(500_000);
const poolAddress = derivePoolAddressWithConfig(
tokenAMint,
tokenBMint,
config,
new PublicKey(PROGRAM_ID),
);
const transactions = await AmmImpl.createPermissionlessConstantProductPoolWithConfig(
connection,
user.publicKey,
tokenAMint,
tokenBMint,
tokenAAmount,
tokenBAmount,
config,
{
cluster: "devnet",
lockLiquidity: true,
},
);
for (const tx of transactions) {
const signature = await sendAndConfirmTransaction(connection, tx, [user]);
console.log(signature);
}
console.log("pool", poolAddress.toBase58());
```
Use `createPermissionlessConstantProductPoolWithConfig2` when you need to pass an `activationPoint` accepted by the selected config.
## Find Authorized Configs
```typescript theme={"system"}
const configs = await AmmImpl.getPoolConfigsWithPoolCreatorAuthority(
connection,
user.publicKey,
);
for (const config of configs) {
console.log({
config: config.publicKey.toBase58(),
tradeFeeNumerator: config.account.poolFees.tradeFeeNumerator.toString(),
activationDuration: config.account.activationDuration.toString(),
});
}
```
Public configs have `pool_creator_authority` set to the default pubkey. Private configs require the configured creator signer.
## Lock LP And Claim Fees
```typescript theme={"system"}
const pool = await AmmImpl.create(connection, poolAddress);
const lpAmount = new BN(100_000);
const lockTx = await pool.lockLiquidity(
user.publicKey,
lpAmount,
user.publicKey,
);
await sendAndConfirmTransaction(connection, lockTx, [user]);
const escrow = await pool.getUserLockEscrow(user.publicKey);
console.log(escrow?.fee.unClaimed);
if (escrow?.fee.unClaimed.lp?.gt(new BN(0))) {
const claimTx = await pool.claimLockFee2(
user.publicKey,
escrow.fee.unClaimed.lp,
user.publicKey,
user.publicKey,
);
await sendAndConfirmTransaction(connection, claimTx, [user]);
}
```
`claimLockFee2` is the newer claim helper. Use `claimLockFee` only when you need the older wrapped-SOL receiver behavior.
# DAMM v1 TS SDK Getting Started
Source: https://docs.meteora.ag/developer-guides/damm-v1/typescript-sdk/getting-started
Learn how to install and initialize @meteora-ag/dynamic-amm-sdk for DAMM v1 pool reads, quotes, swaps, liquidity, and locks.
The DAMM v1 TypeScript SDK is published as `@meteora-ag/dynamic-amm-sdk`. It wraps pool state reads, Dynamic Vault reads, quote math, transaction builders, pool creation helpers, config reads, and LP lock flows.
<CardGroup>
<Card title="DAMM v1 SDK Repository" icon="github" href="https://github.com/MeteoraAg/damm-v1-sdk">
Source for the TypeScript SDK, examples, Rust quote crate, Rust helpers, and CLI.
</Card>
<Card title="NPM Package" icon="npm" href="https://www.npmjs.com/package/@meteora-ag/dynamic-amm-sdk">
Published `@meteora-ag/dynamic-amm-sdk` package.
</Card>
</CardGroup>
## Installation
Install the SDK with Solana Web3. The package uses `bn.js` amounts for token units.
<Tabs>
<Tab title="npm">
```bash theme={"system"}
npm install @meteora-ag/dynamic-amm-sdk @solana/web3.js bn.js
```
</Tab>
<Tab title="pnpm">
```bash theme={"system"}
pnpm install @meteora-ag/dynamic-amm-sdk @solana/web3.js bn.js
```
</Tab>
<Tab title="yarn">
```bash theme={"system"}
yarn add @meteora-ag/dynamic-amm-sdk @solana/web3.js bn.js
```
</Tab>
</Tabs>
## Create A Pool Client
```typescript theme={"system"}
import AmmImpl from "@meteora-ag/dynamic-amm-sdk";
import { Connection, PublicKey } from "@solana/web3.js";
const connection = new Connection(process.env.RPC_URL!, "confirmed");
const poolAddress = new PublicKey("...");
const pool = await AmmImpl.create(connection, poolAddress, {
cluster: "mainnet-beta",
});
console.log({
lpMint: pool.getPoolTokenMint().toBase58(),
tokenA: pool.tokenAMint.address.toBase58(),
tokenB: pool.tokenBMint.address.toBase58(),
tokenAAmount: pool.poolInfo.tokenAAmount.toString(),
tokenBAmount: pool.poolInfo.tokenBAmount.toString(),
virtualPrice: pool.poolInfo.virtualPrice,
});
```
Use `cluster: "devnet"` when working against devnet. The DAMM v1 program ID is the same on mainnet and devnet:
```typescript theme={"system"}
// Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB
```
## Load Multiple Pools
`createMultiple` batches pool, vault, LP mint, token account, clock, and depeg account reads.
```typescript theme={"system"}
import AmmImpl from "@meteora-ag/dynamic-amm-sdk";
import { PublicKey } from "@solana/web3.js";
const pools = await AmmImpl.createMultiple(
connection,
[
new PublicKey("..."),
new PublicKey("..."),
],
{ cluster: "mainnet-beta" },
);
for (const pool of pools) {
console.log(pool.address.toBase58(), pool.poolInfo.virtualPrice);
}
```
## Transactions Are Unsigned
Most SDK methods return an unsigned `Transaction` or an array of unsigned transactions. Your wallet, backend signer, or transaction pipeline must sign and send them.
```typescript theme={"system"}
const tx = await pool.swap(
user.publicKey,
pool.tokenAMint.address,
inAmount,
quote.minSwapOutAmount,
);
tx.sign(user);
const signature = await connection.sendRawTransaction(tx.serialize());
await connection.confirmTransaction(signature, "confirmed");
```
## Development Commands
| Task | Command |
| - | - |
| Install dependencies | `cd damm-v1-sdk/ts-client && pnpm install` |
| Build SDK | `pnpm run build` |
| Run SDK tests | `pnpm test` |
| Run one example | `tsx src/examples/<file-name>.ts` |
Some examples in the repository expect a local keypair and hard-coded devnet or mainnet pool addresses. Replace RPC URLs, pool addresses, mint addresses, and signer loading before reusing them in an application.
## Next Steps
<CardGroup>
<Card title="Examples" icon="code" href="/developer-guides/damm-v1/typescript-sdk/examples">
Practical TypeScript patterns for pool reads, quotes, swaps, deposits, withdrawals, pool creation, and locks.
</Card>
<Card title="Reference" icon="book" href="/developer-guides/damm-v1/typescript-sdk/reference">
SDK exports, constants, public methods, helper functions, types, and integration notes.
</Card>
</CardGroup>
# DAMM v1 TS SDK Reference
Source: https://docs.meteora.ag/developer-guides/damm-v1/typescript-sdk/reference
Understand @meteora-ag/dynamic-amm-sdk exports, constants, AmmImpl methods, quote helpers, PDA helpers, pool creation helpers, lock helpers, and types.
This page is based on the public TypeScript source in `damm-v1-sdk/ts-client`. Use it as the high-level map for the SDK, then open the package types when you need exact parameter shapes.
```typescript theme={"system"}
import AmmImpl, {
PROGRAM_ID,
MAINNET_POOL,
DEVNET_POOL,
calculateSwapQuote,
derivePoolAddress,
type SwapQuote,
type DepositQuote,
type WithdrawQuote,
} from "@meteora-ag/dynamic-amm-sdk";
```
## Dependencies
| Package | Version in local SDK |
| - | - |
| `@coral-xyz/anchor` | `0.29.0` |
| `@solana/web3.js` | `1.98.0` |
| `@solana/spl-token` | `^0.4.6` |
| `@meteora-ag/vault-sdk` | `2.3.1` |
| `@meteora-ag/m3m3` | `1.0.10` |
| `bn.js` | `5.2.1` |
| `decimal.js` | `^10.4.1` |
## Program IDs
| Program | ID |
| - | - |
| DAMM v1 | `Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB` |
| DAMM v1 staging | `ammbh4CQztZ6txJ8AaQgPsWjd6o7GhmvopS2JAo5bCB` |
| Dynamic Vault | `24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi` |
| Metaplex metadata | `metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s` |
## Top-Level Exports
| Export | Use |
| - | - |
| `AmmImpl` | Main SDK class for pool loading, quotes, transactions, configs, and locks. |
| `ConstantProductSwap`, `StableSwap` | Local curve implementations used by quote helpers. |
| `DynamicAmmError` | SDK error decoder. |
| `AmmIdl`, `VaultIdl` | Bundled Anchor IDLs. |
| `PROGRAM_ID`, `MAINNET_POOL`, `DEVNET_POOL`, `CURVE_TYPE_ACCOUNTS` | Program constants, sample pool addresses, and depeg accounts. |
| `CONSTANT_PRODUCT_ALLOWED_TRADE_FEE_BPS`, `STABLE_SWAP_ALLOWED_TRADE_FEE_BPS` | Allowed fee tiers for permissionless pool creation. |
| `getDepegAccounts`, `getOnchainTime` | Account and clock helpers used by quotes. |
| `calculateMaxSwapOutAmount`, `calculateSwapQuote`, `calculatePoolInfo` | Quote and pool information helpers. |
| `checkPoolExists`, `getTokensMintFromPoolAddress`, `derivePoolAddress` | Pool lookup and derivation helpers. |
| Type exports | `AmmImplementation`, `DepositQuote`, `WithdrawQuote`, `SwapQuote`, `PoolState`, `LockEscrow`, `PoolInformation`, curve types, and `Bootstrapping`. |
Some PDA helpers are implemented in `src/amm/utils.ts` but are not top-level exports. Existing examples import them through package build paths.
## Important Constants
| Constant | Value |
| - | - |
| `PROGRAM_ID` | `Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB` |
| `DEVNET_POOL.USDT_USDC` | `BAHscmu1NncGS7t4rc5gSBPv1UFEMkvLaon1Ahdd5rHi` |
| `DEVNET_POOL.USDT_SOL` | `Bgf1Sy5kfeDgib4go4NgzHuZwek8wE8NZus56z6uizzi` |
| `DEVNET_POOL.SOL_MSOL` | `2rkn2yM4wJcHPV57T8fPWeBksrfSpiNZoEjRgjtxNDEQ` |
| `MAINNET_POOL.USDT_USDC` | `32D4zRxNc1EssbJieVHfPhZM3rH6CzfUPrWUuWxD9prG` |
| `MAINNET_POOL.USDC_SOL` | `5yuefgbJJpmFNK2iiYbLSpv1aZXq7F9AUKkZKErTYCvs` |
| `MAINNET_POOL.SOL_STSOL` | `7EJSgV2pthhDfb4UiER9vzTqe2eojei9GEQAQnkqJ96e` |
| `MAINNET_POOL.SOL_MSOL` | `HcjZvfeSNJbNkfLD4eEcRBr96AD3w1GpmMppaeRZf7ur` |
| `CURVE_TYPE_ACCOUNTS.marinade` | `8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC` |
| `CURVE_TYPE_ACCOUNTS.lido` | `49Yi1TKkNyYjPAFdR9LBvoHcUjuPX4Df5T5yv39w2XTn` |
| `CONSTANT_PRODUCT_ALLOWED_TRADE_FEE_BPS` | `[25, 100, 400, 600]` |
| `STABLE_SWAP_ALLOWED_TRADE_FEE_BPS` | `[1, 4, 10, 100]` |
| `PERMISSIONLESS_AMP` | `100` |
| `U64_MAX` | `18446744073709551615` |
## `AmmImpl` Static Methods
| Method | Returns | Use |
| - | - | - |
| `create(connection, pool, opt?)` | `Promise<AmmImpl>` | Load one pool, vault state, reserves, LP supply, clock, depeg accounts, and computed pool info. |
| `createMultiple(connection, poolList, opt?)` | `Promise<AmmImpl[]>` | Batch-load multiple pools and shared account data. |
| `createConfig(...)` | `Promise<Transaction>` | Build an admin `create_config` transaction for a new config PDA index. |
| `searchPoolsByToken(connection, tokenMint)` | Pool account list | Find pools where the mint is token A or token B. |
| `createPermissionlessPool(...)` | `Promise<Transaction>` | Create a permissionless pool with stable or constant-product curve and fee tier. |
| `createPermissionlessConstantProductPoolWithConfig(...)` | `Promise<Transaction[]>` | Create a config-based constant-product pool. Supports optional initial LP lock and initial B-to-A swap. |
| `createPermissionlessConstantProductPoolWithConfig2(...)` | `Promise<Transaction[]>` | Create a config-based pool with optional activation point and optional stake-for-fee lock split. |
| `createCustomizablePermissionlessConstantProductPool(...)` | `Promise<Transaction>` | Create a customizable constant-product launch pool. |
| `createPermissionlessConstantProductMemecoinPoolWithConfig(...)` | `Promise<Transaction[]>` | Create or mint a token, create a config-based pool, and optionally lock/stake/swap liquidity. |
| `getPoolConfigsWithPoolCreatorAuthority(connection, wallet, opt?)` | Config accounts | Fetch configs whose `pool_creator_authority` matches the wallet. |
| `getPoolConfig(connection, config, opt?)` | Config account | Fetch one config account. |
| `getFeeConfigurations(connection, opt?)` | Config summary list | Fetch all config accounts and derived fee bps. |
| `getLockedLpAmountByUser(connection, userPubKey, opt?)` | `Map<string, LockEscrowAccount>` | Fetch lock escrows for one owner, keyed by pool address. |
| `fetchMultipleUserBalance(connection, lpMintList, owner)` | `Promise<BN[]>` | Fetch a wallet's LP balances for multiple LP mints. |
## `AmmImpl` Instance Methods
| Method | Returns | Use |
| - | - | - |
| `updateState()` | `Promise<void>` | Refresh pool, vault, clock, depeg accounts, and computed pool info. |
| `getPoolTokenMint()` | `PublicKey` | Return the pool LP mint. |
| `getLpSupply()` | `Promise<BN>` | Fetch current LP token supply. |
| `getUserBalance(owner)` | `Promise<BN>` | Fetch the owner's LP token balance. |
| `getSwapQuote(inTokenMint, inAmountLamport, slippage, swapInitiator?)` | `SwapQuote` | Compute exact-in swap output, minimum output, fee, and price impact. |
| `getMaxSwapInAmount(tokenMint)` | `BN` | Estimate max source amount for a swap. |
| `getMaxSwapOutAmount(tokenMint)` | `BN` | Estimate max output amount for a token mint. |
| `swap(owner, inTokenMint, inAmountLamport, outAmountLamport, referralOwner?)` | `Promise<Transaction>` | Build an exact-in swap transaction. |
| `swapAndStakeForFee(owner, inTokenMint, inAmount, minOut, outAmount, stakeForFee)` | `Promise<Transaction[]>` | Build a swap followed by a Stake2Earn stake transaction. |
| `getDepositQuote(tokenAInAmount, tokenBInAmount, balance, slippage)` | `DepositQuote` | Quote a balanced or stable imbalanced deposit. |
| `deposit(owner, tokenAInAmount, tokenBInAmount, poolTokenAmount)` | `Promise<Transaction>` | Build a deposit transaction. |
| `getWithdrawQuote(lpTokenAmount, slippage, tokenMint?)` | `WithdrawQuote` | Quote balanced withdrawal or stable single-sided withdrawal. |
| `withdraw(owner, lpTokenAmount, tokenAOutAmount, tokenBOutAmount)` | `Promise<Transaction>` | Build a withdrawal transaction. |
| `getUserLockEscrow(owner)` | `Promise<LockEscrow \| null>` | Fetch a lock escrow and derive claimed/unclaimed fee data. |
| `getLockedLpAmount()` | `Promise<BN>` | Return pool-level locked LP amount from the pool and legacy LP ATA path. |
| `lockLiquidity(owner, amount, feePayer?, opt?)` | `Promise<Transaction>` | Lock LP tokens into a lock escrow, optionally splitting stake-for-fee liquidity. |
| `claimLockFee(owner, maxAmount, payer, receiver?, tempWSolAcc?)` | `Promise<Transaction>` | Build the older lock-fee claim transaction. |
| `claimLockFee2(owner, maxAmount, payer, receiver)` | `Promise<Transaction>` | Build the newer lock-fee claim transaction. |
| `moveLockedLP(owner, newOwner, maxAmount, payer?)` | `Promise<Transaction>` | Move locked LP between two owners' lock escrows. |
| `partnerClaimFees(partnerAddress, maxAmountA, maxAmountB)` | `Promise<Transaction>` | Claim partner fees for config-created pools. |
## Getters
| Getter | Type | Use |
| - | - | - |
| `decimals` | `number` | Max decimals between token A and token B. |
| `isStablePool` | `boolean` | Whether `poolState.curveType` is stable. |
| `isLST` | `boolean` | Whether the stable curve has a non-`none` depeg type. |
| `feeBps` | `BN` | Current trade fee converted to bps. |
| `depegToken` | `Mint \| null` | Heuristic depeg-side token mint for LST pools. |
## Quote Types
| Type | Fields |
| - | - |
| `SwapQuote` | `swapInAmount`, `swapOutAmount`, `minSwapOutAmount`, `fee`, `priceImpact`. |
| `DepositQuote` | `poolTokenAmountOut`, `minPoolTokenAmountOut`, `tokenAInAmount`, `tokenBInAmount`. |
| `WithdrawQuote` | `poolTokenAmountIn`, `minTokenAOutAmount`, `minTokenBOutAmount`, `tokenAOutAmount`, `tokenBOutAmount`. |
| `PoolInformation` | `tokenAAmount`, `tokenBAmount`, `virtualPrice`, `vi프로젝트로 돌아가기