/** Account derived from a local private key (mnemonic or raw key). */ type LocalAccount = { type: "local" address: string /** Compressed public key (hex) */ publicKey: string /** Raw ECDSA sign over a hash */ sign(hash: Uint8Array): Uint8Array /** Sign a raw UTF-8 / byte message (`sha256(bytes)`). Not SIP-018. */ signMessage(message: string | Uint8Array): string }; /** Account with a user-provided signing function (sync or async). */ type CustomAccount = { type: "custom" address: string publicKey: string sign(hash: Uint8Array): Promise | Uint8Array }; /** Browser wallet provider interface (e.g. Leather, Xverse). */ type StacksProvider = { request(method: string, params?: any): Promise }; /** Account backed by a browser wallet {@link StacksProvider}. */ type ProviderAccount = { type: "provider" address: string publicKey: string provider: StacksProvider }; /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */ type NonceManager = { consume(params: { client: Client address: string }): Promise reset(params: { client: Client address: string }): void | Promise /** * Give back a nonce from {@link NonceManager.consume} whose transaction * was never accepted by the node. No-op unless it is the latest issued. */ release(params: { client: Client address: string nonce: bigint }): void | Promise /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */ peek(params: { client: Client address: string }): Promise }; /** Full chain descriptor used by clients and transports for network-aware operations. */ type StacksChain = { /** Chain ID (e.g. 0x00000001 for mainnet) */ id: number /** Human-readable name */ name: string /** Network type */ network: "mainnet" | "testnet" /** Transaction version byte for serialization */ transactionVersion: number /** Peer network ID for P2P broadcasting */ peerNetworkId: number /** Address version bytes */ addressVersion: { singleSig: number multiSig: number } /** Magic bytes for network identification */ magicBytes: string /** Boot address (system contracts deployer) */ bootAddress: string /** Native currency info */ nativeCurrency: { name: string symbol: string decimals: number } /** Default RPC URLs */ rpcUrls: { default: { http: string[] ws?: string[] } } /** Block explorer URLs */ blockExplorers?: { default: { name: string url: string } } }; /** Function that sends an HTTP request to a Stacks node API path. */ type RequestFn = (path: string, options?: RequestOptions) => Promise; /** Options for a transport-level HTTP request. */ type RequestOptions = { method?: "GET" | "POST" | "PUT" | "DELETE" body?: unknown headers?: Record /** * Cancel the request from the caller's side. An aborted signal rejects * with the signal's reason immediately and never retries; it is combined * with the transport's own per-attempt timeout. */ signal?: AbortSignal /** * Override the transport's retry budget for this one request. Broadcasts * pass `0`: re-sending a transaction the node may already hold trades a * transient failure for a confusing nonce conflict. */ retryCount?: number }; /** Shared configuration for all transport types. */ type TransportConfig = { url?: string /** * Per-attempt deadline in ms covering headers AND body. A stalled body * rejects with `TimeoutError` instead of hanging. Default 30_000. */ timeout?: number retryCount?: number retryDelay?: number fetchOptions?: RequestInit /** Sent as `x-api-key`. Held in the request closure and stripped from * `Transport.config` so it never prints with the client. */ apiKey?: string }; /** A resolved transport instance with a bound request function. */ type Transport = { type: string request: RequestFn config: TransportConfig destroy?: () => void }; /** Union of all supported account types (local key, custom signer, or browser provider). */ type Account = LocalAccount | CustomAccount | ProviderAccount; /** * Core client instance that holds chain context, transport, and extensible actions. * Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}. */ type Client = Record> = { chain?: StacksChain account?: Account transport: Transport request: RequestFn /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */ nonceManager?: NonceManager extend: >(fn: (client: Client) => TNew) => Client & TNew } & TExtended; /** Bitcoin address in Clarity tuple format for PoX */ interface PoxAddress { version: Uint8Array; hashbytes: Uint8Array; } /** User-facing params for stack-stx */ interface StackStxParams { amount: bigint; btcAddress: string; lockPeriod: number; signerSig: Uint8Array | null; signerKey: Uint8Array; maxAmount: bigint; authId: bigint; startBurnHeight: bigint; } /** User-facing params for delegate-stx */ interface DelegateStxParams { amount: bigint; delegateTo: string; untilBurnHeight?: bigint | null; poxAddr?: string | null; } /** User-facing params for stack-extend */ interface StackExtendParams { extendCount: number; btcAddress: string; signerSig: Uint8Array | null; signerKey: Uint8Array; maxAmount: bigint; authId: bigint; } /** User-facing params for stack-increase */ interface StackIncreaseParams { increaseBy: bigint; signerSig: Uint8Array | null; signerKey: Uint8Array; maxAmount: bigint; authId: bigint; } /** PoX network info from get-pox-info */ interface PoxInfo { rewardCycleId: bigint; minAmountUstx: bigint; prepareCycleLength: bigint; rewardCycleLength: bigint; firstBurnchainBlockHeight: bigint; totalLiquidSupplyUstx: bigint; } /** Stacker info from get-stacker-info */ interface StackerInfo { firstRewardCycle: bigint; lockPeriod: bigint; poxAddr: PoxAddress; rewardSetIndexes: bigint[]; delegatedTo: string | null; } /** Delegation info from get-delegation-info */ interface DelegationInfo { amountUstx: bigint; delegatedTo: string; untilBurnHt: bigint | null; poxAddr: PoxAddress | null; } declare const POX_ABI: { readonly functions: readonly [{ readonly name: "get-pox-info" readonly access: "read-only" readonly args: readonly [] readonly outputs: { readonly response: { readonly ok: { readonly tuple: readonly [{ readonly name: "reward-cycle-id" readonly type: "uint128" }, { readonly name: "min-amount-ustx" readonly type: "uint128" }, { readonly name: "prepare-cycle-length" readonly type: "uint128" }, { readonly name: "first-burnchain-block-height" readonly type: "uint128" }, { readonly name: "reward-cycle-length" readonly type: "uint128" }, { readonly name: "total-liquid-supply-ustx" readonly type: "uint128" }] } readonly error: "none" } } }, { readonly name: "get-stacker-info" readonly access: "read-only" readonly args: readonly [{ readonly name: "stacker" readonly type: "principal" }] readonly outputs: { readonly optional: { readonly tuple: readonly [{ readonly name: "pox-addr" readonly type: { readonly tuple: readonly [{ readonly name: "version" readonly type: { readonly buff: { readonly length: 1 } } }, { readonly name: "hashbytes" readonly type: { readonly buff: { readonly length: 32 } } }] } }, { readonly name: "lock-period" readonly type: "uint128" }, { readonly name: "first-reward-cycle" readonly type: "uint128" }, { readonly name: "reward-set-indexes" readonly type: { readonly list: { readonly type: "uint128" readonly length: 12 } } }, { readonly name: "delegated-to" readonly type: { readonly optional: "principal" } }] } } }, { readonly name: "get-delegation-info" readonly access: "read-only" readonly args: readonly [{ readonly name: "stacker" readonly type: "principal" }] readonly outputs: { readonly optional: { readonly tuple: readonly [{ readonly name: "amount-ustx" readonly type: "uint128" }, { readonly name: "delegated-to" readonly type: "principal" }, { readonly name: "until-burn-ht" readonly type: { readonly optional: "uint128" } }, { readonly name: "pox-addr" readonly type: { readonly optional: { readonly tuple: readonly [{ readonly name: "version" readonly type: { readonly buff: { readonly length: 1 } } }, { readonly name: "hashbytes" readonly type: { readonly buff: { readonly length: 32 } } }] } } }] } } }, { readonly name: "can-stack-stx" readonly access: "read-only" readonly args: readonly [{ readonly name: "pox-addr" readonly type: { readonly tuple: readonly [{ readonly name: "version" readonly type: { readonly buff: { readonly length: 1 } } }, { readonly name: "hashbytes" readonly type: { readonly buff: { readonly length: 32 } } }] } }, { readonly name: "amount-ustx" readonly type: "uint128" }, { readonly name: "first-reward-cycle" readonly type: "uint128" }, { readonly name: "num-cycles" readonly type: "uint128" }] readonly outputs: { readonly response: { readonly ok: "bool" readonly error: "int128" } } }, { readonly name: "stack-stx" readonly access: "public" readonly args: readonly [{ readonly name: "amount-ustx" readonly type: "uint128" }, { readonly name: "pox-addr" readonly type: { readonly tuple: readonly [{ readonly name: "version" readonly type: { readonly buff: { readonly length: 1 } } }, { readonly name: "hashbytes" readonly type: { readonly buff: { readonly length: 32 } } }] } }, { readonly name: "start-burn-ht" readonly type: "uint128" }, { readonly name: "lock-period" readonly type: "uint128" }, { readonly name: "signer-sig" readonly type: { readonly optional: { readonly buff: { readonly length: 65 } } } }, { readonly name: "signer-key" readonly type: { readonly buff: { readonly length: 33 } } }, { readonly name: "max-amount" readonly type: "uint128" }, { readonly name: "auth-id" readonly type: "uint128" }] readonly outputs: { readonly response: { readonly ok: { readonly tuple: readonly [{ readonly name: "stacker" readonly type: "principal" }, { readonly name: "lock-amount" readonly type: "uint128" }, { readonly name: "signer-key" readonly type: { readonly buff: { readonly length: 33 } } }, { readonly name: "unlock-burn-height" readonly type: "uint128" }] } readonly error: "int128" } } }, { readonly name: "delegate-stx" readonly access: "public" readonly args: readonly [{ readonly name: "amount-ustx" readonly type: "uint128" }, { readonly name: "delegate-to" readonly type: "principal" }, { readonly name: "until-burn-ht" readonly type: { readonly optional: "uint128" } }, { readonly name: "pox-addr" readonly type: { readonly optional: { readonly tuple: readonly [{ readonly name: "version" readonly type: { readonly buff: { readonly length: 1 } } }, { readonly name: "hashbytes" readonly type: { readonly buff: { readonly length: 32 } } }] } } }] readonly outputs: { readonly response: { readonly ok: "bool" readonly error: "int128" } } }, { readonly name: "revoke-delegate-stx" readonly access: "public" readonly args: readonly [] readonly outputs: { readonly response: { readonly ok: { readonly optional: { readonly tuple: readonly [{ readonly name: "amount-ustx" readonly type: "uint128" }, { readonly name: "delegated-to" readonly type: "principal" }, { readonly name: "until-burn-ht" readonly type: { readonly optional: "uint128" } }, { readonly name: "pox-addr" readonly type: { readonly optional: { readonly tuple: readonly [{ readonly name: "version" readonly type: { readonly buff: { readonly length: 1 } } }, { readonly name: "hashbytes" readonly type: { readonly buff: { readonly length: 32 } } }] } } }] } } readonly error: "int128" } } }, { readonly name: "stack-extend" readonly access: "public" readonly args: readonly [{ readonly name: "extend-count" readonly type: "uint128" }, { readonly name: "pox-addr" readonly type: { readonly tuple: readonly [{ readonly name: "version" readonly type: { readonly buff: { readonly length: 1 } } }, { readonly name: "hashbytes" readonly type: { readonly buff: { readonly length: 32 } } }] } }, { readonly name: "signer-sig" readonly type: { readonly optional: { readonly buff: { readonly length: 65 } } } }, { readonly name: "signer-key" readonly type: { readonly buff: { readonly length: 33 } } }, { readonly name: "max-amount" readonly type: "uint128" }, { readonly name: "auth-id" readonly type: "uint128" }] readonly outputs: { readonly response: { readonly ok: { readonly tuple: readonly [{ readonly name: "stacker" readonly type: "principal" }, { readonly name: "unlock-burn-height" readonly type: "uint128" }] } readonly error: "int128" } } }, { readonly name: "stack-increase" readonly access: "public" readonly args: readonly [{ readonly name: "increase-by" readonly type: "uint128" }, { readonly name: "signer-sig" readonly type: { readonly optional: { readonly buff: { readonly length: 65 } } } }, { readonly name: "signer-key" readonly type: { readonly buff: { readonly length: 33 } } }, { readonly name: "max-amount" readonly type: "uint128" }, { readonly name: "auth-id" readonly type: "uint128" }] readonly outputs: { readonly response: { readonly ok: { readonly tuple: readonly [{ readonly name: "stacker" readonly type: "principal" }, { readonly name: "total-locked" readonly type: "uint128" }] } readonly error: "int128" } } }] }; declare const POX_CONTRACTS: { readonly mainnet: { readonly address: "SP000000000000000000002Q6VF78" readonly name: "pox-4" } readonly testnet: { readonly address: "ST000000000000000000002AMW42H" readonly name: "pox-4" } }; declare const MIN_LOCK_PERIOD = 1; declare const MAX_LOCK_PERIOD = 12; /** PoX address version bytes (maps to Bitcoin address types) */ declare const POX_ADDRESS_VERSION: { /** P2PKH - legacy addresses starting with "1" */ readonly p2pkh: 0x00 /** P2SH - script hash addresses starting with "3" */ readonly p2sh: 0x01 /** P2SH-P2WPKH - nested segwit */ readonly p2sh_p2wpkh: 0x02 /** P2SH-P2WSH - nested segwit script */ readonly p2sh_p2wsh: 0x03 /** P2WPKH - native segwit "bc1q" (20-byte hash) */ readonly p2wpkh: 0x04 /** P2WSH - native segwit "bc1q" (32-byte hash) */ readonly p2wsh: 0x05 /** P2TR - taproot "bc1p" (32-byte key) */ readonly p2tr: 0x06 }; /** * Parse a Bitcoin address string into a frozen-pox `PoxAddress` tuple * (`buff 1` version, `buff 32` zero-padded hashbytes). * Supports P2PKH, P2SH, P2WPKH, P2WSH, P2TR (mainnet and testnet). * * Decoding lives in `pox5/btcAddress.ts`, which verifies the base58check * checksum on legacy addresses; this wrapper only pads to the pox-4 shape. */ declare function parseBtcAddress(address: string): PoxAddress; /** Validate lock period is within allowed range (1-12). */ declare function validateLockPeriod(periods: number): boolean; /** Calculate the reward cycle for a given burn height. */ declare function burnHeightToRewardCycle(burnHeight: bigint, firstBurnchainBlockHeight: bigint, rewardCycleLength: bigint): bigint; /** Calculate the burn height at which a reward cycle starts. */ declare function rewardCycleToBurnHeight(cycle: bigint, firstBurnchainBlockHeight: bigint, rewardCycleLength: bigint): bigint; /** Actions provided by the PoX extension. */ type PoxActions = { pox: { getPoxInfo: () => Promise getStackerInfo: (address: string) => Promise getDelegationInfo: (address: string) => Promise canStack: (amount: bigint) => Promise stackStx: (params: StackStxParams) => Promise delegateStx: (params: DelegateStxParams) => Promise revokeDelegateStx: () => Promise stackExtend: (params: StackExtendParams) => Promise stackIncrease: (params: StackIncreaseParams) => Promise } }; /** * PoX stacking extension for Stacks client. * Handles STX stacking for Bitcoin rewards (solo + pool delegation). * * @example * import { createWalletClient, http, mainnet } from "stacks"; * import { pox } from "stacks/pox"; * * const client = createWalletClient({ ... }).extend(pox()); * * // Delegate to pool * await client.pox.delegateStx({ * amount: 100_000n * 1_000_000n, * delegateTo: "SP2...", * }); * * // Solo stack * await client.pox.stackStx({ * amount: 100_000n * 1_000_000n, * btcAddress: "bc1q...", * lockPeriod: 12, * startBurnHeight: 860000n, * signerSig: signature, * signerKey: publicKey, * maxAmount: 100_000_000_000n, * authId: 1n, * }); */ declare function pox(): (client: Client) => PoxActions; export { validateLockPeriod, rewardCycleToBurnHeight, pox, parseBtcAddress, burnHeightToRewardCycle, StackerInfo, StackStxParams, StackIncreaseParams, StackExtendParams, PoxInfo, PoxAddress, PoxActions, POX_CONTRACTS, POX_ADDRESS_VERSION, POX_ABI, MIN_LOCK_PERIOD, MAX_LOCK_PERIOD, DelegationInfo, DelegateStxParams };