{"version":3,"file":"mempool.mjs","names":["createChain"],"sources":["../../src/providers/mempool.ts"],"sourcesContent":["/**\n * Mempool.space provider for Bitcoin and compatible forks serving Litecoin and Pepecoin.\n *\n * Public API, no key needed. All three serve address balances and transactions. Litecoin also\n * carries the fee and block endpoints, while Pepecoin does not expose enough data for those reads.\n *\n * https://mempool.space/docs/api\n */\n\nimport type {\n  ProviderCapabilities,\n  ProviderConfig,\n  ChainKey,\n  Balance,\n  Transaction,\n  TxHistoryOptions,\n  GasData,\n  GasUnit,\n  BlockInfo,\n  TxStatus,\n  TokenTransfer,\n  OpReturnPayload,\n  Utxo,\n} from \"../core/types.js\";\nimport { Provider } from \"../core/provider.js\";\nimport { normalizeBaseUrl } from \"../core/client.js\";\nimport { NotFoundError, UnsupportedChainError, UnsupportedOperationError } from \"../core/errors.js\";\nimport { create as createChain } from \"@agntn/chains\";\nimport { formatWei } from \"../core/types.js\";\nimport { assertSafePathSegment } from \"../core/path-safety.js\";\nimport {\n  getEsploraAddressHistory,\n  getEsploraUtxos,\n  selectEsploraRecipientOutput,\n} from \"../core/esplora.js\";\nimport type { EsploraUnspentOutput } from \"../core/esplora.js\";\n\nconst DEFAULT_BASE = \"https://mempool.space\";\n\nconst CHAIN_BASES: Partial<Record<ChainKey, string>> = {\n  bitcoin: DEFAULT_BASE,\n  litecoin: \"https://litecoinspace.org\",\n  pepecoin: \"https://peppool.space\",\n};\n\n/** Fee rates come back in the chain's smallest unit per virtual byte. */\nconst FEE_UNITS: Partial<Record<ChainKey, GasUnit>> = {\n  bitcoin: \"sat/vB\",\n  litecoin: \"litoshi/vB\",\n};\n\ninterface MempoolAddressSummary {\n  readonly address: string;\n  readonly chain_stats: {\n    readonly funded_txo_count: number;\n    readonly funded_txo_sum: number | string;\n    readonly spent_txo_count: number;\n    readonly spent_txo_sum: number | string;\n    readonly tx_count: number;\n  };\n  readonly mempool_stats?: {\n    readonly funded_txo_count: number;\n    readonly funded_txo_sum: number | string;\n    readonly spent_txo_count: number;\n    readonly spent_txo_sum: number | string;\n    readonly tx_count: number;\n  };\n}\n\ninterface MempoolTx {\n  readonly txid: string;\n  readonly version: number;\n  readonly locktime: number;\n  readonly vin: ReadonlyArray<{\n    readonly txid: string;\n    readonly vout: number;\n    readonly prevout: {\n      readonly scriptpubkey: string;\n      readonly scriptpubkey_asm: string;\n      readonly scriptpubkey_type: string;\n      readonly scriptpubkey_address?: string;\n      readonly value: number | string;\n    } | null;\n    readonly scriptsig: string;\n    readonly sequence: number;\n    readonly witness?: readonly string[];\n  }>;\n  readonly vout: ReadonlyArray<{\n    readonly scriptpubkey: string;\n    readonly scriptpubkey_asm: string;\n    readonly scriptpubkey_type: string;\n    readonly scriptpubkey_address?: string;\n    readonly value: number | string;\n  }>;\n  readonly size: number;\n  readonly weight: number;\n  readonly fee: number | string;\n  readonly status: {\n    readonly confirmed: boolean;\n    readonly block_height?: number;\n    readonly block_hash?: string;\n    readonly block_time?: number;\n  };\n}\n\ninterface MempoolAddressTx {\n  readonly txid: string;\n  readonly version: number;\n  readonly locktime: number;\n  readonly vin: ReadonlyArray<{\n    readonly txid: string;\n    readonly vout: number;\n    readonly prevout: {\n      readonly scriptpubkey_address?: string;\n      readonly value: number | string;\n    } | null;\n    readonly scriptsig: string;\n    readonly sequence: number;\n  }>;\n  readonly vout: ReadonlyArray<{\n    readonly scriptpubkey?: string;\n    readonly scriptpubkey_type: string;\n    readonly scriptpubkey_address?: string;\n    readonly value: number | string;\n  }>;\n  readonly size: number;\n  readonly weight: number;\n  readonly fee: number | string;\n  readonly status: {\n    readonly confirmed: boolean;\n    readonly block_height?: number;\n    readonly block_time?: number;\n  };\n}\n\ninterface MempoolFees {\n  readonly fastestFee: number;\n  readonly halfHourFee: number;\n  readonly hourFee: number;\n  readonly economyFee: number;\n  readonly minimumFee: number;\n}\n\ninterface MempoolBlock {\n  readonly id: string;\n  readonly height: number;\n  readonly version: number;\n  readonly timestamp: number;\n  readonly bits: number;\n  readonly nonce: number;\n  readonly difficulty: number;\n  readonly merkle_root: string;\n  readonly tx_count: number;\n  readonly size: number;\n  readonly weight: number;\n  readonly previousblockhash: string;\n  readonly mediantime: number;\n}\n\n/* Convert the smallest unit to a coin string without floating-point arithmetic. */\nfunction satToCoin(sat: number | string | bigint): string {\n  return formatWei(String(sat), 8);\n}\n\n/** An OP_RETURN output opens with the opcode itself, so the hex says so before it is decoded. */\nconst OP_RETURN_SCRIPT = /^6a/i;\n\nconst OP_0 = 0x00;\nconst OP_PUSHDATA1 = 0x4c;\nconst OP_PUSHDATA2 = 0x4d;\nconst OP_PUSHDATA4 = 0x4e;\n\nconst OP_1NEGATE = 0x4f;\nconst OP_RESERVED = 0x50;\nconst OP_1 = 0x51;\nconst OP_16 = 0x60;\n\n/** Push opcodes that spell their length out, and how many bytes that length takes. */\nconst PUSHDATA_WIDTH: Record<number, number> = {\n  [OP_PUSHDATA1]: 1,\n  [OP_PUSHDATA2]: 2,\n  [OP_PUSHDATA4]: 4,\n};\n\nlet utf8: TextDecoder | undefined;\n\n/* `ignoreBOM` means \"leave a leading U+FEFF in the string\", which is where the filter can see it. */\nfunction decoder(): TextDecoder {\n  utf8 ??= new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true });\n  return utf8;\n}\n\n/** Format characters, invisible on screen, and the line separators no renderer splits on. */\nconst UNPRINTABLE = /[\\p{Cf}\\p{Zl}\\p{Zp}]/u;\n\n/*\n * Decide whether decoded chain data is worth showing as text.\n *\n * A payload anyone can pay to publish must not steer a terminal, reorder the line that renders it,\n * or hide bytes behind characters nobody can see, because the CLI prints this text straight out.\n * Out of the C0 and C1 control blocks only tab and newline survive: real messages write paragraphs\n * with them, and the renderers indent a continuation line so it cannot pose as another field. The\n * trade is that a joiner carries meaning in Persian spelling and in emoji sequences, and those\n * payloads arrive as hex.\n */\nfunction isPrintable(text: string): boolean {\n  if (UNPRINTABLE.test(text)) return false;\n\n  for (const char of text) {\n    const code = char.codePointAt(0) ?? 0;\n    if (code < 0x20 && code !== 0x09 && code !== 0x0a) return false;\n    if (code >= 0x7f && code <= 0x9f) return false;\n  }\n\n  return true;\n}\n\nfunction hexToBytes(hex: string): Uint8Array | undefined {\n  if (hex.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(hex)) return undefined;\n\n  const bytes = new Uint8Array(hex.length / 2);\n  for (let i = 0; i < bytes.length; i += 1) {\n    bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n  }\n  return bytes;\n}\n\nfunction toHex(bytes: Uint8Array): string {\n  return Array.from(bytes, (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/* Read a little-endian push length. Callers check first that all `width` bytes are there. */\nfunction readPushLength(script: Uint8Array, offset: number, width: number): number {\n  let length = 0;\n  for (let i = 0; i < width; i += 1) {\n    length += (script[offset + i] ?? 0) * 256 ** i;\n  }\n  return length;\n}\n\n/*\n * Value an opcode pushes on its own, for the small constants that carry no bytes after them.\n *\n * Nothing comes back for OP_RESERVED: Bitcoin Core counts it as push-type in `IsPushOnly`, yet it\n * leaves no data behind.\n */\nfunction constantPush(opcode: number): Uint8Array | undefined {\n  if (opcode === OP_0) return new Uint8Array();\n  if (opcode === OP_1NEGATE) return Uint8Array.of(0x81);\n  if (opcode >= OP_1 && opcode <= OP_16) return Uint8Array.of(opcode - OP_1 + 1);\n  return undefined;\n}\n\n/* Read a payload as text, leaving binary carriers (Runes, Omni, hashes) without a text reading. */\nfunction decodeText(payload: Uint8Array): string | undefined {\n  try {\n    const text = decoder().decode(payload);\n    return isPrintable(text) ? text : undefined;\n  } catch {\n    return undefined;\n  }\n}\n\nfunction toPayload(bytes: Uint8Array): OpReturnPayload {\n  return { hex: toHex(bytes), text: decodeText(bytes) };\n}\n\nfunction dataPush(\n  script: Uint8Array,\n  cursor: number,\n  opcode: number,\n): { readonly cursor: number; readonly length: number } | undefined {\n  const width = PUSHDATA_WIDTH[opcode];\n  if (width === undefined) return { cursor, length: opcode };\n  if (cursor + width > script.length) return undefined;\n  return { cursor: cursor + width, length: readPushLength(script, cursor, width) };\n}\n\n/*\n * Read the data pushes of an OP_RETURN output.\n *\n * Any other output yields nothing, and is rejected on the hex so a busy address does not pay to\n * decode thousands of ordinary scripts. The walk covers what Bitcoin Core calls push-only: an\n * opcode below OP_PUSHDATA1 is its own byte count, the small constants push themselves, and\n * anything above OP_16 or a truncated push ends the walk with whatever came before it.\n */\nfunction parseOpReturn(scriptHex: string): OpReturnPayload[] {\n  if (!OP_RETURN_SCRIPT.test(scriptHex)) return [];\n\n  const script = hexToBytes(scriptHex);\n  if (!script) return [];\n\n  const payloads: OpReturnPayload[] = [];\n  let cursor = 1;\n\n  while (cursor < script.length) {\n    const opcode = script[cursor]!;\n    cursor += 1;\n\n    if (opcode > OP_16) break;\n    if (opcode === OP_RESERVED) continue;\n\n    const constant = constantPush(opcode);\n    if (constant !== undefined) {\n      payloads.push(toPayload(constant));\n      continue;\n    }\n\n    const push = dataPush(script, cursor, opcode);\n    if (!push || push.cursor + push.length > script.length) break;\n\n    const payload = script.subarray(push.cursor, push.cursor + push.length);\n    cursor = push.cursor + push.length;\n    payloads.push(toPayload(payload));\n  }\n\n  return payloads;\n}\n\n/* Gather the OP_RETURN payloads of all outputs, or nothing when the transaction carries none. */\nfunction collectOpReturns(\n  vout: readonly { readonly scriptpubkey?: string }[],\n): OpReturnPayload[] | undefined {\n  const payloads = vout.flatMap((out) => (out.scriptpubkey ? parseOpReturn(out.scriptpubkey) : []));\n  return payloads.length > 0 ? payloads : undefined;\n}\n\nfunction mempoolTimestamp(status: Readonly<MempoolAddressTx[\"status\"]>): string | undefined {\n  return status.block_time ? new Date(status.block_time * 1000).toISOString() : undefined;\n}\n\nfunction peppoolHistoryPath(encodedAddress: string, encodedCursor: string): string {\n  return `/api/address/${encodedAddress}/txs?after_txid=${encodedCursor}`;\n}\n\nfunction mempoolAddressTotals(\n  raw: Readonly<MempoolAddressTx>,\n  address: string,\n): { readonly input: bigint; readonly output: bigint } {\n  const input = raw.vin\n    .filter((item) => item.prevout?.scriptpubkey_address === address)\n    .reduce((sum, item) => sum + BigInt(item.prevout?.value ?? 0), 0n);\n  const output = raw.vout\n    .filter((item) => item.scriptpubkey_address === address)\n    .reduce((sum, item) => sum + BigInt(item.value), 0n);\n  return { input, output };\n}\n\nfunction mempoolSendingParties(\n  raw: Readonly<MempoolAddressTx>,\n  address: string,\n): { readonly from: string; readonly to: string } {\n  const sender = raw.vin.find((item) => item.prevout?.scriptpubkey_address === address);\n  const recipient = selectEsploraRecipientOutput(raw.vout, address);\n  return {\n    from: sender?.prevout?.scriptpubkey_address ?? address,\n    to: recipient.address ?? address,\n  };\n}\n\nfunction mempoolAddressParties(\n  raw: Readonly<MempoolAddressTx>,\n  address: string,\n  isSend: boolean,\n): { readonly from: string; readonly to: string } {\n  if (isSend) return mempoolSendingParties(raw, address);\n  return { from: raw.vin[0]?.prevout?.scriptpubkey_address ?? \"unknown\", to: address };\n}\n\nfunction mapTx(raw: Readonly<MempoolAddressTx>, address: string): Transaction {\n  const totals = mempoolAddressTotals(raw, address);\n  const netSat = totals.output - totals.input;\n  const isSend = totals.input > 0n;\n  const absoluteNetSat = netSat < 0n ? -netSat : netSat;\n  const amount = isSend ? absoluteNetSat - BigInt(raw.fee) : netSat;\n  const transferredSat = amount < 0n ? 0n : amount;\n  const { from, to } = mempoolAddressParties(raw, address, isSend);\n\n  return {\n    hash: raw.txid,\n    blockNumber: raw.status.block_height ?? 0,\n    timestamp: mempoolTimestamp(raw.status),\n    from,\n    to: to ?? null,\n    value: transferredSat.toString(),\n    valueFormatted: satToCoin(transferredSat),\n    fee: raw.fee.toString(),\n    status: (raw.status.confirmed ? \"success\" : \"pending\") as TxStatus,\n    isContractInteraction: false,\n    tokenTransfers: [] as TokenTransfer[],\n    opReturn: collectOpReturns(raw.vout),\n    raw: raw as unknown as Record<string, unknown>,\n  };\n}\n\nexport class Mempool extends Provider {\n  static readonly key = \"mempool\";\n\n  private baseUrl: string | undefined;\n  private defaultChain: ChainKey;\n\n  constructor(config: Readonly<ProviderConfig>) {\n    super(config);\n    this.baseUrl = config.baseUrl ? normalizeBaseUrl(config.baseUrl) : undefined;\n    this.defaultChain = config.defaultChain ?? \"bitcoin\";\n  }\n  get capabilities(): ProviderCapabilities {\n    return {\n      balances: true,\n      txHistory: true,\n      txDetail: true,\n      utxos: true,\n      contractInfo: false,\n      tokenBalances: false,\n      tokenTransfers: false,\n      gasData: true,\n      blockInfo: true,\n    };\n  }\n\n  /* Chain membership decides support; an explicit `baseUrl` then overrides the host. */\n  private base(chain: ChainKey): string {\n    const base = CHAIN_BASES[chain];\n    if (!base) throw new UnsupportedChainError(chain, \"mempool\");\n    return this.baseUrl ?? base;\n  }\n\n  private async api<T>(chain: ChainKey, path: string): Promise<T> {\n    return this.getJSON<T>(`${this.base(chain)}${path}`);\n  }\n\n  async getBalance(address: string, chain?: ChainKey): Promise<Balance> {\n    const c = chain ?? this.defaultChain;\n\n    assertSafePathSegment(address, \"address\");\n    const data = await this.api<MempoolAddressSummary>(\n      c,\n      `/api/address/${encodeURIComponent(address)}`,\n    );\n\n    const fundedSat = BigInt(data.chain_stats.funded_txo_sum);\n    const spentSat = BigInt(data.chain_stats.spent_txo_sum);\n    const balanceSat = fundedSat - spentSat;\n\n    const unconfirmed = data.mempool_stats\n      ? BigInt(data.mempool_stats.funded_txo_sum) - BigInt(data.mempool_stats.spent_txo_sum)\n      : undefined;\n\n    return this.snapshotBalance({\n      ...(unconfirmed === undefined ? {} : { unconfirmed: unconfirmed.toString() }),\n      address,\n      chain: c,\n      balance: balanceSat.toString(),\n      balanceFormatted: satToCoin(balanceSat),\n      funded: fundedSat.toString(),\n      spent: spentSat.toString(),\n      symbol: createChain(c).symbol,\n    });\n  }\n\n  async getTxHistory(\n    address: string,\n    chain?: ChainKey,\n    options?: Readonly<TxHistoryOptions>,\n  ): Promise<Transaction[]> {\n    const c = chain ?? this.defaultChain;\n    const transactions = await getEsploraAddressHistory(\n      address,\n      options?.limit,\n      async (path) => this.api<MempoolAddressTx[]>(c, path),\n      c === \"pepecoin\" ? peppoolHistoryPath : undefined,\n    );\n\n    return transactions.map((tx) => mapTx(tx, address));\n  }\n\n  override async getUtxos(address: string, chain?: ChainKey): Promise<Utxo[]> {\n    const c = chain ?? this.defaultChain;\n    return getEsploraUtxos(address, async (path) => this.api<EsploraUnspentOutput[]>(c, path));\n  }\n\n  override async getTxDetail(hash: string, chain?: ChainKey): Promise<Transaction> {\n    const c = chain ?? this.defaultChain;\n\n    assertSafePathSegment(hash, \"tx hash\");\n    const data = await this.api<MempoolTx>(c, `/api/tx/${encodeURIComponent(hash)}`);\n\n    const output = selectEsploraRecipientOutput(data.vout);\n    const fromAddr = data.vin[0]?.prevout?.scriptpubkey_address ?? \"unknown\";\n\n    return {\n      hash: data.txid,\n      blockNumber: data.status.block_height ?? 0,\n      timestamp: mempoolTimestamp(data.status),\n      from: fromAddr,\n      to: output.address,\n      value: output.value.toString(),\n      valueFormatted: satToCoin(output.value),\n      fee: data.fee.toString(),\n      status: (data.status.confirmed ? \"success\" : \"pending\") as TxStatus,\n      isContractInteraction: false,\n      tokenTransfers: [],\n      opReturn: collectOpReturns(data.vout),\n      raw: data as unknown as Record<string, unknown>,\n    };\n  }\n\n  override async getGasData(chain?: ChainKey): Promise<GasData> {\n    const c = chain ?? this.defaultChain;\n    if (c === \"pepecoin\") throw new UnsupportedOperationError(\"getGasData\", this.name);\n\n    const fees = await this.api<MempoolFees>(c, \"/api/v1/fees/recommended\");\n\n    return {\n      chain: c,\n      unit: FEE_UNITS[c] ?? \"sat/vB\",\n      safeGasPrice: fees.economyFee.toString(),\n      proposedGasPrice: fees.halfHourFee.toString(),\n      fastGasPrice: fees.fastestFee.toString(),\n      priorityFee: fees.minimumFee.toString(),\n    };\n  }\n\n  override async getBlockInfo(blockNumber: number, chain?: ChainKey): Promise<BlockInfo> {\n    const c = chain ?? this.defaultChain;\n    if (c === \"pepecoin\") throw new UnsupportedOperationError(\"getBlockInfo\", this.name);\n\n    assertSafePathSegment(String(blockNumber), \"block number\");\n    const blocks = await this.api<MempoolBlock[]>(\n      c,\n      `/api/blocks/${encodeURIComponent(String(blockNumber))}`,\n    );\n    const block = blocks.find((candidate) => candidate.height === blockNumber);\n    if (!block) throw new NotFoundError(`Block ${blockNumber}`, \"mempool\");\n\n    return {\n      number: block.height,\n      hash: block.id,\n      parentHash: block.previousblockhash,\n      timestamp: new Date(block.timestamp * 1000).toISOString(),\n      miner: \"\",\n      gasUsed: block.size.toString(),\n      gasLimit: block.weight.toString(),\n      txCount: block.tx_count,\n    };\n  }\n}\n"],"mappings":";;;;;;AAuCA,MAAM,cAAiD;CACrD,SAAS;CACT,UAAU;CACV,UAAU;AACZ;AAGA,MAAM,YAAgD;CACpD,SAAS;CACT,UAAU;AACZ;AA+GA,SAAS,UAAU,KAAuC;CACxD,OAAO,UAAU,OAAO,GAAG,GAAG,CAAC;AACjC;AAGA,MAAM,mBAAmB;AAEzB,MAAM,OAAO;AACb,MAAM,eAAe;AACrB,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,OAAO;AACb,MAAM,QAAQ;AAGd,MAAM,iBAAyC;EAC5C,eAAe;EACf,eAAe;EACf,eAAe;AAClB;AAEA,IAAI;AAGJ,SAAS,UAAuB;CAC9B,SAAS,IAAI,YAAY,SAAS;EAAE,OAAO;EAAM,WAAW;CAAK,CAAC;CAClE,OAAO;AACT;AAGA,MAAM,cAAc;AAYpB,SAAS,YAAY,MAAuB;CAC1C,IAAI,YAAY,KAAK,IAAI,GAAG,OAAO;CAEnC,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,YAAY,CAAC,KAAK;EACpC,IAAI,OAAO,MAAQ,SAAS,KAAQ,SAAS,IAAM,OAAO;EAC1D,IAAI,QAAQ,OAAQ,QAAQ,KAAM,OAAO;CAC3C;CAEA,OAAO;AACT;AAEA,SAAS,WAAW,KAAqC;CACvD,IAAI,IAAI,SAAS,MA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