import { type QuoteResult, type SelectedSwapRoute, KeeperType } from "@bitflowlabs/core-sdk"; import { type Network } from "../config/index.js"; import type { Account, TransferResult } from "../transactions/builder.js"; export interface BitflowTicker { ticker_id: string; base_currency: string; target_currency: string; last_price: string; base_volume: string; target_volume: string; bid: string; ask: string; high: string; low: string; liquidity_in_usd: string; } export interface PriceImpactHop { pool: string; tokenIn: string; tokenOut: string; reserveIn: string; reserveOut: string; feeBps: number; impact: number; } export type ImpactSeverity = "low" | "medium" | "high" | "severe"; export interface PriceImpactResult { /** Combined pure price impact across all hops (0-1 decimal, fee-excluded) */ combinedImpact: number; /** Human-readable percentage string e.g. "2.34%" */ combinedImpactPct: string; /** Severity tier */ severity: ImpactSeverity; /** Per-hop breakdown */ hops: PriceImpactHop[]; /** Total fee across all hops in basis points (approximate) */ totalFeeBps: number; } export interface BitflowSwapQuote { tokenIn: string; tokenOut: string; amountIn: string; expectedAmountOut: string; route: string[]; priceImpact?: PriceImpactResult; } export interface BitflowToken { id: string; name: string; symbol: string; contractId: string; decimals: number; } /** * Bitflow Service * * As of @bitflowlabs/core-sdk v2.4.2, all API keys are optional. * The SDK works out of the box with public rate limits (500 req/min per IP). * * Optional env vars for higher rate limits: * - BITFLOW_API_KEY: Core API (tokens, quotes, routes) * - BITFLOW_API_HOST: Override API host * - BITFLOW_KEEPER_API_KEY: Keeper automation features * - BITFLOW_KEEPER_API_HOST: Override Keeper API host * - BITFLOW_READONLY_API_HOST: Override Stacks read-only node * * Request higher limits: help@bitflow.finance */ export declare class BitflowService { private network; private sdk; private sdkInitialized; private tokenCache; constructor(network: Network); /** * Initialize the Bitflow SDK. * API keys are optional — public endpoints work without them. */ private initializeSdk; private static readonly DEFAULT_TOKEN_DECIMALS; private static toBaseUnits; private ensureMainnet; private ensureSdk; getTicker(): Promise; getTickerByPair(baseCurrency: string, targetCurrency: string): Promise; getAvailableTokens(): Promise; getPossibleSwapTargets(tokenXId: string): Promise; getAllRoutes(tokenXId: string, tokenYId: string): Promise; /** * Get swap quote with price impact calculation. */ getSwapQuote(tokenXId: string, tokenYId: string, amount: number): Promise; private classifyImpact; /** * Call a read-only contract function on the Stacks node used by Bitflow. * Includes a 5-second timeout to avoid blocking indefinitely. */ private callReadOnly; private getStringFromPool; private getUintFromPool; /** * Calculate price impact for a swap route. * * Uses the XYK constant-product formula: impact = dx / (x + dx) * For multi-hop: combined = 1 - (1-i1) * (1-i2) * ... * * For each hop, reads pool token-x-name/token-y-name to determine * swap direction and select the correct reserves and fee fields. * * @param quoteResult The SDK quote result containing route and swap data * @param amountIn The input amount in human units (e.g. 100 = 100 tokens) * @returns PriceImpactResult or null if route has no XYK pools */ calculatePriceImpact(quoteResult: QuoteResult, amountIn: number): Promise; /** * Execute a swap * @param fee Optional fee in micro-STX. If omitted, fee is auto-estimated. */ swap(account: Account, tokenXId: string, tokenYId: string, amountIn: number, slippageTolerance?: number, fee?: bigint): Promise; getOrCreateKeeperContract(stacksAddress: string, keeperType?: KeeperType): Promise<{ contractIdentifier: string; status: string; }>; createKeeperOrder(params: { contractIdentifier: string; stacksAddress: string; actionType: string; fundingTokens: Record; actionAmount: string; minReceived?: { amount: string; autoAdjust: boolean; }; }): Promise<{ orderId: string; status: string; }>; getKeeperOrder(orderId: string): Promise<{ orderId: string; status: string; actionType: string; actionAmount: string; }>; cancelKeeperOrder(orderId: string): Promise<{ success: boolean; }>; getKeeperUser(stacksAddress: string): Promise<{ stacksAddress: string; contracts: Array<{ identifier: string; status: string; }>; orders: Array<{ orderId: string; status: string; }>; }>; } export declare function getBitflowService(network: Network): BitflowService; //# sourceMappingURL=bitflow.service.d.ts.map