import { W as WalletRpcClient } from '../wallet-rpc-sY1qJ24S.cjs'; import { DaemonRpcClient } from '../rpc/index.cjs'; /** * Payment router types for DeroPay smart contract-based instant payments. * * The payment router is a reusable per-merchant contract that splits * payments instantly on-chain. Unlike the escrow contract (one per * transaction, multi-step), the router handles unlimited payments * through a single deployed contract. */ /** The payment router contract state as read from the blockchain */ type RouterOnChainState = { /** Smart Contract ID */ scid: string; /** Merchant address (deployer, receives payouts) */ merchant: string; /** Fee recipient address */ feeRecipient: string; /** Fee rate in basis points (100 = 1%) */ feeBasisPoints: number; /** Total DERO processed in atomic units */ totalProcessed: bigint; /** Total fees collected in atomic units */ totalFees: bigint; /** Number of payments processed */ paymentCount: number; /** Whether the router is paused (merchant can pause/resume) */ paused: boolean; /** DERO balance held by the SC (should always be 0 for a healthy router) */ scBalance: number; }; /** Parameters to deploy a new payment router contract */ type DeployRouterParams = { /** Address that receives the fee split. Ignored if feeBasisPoints is 0. */ feeRecipientAddress?: string; /** Fee in basis points (100 = 1%, 250 = 2.5%, 0 = no fee). Default: 0 */ feeBasisPoints?: number; }; /** Local payment router record with both on-chain and off-chain data */ type RouterRecord = { /** Unique local ID */ id: string; /** Smart Contract ID (set after successful deployment) */ scid: string | null; /** Deployment transaction ID */ deployTxid: string | null; /** Current status */ status: RouterStatus; /** Fee recipient address */ feeRecipientAddress: string; /** Fee in basis points */ feeBasisPoints: number; /** When the router was created locally (ISO 8601) */ createdAt: string; /** Arbitrary metadata */ metadata: Record; }; /** Router lifecycle status */ type RouterStatus = "deploying" | "active" | "deploy_failed"; /** Events emitted by the RouterManager */ type RouterManagerEvents = { /** Router deployed successfully */ routerDeployed: (router: RouterRecord) => void; /** Router deployment failed */ routerDeployFailed: (router: RouterRecord, error: Error) => void; /** Payment processed through a router */ paymentProcessed: (scid: string, invoiceId: string, txid: string) => void; /** Error */ error: (error: Error) => void; }; /** RouterManager configuration */ type RouterManagerConfig = { /** Wallet RPC URL */ walletRpcUrl?: string; /** Daemon RPC URL */ daemonRpcUrl?: string; /** RPC auth */ rpcAuth?: { username: string; password: string; }; }; /** * Payment router smart contract wrapper. * * Provides a typed interface to deploy, invoke, and query * the DERO payment router smart contract via the RPC clients. */ /** * Typed wrapper around the payment router smart contract. * * All methods return transaction IDs or on-chain state. * The contract logic enforces access control on-chain. */ declare class RouterContract { private walletRpc; private daemonRpc; constructor(walletRpc: WalletRpcClient, daemonRpc: DaemonRpcClient); /** Get the payment router smart contract source code. */ getSource(): string; /** * Deploy a new payment router smart contract. * * The deployer (signer) becomes the merchant. * * @returns Deployment TXID (= the SCID) */ deploy(params: { feeRecipientAddress?: string; feeBasisPoints?: number; }): Promise; /** * Send a payment through the router contract. * * The contract instantly splits: merchant gets payout, fee recipient gets fee. * * @param scid - Smart Contract ID of the deployed router * @param invoiceId - Invoice identifier for correlation * @param amount - Amount in atomic units to pay * @returns Transaction ID */ pay(scid: string, invoiceId: string, amount: bigint): Promise; /** * Update the merchant address (merchant-only action). * * @param scid - Smart Contract ID * @param newAddress - New merchant DERO address * @returns Transaction ID */ updateMerchant(scid: string, newAddress: string): Promise; /** * Pause the router (merchant-only). Rejects new payments until resumed. */ pause(scid: string): Promise; /** * Resume a paused router (merchant-only). */ resume(scid: string): Promise; /** * Withdraw any DERO trapped in the SC balance (merchant-only). * This recovers funds that were accidentally sent to non-Pay functions. * * @param scid - Smart Contract ID * @param amount - Amount in atomic units to withdraw */ withdrawTrapped(scid: string, amount: bigint): Promise; /** * Query the full on-chain state of a payment router contract. * * @param scid - Smart Contract ID * @returns Parsed on-chain state */ getState(scid: string): Promise; /** * Check if a payment router contract exists on-chain. */ exists(scid: string): Promise; } /** * RouterManager — lifecycle manager for payment router contracts. * * Manages deployment and interaction with payment router contracts. * Unlike EscrowManager, the router doesn't need polling — payments * are instant (single transaction, no state machine). * * Usage: * ```ts * const manager = new RouterManager({ * walletRpcUrl: "http://127.0.0.1:10103/json_rpc", * daemonRpcUrl: "http://127.0.0.1:10102/json_rpc", * }); * * // Deploy a router with no fee (merchant keeps 100%) * const router = await manager.deployRouter(); * * // Deploy a router with a 2% fee to a partner * const router = await manager.deployRouter({ * feeRecipientAddress: "deto1q...", * feeBasisPoints: 200, * }); * * // Send a payment through the router * const txid = await manager.pay(router.scid!, "inv_abc123", 50000n); * ``` */ declare class RouterManager { private walletRpc; private daemonRpc; private contract; private routers; private scidToId; private listeners; constructor(config?: RouterManagerConfig & { /** Inject RPC clients (for testing); when set, walletRpcUrl/daemonRpcUrl are ignored */ walletRpc?: WalletRpcClient; daemonRpc?: DaemonRpcClient; }); on(event: K, callback: RouterManagerEvents[K]): () => void; private emit; /** * Deploy a new payment router contract. * * The current wallet becomes the merchant (payment recipient). */ deployRouter(params?: DeployRouterParams): Promise; /** * Send a payment through a deployed router contract. * * The contract instantly splits the payment between the merchant * and the fee recipient. * * @param scidOrId - Router SCID or local ID * @param invoiceId - Invoice identifier for correlation * @param amount - Amount in atomic units * @returns Transaction ID */ pay(scidOrId: string, invoiceId: string, amount: bigint): Promise; /** * Update the merchant address on a deployed router. * Only the current merchant can call this. */ updateMerchant(scidOrId: string, newAddress: string): Promise; /** * Pause a router (merchant-only). Rejects new payments until resumed. */ pause(scidOrId: string): Promise; /** * Resume a paused router (merchant-only). */ resume(scidOrId: string): Promise; /** * Withdraw any DERO trapped in the SC balance (merchant-only). */ withdrawTrapped(scidOrId: string, amount: bigint): Promise; /** Get a router record by its local ID. */ getRouter(id: string): RouterRecord | null; /** Get a router record by its SCID. */ getRouterByScid(scid: string): RouterRecord | null; /** List all tracked routers. */ listRouters(): RouterRecord[]; /** Query the live on-chain state of a router contract. */ getOnChainState(scidOrId: string): Promise; /** Get the underlying RouterContract for advanced usage. */ getContract(): RouterContract; /** * Import an existing router (e.g. from persistent storage on restart). */ importRouter(record: RouterRecord): void; private resolveScid; } export { type DeployRouterParams, RouterContract, RouterManager, type RouterManagerConfig, type RouterManagerEvents, type RouterOnChainState, type RouterRecord, type RouterStatus };