SpendingLimit
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
| Name | Type | Description |
|---|---|---|
| data | bytes |
onUninstall
data = abi.encode(uint32 entityId).
function onUninstall(bytes calldata data) external;Parameters
| Name | Type | Description |
|---|---|---|
| data | bytes |
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
| Name | Type | Description |
|---|---|---|
| entityId | uint32 | |
| _ | address | |
| _ | uint256 | |
| data | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes | Context 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
| Name | Type | Description |
|---|---|---|
| _ | 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
| Name | Type | Description |
|---|---|---|
| <none> | string |
supportsInterface
function supportsInterface(bytes4 interfaceId) external pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| interfaceId | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
Events
CapSet
event CapSet(address indexed account, uint32 indexed entityId, uint256 cap);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| entityId | uint32 | |
| cap | uint256 |
Errors
SpendCapExceeded
The call would push cumulative spending past the cap.
error SpendCapExceeded(uint256 attempted, uint256 cap);Parameters
| Name | Type | Description |
|---|---|---|
| attempted | uint256 | |
| cap | uint256 |