# Rate limits

> How Truss vaults limit how fast money can move into sub-accounts, through swaps, into lending and out through instant withdrawals, and which limits can change.

Source: https://docs.trusslabs.io/vaults/architecture/rate-limits

A rate limit caps how much can move in a period of time. It means one bad key, bad price or bad venue cannot move
everything at once. A Truss vault meters money going into sub-accounts, through swaps, into lending venues and out
through instant withdrawals. Each limit is set when the vault is deployed and can change later.

> **Key points**
>
> - Every rate limit is a bucket with a capacity that refills at a fixed rate each second.
> - A bucket starts at zero, which refuses that flow until it is raised.
> - Raising a limit waits the HIGH tier; lowering one is immediate.
> - Limits slow a flow down. They do not decide whether the flow is a good idea.

## How a bucket works

A bucket has a capacity and a refill rate per second. Each flow uses up part of the capacity, which refills over
time back up to the full amount. A flow larger than what is available is refused with `RateLimited`, and nothing
moves. A bucket at zero refuses every flow.

Because a full bucket can be drained and then matched by its refill, the most a flow can take in one refill period
is about twice the capacity. Lowering a capacity also lowers what is left to use. A bucket can be set to unlimited,
with no refill rate, which turns it off.

## What can be limited

| Flow | Bucket | Unit |
|---|---|---|
| Pushes into a sub-account | One per sub-account | USDC |
| Swaps | One in and one out, per sub-account and token | That token |
| Supply to a lending venue | One per sub-account and venue | The venue's asset |
| Instant withdrawals | One window per vault | A share of net assets |

Each sub-account also has a cap on its net deployed principal: what the vault pushed in, less what came back. It
counts principal, not value, so a sub-account that performs well is not capped out.

A swap is metered after it runs, on what the sub-account measured: what left counts against the outbound bucket of
that token, and what arrived against the inbound bucket of the other. Withdrawing from a lending venue is never
metered, so a limit never keeps a vault from leaving a venue.

The instant window is charged each instant withdrawal's share of net assets, rounded up, so a run of small
withdrawals cannot take more than the window holds.

For example, the committed preprod Base config gives its sub-account a push bucket and a supply bucket per venue of
5,000 USDC, each refilling over one day, and starts the instant window at zero.

## Deposits and withdrawals

Deposits are limited by the deposit cap, which caps the total net principal settled into the vault. It is a cap,
not a bucket, so it does not refill. Settled redemptions are not rate-limited, and bringing capital back from a
sub-account with `returnAssetsToVault` is never limited either. The instant path has its own window, above.

## The levers

| Limit | Raised by, after HIGH | Lowered at once by |
|---|---|---|
| Push buckets and sub-account caps | VaultAdmin | Sentry, VaultAdmin |
| Swap buckets | VaultAdmin | Sentry, VaultAdmin |
| Lending supply buckets | VaultAdmin | Sentry, VaultAdmin |
| Instant window | VaultAdmin | Vault managers, Sentry, VaultAdmin |
| Deposit cap | VaultAdmin | Vault managers, Sentry, VaultAdmin |

Each bucket's capacity and refill rate are separate levers. The deployer sets every bucket and cap when the vault is
deployed, and the factory caps the highest any sub-account cap and the deposit cap can ever be raised to.

## Where to read more

| Page | What it covers |
|---|---|
| [Sub-account policies](https://docs.trusslabs.io/vaults/policies/sub-account-policies.md) | Where each bucket is checked |
| [What can change after deployment](https://docs.trusslabs.io/vaults/overview/what-can-change.md) | Every lever and its tier |
| [Instant withdrawals](https://docs.trusslabs.io/vaults/flow-of-funds/instant-withdrawals.md) | How the instant window is used |
| [Deployment parameters](https://docs.trusslabs.io/vaults/reference/deployment-parameters.md) | The factory's limits |
