ERC6551AccountLib
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
| Name | Type | Description |
|---|---|---|
| $ | 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
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| tokenContract | address | |
| tokenId | uint256 |
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
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| tokenContract | address | |
| tokenId | uint256 |
state
function state() internal view returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| signer | address | |
| _ | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| to | address | |
| value | uint256 | |
| data | bytes | |
| operation | uint8 |
Returns
| Name | Type | Description |
|---|---|---|
| result | bytes |
_tokenOwner
The bound token's current owner, or address(0) if bound on another chain or unresolvable.
function _tokenOwner() private view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |