Skip to main content
After you read this page, you can write every amount, range, address and instant that a rule needs, and you know how the engine computes the result.

Where values occur

Value expressions

A value expression computes one amount of one token each time the action fires. Put it in double quotes.

Atoms

<N> is a non-negative integer of at most 19 digits, or a decimal with at most 19 digits before the point and at most 18 after it. There is no sign: a negative literal is not valid. min and max take exactly two arguments. Nest them for more: "min(min(a, b), c)".

Operators

Atoms bind tighter than *. So "10 USDC + 100 USDC * 10%" is 10 + 10 = 20 USDC. The language has no division, no unary minus, no comparison and no condition. Use * 50% for “half”, and min or max for a limit.

Unit rules

Each expression has a unit. The engine checks the units before it stages the document. A percentage and a bare number are two different units. trigger.value without a range has an open unit. It joins any unit in +, -, min and max. Times a percentage, a bare number or another open value, it stays open. Times an amount, it is that amount. See trigger.value. Examples of refusals: The result of an action value must be an amount. The same rule applies to send_batch items (send_batch recipient value must be a token amount) and to exchange.in. An off_ramp.value must be an amount of EURe. See off_ramp.

trigger.value

trigger.value is the amount and the token of the transfer that fired the rule. Without a range, the token of trigger.value is the token of each transfer:
  • "trigger.value" and "trigger.value * 90%" pay in whichever token arrived. These forms are safe.
  • "min(trigger.value, 100 USDC)" validates. It runs only when the transfer is in USDC. For a transfer in another token, the engine records the fire and skips the action.
  • "trigger.value * 100 USDC", "trigger.value * trigger.value" and "min(trigger.value, 50%) * 100 USDC" validate, but every fire refuses them. The action always skips.
Give the trigger a range to decide each form before staging. With value: "0.. USDC", the engine accepts "min(trigger.value, 100 USDC)" and refuses the other forms.
Add a range to each transfer trigger whose actions mix trigger.value with a literal amount. "0.. USDC" watches every USDC transfer and fixes the token.

What a value cannot contain

How the engine computes a value

  • Every number is a fixed-point value with 18 decimals.
  • A product is exact, then the engine cuts the result to 18 decimals toward zero.
  • A sum and a difference are exact. A result outside the range of the format stops at the largest value.
  • The engine converts the result to the decimals of the token, toward zero. USDC has 6 decimals, so "1 USDC * 33.3333333%" pays 0.333333 USDC.
  • A result below zero is refused at the fire. "1 USDC - 5 USDC" validates, and every fire refuses it.
  • A zero exchange input is refused at the fire. Keep every amount above zero.
  • An off_ramp amount computed at the fire is rounded down to whole cents.

Fee floor for literal amounts

When an action value is only a literal amount, such as value: "0.1 USDC", the stage compares it with the minimum Anafi fee. An amount at or below the fee floor is refused:
For a token that is not a dollar stablecoin, the stage converts $0.20 with a current price. If no price is known, the stage refuses with No price is known for <TOKEN>, so the Anafi fee cannot be computed. An expression, such as "trigger.value * 10%", is not checked at staging. See Fees.

Value ranges

A value range filters a transfer trigger by token and amount. It has exactly two parts, separated by a space: the bounds, then the token. Rules:
  • Both bounds are inclusive.
  • There is no space inside the bounds. "1 .. 5 USDC" is refused with bad value range (expected '<N> <TOKEN>' or '<N>..<M> <TOKEN>') '1 .. 5 USDC'.
  • The lower bound must not be above the upper bound: value range lower bound must be <= upper bound.
  • A bound is a number with at most 18 decimals. It is not an expression.
  • "0.. USDC" means “any amount of USDC”. It also fixes the token of trigger.value.
  • Each network has a minimum transfer that can fire a rule, worth a fraction of a dollar. An amount below it never fires, whatever the range says.

Token symbols

A token symbol is case-sensitive and names one asset. The language knows these 26 symbols: AAVE, ETH, EURC, EURe, frxUSD, LINK, OKB, PAXGy, POL, PYUSD, rsETH, sUSDe, uniBTC, USDC, USDC.e, USDe, USDG, USDT, USDT0, WBTC, WETH, wNVDAx, wSPYx, xBTC, xETH, xSOL Another symbol, or another letter case such as usdc or XETH, is refused with unknown token '<symbol>'. The fiat names EUR, USD and GBP are not tokens. Some symbols are easy to confuse:

Tokens per network

A known symbol passes the parser on every network. The stage then refuses each symbol that the network does not have. The text is <TOKEN> is not a token on <network name>., after rule '<rule>': or global.token_allowlist: . On polygon, USDT gets the hint Did you mean USDT0?. These are the tokens that the engine moves on each network, with the decimals of each contract:
ETH and USDT have no contract on any of the three networks. WBTC has a contract only on polygon. The contract addresses are on Networks. Write amounts in whole tokens, not in base units. "1.5 USDC" is 1500000 base units of USDC. A literal with more decimals than the token has is cut toward zero when the engine converts it.

Addresses

An address position accepts two forms: Rules:
  • Letter case is free. The language does not check the EIP-55 checksum.
  • Comparisons for the zero address, the account itself, and account against from or to ignore letter case.
  • The comparison with global.recipient_allowlist uses the exact text after the engine replaces each $name. Write each address in the same letter case in the allowlist and in the actions, or use one variable for both.
  • Another text is refused with bad address (expected 0x + 40 hex chars or $variable reference) '<value>'.
  • A $name must exist in variables (undefined variable '$<name>') and hold an address (variable '$<name>' is used as an address but its value '<value>' is not a 0x + 40-hex address).
Put every address in double quotes. See YAML scalar rules.

IBANs

An IBAN position accepts a canonical IBAN or a $name that holds one.
  • Canonical means uppercase letters and digits, no spaces, 15 to 34 characters, two letters, two check digits, and correct check digits.
  • "DE89370400440532013000" is valid. "de89 3704 0044 0532 0130 00" is not.
  • A $name that holds another text is refused with variable '$<name>' is used as an IBAN but its value '<value>' is not a canonical IBAN (uppercase, no spaces, valid check digits).

Instants

start, expiry, at_fixed_time.timestamps and agent_envelope.expiry use RFC 3339: The calendar trigger uses time_of_day and an IANA timezone instead. See calendar.