> For the complete documentation index, see [llms.txt](https://docs.aftermath.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aftermath.finance/for-developers/typescript-sdk/products/pools.md). Agents can also search and read this documentation through its [MCP server](https://docs.aftermath.finance/~gitbook/mcp).

# Pools

AMM pools for both stable and uncorrelated assets of variable weights with up to 8 assets per pool.

A comprehensive system for managing liquidity pools, trades, and LP tokens in the Aftermath Finance protocol.

### Initialization

```typescript
const afSdk = await Aftermath.create({ network: "MAINNET" });

const pools = afSdk.Pools();
```

### Constants

```typescript
Pools.constants = {
	feePercentages: {
		totalProtocol: 0.00005, // 0.005%
		treasury: 0.5, // 50% of protocol fees
		insuranceFund: 0.3, // 30% of protocol fees
		devWallet: 0.2, // 20% of protocol fees
	},
	referralPercentages: {
		discount: 0.05, // 5% of treasury fees
		rebate: 0.05, // 5% of treasury fees
	},
	bounds: {
		maxCoinsInPool: 8,
		maxTradePercentageOfPoolBalance: 0.3, // 30%
		maxWithdrawPercentageOfPoolBalance: 0.3, // 30%
		minSwapFee: 0.0001, // 0.01%
		maxSwapFee: 0.1, // 10%
		minWeight: 0.01, // 1%
		maxWeight: 0.99, // 99%
		minDaoFee: 0, // 0%
		maxDaoFee: 1, // 100%
	},
	defaults: {
		lpCoinDecimals: 9,
	},
};
```

### Pool Management Methods

#### Getting Pool Information

```typescript
// Get a single pool
const pool = await pools.getPool({
	objectId: "0x...",
});

// Get multiple pools
const somePools = await pools.getPools({
	objectIds: ["0x...", "0x..."],
});

// Get all pools
const allPools = await pools.getAllPools();

// Get owned LP coins
const lpCoins = await pools.getOwnedLpCoins({
	walletAddress: "0x...",
});
```

#### Pool Creation and Publishing

Creating a pool takes two transactions. The first publishes an LP coin package templated with the pool's configuration and mints a `CreatePoolCapV2`. The second creates the pool with that LP coin and cap. Since SDK 5.1.0 the LP coin metadata goes in the publish step, and the create step no longer accepts `lpCoinMetadata` or `forceLpDecimals`. The SDK calls `POST /api/pools/v1/transactions/publish-lp-coin` and `POST /api/pools/v1/transactions/create-pool`.

```typescript
const coins = [
	{ coinType: "0x2::sui::SUI", weight: 0.5, decimals: 9 },
	{ coinType: "0x...::usdc::USDC", weight: 0.5, decimals: 6 },
];

// 1) Publish the LP coin. Sign and execute this before step 2.
const publishTx = await pools.getPublishLpCoinTransaction({
	walletAddress: "0x...",
	lpCoinMetadata: {
		name: "My Pool LP", // ASCII only
		symbol: "MY_POOL_LP", // Uppercase A-Z and underscore only
		iconUrl: "https://...", // Optional
		description: "...", // Optional
	},
	coinsInfo: coins, // Weights must sum to 1
	poolFlatness: 0, // 0 = uncorrelated, 1 = stable
	respectDecimals: true,
});

// From the publish transaction's created objects, take:
// - lpCoinType: the bare `0x<package>::af_lp::AF_LP` type
// - createPoolCapId: the object ID of the `CreatePoolCapV2`

// 2) Create the pool with the same configuration
const createPoolTx = await pools.getCreatePoolTransaction({
	walletAddress: "0x...",
	lpCoinType: "0x<package>::af_lp::AF_LP",
	createPoolCapId: "0x...",
	coinsInfo: [
		{ ...coins[0], tradeFeeIn: 0.003, initialDeposit: 1_000_000_000n },
		{ ...coins[1], tradeFeeIn: 0.003, initialDeposit: 1_000_000n },
	],
	poolName: "My Pool",
	poolFlatness: 0,
	respectDecimals: true,
	daoFeeInfo: { feePercentage: 0.01, feeRecipient: "0x..." }, // Optional
	burnLpCoin: false, // Optional
	isSponsoredTx: false, // Optional
});
```

{% hint style="warning" %}
Validate the LP coin symbol and name before publishing. A symbol with digits, spaces, or punctuation is accepted by the publish step but rejected by `create-pool` with HTTP 400, after the publish has already executed. `Pools.isValidLpCoinTypeSymbol` and `Pools.isValidLpCoinName` implement the current rules.

Pass the bare LP coin type as `lpCoinType`. Publishing creates `CoinMetadata<…::af_lp::AF_LP>` and `TreasuryCap<…::af_lp::AF_LP>` objects but no object of the coin type itself. Passing one of those wrapper types builds a transaction that aborts on chain.

If `create-pool` fails, keep the `lpCoinType` and `createPoolCapId` from step 1 and retry step 2. You do not need to publish again.
{% endhint %}

Verified against `aftermath-ts-sdk` 6.7.0 type declarations and the production OpenAPI specification on 2026-11-26. The `getCreatePoolTransaction` JSDoc example bundled with the SDK still passes `lpCoinMetadata`; follow the types.

#### Pool Information Queries

```typescript
// Get pool object ID from LP coin type
const poolId = await pools.getPoolObjectIdForLpCoinType({
	lpCoinType: "0x...",
});

// Check if coin type is LP token
const isLp = await pools.isLpCoinType({
	lpCoinType: "0x...",
});

// Get 24h volume
const volume = await pools.getTotalVolume24hrs();

// Get pool statistics
const stats = await pools.getPoolsStats({
	poolIds: ["0x..."],
});

// Get pool objects and statistics together
const summaries = await pools.getPoolSummaries({
	poolIds: ["0x..."],
});
// -> Array<{ pool, stats }>
```

Omit `poolIds` to fetch summaries for every pool. `getPoolSummaries` also accepts an optional final `AbortSignal`.

### Pool Class Methods

The Pool class provides methods for interacting with individual pools.

#### Trading and Liquidity Operations

```typescript
const pool = new Pool(poolObject);

// Trade
const tradeTx = await pool.getTradeTransaction({
	walletAddress: "0x...",
	coinInType: "0x...",
	coinInAmount: BigInt("1000000"),
	coinOutType: "0x...",
	slippage: 0.01,
});

// Deposit
const depositTx = await pool.getDepositTransaction({
	walletAddress: "0x...",
	amountsIn: {
		"0x...": BigInt("1000000"),
	},
	slippage: 0.01,
});

// Withdraw
const withdrawTx = await pool.getWithdrawTransaction({
	walletAddress: "0x...",
	amountsOutDirection: {
		"0x...": BigInt("1000000"),
	},
	lpCoinAmount: BigInt("1000000"),
	slippage: 0.01,
});

// Multi-coin withdraw
const multiWithdrawTx = await pool.getAllCoinWithdrawTransaction({
	walletAddress: "0x...",
	lpCoinAmount: BigInt("1000000"),
});
```

#### Price and Amount Calculations

```typescript
// Get spot price
const spotPrice = pool.getSpotPrice({
	coinInType: "0x...",
	coinOutType: "0x...",
	withFees: true,
});

// Calculate trade output amount
const amountOut = pool.getTradeAmountOut({
	coinInType: "0x...",
	coinInAmount: BigInt("1000000"),
	coinOutType: "0x...",
	referral: false,
});

// Calculate trade input amount
const amountIn = pool.getTradeAmountIn({
	coinInType: "0x...",
	coinOutAmount: BigInt("1000000"),
	coinOutType: "0x...",
	referral: false,
});

// Calculate LP tokens for deposit
const lpInfo = pool.getDepositLpAmountOut({
	amountsIn: {
		"0x...": BigInt("1000000"),
	},
	referral: false,
});
```

#### Pool Analytics

```typescript
// Get pool statistics
const stats = await pool.getStats();

// Get volume data
const volumeData = await pool.getVolumeData({
	timeframe: "1D", // "1D" | "1W" | "1M" | "3M" | "6M" | "1Y"
});

// Get fee data
const feeData = await pool.getFeeData({
	timeframe: "1D",
});

// Get 24h volume
const volume24h = await pool.getVolume24hrs();
```

### Types

#### Pool Types

```typescript
interface PoolObject {
	name: string;
	creator: string;
	lpCoinType: string;
	lpCoinSupply: bigint;
	illiquidLpCoinSupply: bigint;
	flatness: bigint;
	coins: Record<string, PoolCoin>;
	lpCoinDecimals: number;
	daoFeePoolObject?: DaoFeePoolObject;
}

interface PoolCoin {
	weight: bigint;
	balance: bigint;
	tradeFeeIn: bigint;
	tradeFeeOut: bigint;
	depositFee: bigint;
	withdrawFee: bigint;
	decimalsScalar: bigint;
	normalizedBalance: bigint;
	decimals?: number;
}

interface PoolStats {
	volume: number;
	tvl: number;
	supplyPerLps: number[];
	lpPrice: number;
	fees: number;
	apr: number;
}
```

### Example Usage

```typescript
const afSdk = await Aftermath.create({ network: "MAINNET" });
const pools = afSdk.Pools();

// Get a pool
const pool = await pools.getPool({
	objectId: "0x...",
});

// Calculate trade output
const amountOut = pool.getTradeAmountOut({
	coinInType: "0x2::sui::SUI",
	coinOutType:
		"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
	coinInAmount: BigInt("1000000000"),
	referral: true,
});

// Execute trade
const tradeTx = await pool.getTradeTransaction({
	walletAddress: "0x...",
	coinInType: "0x2::sui::SUI",
	coinInAmount: BigInt("1000000000"),
	coinOutType:
		"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
	slippage: 0.01,
});
```
