x402_enforce_spend_policy
Enforce x402 per-transaction and daily spend caps with exact integer fee math, payee/network allowlists, and nonce replay rejection before payment authorization.
Instructions
Deterministic SPEC_CLASS_09 spend-cap & integer fee-math gate (net_minor = amount_minor * (10000 - fee_bps) // 10000, strictly rejecting IEEE-754 floats and slippage_bps < 0). Enforces max_per_tx_minor, cumulative_spent_minor + amount_minor <= daily_cap_minor, allowed_payees, allowed_caip2_networks, and idempotency_nonce replay rejection (stateless batch or optional thread-safe SQLite WAL ledger).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"amount_minor": "<amount_minor>",
"payee": "<payee>",
"caip2_network": "<caip2_network>",
"idempotency_nonce": "<idempotency_nonce>"
},
"name": "x402_enforce_spend_policy"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| payee | Yes | Destination wallet or merchant recipient address. | |
| fee_bps | No | Protocol/facilitator fee in integer basis points (`0..10000`). | |
| day_bucket | No | Optional UTC date bucket (`YYYY-MM-DD`) override for deterministic testing. | |
| seen_nonces | No | Optional stateless list of previously used idempotency nonces. | |
| amount_minor | Yes | Exact positive integer payment amount in atomic/minor units (floats rejected). | |
| slippage_bps | No | Slippage tolerance in integer basis points (`>= 0`; negative values rejected). | |
| caip2_network | Yes | CAIP-2 chain identifier (e.g. `eip155:8453`, `stacks:1`). | |
| allowed_payees | No | Optional allowlist of approved payee addresses. | |
| ledger_db_path | No | Optional path to a local SQLite WAL spend ledger for atomic multi-process/thread replay protection. | |
| daily_cap_minor | No | Daily cumulative integer atomic cap (default `50000000`). | |
| commit_to_ledger | No | When `ledger_db_path` is provided and policy passes, atomically record the spend row. | |
| max_per_tx_minor | No | Per-transaction integer atomic cap (defaults to `X402_DEFAULT_MAX_TX_USDC_ATOMIC` or `5000000`). | |
| max_slippage_bps | No | Maximum allowed slippage basis points (default `100` = `1.00%`). | |
| idempotency_nonce | Yes | Unique payment authorization nonce or EIP-3009 `bytes32` nonce. | |
| allowed_caip2_networks | No | Optional allowlist of permitted CAIP-2 networks. | |
| cumulative_spent_minor | No | Prior integer atomic spend in the current UTC day bucket (default `0`). |