Skip to main content
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: 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 every interval_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:
  • 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.

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 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. 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 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.
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 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. There are no defaults. Each field is required.

Sides and crosses

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