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

# Triggers

> Every trigger type of the rule language, with each field, its type, its default, its range, and when the rule fires.

After you read this page, you can choose the trigger for a rule and set each of its fields.

A trigger is the `trigger` mapping of a rule. Its `type` field selects one of six types:

| `type` | The rule fires | `trigger.value` |
| - | - | - |
| [`periodic`](#periodic) | every N seconds, on a fixed grid | not available |
| [`calendar`](#calendar) | at a local time on listed days | not available |
| [`at_fixed_time`](#at_fixed_time) | once at each listed instant | not available |
| [`incoming_tx`](#incoming_tx) | when a watched account receives a transfer | the received amount |
| [`outgoing_tx`](#outgoing_tx) | when a watched account sends a transfer | the sent amount |
| [`price_crossed`](#price_crossed) | when a token price crosses a USD level and holds | not available |

Each type accepts only its own fields. Another field is refused with `unknown field '<key>' in <type> trigger`, for example `unknown field 'max_executions' in periodic trigger`. An unknown `type` is refused with `unknown trigger type '<value>'`.

Three rule keys gate every trigger type: `enabled`, `start` and `expiry`. See [Document structure](https://docs.ana.fi/rules/document.md#rules).

## periodic

The rule fires every `interval_seconds` seconds, on a grid that does not depend on the time of the commit.

| Field | Type | Required | Default | Allowed values |
| - | - | - | - | - |
| `type` | text | yes | none | `periodic` |
| `interval_seconds` | integer | yes | none | 10 to 3153600000 (100 years of 365 days) |

The rule fires at each Unix time `7200 + k × interval_seconds`, for an integer `k`. The grid starts at 02:00 UTC on 1 January 1970. These are the results for common intervals:

| `interval_seconds` | Fires |
| - | - |
| `3600` | every hour, at minute 0 UTC |
| `86400` | every day at 02:00 UTC |
| `604800` | every Thursday at 02:00 UTC |
| `2592000` | every 30 days, not on a fixed day of the month |

A commit, a disable, an enable or an edit does not move the grid. Use [`calendar`](#calendar) for a time of day in a time zone, or for a day of the month.

| Value | Refusal text |
| - | - |
| `0` | `periodic interval_seconds must be > 0` |
| 1 to 9 | `periodic interval_seconds must be at least 10 seconds` |
| above 3153600000 | `periodic interval_seconds must be at most 3153600000 (100 years)` |

```yaml theme={null}
# Pay 10 USDC every hour.
trigger:
  type: periodic
  interval_seconds: 3600
```

```yaml theme={null}
# Pay once a week, every Thursday at 02:00 UTC.
trigger:
  type: periodic
  interval_seconds: 604800
```

## calendar

The rule fires at a local time on the days that you list, in a time zone that you name.

| Field | Type | Required | Default | Allowed values |
| - | - | - | - | - |
| `type` | text | yes | none | `calendar` |
| `day_of_month` | list of integers, at least 1 | see note | none | each `1` to `31`, no duplicate |
| `day_of_week` | list of texts, at least 1 | see note | none | each `"mon"`, `"tue"`, `"wed"`, `"thu"`, `"fri"`, `"sat"`, `"sun"`, no duplicate |
| `time_of_day` | text | yes | none | `"HH:MM"`, `"*:MM"` or `"*/N:MM"` |
| `timezone` | text | no | `"UTC"` | an IANA time zone name, for example `"Europe/Berlin"` |

Note: set `day_of_month`, `day_of_week`, or both. Without either, the trigger is refused with `calendar requires at least one of day_of_month or day_of_week`.

### Day filters

| Filters set | The rule fires on |
| - | - |
| `day_of_month` only | each listed day of the month |
| `day_of_week` only | each listed day of the week |
| both | only a day that is in both lists |

A month that does not have a listed day is skipped. `day_of_month: [31]` does not fire in April. `day_of_month: [28]` fires in every month. The engine does not move a fire to the last day of a short month.

An empty list is refused, for example `day_of_week must not be empty`. A repeated entry is refused, for example `day_of_month must not contain duplicates`. A weekday name is lowercase and has three letters. `"Monday"` is refused with `unknown day-of-week 'Monday'`.

### time\_of\_day

| Form | Example | Fires on each day that the filters allow |
| - | - | - |
| `"HH:MM"` | `"09:30"` | once, at that local time |
| `"*:MM"` | `"*:15"` | every hour, at minute `MM` |
| `"*/N:MM"` | `"*/6:15"` | at minute `MM` of the local hours 0, N, 2N, and so on, below 24 |

The rules of the text:

* `HH` and `MM` have exactly two digits. `HH` is `00` to `23`. `MM` is `00` to `59`.
* `N` is `1` to `23`, without a leading zero. `"*/1:MM"` is the same as `"*:MM"`.
* If `N` does not divide 24, the last step of the day is shorter. `"*/5:00"` fires at 00:00, 05:00, 10:00, 15:00 and 20:00.
* Another text is refused with `bad time_of_day ("HH:MM", "*:MM", or "*/N:MM" with N in 1..=23) '<value>'`.

Put `time_of_day` in double quotes. An unquoted value that starts with `*` is a YAML alias, and the document is refused.

### Time zones

The engine reads `time_of_day` in `timezone`. A rule at `"09:00"` in `"Europe/Berlin"` fires at 09:00 Berlin time in winter and in summer. A name that is not an IANA time zone is refused with `bad IANA timezone '<value>'`.

On a clock change, the rule still fires once on that day:

* A local time that occurs twice fires at its first occurrence.
* A local time that does not exist fires at the first instant after the change.

Set `timezone` each time that a rule names a time of day. The default is UTC.

```yaml theme={null}
# Pay on the 1st and the 15th of each month at 09:00 in New York.
trigger:
  type: calendar
  day_of_month: [1, 15]
  time_of_day: "09:00"
  timezone: "America/New_York"
```

```yaml theme={null}
# Every 6 hours at minute 15, Monday to Friday, in Berlin.
trigger:
  type: calendar
  day_of_week: ["mon", "tue", "wed", "thu", "fri"]
  time_of_day: "*/6:15"
  timezone: "Europe/Berlin"
```

## at\_fixed\_time

The rule fires once at each instant in a list.

| Field | Type | Required | Default | Allowed values |
| - | - | - | - | - |
| `type` | text | yes | none | `at_fixed_time` |
| `timestamps` | list of RFC 3339 instants, at least 1 | yes | none | each with a date, a time and an offset; no duplicate text |

Behavior:

* A one-shot rule is a list with one instant. There is no single-value form.
* The offset of each instant fixes the absolute time. `"2027-07-17T14:00:00+02:00"` is 12:00 UTC.
* An instant that is already in the past when the engine adopts the document never fires.
* An instant at or before the rule's `expiry` fires. A later instant does not.
* An instant before the rule's `start` does not fire.
* A bare date is refused with `bad ISO-8601 timestamp '<value>'`. An empty list is refused with `timestamps must not be empty`. Two equal texts are refused with `timestamps must not contain duplicates`.

If every instant is after `expiry`, or every instant is before `start`, the document is valid and the engine gives a warning. See [Validation](https://docs.ana.fi/rules/validation.md#warnings).

Prefer `calendar` for a schedule that repeats. A list of instants does not tell a reader the pattern.

```yaml theme={null}
# One payment on 1 March 2027 at 10:00 in Berlin.
trigger:
  type: at_fixed_time
  timestamps: ["2027-03-01T10:00:00+01:00"]
```

```yaml theme={null}
# Three payments on one day.
trigger:
  type: at_fixed_time
  timestamps:
    - "2027-07-17T14:00:00+02:00"
    - "2027-07-17T16:00:00+02:00"
    - "2027-07-17T20:00:00+02:00"
```

## incoming\_tx

The rule fires when a watched account receives a transfer that passes the filters.

| Field | Type | Required | Default | Meaning |
| - | - | - | - | - |
| `type` | text | yes | none | `incoming_tx` |
| `account` | address | no | the account of the document | The account that receives. |
| `from` | address | no | any sender | Only a transfer from this address counts. |
| `value` | value range | no | any token, any amount | The token and the amount bounds. See [Value ranges](https://docs.ana.fi/rules/values.md#value-ranges). |

`trigger.value` in an action is the amount and the token of the transfer.

`from` can be the zero address, `"0x0000000000000000000000000000000000000000"`. Then the rule fires on a mint to the watched account.

```yaml theme={null}
# A salary of 1000 to 10000 USDT0 from one employer.
trigger:
  type: incoming_tx
  from: "$employer"
  value: "1000..10000 USDT0"
```

```yaml theme={null}
# Any USDC payment of 1000 USDC or more.
trigger:
  type: incoming_tx
  value: "1000.. USDC"
```

## outgoing\_tx

The rule fires when a watched account sends a transfer that passes the filters.

| Field | Type | Required | Default | Meaning |
| - | - | - | - | - |
| `type` | text | yes | none | `outgoing_tx` |
| `account` | address | no | the account of the document | The account that sends. |
| `to` | address | no | any receiver | Only a transfer to this address counts. |
| `value` | value range | no | any token, any amount | The token and the amount bounds. |

`trigger.value` in an action is the amount and the token of the transfer.

`to` cannot be the zero address. A burn is not a payment. The trigger is refused with `outgoing_tx to '<to>' resolves to the zero address; a burn is not an outbound payment`.

```yaml theme={null}
# Each USDC payment of 1 to 500 USDC that a partner account sends.
trigger:
  type: outgoing_tx
  account: "$partner"
  value: "1..500 USDC"
```

```yaml theme={null}
# Each payment that the account of the document sends to one supplier.
trigger:
  type: outgoing_tx
  to: "$supplier"
  value: "0.. USDC"
```

## Rules for both transfer triggers

These rules apply to `incoming_tx` and to `outgoing_tx`.

### The watched account

* Without `account`, the rule watches the account that committed the document.
* With `account`, the rule watches another address. The actions still pay from the account of the document.
* `account` cannot be the zero address: `transfer account '<account>' resolves to the zero address`.
* `account` cannot be equal to `from` or `to` of the same trigger: `transfer account '<account>' and counterparty '<other>' resolve to the same address`.
* `account` cannot be the account of the document. The stage refuses it with `rule '<rule>': account '<account>' is this wallet; omit account to watch this wallet`. Omit `account` to watch your own account.

The comparison of addresses ignores letter case, and a `$name` is replaced by its value first.

### The token and the amount

* With a `value` range, the rule watches only the token of the range. The amount must be inside the bounds. Both bounds are inclusive.
* Without a `value` range, the rule watches the native coin and every registered token of the network. If `global.token_allowlist` is present, the rule watches only the tokens on that list.
* The token of a range must be on `global.token_allowlist`, if the list is present.
* Each network has a small minimum transfer, worth a fraction of a dollar in the token of the transfer. A smaller transfer never fires a rule. So `"0.. USDC"` and an absent range both start at this minimum. A range that is fully below it validates and never fires.

### What does not count as a transfer

These transfers never fire a transfer trigger:

* A transaction in which the watched account both receives and sends, each leg above the minimum. The engine reads this as a swap, also a swap that the owner made by hand. A mint and a burn count as legs. This test looks at every token of the network, not only the token of the rule. It can also skip a payment that has a refund in the same transaction.
* A transaction that the engine made for the account of the document, such as the output of its own swap or a payment to itself. So no rule fires on the output of its own account.
* For a rule with `account`: every transaction that the engine made for any Anafi account.
* For `outgoing_tx`: a transfer to the zero address, such as a burn.
* A native transfer in a `CALLCODE` frame.

A transfer that the engine makes for another Anafi account can fire a rule without `account`.

### How often the rule fires

* A transfer trigger has no limit in time. There is no count and no sum per day or per month.
* A rule without `account` fires on each transfer that passes its filters.
* A rule with `account` fires on its first transfer in a block, and on no other transfer of that block.

Transfer fires follow the order of the transfers in the block: the transaction index, then native transfers before ERC-20 transfers in one transaction. Rules that match one transfer fire in document order.

> [!WARNING]
>
> Accept these risks before you commit a transfer trigger. Another party can fire the rule on purpose: a stranger can send a transfer to a watched account, and a watched party can pay an address that it controls. A loop can leave Anafi and return in a later transaction. Use a range and the [limits](https://docs.ana.fi/rules/limits.md) to bound each fire.

## price\_crossed

The rule fires when the USD price of a token crosses a level and stays on the far side for a time.

| Field | Type | Required | Default | Allowed values |
| - | - | - | - | - |
| `type` | text | yes | none | `price_crossed` |
| `token` | token symbol | yes | none | a token that the network prices, see the table below |
| `direction` | text | yes | none | `above` or `below` |
| `price_usd` | number | yes | none | greater than 0, up to 18 decimals |
| `hold_seconds` | integer | yes | none | 0 or more |
| `cooldown_seconds` | integer | yes | none | 0 or more |

There are no defaults. Each field is required.

### Sides and crosses

| `direction` | On side | Off side |
| - | - | - |
| `above` | price at or above `price_usd` | price below `price_usd` |
| `below` | price at or below `price_usd` | price above `price_usd` |

The rule works like this:

1. A cross is a move from the off side to the on side.
2. After a cross, the price must stay on side for `hold_seconds`. Then the rule fires. One price on the off side stops the hold, and nothing fires. `hold_seconds: 0` fires at the price that shows the cross.
3. The rule fires at most one time for each cross. The price must go back to the off side before a new cross can start a new hold.
4. A rule that the engine adopts while the price is already on side does not fire. It fires only after the price goes to the off side and crosses again.
5. `cooldown_seconds` applies at the cross, not at the fire. A cross less than `cooldown_seconds` after the last fire starts no hold. That cross is dropped, not delayed. `cooldown_seconds: 0` sets no limit.
6. While `enabled` is `false`, or outside `start` and `expiry`, no hold starts and a hold stops. The engine still follows the side, so a new cross needs a new move.
7. If the network has no price for the token at one observation, the last price stays in force. The side does not change, and the time of the hold continues.

Each time here is the block time of a price observation. The network sets how often the engine observes a price. On X Layer it is about once a minute. A hold ends at the first observation at or after `hold_seconds`.

On `polygon-amoy` the token prices are fixed test values, so a `price_crossed` rule there does not follow the market.

`trigger.value` is not available in a `price_crossed` rule.

### Which tokens each network prices

The stage accepts `price_crossed` only on a token that the network prices:

| Network | Tokens accepted in `price_crossed` |
| - | - |
| `polygon` | `AAVE`, `EURe`, `LINK`, `POL`, `WBTC`, `WETH` |
| `xlayer` | `frxUSD`, `LINK`, `OKB`, `PAXGy`, `PYUSD`, `rsETH`, `sUSDe`, `uniBTC`, `USDe`, `wNVDAx`, `wSPYx`, `xBTC`, `xETH`, `xSOL` |
| `polygon-amoy` | `EURe`, `POL` |

The dollar stablecoins are not accepted: `USDC`, `USDC.e` and `USDT0` on `polygon`, `USDC`, `USDG` and `USDT0` on `xlayer`, and `USDC` on `polygon-amoy`. The stage refuses a token that the network has but does not price, with this text:

```text theme={null}
rule '<rule>': <network name> has no price for <TOKEN>, so a `price_crossed` on it could never fire
```

The `<network name>` is `Polygon PoS`, `X Layer` or `Polygon Amoy testnet`.

The `token` must also be on `global.token_allowlist`, if the list is present.

| Value | Refusal text |
| - | - |
| `price_usd: 0` or a negative number | `price_crossed price_usd must be > 0` |
| `direction: sideways` | `unknown direction 'sideways'` |
| `token: btc` | `unknown token 'btc'` |

```yaml theme={null}
# Take profit: fire when xBTC stays at or above 80000 USD for 10 minutes.
# At most one fire per day.
trigger:
  type: price_crossed
  token: xBTC
  direction: above
  price_usd: 80000
  hold_seconds: 600
  cooldown_seconds: 86400
```

```yaml theme={null}
# Stop-loss: fire when WETH falls to 2000 USD or less and stays there for 5 minutes.
trigger:
  type: price_crossed
  token: WETH
  direction: below
  price_usd: 2000
  hold_seconds: 300
  cooldown_seconds: 0
```


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