Skip to main content
After you read this page, you know how a Safe accepts an engine-signed off-ramp order, which policy bounds it, and every function, event and error of the handler. AnafiOffRampFallbackHandler is a Safe fallback handler. A Safe installs it with its own setFallbackHandler. The off-ramp provider that the rule language names, Monerium, asks the Safe for an ERC-1271 signature check, isValidSignature(hash, signature). The Safe forwards the question to this handler. The stablecoin stays in the Safe, and the provider burns it from the Safe. The handler is one plain contract for all Safes. It has no owner, no proxy and no upgrade path. Its state is keyed by the Safe that calls it. A fix is a new handler that each Safe installs itself.
Only the polygon-amoy deployment records an offRampFallbackHandler address. See Deployments.

Requirements and limits

  • The handler works with Safe 1.5.0 only. Its standard signature path calls checkSignatures(address,bytes32,bytes), which only a 1.5.0 Safe has. On a 1.3.0 or 1.4.1 Safe, an owner signature does not validate through this handler.
  • A Safe has one fallback handler. When the Safe installs another handler, orders stop validation. No funds move. The policy and the approvals stay in this handler and apply again when the Safe installs it again.
  • For an order, the handler checks the policy and the engine signature. It reads no token balance.

What the handler accepts

isValidSignature(bytes32 hash, bytes signature) answers for msg.sender, which is the Safe that forwards the call. It tries three paths in this order.

1. An approved message hash

When signature is empty and the Safe approved hash with setApprovedMessageHash, and the approval did not lapse, the answer is the magic value 0x1626ba7e. An approved hash is a public proof. Anyone can present it with an empty signature while the approval is valid. It does not authorize an order.

2. An engine-signed order

When signature is at least 160 bytes long and its first 32-byte word equals OFF_RAMP_BLOB_KIND (1), the handler reads it as an order:
The handler answers the magic value 0x1626ba7e only when every check passes. Each failed check answers 0xffffffff, and the call does not revert:
  1. The blob decodes.
  2. The policy of the Safe has a non-zero authority.
  3. block.timestamp is less than the policy expiry.
  4. amountMinor is not more than the policy perOrderCapMinor.
  5. The IBAN is on the policy allowlist, or the allowlist is empty. The handler compares keccak256(bytes(iban)).
  6. The EIP-191 hash of the sentence Send EUR <amount> to <iban> at <timestamp> equals hash. The handler writes <amount> as the whole euros, a point, and exactly two digits of cents.
  7. engineSig recovers, with no error, to a non-zero signer over the raw digest below.
  8. authority.engineSigKey() answers with one address word, and that address equals the signer.
The digest holds the chain and the Safe, so one order is valid for one Safe on one chain. The engine key is the one that the authority returns at the time of the check, so a key change at the registry applies at once. The handler keeps no record of the orders that it accepted. One order stays valid at its own Safe while its policy checks pass. The handler itself does not limit a replay of an order. Example of the sentence and its hash:

3. The standard Safe check

Each other signature goes to the standard Safe check, which the handler copies from Safe CompatibilityFallbackHandler v1.5.0:
  • With an empty signature, the Safe must have the SafeMessage hash of hash in its signedMessages. Else the call reverts with "Hash not approved".
  • With a signature, the Safe checks the owner signatures over the SafeMessage hash with checkSignatures(address(0), messageHash, signature). A refusal reverts in the Safe.

Functions of the Safe

The Safe calls these functions on itself, for example safe.setOffRampPolicy(terms) in a Safe transaction. The Safe fallback forwards the call to the handler with the original sender appended. The handler accepts the call only when that sender is the Safe itself. Else it reverts CallerNotSafeItself(). A module that the Safe enabled can also make the Safe call itself, so a module can also write these entries.

setOffRampPolicy

Replaces the off-ramp policy of the Safe. A zero authority switches off-ramp orders off. The handler stores keccak256(bytes(iban)) of each IBAN. It emits OffRampPolicySet with the hashes. Reverts OffRampAllowlistTooLong() when the allowlist has more than MAX_OFF_RAMP_IBAN_ALLOWLIST (16) entries, and CallerNotSafeItself() for a stranger.

setApprovedMessageHash

Approves messageHash for the Safe until validUntil. The handler then accepts it with an empty signature. A zero validUntil withdraws the approval. A new call replaces an earlier approval. Emits MessageHashApprovalSet. A Safe can use this path to prove its address to the provider at link time, with the EIP-191 hash of the link sentence of the provider. The link sentence is the same for every account, so its approval lets anyone claim the Safe address while the approval is valid. The owner signature path of the standard check proves ownership with no such public approval.

Views

Standard Safe handler functions

The handler copies these functions from Safe CompatibilityFallbackHandler v1.5.0, and inherits the token callbacks from Safe TokenCallbackHandler. Each one assumes that the caller is a Safe.

Constants

Events

Errors

The order path never reverts. It answers 0xffffffff for each refusal. The standard path can revert, as the Safe handler does.

Stop off-ramp orders

The Safe owners can stop the order path in one Safe transaction, with either call:
  • setOffRampPolicy with a zero authority.
  • setFallbackHandler on the Safe with another handler.