> ## Documentation Index
> Fetch the complete documentation index at: https://docs.picon.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Pools and swaps

> Quoting, fee rates, transfer fees, and syncing the active bin

## Fetching a pool

```ts theme={null}
const pool = await dlmmProgram.getPool(poolAddress);
```

Caches the pool's account data, mints, and token programs in one call. Refresh it after a
change you expect to have landed on-chain (e.g. before building a deposit against a possibly
stale `activeBinId`):

```ts theme={null}
await pool.refresh();
```

## Swapping and quoting

`swapExactIn`/`swapExactOut`/`quoteExactIn`/`quoteExactOut`/`sync` never take a bin-array-count
parameter. The quote methods always quote against the protocol's max traversal window (6 bin
arrays) internally; the matching swap method then trims the bin-array set down to only what the
quote says it actually needs, plus a one-array drift margin — so you never pay for more
accounts than the trade is likely to touch.

```ts theme={null}
// quoteExactIn() is a thin wrapper — same internal fetch/simulate/trim as swapExactIn(), just
// returns the quote without building instructions.
const quoteOutput = await pool.quoteExactIn({ xToY: true, amountIn: 1_000_000n, slippageToleranceBps: 50 });

const { quoteOutput: sameQuote, instructions } = await pool.swapExactIn(userSigner, {
  xToY: true,
  amountIn: 1_000_000n,
  slippageToleranceBps: 50,
});

// swapExactOut()/quoteExactOut() fix the output amount instead — the trader specifies exactly
// what they want to receive, and pays whatever gross input that requires (capped by
// slippageToleranceBps via maxAmountIn on the quote output).
const { quoteOutput: exactOutQuote, instructions: exactOutInstructions } = await pool.swapExactOut(userSigner, {
  xToY: true,
  amountOut: 1_000_000n,
  slippageToleranceBps: 50,
});
```

`Pool.sync(user, desiredBinId)` repositions the pool's active bin toward `desiredBinId` across
empty bins only — also always uses the max traversal window, no count parameter:

```ts theme={null}
// Useful before quoting/depositing against a pool whose active bin may have drifted across
// empty bins since it was last touched — sync moves the pointer without needing a real trade.
const syncIxs = await pool.sync(userSigner, targetBinId);
```

<Tip>
  The quote engine internally replicates the exact same dynamic-fee decay/accumulate state
  machine the on-chain program runs, bin by bin — see [Fees](/concepts/fees). This is why
  `quoteExactIn`/`quoteExactOut` need `pool.activeBinId` and the pool's live dynamic-fee state,
  not just a static fee rate.
</Tip>

## Handling quote failures

`quoteExactIn`/`quoteExactOut`/`swapExactIn`/`swapExactOut` reject with a real thrown `Error`
when the underlying quote can't be filled — catch it rather than assuming a quote always
succeeds for a nonzero amount:

```ts theme={null}
try {
  const quoteOutput = await pool.quoteExactIn({ xToY: true, amountIn, slippageToleranceBps: 50 });
} catch (error) {
  // error.message is one of exactly three strings:
  //   "Insufficient liquidity for swap" — the trade needs more bin-array coverage than the
  //     protocol's max traversal window (6 arrays) can supply; it must be split across
  //     multiple transactions, it isn't retriable as one swap.
  //   "Swap amount is zero" — after netting out an input-side Token-2022 transfer fee, nothing
  //     was left to swap.
  //   "Arithmetic overflow" — only reachable at extreme, effectively unreachable input sizes.
}
```

## Fee rates

```ts theme={null}
const { baseFeeRate, dynamicFeeRate, totalFeeRate } = await pool.getFeeRates();
```

Returns the base/dynamic/total fee rate the pool would charge for a swap *right now* — it
decays the dynamic fee state first, the same "clock sim" the on-chain program runs immediately
before pricing a real swap, so this reflects what a swap would actually pay rather than a raw,
potentially stale, stored volatility accumulator.

## Transfer fees

```ts theme={null}
const { transferFeeX, transferFeeY } = await pool.getTransferFees();
```

Resolves each mint's active Token-2022 transfer-fee config from cached mint data.
`undefined` per side means that mint has no `TransferFeeConfig` extension at all — not that the
fee is zero.

## Transfer hooks

If either mint carries an active Token-2022 `TransferHook`, `swapExactIn()`/`swapExactOut()`
(and every position method) resolve and append its extra accounts automatically — nothing to
configure. `Pool.resolveTransferHookAccountsX(transferAccounts)`/`resolveTransferHookAccountsY(transferAccounts)`
are exposed publicly if you need to resolve them yourself for a custom instruction outside the
SDK's own builders.
