> ## 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.

# Types

> Request, response, and config types exported by @alephium/powfi-sdk.

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={[]} lang="en" />

All types are exported from the package root.

## Common

```ts theme={null}
interface PowfiLoadParams {
  networkId: NetworkId // 'mainnet' | 'testnet' | 'devnet'
  signer?: SignerProvider
  networkOverrides?: NetworkOverrides
}

type NetworkOverrides = Partial<Omit<Network, 'id'>>

interface Network {
  id: NetworkId
  name: string
  nodeUrl: string
  nodeApiKey?: string
  explorerApiUrl: string
  explorerUrl: string
  tokenListUrl: string
}

type NumericLike = Decimal | bigint | number | string | undefined | null
type Rounding = 'floor' | 'ceil'
```

## CPMM

```ts theme={null}
type CpmmTokenId = string
type CpmmSlippageBps = bigint
type CpmmInputType = 'TokenA' | 'TokenB'

interface CpmmConfig {
  groupIndex: number
  factoryId: string
  routerId: string
  accountRoot?: string
  feeCollectorFactoryId?: string
}

interface CpmmPoolContractState {
  poolId: string
  reserve0: bigint
  reserve1: bigint
  token0Info: TokenInfo
  token1Info: TokenInfo
  totalSupply: bigint
  dexRoot: string
}

interface CpmmSwapRequest {
  tokenInId: string
  tokenOutId: string
  amountIn?: bigint
  amountOut?: bigint
  slippageBps: bigint
  sender: string
  ttlMinutes?: number // default 60
  fee?: bigint
  feeRecipient?: string
}

interface CpmmSwapQuoteParams {
  state: CpmmPoolContractState
  tokenInId: string
  tokenOutId: string
  amountIn?: bigint
  amountOut?: bigint
  slippageBps: bigint
}

interface CpmmSwapQuote {
  swapType: 'ExactIn' | 'ExactOut'
  state: CpmmPoolContractState
  tokenInInfo: TokenInfo
  tokenOutInfo: TokenInfo
  tokenInAmount: bigint
  maximalTokenInAmount: bigint | undefined
  tokenOutAmount: bigint
  minimalTokenOutAmount: bigint | undefined
  priceImpact: number // percent
}

interface CpmmAddLiquidityRequest {
  poolState: CpmmPoolContractState
  tokenAId: string
  tokenBId: string
  amountA: bigint
  amountB: bigint
  slippageBps: bigint
  sender: string
  ttlMinutes?: number
}

interface CpmmAddLiquidityQuoteParams {
  poolState?: CpmmPoolContractState // omit for a new pool
  tokenAId: string
  tokenBId: string
  amountA?: bigint
  amountB?: bigint
  inputType?: 'TokenA' | 'TokenB' // default 'TokenA'
}

interface CpmmAddLiquidityQuote {
  state?: CpmmPoolContractState
  tokenAId: string
  tokenBId: string
  amountA: bigint
  amountB: bigint
  shareAmount: bigint     // LP tokens minted
  sharePercentage: number // percent of pool after deposit
}

interface CpmmRemoveLiquidityRequest {
  poolState: CpmmPoolContractState
  liquidity: bigint
  totalLiquidityAmount?: bigint
  slippageBps: bigint
  sender: string
  ttlMinutes?: number
}

interface CpmmRemoveLiquidityQuote {
  state: CpmmPoolContractState
  token0: TokenInfo
  amount0: bigint
  token1: TokenInfo
  amount1: bigint
  remainShareAmount: bigint
  remainSharePercentage: number
}

interface CpmmClaimableAmounts {
  token0: TokenInfo
  amount0: bigint
  token1: TokenInfo
  amount1: bigint
}

interface CpmmCreatePoolRequest {
  tokenAId: string
  tokenBId: string
  sender: string
  initialLiquidity?: { tokenAAmount: bigint; tokenBAmount: bigint }
}

```

## CLMM

```ts theme={null}
interface ClmmConfig {
  groupIndex: number
  factoryId: string
  positionManagerId: string
  defaultConfigIndex: bigint
  accountRoot: string
}

interface ClmmPoolConfig {
  configIndex: bigint
  tickSpacing: bigint
  tradingFee: bigint  // pips
  protocolFee: bigint
}

interface ClmmPoolContractState extends ClmmPoolConfig {
  poolId: string
  token0Info: TokenInfo
  token1Info: TokenInfo
  liquidity: bigint
  sqrtPriceX96: bigint
  tick: bigint
}

interface ClmmSimulateSwapParams {
  configIndex: bigint
  token0: string
  token1: string
  zeroForOne: boolean
  amount: bigint // > 0 exact-in, < 0 exact-out
  data?: string
  interestedContracts?: string[]
}

interface LiquidityForPrice { liquidity: bigint; sqrtPriceX96: bigint }

interface ClmmSimulateSwapQuote {
  baseSqrtPriceX96: bigint
  sqrtPriceX96: bigint
  liquidity: bigint
  fee: bigint
  rows: LiquidityForPrice[]
}

interface ClmmSwapRequest {
  token0: string       // input token
  token1: string       // output token
  amount: bigint       // > 0 exact-in, < 0 exact-out
  amountIn: bigint     // input token amount to attach
  slippage: bigint     // bps
  routePlan: bigint[]  // [configIndex]
  fee?: bigint
  feeRecipient?: string
}

interface ClmmSwapToRequest {
  tokenIn: string
  tokenOut: string
  configIndex: bigint
  targetSqrtPriceX96: bigint
  amountInMax: bigint
}

interface ClmmAddLiquidityRequest {
  token0: string
  token1: string
  configIndex: bigint
  owner?: string
  tickLower: bigint
  tickUpper: bigint
  slippage: bigint
  amount0: bigint
  amount1: bigint
  existingPosition?: boolean
}

interface ClmmRemoveLiquidityRequest {
  token0: string
  token1: string
  configIndex: bigint
  owner: string
  tickLower: bigint
  tickUpper: bigint
  liquidity: bigint
  base: 'token0' | 'token1'
  baseAmount: bigint     // min amount of `base`
  otherAmountMax: bigint // min amount of the other token
}

interface ClmmCollectTokensRequest {
  token0: string
  token1: string
  configIndex: bigint
  owner: string
  recipient: string
  tickLower: bigint
  tickUpper: bigint
  amount0Max: bigint
  amount1Max: bigint
}

interface ClmmPositionInfoRequest {
  poolId: string
  owner: string
  tickLower: bigint
  tickUpper: bigint
  acc: bigint
  iacc0: bigint
  iacc1: bigint
  t0: bigint
  acct0: bigint
}

type ClmmPositionInfo = {
  amount0: bigint
  amount1: bigint
  fees: [bigint, bigint, bigint]
  avgValue: bigint
  avgFees: bigint
  avgTime: bigint
}

interface ClmmRewardInfo { amount: bigint; openTime: bigint; endTime: bigint }
interface ClmmPoolRewardState { token2Info?: TokenInfo; rewardInfos: ClmmRewardInfo[] }

interface GetPositionAmountsFromPriceProps {
  sqrtRatioX96: bigint
  tokenBaseId: string
  tokenQuoteId: string
  lowerTick: bigint
  upperTick: bigint
  amountBase: bigint
  amountQuote: bigint
}

interface GetPositionAmountsFromPriceReturn {
  newAmountBase: bigint
  newAmountQuote: bigint
  liquidity: bigint
}
```

## Staking

```ts theme={null}
interface StakingConfig {
  groupIndex: number
  alphUnstakeVaultTemplateId: string
  xAlphTokenId: string
  xAlphTokenAddress: string
  feeCollectorId: string
}

type StakingSettings = {
  unstakeDuration: bigint // ms
  maxActiveUnstakeRequestsPerUser: bigint
  maxConnectedDapps: bigint // max dApps one staker's xALPH can be connected to
}
```

## Contract types

Each Powfi contract comes with a generated TypeScript namespace describing its on-chain data. The SDK re-exports these from the package root, so you can annotate your own code without importing from internal paths. They are **types only**: they don't call contracts or send transactions.

| Type | Contract |
| - | - |
| `CpmmTokenPairTypes` | CPMM `TokenPair` |
| `CpmmTokenPairFactoryTypes` | CPMM `TokenPairFactory` |
| `ClmmPoolTypes` | CLMM `Pool` |
| `ClmmPoolFactoryTypes` | CLMM `PoolFactory` |
| `ClmmPositionManagerTypes` | CLMM `PositionManager` |
| `XAlphTokenTypes` | Staking `XAlphToken` |

Each namespace contains:

| Member | Describes |
| - | - |
| `Fields` / `State` | Contract storage fields, and the full state returned by `fetchState()` |
| `<Name>Event` | Events the contract emits, e.g. `XAlphTokenTypes.StakedEvent` |
| `CallMethodParams<'m'>` / `CallMethodResult<'m'>` | Arguments and return value of read-only method `m` |
| `SignExecuteMethodParams<'m'>` / `SignExecuteMethodResult<'m'>` | Arguments and result of transaction method `m` |

```ts theme={null}
import type { XAlphTokenTypes } from '@alephium/powfi-sdk'

// Typed contract state
const state: XAlphTokenTypes.State = await powfi.staking.getXAlphTokenState()
state.fields.totalDepositedAlph
state.fields.totalXAlphSupply

// Typed event handler
function onStaked(event: XAlphTokenTypes.StakedEvent) {
  const { to, alphAmount, xAlphAmount } = event.fields
}

// Return type of powfi.staking.stakeAlph()
type StakeResult = XAlphTokenTypes.SignExecuteMethodResult<'stake'>
```

You only need these when passing SDK results into your own functions or storing them. Calling `powfi.*` methods directly needs no annotations: TypeScript infers the types.


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