AnafiDelegationAdapterSafe is the adapter of the safe_module account kind. It runs behind an ERC-1967 proxy with UUPS upgrades. It has no owner of its own. Its admin is AnafiRegistry.owner().
The permission
The grant is one Safe call, and the revocation is one Safe call. The adapter keeps no record of either.
The Safe owners send both calls through a Safe transaction. See Safe account flow and Safe for how the SDK builds them.
The adapter executes each engine-signed leg as a plain call from the Safe, with the target, the value and the call data of the leg. It never sends a delegatecall. Its checks are the registry list, the deadline, the engine signature, the nonce and the account. It sets no limit on the target, the value or the call data of a leg. A leg can call any contract, the Safe itself included.
Which Safes the adapter accepts
redeemAsEngine accepts an account only when all three checks pass:
- The
EXTCODEHASHof the account is inadmittedSafeProxyCodehashes. Each proxy of one Safe release has the same runtime code, so one entry covers one release. - The account answers
masterCopy()(selector0xa619486e) with a singleton inadmittedSafeSingletons. The call gets 30,000 gas. - The module guard slot of the Safe,
0xb104e0b93118902c651344349b610029d694cfdec91c589c91ebafbcd0289947, holds zero. The adapter reads it with the Safe functiongetStorageAt(slot, 1)and 30,000 gas.
SafeNotAdmitted(account). Check 3 fails, or its read fails: SafeHasModuleGuard(account). Both reverts come before the gas charge.
You can run the same checks before you enable the module:
Functions for anyone
redeemAsEngine
The adapter calls
avatar.execTransactionFromModule(target, value, data, 0) for each leg, in order. A native coin send has the recipient as target, the amount as value, and empty data. An ERC-20 send has the token as target, zero value, and transfer(to, amount) as data.
Returns:
Redeem gives the digest, the order of checks, the gas formula, and the full list of revert and failure causes.
claimGasCredit
msg.sender in token to to. A credit comes from a failed payment of a charge or a refund. The call needs no module grant, so a Safe that disabled the adapter can still claim. The zero address as token is the native coin.
The adapter clears the credit before it pays. A failed payment reverts GasCreditClaimFailed() and keeps the credit. A zero credit reverts NoGasCredit(). On success, it emits GasCreditClaimed(msg.sender, token, to, amount). The payment gets 100,000 gas.
A Safe claims in a Safe transaction, because the Safe must be msg.sender. The SDK exports readGasCredit and buildClaimGasCreditCalldata.
readGasCredit takes publicClient as the viem PublicClient type of the viem version that the SDK pins (2.55.10). With another viem version in your project, TypeScript can refuse your client. Install viem@2.55.10 in your project, or cast the client to the parameter type as below. The cast type-checks with both versions.
receive
Functions that only the adapter calls
redeemAsEngine calls it on the adapter itself with exactly legsGasLimit gas. Any other caller gets CallerNotSelf().
Functions of the registry owner
Each function revertsCallerNotRegistryOwner() when the caller is not AnafiRegistry.owner().
initialize(address anafiRegistry_) ran once at deployment. It reverts RegistryNotUsable(address registry) when the registry has no code or its owner() is zero, and InvalidInitialization() on a second call.
Views and constants
Events
Errors
A leg that the Safe refuses because the module is not enabled fails inside the Safe.
legsRevertData then holds Error("GS104"). A payload that does not decode as (address, bytes32[], bytes[]) reverts the whole call, so no nonce is spent. A leg shorter than 52 bytes, or a modes array shorter than callDatas, makes the inner call fail with a panic.
Invariants
- The adapter never sends a delegatecall as the Safe.
- A nonce is spent at most once on this adapter. It is spent exactly when
redeemAsEnginedoes not revert. - Each redeem that does not revert emits exactly one of
EngineRedeemedandEngineRedeemFailed, and then oneGasCharged. - The charge is never more than
maxCharge. The Safe gets backmaxCharge - charge, or a credit of that amount. - Outside a redeem, the adapter holds only gas credits and funds that someone sent to it directly.
- Revocation does not cancel a signed redeem. If the Safe enables the module again, an unexpired redeem that was signed before can land. Only
validUntilbounds it.
Storage
All state is in one ERC-7201 namespace,anafi.storage.AnafiDelegationAdapterSafe, at slot 0x0f316d144a00e04e6022aee201937b9e65bf3af3bbc2cf91d90411ac28105600.