> For the complete documentation index, see [llms.txt](https://metya.gitbook.io/metya/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://metya.gitbook.io/metya/product-and-architecture/payfi-middle-layer-engineering-the-spend-path.md).

# PayFi Middle Layer: Engineering the “Spend” Path

Top-up & Settlement (sequence):

Top‑up → FX → Ledger → Auth → Capture → Anchor → Rewards (serialized)

1. Top‑up: User funds with MY/USDT → price source (multi‑exchange VWAP) sets base → create TopupIntent.
2. FX & net calc: Apply fees (FX/platform/fixed card fee) → compute NetUSD.
3. Double‑entry: Write into Ledger (T+0, idempotent), append audit log.
4. Authorization/Capture: Channel auth hold → capture.
5. Reconcile & anchor: Intraday reconciliation → batch Merkle root on‑chain (PaymentAnchored event) with proof fingerprints.
6. Rebates/rights: Generate rewards per merchant/quest rules (points/NFT/rebates) → write RewardLedger.<br>

Three-phase risk:

* Pre-event: region/device/account fingerprinting, MCC allowlist, per-tx/day limits (user + rail layers).
* In-event: anomaly in frequency/amount, failure spikes, IP/device clustering → trigger KBA or temp freeze.
* Post-event: chargeback/refund workflows, merchant dispute arbitration, list updates with explainable evidence.

**Why on-chain anchoring:**

Anchor Merkle roots (with stats: count, net amount, region, windowId) instead of sensitive detail. This enables non-repudiation without leaking PII/merchant info. For audit/disputes, recover proofs via Merkle paths.
