> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fade.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Reward tables

> The invariant in exact integers, how to size a reward against the vault, and the common refusals.

A reward table is an array of 1 to 32 reward levels `{ p, m }`:

* `p`: probability as a `u64` in billionths. Every `p` is greater than zero, and they sum to **exactly** 1 000 000 000.
* `m`: multiplier as a `u64` in basis points of the cost. 10 000 is 1×, 0 pays nothing, and the ceiling is 100 000 000 (10 000×).

A level's reward is `cost × m / 10 000`, rounded down, in USDC base units.

## The invariant

`open_entry` computes, in 128-bit integers with no rounding:

```
lhs = Σ p_i · m_i
```

and admits the reward table only if, for the app share `f` it passes and the app's protocol share `s`:

```
lhs ≤ (10 000 − 100 − s − f) · 1 000 000 000
```

That is the **margin floor**: the declared margin must cover the 100 bps vault margin floor, the protocol share and the app's own share. `s` is 200 bps at the base and falls to 100 bps with the app's cumulative volume; the program resolves it once per open, and the same `s` is used for the split and the cap ([Protocol share tiers](https://docs.fade.finance/build/fees.md#protocol-share-tiers)). At the base and with no app share, the floor is `lhs ≤ 9 700 × 1e9`, a 3 % margin. The program also derives the declared margin it stores in the entry:

```
margin_bps = 10 000 − ceil(lhs / 1 000 000 000)
vault_margin_bps     = margin_bps − f − s
```

No floating-point value is involved anywhere, and your client should not use one either. Build reward tables in `bigint`.

> [!TIP]
>
> Round in the vault's favour: round probabilities down, and if you round a multiplier up, derive the probability from the rounded multiplier. Put the remainder of 1 000 000 000 on the zero level so the sum is exact.

## Examples

**Reward or nothing.** For a target reward `T` on cost `s` at margin `e` bps:

```ts theme={"dark"}
const m = (T * 10_000n + s - 1n) / s;          // round up so the reward is at least T
const p = ((10_000n - e) * 1_000_000_000n) / m; // round down to keep the margin
const rewardTable = [{ p, m }, { p: 1_000_000_000n - p, m: 0n }];
```

**Three levels at a 3 % margin.**

| Level | `p` | `m` | `p · m` |
| - | - | - | - |
| 10× | 50 000 000 | 100 000 | 5.000 × 10¹² |
| 0.9× | 450 000 000 | 9 000 | 4.050 × 10¹² |
| 0.13× | 500 000 000 | 1 300 | 0.650 × 10¹² |
| | 1 000 000 000 | | 9 700 × 10⁹ |

**Refused: pays more in rewards than it takes in costs.** `[{ p: 500_000_000n, m: 21_000n }, { p: 500_000_000n, m: 0n }]` returns 105 % on average. `open_entry` fails with `RewardTableOverpays`.

**Refused: fair, but the margin does not cover the split.** A reward table with a 2.5 % margin and no app share, opened by an app at the base protocol share, is fair but leaves the vault less than its 100 bps floor once the 200 bps protocol share is taken. `open_entry` fails with `MarginFloor`. The same table opens for an app whose volume has brought its protocol share to 150 bps or less.

## How much a vault can back

The vault reserves each entry's **liability**, its worst case net of what the cost brought in:

```
vault_credit = cost − protocol_share − app_share
max_reward   = cost × max(m) / 10 000
liability    = max_reward − vault_credit
```

Admission then checks, against the vault as it stands at open:

| Check | Rule | Refusal |
| - | - | - |
| Per-entry cap | `liability ≤ min(0.5 × vault_margin × free_balance, 150 bps × assets)` | `PerEntryCap` |
| App ceiling | the app's open liability, this entry included, `≤ 20 % × assets` | `IntegratorCap` |
| Utilisation | `(reserved + open credits) < 70 % × assets`, after this entry | `UtilisationBreaker` |
| Global exposure | `reserved ≤ 80 % × assets`, after this entry | `GlobalExposure` |
| Gross solvency | `reserved + open credits ≤ assets` | `Insolvent` |

`free_balance = assets − reserved liability − open vault credits`. The per-entry cap uses the **vault margin**, net of shares, so inflating the declared margin does not widen it, and every basis point of app share narrows it. After a drawdown trip the cap is halved for 48 hours.

### Sizing a reward

Two consequences matter for an interface:

1. **Only the top multiplier costs capital.** A reward table that pays something 90 % of the time can be trivial to back; a single large reward decides what the vault must hold.
2. **The cap bounds the liability, not the multiplier.** On a fixed reward table, a cap `C` admits a cost of about `C / (max(m) − 1)`.

On an idle vault with a 3 % declared margin, the smallest a reward table can declare at the base protocol share, and no app share (vault margin 100 bps), the Kelly term binds first: 0.5 × 100 bps is 50 bps of the free balance, below the 150 bps bound on assets. The smallest vault that carries a reward-or-nothing entry is roughly `liability / 0.005`, with a vault credit of the cost less its 2 % protocol share:

| Cost | Reward | Liability | Vault needed, idle (USDC) |
| - | - | - | - |
| 1 USDC | 10 USDC | 9.02 | about 1 850 |
| 2 USDC | 19.40 USDC | 17.44 | about 3 500 |
| 1.92 USDC | 185.90 USDC | 184.02 | about 36 850 |
| 6.45 USDC | 622.44 USDC | 616.12 | about 123 250 |
| 7.5 USDC | 7 500 USDC (1 000×) | 7 492.65 | about 1.5 million |

An app whose volume has lowered its protocol share and that declares the smallest margin it may, 100 bps above its own share, has the same 100 bps vault margin and needs about the same vaults: only the vault credit grows, by the share the tier takes off (at the 100 bps tier, the first row's liability is 9.01 USDC).

> [!NOTE]
>
> The minimum margin returns the most reward per unit of budget and is the most demanding margin for capacity. Its vault margin is 100 bps, so the Kelly term of the per-entry cap is 50 bps of the free balance, against 75 bps at the app's 3.5 % margin at the base protocol share (vault margin 150 bps). For the same liability, every vault size here is 1.5 times what a 3.5 % reward table needs at the base, and a given vault backs a top reward about two thirds as large: large top rewards at the minimum margin need a larger vault. A tier raises the vault margin of the same declared margin: at the 100 bps tier, 3.5 % leaves 250 bps and a Kelly term of 125 bps. Above a 5 % margin with no app share at the base protocol share, or above 4 % at the 100 bps tier, the 150 bps bound on assets binds first on an idle vault.

A table whose top level is above 100× resolves on the VRF route rather than by commit-reveal ([Settlement and keepers](https://docs.fade.finance/build/settlement.md#two-routes-chosen-by-the-program)); the caps are the same on both routes. Between an epoch's close and its strike, a commit-reveal entry is sized on the assets that stay in the vault, without the withdrawals queued for that strike.

As the vault fills up, the free balance shrinks with it, so the largest reward the vault accepts falls as utilisation rises.

### Show the limit, do not hit it

Read `Config` (for the parameters) and `Vault` (for `totalAssets`, `totalReservedLiability`, `openVaultCredits`) and apply the checks above in integers to show users the largest reward, or the largest cost, the vault accepts right now. Then simulate the transaction before asking for a signature: the program is the authority, and the vault can move between your read and the user's click.

```ts theme={"dark"}
import { fetchConfig, fetchVault, findConfigPda, findVaultPda } from "./generated/fade";
import { protocolShareBps } from "./protocol-share"; // from Margin and shares, "Read your own rate"

const params = (await fetchConfig(rpc, (await findConfigPda(cfg))[0])).data.params;
const vault = (await fetchVault(rpc, (await findVaultPda(cfg))[0])).data;

const free = vault.totalAssets - vault.totalReservedLiability - vault.openVaultCredits;
const marginBps = 300n; // the reward table's declared margin
const appShareBps = 0n;
const protocolBps = await protocolShareBps(appAddress); // the rate of the wallet that signs as the app
const vaultMarginBps = marginBps - appShareBps - protocolBps;
const kelly = (((free * vaultMarginBps) / 10_000n) * params.exposureFractionBps) / 10_000n;
const flat = (vault.totalAssets * params.censorshipBps) / 10_000n;
const cap = kelly < flat ? kelly : flat; // largest liability one entry may take now
```

## Common refusals

| Error | Cause | Fix |
| - | - | - |
| `LevelCount` | 0 or more than 32 levels | Group levels that share a multiplier |
| `ProbabilityRange` | A `p` of 0, or above 1e9 | Remove unreachable levels |
| `ProbabilitySum` | Probabilities do not sum to exactly 1e9 | Put the remainder on the zero level |
| `RewardCeiling` | A multiplier above 10 000× | Lower the top reward |
| `RewardTableOverpays` | Expected return above 100 % | Lower probabilities or multipliers |
| `MarginFloor` | Margin below 100 bps + your protocol share + app share (300 bps + app share at the base) | Raise the margin or lower the app share |
| `AppShareTooHigh` | App share above 500 bps | Lower it |
| `CostBounds` | Cost below `min_cost` or above `max_cost` | See [Devnet addresses and parameters](https://docs.fade.finance/build/devnet.md) |
| `PerEntryCap` | Liability above the cap | Smaller top reward, lower cost, lower app share, or a larger vault |
| `IntegratorCap` | Your open liability above 20 % of assets | Wait for your open entries to resolve |
| `UtilisationBreaker` | The vault would be 70 % committed or more | Wait; new entries resume as entries resolve |

The full list is on [Errors](https://docs.fade.finance/build/errors.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.