# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://metya.gitbook.io/metya/product-and-architecture/payfi-middle-layer-engineering-the-spend-path.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
