Skip to main content
After you read this page, you know which Anafi contract does what, which party can call which function, what the contract admin can change, and how each account kind stops Anafi with one transaction. The pages after it give each contract function by function. All Anafi contracts are on public chains. Each network has its own copy of the set. The addresses are on Deployments.

The contract set

Two more source units have no deployment of their own:
  • IAnafiDelegationAdapter is the interface that each adapter implements. It has one function, anafiRegistry(), which returns the registry that the adapter reads.
  • AdapterGasSettlement is an internal library. Both adapters use it to compute the redeem digest and the gas charge. Redeem gives its formulas.
The Safe adapter also calls one function of the Safe, which the source declares as IAvatar:
A Safe executes the call only when the caller is an enabled module. The Safe returns false for a failed inner call and does not revert. The adapter always sends operation = 0, a plain call. It never sends a delegatecall.

How the contracts relate

The registry is the root. Each other upgradeable contract stores the registry address once, at initialization, and reads three things from it:
  • engineSigKey(): the address that must sign each redeem and each attested commit.
  • isDelegationAdapter(address): an adapter checks its own entry first on each redeem.
  • owner(): the only address that can call the admin functions and upgrade the contract.
The off-ramp handler reads engineSigKey() from the registry that each Safe names in its own policy.

Who can call what

The contracts know four parties. The engine never needs to send a transaction itself: a signature of the engine key is the authorization, and any address can submit it.

Admin powers and upgrades

The registry uses OpenZeppelin Ownable2Step. Ownership moves only in two steps: the owner calls transferOwnership(newOwner), and then newOwner calls acceptOwnership(). renounceOwnership() always reverts with OwnershipNotRenounceable(). So the set always has an admin. The DSL registry and both adapters have no owner of their own. Each one returns AnafiRegistry.owner() from its own owner() and reads it at the time of each call. A handover at the registry moves the admin of all four contracts in the same transaction. The registry owner can do these things: The admin functions above do not include these things:
  • An upgrade of AnafiSwapExecutor or AnafiOffRampFallbackHandler. Neither has a proxy or an owner. A fix is a new contract.
  • A change of the swap executor after initializeSwaps, other than through an upgrade of the ERC20Allow adapter.
  • A call to a Safe, or a change of the allowance that an owner gave to a token.
  • A renounce of the admin role.
A redeem leg of the Safe adapter is a plain call from the Safe to any target, the Safe itself included. See Safe adapter.
The Safe adapter executes each leg as a plain call from the Safe, with the target, the value and the call data of the leg. The ERC20Allow adapter pulls tokens only through the allowances that the account gave it. Redeem lists the checks of each adapter.
Each upgradeable contract emits the OpenZeppelin event Upgraded(address indexed implementation) on an upgrade. The registry emits EngineIdentitySet on each key change, and DelegationAdapterAdded and DelegationAdapterRemoved on each list change. Verification shows how to watch these events.

The exit of each account kind

The owner can stop Anafi without the Anafi engine, the Anafi API or the registry owner. The exit is one owner transaction for a Safe, and one transaction for each approved token for an ERC20Allow account. It takes effect in the block where it lands. Use these facts when you build an exit:
  • prevModule is the module before the adapter in the linked module list of the Safe. Read it with getModulesPaginated on the Safe. Do not guess it.
  • An exit does not cancel a redeem that the engine signed before. The adapter keeps no record of the grant. If the owner grants the permission again, an unexpired signed redeem can land. Only its validUntil bounds it.
  • For an ERC20Allow account, setBlocked(true) stops all pulls in one transaction. The block switch is state of the adapter. The allowance is state of the token, and only the account can set it.
  • When the registry owner delists an adapter, its redeems stop, but no grant changes. The owner exit is still the only call that removes the grant.
  • An exit does not clear a gas credit. The account claims a credit with claimGasCredit(token, to) at any time, with no grant.
  • A Safe that installed the off-ramp handler stops off-ramp orders with setOffRampPolicy and a zero authority, or with a new fallback handler. See Off-ramp handler.
The SDK builds these calls. See Update, pause and revoke.

Read more

Redeem

How one payment is authorized and executed on chain.

Verification

What the chain publishes about the engine, and how to check it.

Deployments

The addresses on each network.

Security

The trust model in plain words.