> For the complete documentation index, see [llms.txt](https://hyperpnl.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hyperpnl.gitbook.io/docs/architecture/smart-contracts/payment-router.md).

# Payment Router

The Payment Router is the entry point for all challenge purchases on HYPERPNL.

When a user purchases a funded account, the payment is sent directly to the Payment Router smart contract. This contract determines how the funds are split and where they are allocated.

#### <mark style="color:$warning;">**Payment Split**</mark>

Each purchase is split into three possible parts.

1. **Payout Reserve**\
   Funds reserved to cover future trader payouts.
2. **Protocol Revenue**\
   Revenue allocated to the protocol for long-term sustainability.
3. **Referral Fee**\
   A share paid to the referrer if the user was referred by another user.

If no referrer exists, the referral portion is not applied.

{% @mermaid/diagram content="flowchart LR
U\[User Purchase] --> PR\[Payment Router]

```
PR --> PT[Payout Reserve]
PR --> REV[Protocol Revenue]
PR --> REF[Referral Fee]
```

" %}

#### <mark style="color:$warning;">**Dynamic Allocation via Payout Stress Factor (PSF)**</mark>

The allocation between the Payout Treasury and Protocol Revenue is not fixed.

It is determined dynamically using the **Payout Stress Factor (PSF)**, which reflects the health of the payout reserves relative to expected obligations.

As the payout treasury grows and the system becomes safer, a larger portion of incoming payments is redirected from the treasury to protocol revenue.

#### <mark style="color:$warning;">**Payout Stress Factor Thresholds**</mark>

The protocol is considered **Safe** when **PSF > 4** and **Super Safe** when **PSF > 8**.<br>

<p align="center"><span class="math"> \text{Payout Stress Factor} = \frac{\text{Payout Reserve}}{\text{Predicted Payout}} </span></p>

$$
\text{Predicted Payout}
=======================

\left(
N\_{p1} \cdot \pi\_{p1}
\+
N\_{p2} \cdot \pi\_{p2}
\+
N\_{f} \cdot \pi\_{f}
\right)
\cdot \bar{\rho}
\cdot C\_{\text{total}}
$$

$$
\pi\_{p1} = \alpha\_{p1} \cdot \alpha\_{p2} \cdot \alpha\_{po}
\quad\quad
\pi\_{p2} = \alpha\_{p2} \cdot \alpha\_{po}
\quad\quad
\pi\_{f} = \alpha\_{po}
$$

$$
\begin{aligned}
N\_{p1} &= \text{Active Phase 1 Traders} \\
N\_{p2} &= \text{Active Phase 2 Traders} \\
N\_{f}  &= \text{Active Funded Traders} \\
\alpha\_{p1} &= \text{Phase 1 Pass Rate} \\
\alpha\_{p2} &= \text{Phase 2 Pass Rate} \\
\alpha\_{po} &= \text{Payout Success Rate} \\
\bar{\rho} &= \text{Average Payout Percentage} \\
C\_{\text{total}} &= \text{Total Capital}
\end{aligned}
$$

#### <mark style="color:$warning;">**Allocation Table**</mark>

| Payout Stress Factor | Payout Reserve | Protocol Revenue |
| -------------------- | -------------- | ---------------- |
| 0.00                 | 100%           | 0%               |
| 2.00                 | 67%            | 33%              |
| 4.00                 | 36%            | 64%              |
| 6.00                 | 20%            | 80%              |
| 8.00                 | 0%             | 100%             |
