trigger mapping of a rule. Its type field selects one of six types:
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.
periodic
The rule fires everyinterval_seconds seconds, on a grid that does not depend on the time of the commit.
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:
A commit, a disable, an enable or an edit does not move the grid. Use
calendar for a time of day in a time zone, or for a day of the month.
calendar
The rule fires at a local time on the days that you list, in a time zone that you name.
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
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
The rules of the text:
HHandMMhave exactly two digits.HHis00to23.MMis00to59.Nis1to23, without a leading zero."*/1:MM"is the same as"*:MM".- If
Ndoes 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>'.
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 readstime_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.
timezone each time that a rule names a time of day. The default is UTC.
at_fixed_time
The rule fires once at each instant in a list.
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
expiryfires. A later instant does not. - An instant before the rule’s
startdoes not fire. - A bare date is refused with
bad ISO-8601 timestamp '<value>'. An empty list is refused withtimestamps must not be empty. Two equal texts are refused withtimestamps must not contain duplicates.
expiry, or every instant is before start, the document is valid and the engine gives a warning. See Validation.
Prefer calendar for a schedule that repeats. A list of instants does not tell a reader the pattern.
incoming_tx
The rule fires when a watched account receives a transfer that passes the filters.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.
outgoing_tx
The rule fires when a watched account sends a transfer that passes the filters.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.
Rules for both transfer triggers
These rules apply toincoming_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. accountcannot be the zero address:transfer account '<account>' resolves to the zero address.accountcannot be equal tofromortoof the same trigger:transfer account '<account>' and counterparty '<other>' resolve to the same address.accountcannot be the account of the document. The stage refuses it withrule '<rule>': account '<account>' is this wallet; omit account to watch this wallet. Omitaccountto watch your own account.
$name is replaced by its value first.
The token and the amount
- With a
valuerange, the rule watches only the token of the range. The amount must be inside the bounds. Both bounds are inclusive. - Without a
valuerange, the rule watches the native coin and every registered token of the network. Ifglobal.token_allowlistis 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
CALLCODEframe.
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
accountfires on each transfer that passes its filters. - A rule with
accountfires on its first transfer in a block, and on no other transfer of that block.
price_crossed
The rule fires when the USD price of a token crosses a level and stays on the far side for a time.
There are no defaults. Each field is required.
Sides and crosses
The rule works like this:
- A cross is a move from the off side to the on side.
- 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: 0fires at the price that shows the cross. - 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.
- 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.
cooldown_secondsapplies at the cross, not at the fire. A cross less thancooldown_secondsafter the last fire starts no hold. That cross is dropped, not delayed.cooldown_seconds: 0sets no limit.- While
enabledisfalse, or outsidestartandexpiry, no hold starts and a hold stops. The engine still follows the side, so a new cross needs a new move. - 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.
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 acceptsprice_crossed only on a token that the network prices:
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:
<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.