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

# Limits

> Every limit that a rule document can declare, how each one bounds what the engine can do, and the on-chain caps of an erc20_allow account.

After you read this page, you can bound what a rule document allows, and you know which bounds the document sets and which bounds the chain enforces.

Limits come from three places:

| Place | Set by | Checked | Result of a breach |
| - | - | - | - |
| The document: allowlists, amounts, ranges, time bounds | the owner, in the YAML | by the engine, at staging and again at the commit | The document is refused before the owner signs it. |
| The permission: the Safe module, or the ERC-20 allowance and caps | the owner, on chain | by the adapter contract, at each payment | The payment reverts. |
| The revoke: disable the module, set the block switch, or remove the allowance | the owner, on chain | by the adapter contract | Every later payment reverts. |

This page describes the document limits and the settings of an `erc20_allow` account. The checks of each contract are on [Contracts overview](https://docs.ana.fi/contracts/overview.md) and [Redeem](https://docs.ana.fi/contracts/redeem.md).

## Allowlists

Each allowlist is optional. When it is absent, it sets no limit. When it is present, it must have at least one entry. `[]` is refused, because it looks like "nobody" and would mean "anybody".

The engine checks the allowlists when it stages the document, and again when the commit lands. A rule that breaks an allowlist is refused. It does not wait for a fire.

### global.token\_allowlist

```yaml theme={null}
global:
  token_allowlist: [USDC, WETH]
```

Every token that the document names must be on the list:

| Where the token occurs | Example |
| - | - |
| Each literal amount in `send_one`, `send_batch`, `exchange.in` and `off_ramp` values | `"100 USDC"` |
| `exchange.out` | `out: WETH` |
| The token of a transfer trigger range | `value: "100.. USDC"` |
| `price_crossed.token` | `token: WETH` |
| The fee token: `fees_method.token`, or the native coin without `fees_method` | `POL` on `polygon` |

A transfer trigger without a range watches only the tokens on the list. So `trigger.value` in such a rule is always a token on the list.

Refusal texts:

* `rule '<rule>': token '<TOKEN>' not in global.token_allowlist`
* `global.token_allowlist does not contain fee token <TOKEN>`

Each entry must also be a token of the network. The stage refuses another entry with `global.token_allowlist: <TOKEN> is not a token on <network name>.`

> [!WARNING]
>
> Add the fee token to `token_allowlist`. Without `fees_method`, the fee token is the native coin, such as `POL` or `OKB`. A list without it refuses the document.

### global.recipient\_allowlist

```yaml theme={null}
variables:
  landlord: "0x1111111111111111111111111111111111111111"
global:
  recipient_allowlist: ["$landlord"]
```

Every `to` of `send_one` and of each `send_batch` item must be on the list. The engine replaces each `$name` with its value first, so `"$landlord"` and the literal address match.

The comparison uses the exact text after that replacement. Write an address in the same letter case on the list and in the actions, or refer to one variable in both places.

The list does not apply to:

* the `account`, `from` and `to` filters of transfer triggers, which watch and do not pay,
* `exchange`, which pays the account itself,
* `off_ramp`, which uses `iban_allowlist`.

Refusal text: `rule '<rule>': address '<address>' not in global.recipient_allowlist`. The address is shown as the document writes it.

### global.iban\_allowlist

```yaml theme={null}
variables:
  landlord_iban: "DE89370400440532013000"
global:
  iban_allowlist: ["$landlord_iban"]
```

Every `off_ramp.to.iban` must be on the list. The comparison works like `recipient_allowlist`. Refusal text: `rule '<rule>': IBAN '<iban>' not in global.iban_allowlist`.

The engine checks this list at staging and again at the commit. The Safe can keep a second list of IBANs on chain, in the off-ramp policy of its fallback handler. Nothing keeps the two lists equal. See [Off-ramp handler](https://docs.ana.fi/contracts/off-ramp-handler.md).

## Amounts as limits

The language has no budget, no counter and no sum per day or per month. Each action value is its own limit: the action pays what the expression computes, and no more.

| Need | Write |
| - | - |
| A fixed amount | `value: "100 USDC"` |
| A share with a maximum | `value: "min(trigger.value * 20%, 100 USDC)"` |
| A share with a minimum | `value: "max(trigger.value * 1%, 1 USDC)"` |
| Only payments of a size | `value: "10..500 USDC"` on the trigger |
| Only payments from one sender | `from: "$employer"` on the trigger |

A transfer trigger fires on each transfer that passes its filters, with no limit in time. A rule with `account` fires at most once per block. To bound the total over time, use the on-chain caps of an `erc20_allow` account, or keep only the funds that you want to automate in the account.

## Time limits

| Field | Effect |
| - | - |
| `enabled: false` | The rule never fires. |
| `start` | The rule does not fire before this instant. |
| `expiry` | The rule does not fire after this instant. |
| `price_crossed.cooldown_seconds` | Two fires of the rule are at least this far apart. |
| `price_crossed.hold_seconds` | The price must stay past the level this long. |

See [start and expiry](https://docs.ana.fi/rules/document.md#start-and-expiry) and [price\_crossed](https://docs.ana.fi/rules/triggers.md#price_crossed).

## What the language does not have

These do not exist. A document that names one is refused as an unknown field:

* a budget per rule, per token or per period,
* a maximum number of fires,
* a slippage field on `exchange`,
* an approval step before a fire,
* a cap in `agent_envelope` that the engine enforces. The engine accepts `agent_envelope` and enforces none of its fields.

## Structural limits

| Limit | Value |
| - | - |
| Length of the document | 65536 bytes |
| Nesting depth | 32 levels |
| YAML anchors and aliases | none |
| Rules per document | 32 |
| Length of one value expression | 256 bytes |
| Recipients in one `send_batch` | 24 |
| `periodic.interval_seconds` | 10 to 3153600000 |
| `off_ramp.memo` | 5 to 140 characters |
| Decimals in a literal number | 18 |

The refusal texts are on [Validation](https://docs.ana.fi/rules/validation.md).

## A safe\_module account

For a Safe, the adapter is a Safe module that the owner enables. The checks of the module are on [Safe adapter](https://docs.ana.fi/contracts/safe-adapter.md).

The owner stops all automation with one Safe transaction: disable the module. See [Update, pause and revoke](https://docs.ana.fi/flows/update-pause-revoke.md).

## On-chain limits of an erc20\_allow account

For a plain address, the adapter pulls ERC-20 tokens with `transferFrom`. Three on-chain settings bound it, all set by the owner and all readable by anyone:

| Setting | Set with | Read with | Effect |
| - | - | - | - |
| Allowance | `approve(adapter, amount)` on each token | `allowance(owner, adapter)` on the token | The adapter can pull at most this amount of the token, in total. |
| Cap | `setCaps(entries)` on the adapter | `capOf(account, token)` on the adapter | The adapter can pull at most `limit` base units of the token in each window of `periodSeconds`. |
| Block switch | `setBlocked(true)` on the adapter | `isBlocked(account)` on the adapter | The adapter refuses every payment of the account. |

### Caps

A cap entry has three fields: `token`, `limit` (base units) and `periodSeconds`.

* `periodSeconds` must be at least 3600 (`MIN_CAP_PERIOD_SECONDS`). A shorter period reverts the whole call with `CapPeriodTooShort(periodSeconds)`.
* The windows are fixed. A window is the time from `k × periodSeconds` to `(k + 1) × periodSeconds` in Unix seconds. They do not start when you call `setCaps`.
* Each pull of the token counts against the cap: each transfer of a send, the input of a swap, and the gas charge when the token pays the fee. For the gas charge, the adapter counts the maximum charge first and releases the unused part after the payment.
* A leg pull that does not fit in the rest of the window makes every leg of the payment fail with `CapExceeded(owner, token)`. No leg of that payment happens, and the gas charge is still paid. A gas reservation that does not fit reverts the whole redeem with the same error, before any leg and any charge.
* `setCaps` with the same `periodSeconds` in the same window keeps the amount already spent. Another call starts the count at zero.
* `clearCaps(tokens)` removes the caps. A token without a cap has no window limit, only its allowance.
* `capOf` returns `(isSet, limit, periodSeconds, spentInPeriod)`. `spentInPeriod` is 0 after its window ends.

Each function acts on the caps of the caller only.

### Choose the caps from the document

The adapter pulls these tokens for a document: the token of each send, the sold token of each exchange, and the fee token. The SDK function `erc20AllowDocumentTokenSymbols` returns this list, and `readErc20AllowDocumentTokens` returns it with the contracts. Give each of these tokens an allowance. Set a cap on each token where you want a limit in time.

For example, a document that pays 1500 USDC on the 1st of each month, with `fees_method` in `USDC`, can run under a `USDC` cap of a little more than 1500 USDC per 31 days (`periodSeconds: 2678400`). Because the windows are fixed, a 31-day window does not follow calendar months. Leave room for two payments in one window, or accept that a payment can revert.

See [ERC20Allow adapter](https://docs.ana.fi/contracts/erc20-allow-adapter.md) for every function and error, and [ERC20Allow in the SDK](https://docs.ana.fi/sdk/erc20-allow.md) for the calls that build these transactions.


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