erc20_allow) is a plain address: a key with no code, or an address with an EIP-7702 pointer. The account grants its permission with ERC-20 allowances to AnafiDelegationAdapterERC20Allow. It can also set a block switch and caps on the adapter. See the ERC20Allow adapter and the ERC20Allow account flow.
Rules of this leg
- Every write is a plain transaction from the account. The account sends it and pays the gas. The client never asks for a relay and never reads the sponsorship for this leg.
- One transaction at a time. Each transaction waits for its receipt (up to 180 seconds) before the next prompt. A reverted receipt rejects with
Error("owner transaction <hash> reverted"). The transactions that landed before stay on chain. - The adapter must be the configured row. Each method throws
Error("<adapter> is not this chain's configured ERC20Allow adapter")whenadapteris notdelegationAdapters.erc20_allow. - Only ERC-20 tokens. The adapter cannot pull the native coin. A document of this leg cannot send, sell or buy
native. - A fee token is required. A document of this leg must set
global.fees_method. See fees. - The client copies your input. The stage and the commit read their parameters one time, when you call them. A later change to your object, also from a callback, changes nothing.
tokens(D)
tokens(D) is the list of tokens that the engine can pull for a document D. The client computes it from the text:- each token that a
send_oneor asend_batchrow spends, and each token that anexchangesells, in document order, each one time; - then the fee token of
global.fees_method, when no action spends it.
exchange buys is not in tokens(D), unless an action also spends it or it is the fee token. The account must approve each token of tokens(D) to the adapter.
classifyErc20AllowAccount
account for this leg. Every read is at one block: options.block, or the uncached tip. With no erc20_allow row in the config, it answers leg_not_live and reads nothing.
readErc20AllowDelegation
adapter.isBlocked(account), and for each token token.allowance(account, adapter) and adapter.capOf(account, token). An answer of the wrong type throws.
readErc20AllowSwapSupport
swapExecutor() of the configured ERC20Allow adapter at the latest block.
Any other failure throws
Erc20AllowSwapSupportUnreadError. A failure never reads as not_served.
served does not promise that a swap can run. The adapter can permit no router pair yet. The engine also refuses every exchange action on polygon-amoy, where no swap aggregator is available.
The function behind it:
stageErc20AllowDsl
Checks, in order
The method stops at the first check that fails.
An allowance of 0 does not stop the stage. The token goes to
approvals, and the commit approves it.
Return value: StagedErc20AllowDsl
commitStagedErc20AllowDsl
- Checks that
staged.adapteris the configured row. - Throws
Error("commitStagedErc20AllowDsl: the engine's attestation over this staged document has lapsed; stage it again")when the deadline has passed. - Checks that
staged.commitmentisdslCommitment(staged.salt, staged.yaml), and thatstaged.tokensis tokens(D) ofstaged.yamlin order. Else it throwsErc20AllowStagedDocumentMismatchError. - Applies to
staged.yamlthe token checks 2 to 9 of the stage, with a new read ofswapExecutor()for a document with a swap. - Reads the allowance of each token of
staged.tokensagain, at one tip block. The owner can have revoked or approved in the meantime, so the list can differ fromstaged.approvals. - Checks the deadline again.
- For each token with allowance 0, in order:
onStep({ kind: "approve", token }), then the prompt fortoken.approve(adapter, 2^256 - 1), then the receipt, thenonConfirmed(block). - Checks the deadline again.
onStep({ kind: "commit" }), then the prompt forAnafiDslRegistry.commitDsl(commitment, validUntil, engineSig, adapter)from the account.onSigned()runs when the wallet returns the hash. Then the receipt andonConfirmed(block).
{ txHash, kind: "committed", confirmedBlock }. A reverted receipt rejects. Prompts: one per token with allowance 0, then one.
The commit does not check the block switch or the caps again. The engine reports a later problem of the permission, such as a block or a full cap, in the tenant field of recover.
setErc20AllowBlocked
adapter.setBlocked(blocked) from the account. With true, the adapter refuses each pull of every token of this account. The allowances stay. With false, the pulls work again. Prompts: 1.
This is the fastest stop of this leg: one transaction pauses all payments, and one transaction resumes them.
setErc20AllowCaps
adapter.setCaps(entries) from the account. Each entry lets the adapter pull at most limit base units of token in each window of periodSeconds. Prompts: 1.
Throws Error("setCaps needs at least one cap") for an empty list. Throws an Error when a window is under ERC20_ALLOW_MIN_CAP_PERIOD_SECONDS (3600 seconds), because setCaps reverts on it.
When the window length stays the same, the adapter keeps the amount spent in the window. A new cap, or a new window length, starts with nothing spent. erc20AllowCapAfterSetCaps computes this.
clearErc20AllowCaps
adapter.clearCaps(tokens) from the account. Throws Error("clearCaps needs at least one token") for an empty list. Prompts: 1.
approveErc20AllowTokens
onStep(token) runs before each prompt. onConfirmed gets the block of each receipt, also when a later transaction fails. With no token to change, it sends nothing and returns { txHashes: [], confirmedBlock: null }.
revokeErc20Allowances
erc20s, at one tip block. Then it sends approve(adapter, 0) to each token whose allowance is above 0, in table order. onStep(token) runs before each prompt. It needs no Anafi API. Prompts: one per token with an allowance.
A token that is not in your erc20s table is not revoked. Revoke such a token yourself with buildErc20ApproveCalldata(adapter, 0n).
Helpers of this leg
Allowance and cap helpers
Live check
tokens, or null when it can. The block switch comes first. Then, for each token in order: an allowance of 0 (or no row) answers allowance_zero, and a cap with spentInPeriod >= limit answers cap_exhausted.
Document refusal
null. It throws nothing. Use it to show a refusal in an editor before any request. The causes are weighed in this order, and the first that holds answers:
findErc20AllowDocumentRefusalFromActions takes the result of documentActionTokens, so you read the text one time.
tokens(D) readers
erc20AllowDocumentTokenSymbols returns the spent tokens, then the fee token when it is new. readErc20AllowDocumentTokens returns tokens(D) with their contracts. It throws the errors of checks 2 to 8 of the stage. It does not read the swap support.
Erc20AllowOwnerTransaction and the calldata builders
buildErc20AllowCommitTransaction returns one. The calldata builders of this leg are on low-level helpers.
Errors of this leg
See errors for each class.