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>
6.6 KiB
ERC6909
Simple EIP-6909 implementation.
Note:
The ERC6909 standard allows minting and transferring to and from the zero address, minting and transferring zero tokens, as well as self-approvals. For performance, this implementation WILL NOT revert for such actions. Please add any checks with overrides if desired.
If you are overriding:
- Make sure all variables written to storage are properly cleaned
(e.g. the bool value for
isOperatorMUST be either 1 or 0 under the hood). - Check that the overridden function is actually used in the function you want to change the behavior of. Much of the code has been manually inlined for performance.
Custom Errors
InsufficientBalance()
error InsufficientBalance()
Insufficient balance.
InsufficientPermission()
error InsufficientPermission()
Insufficient permission to perform the action.
BalanceOverflow()
error BalanceOverflow()
The balance has overflowed.
Events
Transfer(address,address,address,uint256,uint256)
event Transfer(
address by,
address indexed from,
address indexed to,
uint256 indexed id,
uint256 amount
)
Emitted when by transfers amount of token id from from to to.
OperatorSet(address,address,bool)
event OperatorSet(
address indexed owner, address indexed operator, bool approved
)
Emitted when owner enables or disables operator to manage all of their tokens.
Approval(address,address,uint256,uint256)
event Approval(
address indexed owner,
address indexed spender,
uint256 indexed id,
uint256 amount
)
Emitted when owner approves spender to use amount of id token.
ERC6909 Metadata
tokenURI(uint256)
function tokenURI(uint256 id) public view virtual returns (string memory);
Returns the Uniform Resource Identifier (URI) for token id.
ERC6909
balanceOf(address,uint256)
function balanceOf(address owner, uint256 id)
public
view
virtual
returns (uint256 amount)
Returns the amount of token id owned by owner.
allowance(address,address,uint256)
function allowance(address owner, address spender, uint256 id)
public
view
virtual
returns (uint256 amount)
Returns the amount of token id that spender can spend on behalf of owner.
isOperator(address,address)
function isOperator(address owner, address spender)
public
view
virtual
returns (bool status)
Checks if a spender is approved by owner to manage all of their tokens.
transfer(address,uint256,uint256)
function transfer(address to, uint256 id, uint256 amount)
public
payable
virtual
returns (bool)
Transfers amount of token id from the caller to to.
Requirements:
- caller must at least have
amount.
Emits a Transfer event.
transferFrom(address,address,uint256,uint256)
function transferFrom(address from, address to, uint256 id, uint256 amount)
public
payable
virtual
returns (bool)
Transfers amount of token id from from to to.
Note:
- Allowance is NOT deducted if it is
type(uint256).max. - Allowance is NOT deducted if
fromis an operator. - For efficiency, allowance is deducted even if
fromis the caller.
Requirements:
frommust at least haveamountof tokenid.- The caller must have at least
amountof allowance to transfer the
tokens offromor approved as an operator.
Emits a Transfer event.
approve(address,uint256,uint256)
function approve(address spender, uint256 id, uint256 amount)
public
payable
virtual
returns (bool)
Sets amount as the allowance of spender for the caller for token id.
Emits a Approval event.
setOperator(address,bool)
function setOperator(address operator, bool approved)
public
payable
virtual
returns (bool)
Sets whether operator is approved to manage the tokens of the caller.
Emits OperatorSet event.
supportsInterface(bytes4)
function supportsInterface(bytes4 interfaceId)
public
view
virtual
returns (bool result)
Returns true if this contract implements the interface defined by interfaceId.
Internal Functions
_mint(address,uint256,uint256)
function _mint(address to, uint256 id, uint256 amount) internal virtual
Mints amount of token id to to.
Emits a Transfer event.
_burn(address,uint256,uint256)
function _burn(address from, uint256 id, uint256 amount) internal virtual
Burns amount token id from from.
Emits a Transfer event.
_transfer(address,address,address,uint256,uint256)
function _transfer(
address by,
address from,
address to,
uint256 id,
uint256 amount
) internal virtual
Transfers amount of token id from from to to.
Note:
- Allowance is NOT deducted if it is
type(uint256).max. - Allowance is NOT deducted if
fromis an operator. - For efficiency, allowance is deducted even if
fromisby.
Requirements:
frommust at least haveamountof tokenid.- If
byis not the zero address,
it must have at leastamountof allowance to transfer the
tokens offromor approved as an operator.
Emits a Transfer event.
_approve(address,address,uint256,uint256)
function _approve(
address owner,
address spender,
uint256 id,
uint256 amount
) internal virtual
Sets amount as the allowance of spender for owner for token id.
Emits a Approval event.
_setOperator(address,address,bool)
function _setOperator(address owner, address operator, bool approved)
internal
virtual
Sets whether operator is approved to manage the tokens of owner.
Emits OperatorSet event.
Hooks To Override
_beforeTokenTransfer(address,address,uint256,uint256)
function _beforeTokenTransfer(
address from,
address to,
uint256 id,
uint256 amount
) internal virtual
Hook that is called before any transfer of tokens.
This includes minting and burning.
_afterTokenTransfer(address,address,uint256,uint256)
function _afterTokenTransfer(
address from,
address to,
uint256 id,
uint256 amount
) internal virtual
Hook that is called after any transfer of tokens.
This includes minting and burning.