AnafiDelegationAdapterSafe. You know each prompt, each HTTP route, each contract call, each refusal, and how to resume.
When to use it
Use the Safe kind (safe_module) when:
- the rules must move the native coin, or a token that the ERC20Allow kind cannot serve;
- the rules use
off_ramp(bank payouts,polygon-amoyonly); - the owner wants the funds in a Safe, and one module grant in place of token approvals.
Preconditions
Today, the Anafi API hosts answer CORS only for
https://app.ana.fi. Run the calls that use the Anafi API from a server, a script, or your own same-origin proxy.
Admitted Safes
AnafiDelegationAdapterSafe serves a Safe only when two facts hold. Read both on the adapter:
admittedSafeProxyCodehashes(keccak256(code of the Safe))istrue;admittedSafeSingletons(masterCopy())istrue.
polygon and polygon-amoy list the singletons of Safe 1.3.0, 1.4.1 and 1.5.0. The Safe that the SDK provisions runs Safe 1.5.0 on SafeL2. Always read the adapter on chain, because the admitted sets can change. See Safe adapter and Deployments.
Sequence
Steps
1
Find the Safe
Two ways:
- Predict.
predictSafe(eoa)readsproxyCreationCode()from the Safe proxy factory and computes the CREATE2 address of a Safe with one owner (eoa), threshold 1, a setup callsetupToL2(singletonL2)ontoL2Setup, and the salt nonceuint256(keccak256(eoa)). No prompt. No HTTP call. The result is the same before and after the deploy. - Discover.
discoverAccounts(eoa)callsGET /api/accounts/discover?eoa=.... Each suggestion hasaddress,kind,source(predicted_safe,safe_transaction_service,connected_address) anddeployed. A suggestion authorizes nothing. Checkcompleteness: onlyevery_source_consultedmeans the list is complete. See Accounts.
readAccountAdapter(safe). It returns the Safe adapter when the adapter admits the Safe, else the ERC20Allow adapter when that kind serves the address, else null.2
Decide who pays
The SDK reads
GET /api/wallets/{safe}/sponsorship before each owner operation. Anafi relays when feesOn is false or sponsored is true. In each other case, the owner address sends the transaction and pays the gas. You can read the same answer with fetchWalletSponsorship(safe) to tell the owner in advance.3
Stage the document for arm
Call
stageDsl({ safe, eoa, adapter, yaml, salt, parent, write: "arm" }). Use a new random 32-byte salt for each commit. Set parent to await readDslCommitment(safe): null for a first document.a. Provision, only when the Safe has no code. The SDK calls provisionPredictedSafe({ safe, eoa }):The SDK refuses a
safe that is not predictSafe(eoa), and a relayed reply that names another address. onProvisioned(confirmedBlock) runs once after the provision, also when a later part of the stage fails. The Safe stays deployed in all cases.b. Checks. The SDK checks the adapter, the admission of the Safe, the threshold, the owner, and isModuleEnabled(adapter). After a provision, it reads at or above the block of the provision. For write: "arm", enableAdapter is true when the module is not enabled yet.c. Seal and send. The SDK reads AnafiRegistry.engineEncKey() and encrypts the adapter, the parent, the salt and the text to the engine. It sends POST /api/wallets/{safe}/dsl/commit/stage with { "sealed": ... }. The Anafi API cannot read the document. See Sealed requests.d. Check the reply. The reply holds adapter, commitment, engineSig, dslVersion, attestationValidUntil and optional sealedWarnings. The SDK refuses a reply when the adapter is not the requested one, when commitment is not keccak256(salt ‖ yaml), when the deadline has passed, or when the deadline is more than 1 hour away. It decrypts the findings into staged.warnings.The stage shows no wallet prompt, except the deploy transaction of step a.4
Show the findings
staged.warnings holds the findings of the engine, verbatim and in order. An empty list means a clean document. Show each finding to the owner before the commit. See Validation for the findings that the rule language defines.5
Commit in one prompt
Call
commitStagedDsl({ staged, onStep, onSigned }).- The SDK refuses a staged value whose attestation deadline has passed:
commitStagedDsl: the engine's attestation over this staged document has lapsed; stage it again. - It builds the call
AnafiDslRegistry.commitDsl(commitment, attestationValidUntil, engineSig, adapter). - When
staged.enableAdapteristrue, it puts two calls in oneMultiSendbatch (a delegatecall from the Safe): firstSafe.enableModule(adapter), thencommitDsl. Else it sendscommitDslas one plain call. - It reads the Safe nonce (at or above
staged.minReadBlock) and the sponsorship. - It calls
onStep("safe"), then asks the wallet for one prompt:
onSignedruns after the wallet answers, before the relay request or the receipt wait.
{ txHash, kind, confirmedBlock }. kind is "committed", or "inner_reverted" when the Safe reports that its inner call failed. confirmedBlock is null when a relayed receipt did not arrive in time.armSafe(...) runs stageDsl with write: "arm" and then commitStagedDsl in one call. Use the two calls when you want to show the findings before the prompt.What can refuse
At the stage
See Errors and API errors.
At the commit
Resume after a failure or a reload
The
staged value is plain data. You can store it and pass it to commitStagedDsl after a reload, until its deadline.
End state on chain
The chain holds only the salted hash. To read the plaintext and the state that the engine holds, see Read-back.
Other Safe calls
See Safe methods for each signature.