/** * Where the services and the contracts are. The network is the SDK's * default, Base, unless PX402_NETWORK names another preset. Every value * below comes from the environment and defaults to that network's preset: * its reserve, and PRXVT's hosted issuer, registry and bridge facilitator * (issuer.prxvt.com, registry.prxvt.com, facilitator.prxvt.com). */ import { resolveNetwork, resolveServices } from "px402"; export interface AgentConfig { readonly issuerUrl: string; readonly registryUrl: string; /** * The bridge facilitator that pays merchants quoting only `exact`, or * `undefined`: then only merchants whose 402 has a px402 entry are paid. A * 402 names no px402 facilitator for an `exact` entry, so you name one. */ readonly bridgeFacilitator: string | undefined; /** Where the chain is read. */ readonly rpcUrl: string; /** Where transactions are sent and their receipts read: PX402_RPC_URL when set, else the preset's. */ readonly txRpcUrl: string; readonly chainId: number; readonly reserve: string; readonly usdc: string; /** `DOMAIN_SEPARATOR()` of the reserve, 0x-prefixed hex. */ readonly domainSeparator: string; /** The reserve's deployment block: where a recovery scan of its logs starts. */ readonly deployBlock: bigint; /** Blocks per eth_getLogs call. Base's public endpoint serves at most 500. */ readonly logBlockRange: bigint; } export function loadConfig(): AgentConfig { const env = process.env; // PX402_NETWORK when set, else Base. const network = resolveNetwork(); // PX402_ISSUER_URL, PX402_REGISTRY_URL, PX402_BRIDGE_FACILITATOR and // PX402_RPC_URL when set, else the preset's: the drop-in's own resolution. const services = resolveServices(network); return { issuerUrl: services.issuerUrl, registryUrl: services.registryUrl, bridgeFacilitator: services.bridgeFacilitator, rpcUrl: services.rpcUrl, txRpcUrl: services.txRpcUrl, chainId: Number(env["PX402_CHAIN_ID"] ?? network.chainId), reserve: env["PX402_RESERVE"] ?? network.reserveContract, usdc: env["PX402_USDC"] ?? network.usdc, domainSeparator: env["PX402_DOMAIN_SEPARATOR"] ?? network.domainSeparator, deployBlock: BigInt(env["PX402_DEPLOY_BLOCK"] ?? network.deployBlock), logBlockRange: BigInt(env["PX402_LOG_BLOCK_RANGE"] ?? network.logBlockRange ?? 500n), }; }