Skip to content
Lattice

SpendingLimit

Git Source

Inherits: IERC6900ExecutionHookModule

Title: SpendingLimit

Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)

A reference ERC-6900 execution-hook module: a cumulative native-value spending cap per (account, entityId). Installed as a PRE-execution hook on execute (the native call selector), it decodes the call's value and reverts once the running total would exceed the configured cap — the canonical "session key may spend at most X" permission, expressed as a hook.

Standalone module invoked by the account via CALL (msg.sender is the account; budget is per-account). The hook receives the wrapped native call's full calldata (execute(address,uint256,bytes)), from which it reads the value argument. Reference quality: cumulative-only (no time windows / per-token limits).

State Variables

capOf

The cumulative native-value cap for (account, entityId).

mapping(address account => mapping(uint32 entityId => uint256 cap)) public capOf;

spentOf

The native value spent so far against (account, entityId).

mapping(address account => mapping(uint32 entityId => uint256 spent)) public spentOf;

Functions

onInstall

data = abi.encode(uint32 entityId, uint256 cap).

function onInstall(bytes calldata data) external;

Parameters

NameTypeDescription
databytes

onUninstall

data = abi.encode(uint32 entityId).

function onUninstall(bytes calldata data) external;

Parameters

NameTypeDescription
databytes

preExecutionHook

data is the wrapped execute(address target, uint256 value, bytes data) calldata; the cap applies to the cumulative value.

function preExecutionHook(uint32 entityId, address, uint256, bytes calldata data) external returns (bytes memory);

Parameters

NameTypeDescription
entityIduint32
_address
_uint256
databytes

Returns

NameTypeDescription
<none>bytesContext passed to the matching post-execution hook (MAY be empty); MUST revert to reject.

postExecutionHook

MUST revert to reject; preExecHookData is the context from the matching pre-execution hook.

function postExecutionHook(uint32, bytes calldata) external;

Parameters

NameTypeDescription
_uint32
_bytes

moduleId

Unique id in the format "vendor.module.semver"; vendor/module names MUST NOT contain a period.

function moduleId() external pure returns (string memory);

Returns

NameTypeDescription
<none>string

supportsInterface

function supportsInterface(bytes4 interfaceId) external pure returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4

Returns

NameTypeDescription
<none>bool

Events

CapSet

event CapSet(address indexed account, uint32 indexed entityId, uint256 cap);

Parameters

NameTypeDescription
accountaddress
entityIduint32
capuint256

Errors

SpendCapExceeded

The call would push cumulative spending past the cap.

error SpendCapExceeded(uint256 attempted, uint256 cap);

Parameters

NameTypeDescription
attempteduint256
capuint256