Common
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
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
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
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 |
| 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 |
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'>
powfi.* methods directly needs no annotations: TypeScript infers the types.