IAllowanceManager

Git Source

Author: Ultrasound Labs

Interface for the AllowanceManager contract responsible for time-boxed pull-allowances that subaccounts (Safes) can spend. It supports batch EIP-712(x) signing across chains.

Functions

bootstrapAllowance

Bootstrap an allowance once immediately after AllowanceHolder deployment.

Can only be called by the canonical AllowanceHolder for (owner, token) and only when nonce == 0. After a successful call, allowanceNonces[owner][subaccount][token] will be incremented to 1 so that any subsequent changes require a signed setAllowances().

function bootstrapAllowance(address owner, address subaccount, address token, uint256 amount, uint256 timeframe)
    external;

Parameters

NameTypeDescription
owneraddressThe owner of the allowance (signer of the permit given to the holder).
subaccountaddressSubaccount that the allowance applies to.
tokenaddressERC-20 token address.
amountuint256Allowance amount.
timeframeuint256Time window in seconds for the allowance resets.

commitHolder

Commits the expected AllowanceHolder address for an (owner, token) pair before deployment.

Must be called exactly once per (owner, token) pair and before the first bootstrapAllowance call. The first bootstrap must come from the committed holder; after a successful bootstrap the commit is cleared so future holders (for different subaccounts) can be deployed without an extra commit.

Access control: This function MAY only be called by the canonical SubaccountFactory (address set in the AllowanceManager constructor). Any call from another address MUST revert.

function commitHolder(address owner, address token, address holder) external;

Parameters

NameTypeDescription
owneraddressThe token owner that will grant allowance.
tokenaddressThe ERC-20 token the holder will manage.
holderaddressThe deterministic address where the AllowanceHolder will be deployed (CREATE2 pre-image).

registerHolder

Registers an additional AllowanceHolder address after the canonical one has been initialised.

Must be called by the canonical SubaccountFactory before the new holder constructor executes so that the holder can successfully call bootstrapAllowance. Skips commit-reveal checks and only pre-authorises the address.

function registerHolder(address holder) external;

Parameters

NameTypeDescription
holderaddressThe deterministic address of the new AllowanceHolder.

setAllowances

Sets allowances for a batch of subaccounts

function setAllowances(address owner, AllowanceRequestBatch calldata requests, bytes calldata signature) external;

Parameters

NameTypeDescription
owneraddressThe owner of the subaccounts
requestsAllowanceRequestBatchThe AllowanceRequestBatch struct containing the requests
signaturebytesThe EIP-712x (EIP-712 with chainId = 1) signature of the owner

spendAllowance

Spends an allowance for the caller

function spendAllowance(address owner, address token, uint256 amount) external;

Parameters

NameTypeDescription
owneraddressThe owner of the subaccount
tokenaddressThe token to spend the allowance for
amountuint256The amount to spend

holderAddress

Deterministically computes the canonical AllowanceHolder address for a pair (owner, token).

function holderAddress(address owner, address token) external view returns (address holder);

Parameters

NameTypeDescription
owneraddressThe token owner.
tokenaddressThe ERC-20 token.

Returns

NameTypeDescription
holderaddressThe predicted holder address (or address(0) if unknown).

allowances

Mapping to track allowances for subaccounts.

function allowances(address owner, address subaccount, address token) external view returns (Allowance memory);

Parameters

NameTypeDescription
owneraddressThe owner of the subaccount.
subaccountaddressThe subaccount that the allowance is set for.
tokenaddressThe token that the allowance is set for.

Returns

NameTypeDescription
<none>Allowanceallowance The allowance struct.

allowanceNonces

Mapping to track allowance nonces for subaccounts.

function allowanceNonces(address owner, address subaccount, address token) external view returns (uint256 nonce);

Parameters

NameTypeDescription
owneraddressThe owner of the subaccount.
subaccountaddressThe subaccount that the allowance is set for.
tokenaddressThe token that the allowance is set for.

Returns

NameTypeDescription
nonceuint256The nonce of the allowance.

permit2

The Permit2 contract address

function permit2() external view returns (address permit2Addr);

Returns

NameTypeDescription
permit2AddraddressThe Permit2 contract address.

allowanceRequestTypehash

EIP-712(x) typehash for the AllowanceRequest struct (per-subaccount)

function allowanceRequestTypehash() external pure returns (bytes32 typeHash);

Returns

NameTypeDescription
typeHashbytes32The struct type-hash.

allowanceRequestBatchTypehash

EIP-712(x) typehash for the AllowanceRequestBatch struct (per-subaccount)

function allowanceRequestBatchTypehash() external pure returns (bytes32 typeHash);

Returns

NameTypeDescription
typeHashbytes32The struct type-hash.

hashAllowanceRequestBatch

Computes the EIP-712 struct hash for a batch of allowance requests.

function hashAllowanceRequestBatch(AllowanceRequestBatch calldata batch) external pure returns (bytes32 structHash);

Parameters

NameTypeDescription
batchAllowanceRequestBatchThe AllowanceRequestBatch struct to hash.

Returns

NameTypeDescription
structHashbytes32The EIP-712 struct hash.

Events

AllowanceSet

Emitted when a new allowance is set.

event AllowanceSet(
    address indexed owner, address indexed subaccount, address indexed token, uint256 amount, uint256 timeframe
);

Parameters

NameTypeDescription
owneraddressThe owner of the subaccount.
subaccountaddressThe subaccount that the allowance is set for.
tokenaddressThe token that the allowance is set for.
amountuint256The amount of the allowance.
timeframeuint256The timeframe of the allowance.

AllowanceSpent

Emitted when an allowance is spent.

event AllowanceSpent(address indexed owner, address indexed subaccount, address indexed token, uint256 amount);

Parameters

NameTypeDescription
owneraddressThe owner of the subaccount.
subaccountaddressThe subaccount that the allowance is spent for.
tokenaddressThe token that the allowance is spent for.
amountuint256The amount of the allowance that was spent.

Errors

AllowanceExceeded

Emitted when an allowance is exceeded.

error AllowanceExceeded();

Structs

AllowanceRequest

Struct for a single allowance request.

struct AllowanceRequest {
    address subaccount;
    address token;
    uint256 amount;
    uint256 timeframe;
    uint256 nonce;
}

AllowanceRequestBatch

Struct for a batch of allowance requests.

struct AllowanceRequestBatch {
    AllowanceRequest[] requests;
    uint256[] chainIds;
}

Allowance

Struct for an allowance.

struct Allowance {
    uint256 amount;
    uint256 timeframe;
    uint256 spent;
    uint256 resetsAt;
}