caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

312 lines
7.5 KiB
Markdown

# ERC6551
Simple ERC6551 account implementation.
<b>Recommended usage (regular):</b>
1. Deploy the ERC6551 as an implementation contract, and verify it on Etherscan.
2. Use the canonical ERC6551Registry to deploy a clone to the ERC6551 implementation.
The UUPSUpgradeable functions will be disabled.
<b>Recommended usage (upgradeable):</b>
1. Deploy the ERC6551 as an implementation contract, and verify it on Etherscan.
2. Deploy the ERC6551Proxy pointing to the implementation.
This relay proxy is required, but Etherscan verification of it is optional.
3. Use the canonical ERC6551Registry to deploy a clone to the ERC6551Proxy.
If you want to reveal the "Read as Proxy" and "Write as Proxy" tabs on Etherscan,
send 0 ETH to the clone to initialize its ERC1967 implementation slot,
the click on "Is this a proxy?" on the clone's page on Etherscan.
<b>Note:</b>
- This implementation does NOT include ERC4337 functionality.
This is intentional, because the canonical ERC4337 entry point may still change and we
don't want to encourage upgradeability by default for ERC6551 accounts just to handle this.
We may include ERC4337 functionality once ERC4337 has been finalized.
Recent updates to the account abstraction validation scope rules
[ERC7562](https://eips.ethereum.org/EIPS/eip-7562) has made ERC6551 compatible with ERC4337.
For an opinionated implementation, see https://github.com/tokenbound/contracts.
If you want to add it yourself, you'll just need to add in the
user operation validation functionality (and use ERC6551's execution functionality).
- Please refer to the official [ERC6551](https&#58;//github.com/erc6551/reference) reference
for latest updates on the ERC6551 standard, as well as canonical registry information.
<b>Inherits:</b>
- [`utils/UUPSUpgradeable.sol`](utils/uupsupgradeable.md)
- [`accounts/Receiver.sol`](accounts/receiver.md)
- [`accounts/ERC1271.sol`](accounts/erc1271.md)
<!-- customintro:start --><!-- customintro:end -->
## Structs
### Call
```solidity
struct Call {
address target;
uint256 value;
bytes data;
}
```
Call struct for the `executeBatch` function.
## Custom Errors
### Unauthorized()
```solidity
error Unauthorized()
```
The caller is not authorized to call the function.
### OperationNotSupported()
```solidity
error OperationNotSupported()
```
The operation is not supported.
### SelfOwnDetected()
```solidity
error SelfOwnDetected()
```
Self ownership detected.
## Constants And Immutables
### _ERC6551_STATE_SLOT
```solidity
uint256 internal constant _ERC6551_STATE_SLOT =
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffb919c7a5
```
The ERC6551 state slot is given by:
`bytes32(~uint256(uint32(bytes4(keccak256("_ERC6551_STATE_SLOT_NOT")))))`.
It is intentionally chosen to be a high value
to avoid collision with lower slots.
The choice of manual storage layout is to enable compatibility
with both regular and upgradeable contracts.
## Token-bound Ownership Operations
### token()
```solidity
function token()
public
view
virtual
returns (uint256 chainId, address tokenContract, uint256 tokenId)
```
Returns the token-bound information.
### owner()
```solidity
function owner() public view virtual returns (address result)
```
Returns the owner of the contract.
### _isValidSigner(address,bytes32,bytes)
```solidity
function _isValidSigner(
address signer,
bytes32 extraData,
bytes calldata context
) internal view virtual returns (bool)
```
Returns if `signer` is an authorized signer.
`extraData` can be anything (e.g. an address, a pointer to a struct / string in memory).
### isValidSigner(address,bytes)
```solidity
function isValidSigner(address signer, bytes calldata context)
public
view
virtual
returns (bytes4 result)
```
Returns if `signer` is an authorized signer, with an optional `context`.
MUST return the bytes4 magic value `0x523e3260` if the given signer is valid.
By default, the holder of the non-fungible token the account is bound to
MUST be considered a valid signer.
### _emptyContext()
```solidity
function _emptyContext() internal pure returns (bytes calldata context)
```
Returns empty calldata bytes.
### onlyValidSigner()
```solidity
modifier onlyValidSigner() virtual
```
Requires that the caller is a valid signer (i.e. the owner).
## State Operations
### state()
```solidity
function state() public view virtual returns (bytes32 result)
```
Returns the current value of the state.
### _updateState()
```solidity
function _updateState() internal virtual
```
Mutates the state. This function is required to be called in every
public / external function that may modify storage or emit events.
## Execution Operations
### execute(address,uint256,bytes,uint8)
```solidity
function execute(
address target,
uint256 value,
bytes calldata data,
uint8 operation
) public payable virtual onlyValidSigner returns (bytes memory result)
```
Execute a call from this account.
Reverts and bubbles up error if operation fails.
Returns the result of the operation.
Accounts MUST accept the following operation parameter values:
- 0 = CALL
- 1 = DELEGATECALL
- 2 = CREATE
- 3 = CREATE2
Accounts MAY support additional operations or restrict a signer's
ability to execute certain operations.
### executeBatch(Call[],uint8)
```solidity
function executeBatch(Call[] calldata calls, uint8 operation)
public
payable
virtual
onlyValidSigner
returns (bytes[] memory results)
```
Execute a sequence of calls from this account.
Reverts and bubbles up error if an operation fails.
Returns the results of the operations.
This is a batch variant of `execute` and is not required for `IERC6551Executable`.
## ERC165
### supportsInterface(bytes4)
```solidity
function supportsInterface(bytes4 interfaceId)
public
view
virtual
returns (bool result)
```
Returns true if this contract implements the interface defined by `interfaceId`.
See: https://eips.ethereum.org/EIPS/eip-165
This function call must use less than 30000 gas.
## Internal Helpers
### _hasOwnershipCycle()
```solidity
function _hasOwnershipCycle() internal view virtual returns (bool result)
```
Returns whether there is an ownership cycle.
## Overrides
### _authorizeUpgrade(address)
```solidity
function _authorizeUpgrade(address)
internal
virtual
override(UUPSUpgradeable)
onlyValidSigner
onlyViaERC6551Proxy
```
To ensure that only the owner or the account itself can upgrade the implementation.
If you don't need upgradeability, override this function to return false for extra safety.
### onlyViaERC6551Proxy()
```solidity
modifier onlyViaERC6551Proxy() virtual
```
Guards `_authorizeUpgrade` such that it must be used via an ERC6551Proxy.
### _erc1271Signer()
```solidity
function _erc1271Signer()
internal
view
virtual
override(ERC1271)
returns (address)
```
Uses the `owner` as the ERC1271 signer.
### receiverFallback()
```solidity
modifier receiverFallback() override(Receiver)
```
For handling token callbacks.
Safe-transferred ERC721 tokens will trigger an ownership cycle check.
### _useLibZipCdFallback()
```solidity
function _useLibZipCdFallback() internal view virtual returns (bool)
```
If you don't need to use `LibZip.cdFallback`, override this function to return false.
### fallback()
```solidity
fallback() external payable virtual override(Receiver) receiverFallback
```
Handle token callbacks. If no token callback is triggered,
use `LibZip.cdFallback` for generalized calldata decompression.