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

# Examples

> Complete rule documents for real use cases, each with its meaning and the networks and account kinds where it runs.

After you read this page, you can start from the example closest to your use case and change it.

Each document on this page passes the parser and the type checks of the engine. Each note says on which network and for which account kind the stage accepts it. Replace the example addresses with real ones before you stage a document. Never use the account itself or the zero address as a recipient.

Most examples set `global.fees_method` to `USDC`. That makes them valid for both account kinds: an `erc20_allow` account needs an ERC-20 fee token, and a `safe_module` account accepts it too. A Safe can remove the `global` block and pay the fees in the native coin.

## Standing order

Pay 1200 USDC to the landlord on the 1st of each month at 09:00 Berlin time.

```yaml theme={null}
variables:
  landlord: "0x1111111111111111111111111111111111111111"

global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  dapp_standing_order_a1b2c3:
    trigger:
      type: calendar
      day_of_month: [1]
      time_of_day: "09:00"
      timezone: "Europe/Berlin"
    actions:
      - type: send_one
        to: "$landlord"
        value: "1200 USDC"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | Use `day_of_month: [28]` or lower to fire in every month. |

## Payroll batch

Pay three people on the 25th of each month, all in one transaction, and only to listed addresses.

```yaml theme={null}
variables:
  alice: "0x1111111111111111111111111111111111111111"
  bob: "0x2222222222222222222222222222222222222222"
  carol: "0x3333333333333333333333333333333333333333"

global:
  fees_method: { type: fixed_token, token: USDC }
  recipient_allowlist: ["$alice", "$bob", "$carol"]

rules:
  monthly_payroll:
    trigger:
      type: calendar
      day_of_month: [25]
      time_of_day: "10:00"
      timezone: "Europe/Lisbon"
    actions:
      - type: send_batch
        recipients:
          - { to: "$alice", value: "4200 USDC" }
          - { to: "$bob", value: "3800 USDC" }
          - { to: "$carol", value: "2500.50 USDC" }
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | If the account holds less than 10500.50 USDC, nobody is paid. At most 24 recipients. |

## Savings split

When the employer pays between 1000 and 20000 USDC, send 20% to savings and 10% to a brokerage. The rest stays in the account.

```yaml theme={null}
variables:
  employer: "0x4444444444444444444444444444444444444444"
  savings: "0x5555555555555555555555555555555555555555"
  brokerage: "0x6666666666666666666666666666666666666666"

global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  split_salary:
    trigger:
      type: incoming_tx
      from: "$employer"
      value: "1000..20000 USDC"
    actions:
      - type: send_batch
        recipients:
          - { to: "$savings", value: "trigger.value * 20%" }
          - { to: "$brokerage", value: "trigger.value * 10%" }
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | The range fixes the token of `trigger.value` to `USDC`. That is required for `erc20_allow`. |

## Tax set-aside

Move 25% of each USDC arrival to a tax reserve, at most 2500 USDC per arrival.

```yaml theme={null}
variables:
  tax_reserve: "0x7777777777777777777777777777777777777777"

global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  set_aside_tax:
    trigger:
      type: incoming_tx
      value: "0.. USDC"
    actions:
      - type: send_one
        to: "$tax_reserve"
        value: "min(trigger.value * 25%, 2500 USDC)"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | `"0.. USDC"` watches every USDC arrival above the minimum transfer of the network. Without the range, `min` would run only on USDC arrivals and skip others. |

## Auto-convert on arrival

Swap each arrival of 10 USDT0 or more to USDC.

```yaml theme={null}
global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  usdt0_to_usdc:
    trigger:
      type: incoming_tx
      value: "10.. USDT0"
    actions:
      - type: exchange
        in: "trigger.value"
        out: USDC
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer` | both | Not on `polygon-amoy`: no swap venue, and no `USDT0`. The output of the swap does not fire the rule again. |

## Dollar-cost average (DCA)

Buy WETH for 50 USDC every Friday at noon New York time, during 2027 only.

```yaml theme={null}
global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  dapp_dca_528aff:
    trigger:
      type: calendar
      day_of_week: ["fri"]
      time_of_day: "12:00"
      timezone: "America/New_York"
    actions:
      - type: exchange
        in: "50 USDC"
        out: WETH
    start: "2027-01-01T00:00:00Z"
    expiry: "2027-12-31T23:59:59Z"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon` | both | `WETH` exists only on `polygon`. On `xlayer`, use `out: xETH`. |

## Stop-loss with a price trigger

Sell 0.5 WETH for USDC when the WETH price falls to 2000 USD or less and stays there for 5 minutes. At most one sale per day. The rule ends after June 2027.

```yaml theme={null}
global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  weth_stop_loss:
    trigger:
      type: price_crossed
      token: WETH
      direction: below
      price_usd: 2000
      hold_seconds: 300
      cooldown_seconds: 86400
    actions:
      - type: exchange
        in: "0.5 WETH"
        out: USDC
    expiry: "2027-06-30T23:59:59Z"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon` | both | If WETH is already at or below 2000 USD when the engine adopts the document, the rule waits for the price to rise above the level and fall again. |

## Take profit on X Layer

When xBTC stays at or above 80000 USD for 10 minutes, send 0.01 xBTC to an exchange deposit address and send an email.

```yaml theme={null}
variables:
  exchange_deposit: "0x8888888888888888888888888888888888888888"

global:
  fees_method: { type: fixed_token, token: USDT0 }

rules:
  btc_take_profit:
    trigger:
      type: price_crossed
      token: xBTC
      direction: above
      price_usd: 80000
      hold_seconds: 600
      cooldown_seconds: 86400
    actions:
      - type: send_one
        to: "$exchange_deposit"
        value: "0.01 xBTC"
      - type: notify
        channel: email
        message: "xBTC stayed above 80000 USD: 0.01 xBTC sent to the exchange"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `xlayer` | both | The stage gives warning 4: the document has no `global.notification_email`, so the email is not delivered. The send still runs. |

## Reimbursement

Each time a partner account pays between 1 and 500 USDC, pay the partner back half of it.

```yaml theme={null}
variables:
  partner: "0x9999999999999999999999999999999999999999"

global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  reimburse_half:
    trigger:
      type: outgoing_tx
      account: "$partner"
      value: "1..500 USDC"
    actions:
      - type: send_one
        to: "$partner"
        value: "trigger.value * 50%"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | The partner can fire the rule at will. Commit it only for a partner that you trust. The rule fires at most once per block. |

## Bank payout

Pay rent of 1500 euros to a person's bank account on the 1st of each month. Send each EURe arrival of 100 EURe or more to a company bank account.

```yaml theme={null}
variables:
  landlord_iban: "DE89370400440532013000"
  savings_iban: "GB82WEST12345698765432"

global:
  token_allowlist: [EURe, POL]
  iban_allowlist: ["$landlord_iban", "$savings_iban"]

rules:
  rent_to_bank:
    trigger:
      type: calendar
      day_of_month: [1]
      time_of_day: "09:00"
      timezone: "Europe/Berlin"
    actions:
      - type: off_ramp
        provider: monerium
        value: "1500 EURe"
        to:
          iban: "$landlord_iban"
          first_name: "Erika"
          last_name: "Mustermann"
          country: "DE"
        memo: "Monthly rent"

  sweep_euro_deposits:
    trigger:
      type: incoming_tx
      value: "100.. EURe"
    actions:
      - type: off_ramp
        provider: monerium
        value: "trigger.value"
        to:
          iban: "$savings_iban"
          company_name: "Musterhaus GmbH"
          country: "GB"
        memo: "Savings sweep"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon-amoy` | `safe_module` only | The Safe must be linked to Monerium, and its on-chain off-ramp policy must accept both IBANs and each amount. `POL` is on `token_allowlist` because it pays the fees. See [Bank payouts](https://docs.ana.fi/flows/bank-payouts.md). |

## Notify only

Send an email when the employer pays 1000 USDC or more, and when 5000 USDC or more leaves the account. No funds move.

```yaml theme={null}
variables:
  employer: "0x4444444444444444444444444444444444444444"

global:
  notification_email: "owner@example.com"

rules:
  salary_alert:
    trigger:
      type: incoming_tx
      from: "$employer"
      value: "1000.. USDC"
    actions:
      - type: notify
        channel: email
        message: "Salary received"

  large_outflow_alert:
    trigger:
      type: outgoing_tx
      value: "5000.. USDC"
    actions:
      - type: notify
        channel: email
        message: "A payment of 5000 USDC or more left the account"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both, but see the note | Replace `owner@example.com` with the inbox that the owner verified for this account. Another address is refused at staging. An `erc20_allow` account also needs `global.fees_method`, such as `{ type: fixed_token, token: USDC }`. |

## Several rules under global limits

Four rules share one document. The allowlists bound every rule: only `USDC` and `WETH`, and only three recipients.

```yaml theme={null}
variables:
  landlord: "0x1111111111111111111111111111111111111111"
  ops: "0x2222222222222222222222222222222222222222"
  cold_wallet: "0x3333333333333333333333333333333333333333"

global:
  token_allowlist: [USDC, WETH]
  recipient_allowlist: ["$landlord", "$ops", "$cold_wallet"]
  fees_method: { type: fixed_token, token: USDC }

rules:
  rent:
    trigger:
      type: calendar
      day_of_month: [1]
      time_of_day: "09:00"
      timezone: "Europe/Berlin"
    actions:
      - type: send_one
        to: "$landlord"
        value: "1200 USDC"

  weekly_ops_float:
    trigger:
      type: calendar
      day_of_week: ["mon"]
      time_of_day: "08:00"
      timezone: "Europe/Berlin"
    actions:
      - type: send_one
        to: "$ops"
        value: "200 USDC"

  sweep_large_inflows:
    trigger:
      type: incoming_tx
      value: "10000.. USDC"
    actions:
      - type: send_one
        to: "$cold_wallet"
        value: "trigger.value * 90%"

  weekly_weth:
    trigger:
      type: calendar
      day_of_week: ["wed"]
      time_of_day: "12:00"
      timezone: "Europe/Berlin"
    actions:
      - type: exchange
        in: "100 USDC"
        out: WETH
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon` | both | The stage gives warning 1: `token 'USDC' is spent by multiple rules (rent, weekly_ops_float, weekly_weth); ordering may cause later rules to fail at runtime`. Keep enough USDC for all three. `fees_method.token` is on `token_allowlist`, as required. |

## A rule with start and expiry, and a paused rule

Pay a contractor 750 USDC every Friday at 17:00 Paris time in the first quarter of 2027 only. Keep a weekly stipend in the document, but do not pay it.

```yaml theme={null}
variables:
  contractor: "0x5555555555555555555555555555555555555555"
  intern: "0x6666666666666666666666666666666666666666"

global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  contract_q1:
    trigger:
      type: calendar
      day_of_week: ["fri"]
      time_of_day: "17:00"
      timezone: "Europe/Paris"
    actions:
      - type: send_one
        to: "$contractor"
        value: "750 USDC"
    start: "2027-01-01T00:00:00+01:00"
    expiry: "2027-03-31T23:59:59+02:00"

  intern_stipend_paused:
    trigger:
      type: periodic
      interval_seconds: 604800
    actions:
      - type: send_one
        to: "$intern"
        value: "100 USDC"
    enabled: false
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | To resume the stipend, commit the document again with `enabled: true` and the same rule name and trigger. It then fires every Thursday at 02:00 UTC. Warning 1 appears, because a disabled rule still counts. |

## One-shot payment

Pay one invoice of 980 USDC on 15 March 2027 at 10:00 Paris time.

```yaml theme={null}
variables:
  supplier: "0x7777777777777777777777777777777777777777"

global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  pay_invoice_once:
    trigger:
      type: at_fixed_time
      timestamps: ["2027-03-15T10:00:00+01:00"]
    actions:
      - type: send_one
        to: "$supplier"
        value: "980 USDC"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | If the engine adopts the document after this instant, the rule never fires. |

## Match donations to another account

Each time a charity account receives a donation of 10 to 500 USDC, pay the same amount to a charity fund.

```yaml theme={null}
variables:
  charity: "0x1111111111111111111111111111111111111111"
  charity_fund: "0x2222222222222222222222222222222222222222"

global:
  fees_method: { type: fixed_token, token: USDC }

rules:
  match_donations:
    trigger:
      type: incoming_tx
      account: "$charity"
      value: "10..500 USDC"
    actions:
      - type: send_one
        to: "$charity_fund"
        value: "trigger.value"
```

| Networks | Account kinds | Notes |
| - | - | - |
| `polygon`, `xlayer`, `polygon-amoy` | both | `charity` must not be the account of the document. A stranger can donate to fire the rule. Each fire pays at most 500 USDC, but there is no limit over time. Use an `erc20_allow` cap to bound the total. |

## Stop every rule

Retire every rule of the account and keep the permission in place.

```yaml theme={null}
global:
  fees_method: { type: fixed_token, token: USDC }

rules: {}
```

| Networks | Account kinds | Notes |
| - | - | - |
| all | both | An `erc20_allow` account needs `global.fees_method` also in this document. Without it, the stage refuses the document with `the ERC20Allow leg needs global.fees_method`. A Safe can also commit `rules: {}` alone. The engine keeps only this empty document. Keep your own copy of the old rules. A later commit with rules starts them again. To stop Anafi without the engine, revoke the permission instead. See [Update, pause and revoke](https://docs.ana.fi/flows/update-pause-revoke.md). |


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