Skip to content

SpendPermissionManager.sol smart contract

The open-source contracts repository is here.

Structs

SpendPermission

Defines the complete parameters of a spend permission.

FieldTypeDescription
accountaddressSmart account this spend permission is valid for.
spenderaddressEntity that can spend account's tokens.
tokenaddressToken address (ERC-7528 native token address or ERC-20 contract).
allowanceuint160Maximum allowed value to spend within each period.
perioduint48Time duration for resetting used allowance on a recurring basis (seconds).
startuint48Timestamp this spend permission is valid starting at (unix seconds).
enduint48Timestamp this spend permission is valid until (unix seconds).
saltuint256An arbitrary salt to differentiate unique spend permissions with otherwise identical data.
extraDatabytesArbitrary data to include in the permission.

PeriodSpend

Describes the cumulative spend for the current active period.

FieldTypeDescription
startuint48Start time of the period (unix seconds).
enduint48End time of the period (unix seconds).
spenduint160Accumulated spend amount for period.

Contract functions

approve

Approve a spend permission via a direct call from the account. Only callable by the account specified in the spend permission.

function approve(SpendPermission calldata spendPermission) external;

approveWithSignature

Approve a spend permission via a signature from the account owner. Compatible with ERC-6492 signatures for automatic account creation if needed.

function approveWithSignature(SpendPermission calldata spendPermission, bytes calldata signature) external;

spend

Spend tokens using a spend permission, transferring them from the account to the spender. Only callable by the spender specified in the permission.

function spend(SpendPermission memory spendPermission, uint160 value) external;

revoke

Revoke a spend permission, permanently disabling its use. Only callable by the account owner specified in the spend permission.

function revoke(SpendPermission calldata spendPermission) external;

getHash

Generate a hash of a SpendPermission struct for signing, in accordance with EIP-712.

function getHash(SpendPermission memory spendPermission) public view returns (bytes32);

isApproved

Check if a spend permission is approved and not revoked, regardless of whether the current time is within the valid time range of the permission.

function isApproved(SpendPermission memory spendPermission) public view returns (bool);

getCurrentPeriod

Retrieve the start, end, and accumulated spend for the current period of a spend permission. Reverts if the current time is outside the valid time range of the permission, but does not validate whether the spend permission has been approved or revoked.

function getCurrentPeriod(SpendPermission memory spendPermission) public view returns (PeriodSpend memory);