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

# Amounts & slippage

> bigint units, token decimals, basis points, and how each pool type applies slippage.

export const VersionBanner = ({network = 'mainnet', products = [], lang = 'en'}) => {
  const SDK_VERSION = '1.0.2';
  const ADDRESSES = {
    mainnet: {
      cpmm: {
        Router: 'ze15rnAwTyVCPnDhN7J8An3SvNeWBsZHAVMeBx1ehXeP',
        TokenPairFactory: '24CXRLvj1QiDH6riwr1EPERG7BcduHKZtktygbq97MfYb'
      },
      clmm: {
        PoolFactory: '24gqd4DMQXVzjm5QDAGxUtYupx3WM2PSu3vZUseuBCV9h',
        PositionManager: 'vFyKSqnJHS9MicrojBcLgztyRFqhS4hB349Ci3LJCELw'
      },
      staking: {
        XAlphToken: '225WevmFp5ZgzPsyVJTvyp2v2uyKrvp329HfrVmzffnWj',
        RewardFeeCollector: '22CE7vG6u64zjjsLZLxeJqQuPDydjPvbP9iG1d861j2G7'
      }
    },
    testnet: {
      cpmm: {
        Router: 'xaueT8kPMvpnaFJEfHv6CJLgqsSPpoNmHjF1QgTxoF9R',
        TokenPairFactory: '29hdd9b9Gp7oXuamwHKfUqBaRXP487HoeTcutS3RhZJEj'
      },
      clmm: {
        PoolFactory: 'z2QFT7qBQrfm8UwAYG3VHWoHs7B56ZDFNdSCcDu5j53m',
        PositionManager: '21p6egW8d6FEyVVuH17WqvHCARsCsD61GcBmeCr75XdGT'
      },
      staking: {
        XAlphToken: '23psDicimC5VdpM56wrgqgCzQzcyXWGCkQGSYWbtZAPRq',
        RewardFeeCollector: '29qQ1LPJ5uqawRviXLVDMeo19JUygRrNNTQy5RUBh817D'
      }
    }
  };
  const EXPLORERS = {
    mainnet: 'https://explorer.alephium.org/addresses/',
    testnet: 'https://testnet.alephium.org/addresses/'
  };
  const LABELS = {
    en: {
      sdk: 'SDK',
      network: 'Network',
      contracts: 'Contracts',
      all: 'All addresses',
      allNetworks: 'mainnet · testnet · devnet',
      devnet: 'Local deployment (addresses vary per devnet)'
    },
    zh: {
      sdk: 'SDK 版本',
      network: '网络',
      contracts: '合约',
      all: '全部地址',
      allNetworks: 'mainnet · testnet · devnet',
      devnet: '本地部署（每个 devnet 的地址不同）'
    },
    fr: {
      sdk: 'SDK',
      network: 'Réseau',
      contracts: 'Contrats',
      all: 'Toutes les adresses',
      allNetworks: 'mainnet · testnet · devnet',
      devnet: 'Déploiement local (adresses propres à chaque devnet)'
    }
  };
  const t = LABELS[lang] ?? LABELS.en;
  const contractsPage = lang === 'en' ? '/reference/contracts' : `/${lang}/reference/contracts`;
  const short = a => `${a.slice(0, 6)}…${a.slice(-4)}`;
  const entries = [];
  const addrs = ADDRESSES[network];
  if (addrs) {
    for (const p of products) {
      for (const [name, address] of Object.entries(addrs[p] ?? ({}))) entries.push({
        name,
        address
      });
    }
  }
  let contractsCell;
  if (network === 'devnet' && products.length > 0) {
    contractsCell = <span>{t.devnet}</span>;
  } else if (entries.length > 0) {
    contractsCell = entries.map(({name, address}, i) => <span key={name}>
        {i > 0 && <span className="mx-1 opacity-50">·</span>}
        {name}{' '}
        <a href={EXPLORERS[network] + address} target="_blank" rel="noreferrer" title={address}>
          <code>{short(address)}</code>
        </a>
      </span>);
  }
  const row = (label, value) => <div className="flex flex-wrap gap-x-2">
      <span className="font-semibold min-w-[5.5rem]">{label}</span>
      <span className="flex-1 min-w-0 break-words">{value}</span>
    </div>;
  return <div className="not-prose mb-6 rounded-xl border border-zinc-950/10 dark:border-white/10 bg-zinc-50 dark:bg-white/5 px-4 py-3 text-sm leading-6 text-zinc-700 dark:text-zinc-300">
      {row(t.sdk, <code>@alephium/powfi-sdk@{SDK_VERSION}</code>)}
      {row(t.network, network === 'all' ? t.allNetworks : network)}
      {contractsCell && row(t.contracts, <span>
            {contractsCell}
            <span className="mx-1 opacity-50">·</span>
            <a href={contractsPage}>{t.all} →</a>
          </span>)}
    </div>;
};

<VersionBanner network="mainnet" products={['cpmm', 'clmm']} lang="en" />

## Amounts are raw bigints

Every amount the SDK accepts or returns is a `bigint` in the token's **smallest unit**, exactly as stored on-chain:

| Token | Decimals | `1.5` tokens as bigint |
| - | - | - |
| ALPH | 18 | `1_500_000_000_000_000_000n` |
| A 6-decimal stablecoin | 6 | `1_500_000n` |

Get decimals from the token list (`(await powfi.token.getTokenById(id)).decimals`) or from pool state (`state.token0Info.decimals`).

Convert with [`NumericUtils`](/utilities/math#numericutils):

```ts theme={null}
import { NumericUtils } from '@alephium/powfi-sdk'
import Decimal from 'decimal.js'

// human -> raw
const raw = NumericUtils.numericToBigInt(new Decimal('1.5').mul(new Decimal(10).pow(18)))

// raw -> human
NumericUtils.scaleToString(1_500_000_000_000_000_000n, 18) // "1.5"
```

`@alephium/web3` also exports `convertAmountWithDecimals` and `prettifyTokenAmount` for the same job.

<Warning>
  Never pass JavaScript `number` values for amounts. 18-decimal amounts overflow `Number.MAX_SAFE_INTEGER` almost immediately, and the SDK types require `bigint`.
</Warning>

## Basis points

Slippage is expressed in **basis points** (`bps`) as a `bigint`, with `BPS = 10_000n`:

| `slippageBps` | Tolerance |
| - | - |
| `10n` | 0.1% |
| `50n` | 0.5% |
| `100n` | 1% |
| `500n` | 5% |

Valid values satisfy `0n <= slippage < 10_000n`. Anything else throws.

## CPMM: slippage on amounts

CPMM quotes apply slippage to the **amount** you are not fixing:

```ts theme={null}
// exact-in: minimum you accept to receive
CpmmModule.minimalAmount(amount, slippageBps) // = amount * 10000 / (10000 + slippageBps)

// exact-out: maximum you accept to pay (rounded up)
CpmmModule.maximalAmount(amount, slippageBps) // = ceil(amount * (10000 + slippageBps) / 10000)
```

`computeSwapAmount` fills `minimalTokenOutAmount` (exact-in) or `maximalTokenInAmount` (exact-out). The other field is `undefined`.

<Note>
  `minimalAmount` divides by `(1 + s)` rather than multiplying by `(1 − s)`. For 0.5% this gives 99.5025% instead of 99.5%: slightly stricter, and it keeps `minimalAmount` and `maximalAmount` exact inverses.
</Note>

For add-liquidity on an existing pool, both desired amounts get `minimalAmount` applied. On the **first** deposit into an empty pool no slippage is applied, because the depositor sets the price.

## CLMM: slippage on price

CLMM operations turn slippage into a **square-root price limit**. The swap stops (or the add-liquidity reverts) if the pool price would move past it:

```ts theme={null}
TickUtils.getSqrtPriceX96Bounds(sqrtPriceX96, slippageBps)
// => [ sqrtPriceX96 * sqrt(1 - s), sqrtPriceX96 * sqrt(1 + s) ]

TickUtils.getSqrtPriceLimitX96(sqrtPriceX96, slippageBps, zeroForOne)
// zeroForOne (price goes down) -> lower bound; otherwise -> upper bound
// always strictly beyond the current price and inside [MIN_SQRT_RATIO, MAX_SQRT_RATIO]
```

So a 1% slippage on a CLMM swap means "the pool price may move by up to 1%". For a large trade in a thin range, that can still translate to a big difference in output amount. Always check the simulated output against your own minimum.

## Price impact

`CpmmSwapQuote.priceImpact` is a **percentage** number (for example `0.42` means 0.42%), computed from the reserves before and after the trade. `cpmm.swap` refuses trades with `priceImpact >= 5` (`MAX_PRICE_IMPACT`).

## Fees

| Pool | Swap fee | Unit |
| - | - | - |
| CPMM | 0.3% (`997 / 1000`) | fixed |
| CLMM | per fee tier: `tradingFee` in the pool config | pips, where `MAX_PIPS = 1_000_000n` (so `3000n` = 0.3%) |

## Deadlines

CPMM write methods accept `ttlMinutes` (default `60`). The SDK converts it to a millisecond timestamp (`Date.now() + ttl`), and the router rejects the transaction after that time.

## ALPH deposits and dust

Alephium outputs that carry tokens must hold a minimum amount of ALPH (`DUST_AMOUNT`), and new contracts need `MINIMAL_CONTRACT_DEPOSIT`. The SDK attaches the right amount of ALPH automatically. For example, a CPMM swap attaches 2–3× `DUST_AMOUNT` on top of the input, and creating a CPMM pool attaches 1 ALPH as the contract deposit. Budget a little extra ALPH in the sender's balance for this and for gas.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.