Skip to content
Lattice

ERC6551AccountLib

Git Source

Title: ERC6551AccountLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from ERC-6551 reference (https://github.com/erc6551/reference)

Logic + ERC-7201 storage for the ERC-6551 token-bound account. The account is controlled by the current owner of the bound ERC-721 token: that owner is the sole valid signer and the only caller of execute. The binding is set once at init.

v1 supports operation == 0 (CALL) and resolves ownership only on the token's home chain (a token bound on a foreign chain has no on-chain-resolvable owner → no valid signer). state bumps on each execution so consumers can detect account mutations.

Functions

erc6551AccountStorage

function erc6551AccountStorage() internal pure returns (ERC6551AccountStorage storage $);

Returns

NameTypeDescription
$ERC6551AccountStorage

__ERC6551Account_init

Binds the account to (chainId, tokenContract, tokenId) and registers the ERC-6551 ids.

function __ERC6551Account_init(uint256 chainId, address tokenContract, uint256 tokenId) internal;

Parameters

NameTypeDescription
chainIduint256
tokenContractaddress
tokenIduint256

registerInterfaces

Writes true to the ERC-165 map slots for IERC6551Account and IERC6551Executable.

function registerInterfaces() internal;

token

function token() internal view returns (uint256 chainId, address tokenContract, uint256 tokenId);

Returns

NameTypeDescription
chainIduint256
tokenContractaddress
tokenIduint256

state

function state() internal view returns (uint256);

Returns

NameTypeDescription
<none>uint256

isValidSigner

Returns the ERC-6551 magic value iff signer is the bound token's current owner.

function isValidSigner(address signer, bytes calldata) internal view returns (bytes4);

Parameters

NameTypeDescription
signeraddress
_bytes

Returns

NameTypeDescription
<none>bytes4

execute

Executes a CALL on behalf of the token owner. Reverts InvalidSigner for any other caller and UnsupportedOperation for operation != 0. Bumps state; bubbles inner revert data.

function execute(address to, uint256 value, bytes calldata data, uint8 operation)
        internal
        returns (bytes memory result);

Parameters

NameTypeDescription
toaddress
valueuint256
databytes
operationuint8

Returns

NameTypeDescription
resultbytes

_tokenOwner

The bound token's current owner, or address(0) if bound on another chain or unresolvable.

function _tokenOwner() private view returns (address);

Returns

NameTypeDescription
<none>address