redeemAsEngine on an adapter. It carries a payload of legs, the gas terms, a nonce, a deadline and an engine signature. This page describes only what the contracts check and do.
GasTerms struct. The payload has a different shape for each adapter.
The flow of one redeem
Any address can submit a redeem. The engine signature is the whole authorization. In practice, Anafi submits the transaction.The signed digest
The adapter does not use EIP-712 or EIP-191. The engine key signs a rawkeccak256 digest of abi.encode of 13 values:
The chain id and the adapter address are in the digest, so one signature is valid at one adapter on one chain. Every field of
GasTerms and the deadline are in the digest, so a sender cannot change them.
Check a redeem signature yourself
0x04e7a47e8fe1ff58013d96c937f5c85e4bdc2b70205b3daeaa3c5512e2873a16.
Who signs
The signer must beAnafiRegistry.engineSigKey() at the time of the call. The adapter reads the key on each redeem. After a key change at the registry, a redeem that the old key signed fails with InvalidEngineSignature().
The signature is 65 bytes. A malformed signature reverts with an OpenZeppelin ECDSA error: ECDSAInvalidSignature(), ECDSAInvalidSignatureLength(uint256) or ECDSAInvalidSignatureS(bytes32).
Nonce and deadline
A revocation does not cancel a signed redeem. If the owner grants the permission again before
validUntil, a signed redeem that did not land can land. Only validUntil bounds it.
The order of checks
Each step that fails reverts the whole transaction. Then the adapter spends no nonce, takes no charge and runs no leg.The payload and its legs
Safe adapter
avatar.execTransactionFromModule(target, value, data, 0) for each leg, in order. A leg that returns false fails all legs with AvatarExecutionFailed(legIndex). The Safe adapter has no leg types: each leg is a plain call from the Safe.
ERC20Allow adapter
token.transferFrom(account, to, amount). A swap leg goes through AnafiSwapExecutor and pays the output to the account.
Kinds of payment
All legs of one payload succeed together or fail together. One engine signature covers the whole array.
For the full list of the ERC20Allow pull rules, the caps and the block switch, see AnafiDelegationAdapterERC20Allow.
The gas charge
Each redeem charges the account the gas of the whole transaction, also when the legs fail. AmaxCharge of zero is a sponsored redeem: no gas token moves and GasCharged shows a zero charge.
Collection before the legs
The registry owner admits a gas token with
setGasOverhead(token, overhead) on each adapter. Read gasOverhead(token): zero means the adapter refuses a charge in that token.
The charge formula
gasUsed = 123456, baseGas = 54321, overhead 98765, floorGas = 0, gas price 1500000000 wei, tokenUnitsPerNativeCoin = 1700123456, maxCharge = 25000000. The billed gas is 276,542, the cost is 414,813,000,000,000 wei, and the charge is 705234 token units.
Payment after the legs
- The adapter pays
chargetoreceiver, with 100,000 gas. - The adapter pays
maxCharge - chargeback to the account, with 100,000 gas. - On the ERC20Allow adapter, it subtracts
maxCharge - chargefrom the cap of the gas token. It does this only when the same cap still holds the reservation.
GasCreditKept(payee, token, amount). The payee claims the credit with claimGasCredit(token, to). The claim needs no grant.
A token payment passes only when the call did not revert and returned no data, or exactly one 32-byte word equal to 1. Each other result is a failed payment.
On the Safe adapter, a native refund runs code of the Safe. So the adapter checks the Safe again before it sends a native refund: the code hash and the singleton must still be admitted. When the check fails, the refund becomes a credit of the Safe, and the adapter sends no native coin to the Safe.
Revert or failed legs
A redeem ends in one of three ways.
These causes revert the whole transaction:
RedeemReentered(),AdapterNotAllowed(),RedeemWindowExpired(),InvalidEngineSignature(), theECDSAerrors,NonceAlreadyUsed().- A payload that does not decode.
- Safe adapter:
SafeNotAdmitted(address),SafeHasModuleGuard(address). - ERC20Allow adapter:
OwnerBlocked(address), andCapExceeded(address,address)for the gas reservation. GasTokenNotSupported(address),GasChargeCollectionFailed(),GasForLegsTooLow(uint256,uint256).- An arithmetic overflow in the charge formula.
legsRevertData:
- Safe adapter:
UnsupportedMode(bytes32),AvatarExecutionFailed(uint256), a Safe error such asGS104when the module is not enabled andmaxChargeis zero, a malformed leg, or the inner call out of gas. - ERC20Allow adapter:
UnsupportedLegKind(uint8),CapExceeded(address,address)for a leg, the error of a token for a low allowance or balance,SafeERC20FailedOperation(address), the swap errorsSwapExecutorNotSet(),SwapRouterNotAllowed(address,address),SwapLegNotValid(),SwapInputNotReceived(address,uint256,uint256),SwapInputDebitNotExact(address,uint256,uint256),SwapOutputBelowMinimum(address,uint256,uint256), the executor errorsRouterCallFailed(bytes)andSwapReentered(), or the inner call out of gas.
GasChargeCollectionFailed() when maxCharge is above zero. When maxCharge is zero, the legs fail with GS104.
Watch redeems
payload from the transaction input to get it: the first ABI word of the payload is the account on both adapters. The ERC-20 Transfer events of the same receipt show the moved funds.
For the status of a payment as the Anafi API reports it, see Execution.