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

# Flows overview

> The life cycle of an Anafi account, the two account kinds side by side, and who pays the gas in each step.

After this page, you know each step in the life of an account, which SDK call does it, and which party pays its gas. Each step links to the page with the full flow.

## The life cycle

```mermaid theme={null}
sequenceDiagram
    autonumber
    participant W as Owner wallet
    participant A as Your app (SDK)
    participant API as Anafi API
    participant E as Anafi engine (black box)
    participant C as Chain
    A->>C: Choose or predict the account (read code, Safe owners)
    A->>API: Stage: sealed rule document
    API->>E: Relay the sealed document
    E-->>A: Commitment, engine attestation, deadline, findings
    W->>C: Grant the permission (ERC20Allow: approve per token)
    W->>C: Commit: AnafiDslRegistry.commitDsl (Safe: enableModule in the same Safe transaction)
    E->>C: Rule fires: adapter.redeemAsEngine(...)
    A->>API: Read activity
    W->>C: Update (new commit), pause, or revoke
    A->>API: Read back the document (signed sign-in)
```

| Step | What happens | Safe (`safe_module`) | Plain address (`erc20_allow`) | Page |
| - | - | - | - | - |
| Create or choose the account | Find the account that the rules act for. | `predictSafe`, `provisionPredictedSafe`, or a Safe that already exists | The connected address itself, `classifyErc20AllowAccount` | [Safe](https://docs.ana.fi/flows/safe-account.md), [ERC20Allow](https://docs.ana.fi/flows/erc20-account.md) |
| Grant the permission | Let the adapter move funds of the account. | `enableModule(adapter)` on the Safe, in the same Safe transaction as the first commit | `approve(adapter, max)` on each token that the document spends | same |
| Stage | Encrypt the document to the engine. The engine checks it and signs an attestation. | `stageDsl` | `stageErc20AllowDsl` | same |
| Commit | Put the salted hash of the document on chain. | `commitStagedDsl`, one Safe transaction | `commitStagedErc20AllowDsl`, plain transactions | same |
| Runs | The engine fires the rules and pays through the adapter. | `redeemAsEngine` on `AnafiDelegationAdapterSafe` | `redeemAsEngine` on `AnafiDelegationAdapterERC20Allow` | [Execution](https://docs.ana.fi/flows/execution.md) |
| Update | Replace the whole document. | `commitDslFromSafe`, or `stageDsl` with `write: "update"` | stage and commit again | [Update, pause, revoke](https://docs.ana.fi/flows/update-pause-revoke.md) |
| Pause | Stop payments, keep the permission. | Commit a document with `enabled: false` rules or with no rules | `setErc20AllowBlocked`, or commit a new document | same |
| Revoke | Remove the permission. | `disableSafeModule` | `revokeErc20Allowances` | same |
| Read back | Get the plaintext document and the account state. | `recover` | `recover` | [Read-back](https://docs.ana.fi/flows/read-back.md) |

A commit always replaces the whole rule document of the account. Each account holds one document, and the document holds all its rules.

## The two account kinds

| | Safe (`safe_module`) | Plain address (`erc20_allow`) |
| - | - | - |
| Account | A Safe with threshold 1 that the owner controls | An address with no code, or with an EIP-7702 pointer |
| Adapter | `AnafiDelegationAdapterSafe` | `AnafiDelegationAdapterERC20Allow` |
| Permission | The Safe enables the adapter as a module | The address approves the adapter on each token |
| Tokens that a rule can pay | ERC-20 tokens and the native coin | ERC-20 tokens only |
| Swaps (`exchange`) | Where the engine serves swaps on the network | Only when the adapter has a swap executor, and only ERC-20 to ERC-20 |
| Bank payout (`off_ramp`) | Yes, on `polygon-amoy` only | No |
| Owner controls | Enable or disable the module | Approvals, per-token caps, and a block switch |
| Wallet prompts for the first commit | One deploy transaction when the owner sends the deploy, then one prompt for the commit (EIP-712 typed data when relayed, a transaction when owner-sent) | One transaction per approval, then one commit transaction |
| Revoke | One Safe transaction: `disableModule` | One `approve(adapter, 0)` per token |

See [Accounts](https://docs.ana.fi/concepts/accounts.md) for the model behind the two kinds, and [Contracts](https://docs.ana.fi/contracts/overview.md) for the contracts.

## Who pays the gas

The SDK decides per step. It never asks you to choose, except for `executeSafeOwnerCalls`, which takes `ownerSent: true`.

| Step | Safe account | ERC20Allow account |
| - | - | - |
| Deploy the predicted Safe | Relayed by Anafi, or sent by the owner | Not applicable |
| Enable module, commit, update | Relayed by Anafi, or sent by the owner | Sent by the account, always |
| Approvals, caps, block switch | Not applicable | Sent by the account, always |
| Revoke | Relayed by Anafi, or sent by the owner | Sent by the account, always |
| Rule payments (`redeemAsEngine`) | Anafi submits the transaction and pays the chain gas. The adapter charges the account a gas charge, which can be zero. | Same |

For a Safe owner operation, the SDK reads `GET /api/wallets/{account}/sponsorship` (`fetchWalletSponsorship`). The answer is `{ feesOn, sponsored }`.

* When `feesOn` is `false`, or `sponsored` is `true`, Anafi relays the operation and pays its gas. The owner signs an EIP-712 `SafeTx` message. The SDK sends it to `POST /api/wallets/{account}/safe/sponsor_exec`, or for a deploy to `POST /api/wallets/provision`.
* In each other case, the owner address sends the transaction and pays its gas. For a Safe transaction, the owner sends `execTransaction` to the Safe with a pre-validated signature, so the wallet shows one transaction prompt and no typed-data prompt.
* For a revoke, a failed sponsorship read selects the owner-sent path. The SDK then refuses only when the owner address holds no gas.

The SDK never relays an ERC20Allow operation, and the ERC20Allow methods read no sponsorship. Read the fee terms with `fetchFeeTerms` (`GET /api/fees`). See [Fees](https://docs.ana.fi/concepts/fees.md).

## Where your code can run

Today, the Anafi API hosts send the CORS header `Access-Control-Allow-Origin` only for `https://app.ana.fi`. A browser page on another origin cannot call the Anafi API directly. A server, a script, or your own same-origin proxy can. Chain reads and owner-sent transactions do not go through the Anafi API, so this limit does not apply to them.

The two sign-in flows, `recover` and the notification-email code request, are accepted only when the EIP-4361 message names the domain of the Anafi dapp, `app.ana.fi`. The Anafi API refuses a sign-in for another domain with `422`. An integration on another domain cannot complete these two flows today.

## Flow pages

> [card] [Safe account](https://docs.ana.fi/flows/safe-account.md)
>
> Predict, provision, stage, and commit for a Safe.

> [card] [ERC20Allow account](https://docs.ana.fi/flows/erc20-account.md)
>
> Approvals, caps, block switch, stage, and commit.

> [card] [Update, pause, revoke](https://docs.ana.fi/flows/update-pause-revoke.md)
>
> Replace a document, stop payments, and leave.

> [card] [Execution](https://docs.ana.fi/flows/execution.md)
>
> The redeem transaction and the activity feed.

> [card] [Read-back](https://docs.ana.fi/flows/read-back.md)
>
> Recover the plaintext document and the account state.

> [card] [Notification email](https://docs.ana.fi/flows/notification-email.md)
>
> Verify an inbox for `notify` actions.

> [card] [Payments and subscriptions](https://docs.ana.fi/flows/payments-and-subscriptions.md)
>
> One-time payments and monthly payments from a pay page.

> [card] [Bank payouts](https://docs.ana.fi/flows/bank-payouts.md)
>
> Pay a bank account from a Safe on Polygon Amoy.


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