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
Whensignature 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
Whensignature 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:
0x1626ba7e only when every check passes. Each failed check answers 0xffffffff, and the call does not revert:
- The blob decodes.
- The policy of the Safe has a non-zero
authority. block.timestampis less than the policyexpiry.amountMinoris not more than the policyperOrderCapMinor.- The IBAN is on the policy allowlist, or the allowlist is empty. The handler compares
keccak256(bytes(iban)). - The EIP-191 hash of the sentence
Send EUR <amount> to <iban> at <timestamp>equalshash. The handler writes<amount>as the whole euros, a point, and exactly two digits of cents. engineSigrecovers, with no error, to a non-zero signer over the raw digest below.authority.engineSigKey()answers with one address word, and that address equals the signer.
3. The standard Safe check
Each other signature goes to the standard Safe check, which the handler copies from SafeCompatibilityFallbackHandler v1.5.0:
- With an empty signature, the Safe must have the
SafeMessagehash ofhashin itssignedMessages. Else the call reverts with"Hash not approved". - With a signature, the Safe checks the owner signatures over the
SafeMessagehash withcheckSignatures(address(0), messageHash, signature). A refusal reverts in the Safe.
Functions of the Safe
The Safe calls these functions on itself, for examplesafe.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
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
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 SafeCompatibilityFallbackHandler 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:setOffRampPolicywith a zeroauthority.setFallbackHandleron the Safe with another handler.