Skip to content

Commit

Permalink
Add new ERC interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
acuarica committed Dec 17, 2024
1 parent 2d1a8d4 commit 561c15e
Show file tree
Hide file tree
Showing 2 changed files with 316 additions and 0 deletions.
166 changes: 166 additions & 0 deletions scripts/ercs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,169 @@ interface ERC721 is ERC165 {
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}


/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// Note: the ERC-165 identifier for this interface is 0x5b5e139f.
interface ERC721Metadata is ERC721 {
/// @notice A descriptive name for a collection of NFTs in this contract
function name() external view returns (string memory);

/// @notice An abbreviated name for NFTs in this contract
function symbol() external view returns (string memory);

/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
function tokenURI(uint256 _tokenId) external view returns (string memory);
}

/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// Note: the ERC-165 identifier for this interface is 0x780e9d63.
interface ERC721Enumerable is ERC721 {
/// @notice Count NFTs tracked by this contract
/// @return A count of valid NFTs tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256);

/// @notice Enumerate valid NFTs
/// @dev Throws if `_index` >= `totalSupply()`.
/// @param _index A counter less than `totalSupply()`
/// @return The token identifier for the `_index`th NFT,
/// (sort order not specified)
function tokenByIndex(uint256 _index) external view returns (uint256);

/// @notice Enumerate NFTs assigned to an owner
/// @dev Throws if `_index` >= `balanceOf(_owner)` or if
/// `_owner` is the zero address, representing invalid NFTs.
/// @param _owner An address where we are interested in NFTs owned by them
/// @param _index A counter less than `balanceOf(_owner)`
/// @return The token identifier for the `_index`th NFT assigned to `_owner`,
/// (sort order not specified)
function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256);
}

/**
@title ERC-1155 Multi Token Standard
@dev See https://eips.ethereum.org/EIPS/eip-1155
Note: The ERC-165 identifier for this interface is 0xd9b67a26.
*/
interface ERC1155 is ERC165 {
/**
@dev Either `TransferSingle` or `TransferBatch` MUST emit when tokens are transferred, including zero value transfers as well as minting or burning (see "Safe Transfer Rules" section of the standard).
The `_operator` argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender).
The `_from` argument MUST be the address of the holder whose balance is decreased.
The `_to` argument MUST be the address of the recipient whose balance is increased.
The `_id` argument MUST be the token type being transferred.
The `_value` argument MUST be the number of tokens the holder balance is decreased by and match what the recipient balance is increased by.
When minting/creating tokens, the `_from` argument MUST be set to `0x0` (i.e. zero address).
When burning/destroying tokens, the `_to` argument MUST be set to `0x0` (i.e. zero address).
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value);

/**
@dev Either `TransferSingle` or `TransferBatch` MUST emit when tokens are transferred, including zero value transfers as well as minting or burning (see "Safe Transfer Rules" section of the standard).
The `_operator` argument MUST be the address of an account/contract that is approved to make the transfer (SHOULD be msg.sender).
The `_from` argument MUST be the address of the holder whose balance is decreased.
The `_to` argument MUST be the address of the recipient whose balance is increased.
The `_ids` argument MUST be the list of tokens being transferred.
The `_values` argument MUST be the list of number of tokens (matching the list and order of tokens specified in _ids) the holder balance is decreased by and match what the recipient balance is increased by.
When minting/creating tokens, the `_from` argument MUST be set to `0x0` (i.e. zero address).
When burning/destroying tokens, the `_to` argument MUST be set to `0x0` (i.e. zero address).
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);

/**
@dev MUST emit when approval for a second party/operator address to manage all tokens for an owner address is enabled or disabled (absence of an event assumes disabled).
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);

/**
@dev MUST emit when the URI is updated for a token ID.
URIs are defined in RFC 3986.
The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema".
*/
event URI(string _value, uint256 indexed _id);

/**
@notice Transfers `_value` amount of an `_id` from the `_from` address to the `_to` address specified (with safety call).
@dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
MUST revert if `_to` is the zero address.
MUST revert if balance of holder for token `_id` is lower than the `_value` sent.
MUST revert on any other error.
MUST emit the `TransferSingle` event to reflect the balance change (see "Safe Transfer Rules" section of the standard).
After the above conditions are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call `onERC1155Received` on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
@param _from Source address
@param _to Target address
@param _id ID of the token type
@param _value Transfer amount
@param _data Additional data with no specified format, MUST be sent unaltered in call to `onERC1155Received` on `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external;

/**
@notice Transfers `_values` amount(s) of `_ids` from the `_from` address to the `_to` address specified (with safety call).
@dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
MUST revert if `_to` is the zero address.
MUST revert if length of `_ids` is not the same as length of `_values`.
MUST revert if any of the balance(s) of the holder(s) for token(s) in `_ids` is lower than the respective amount(s) in `_values` sent to the recipient.
MUST revert on any other error.
MUST emit `TransferSingle` or `TransferBatch` event(s) such that all the balance changes are reflected (see "Safe Transfer Rules" section of the standard).
Balance changes and events MUST follow the ordering of the arrays (_ids[0]/_values[0] before _ids[1]/_values[1], etc).
After the above conditions for the transfer(s) in the batch are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call the relevant `ERC1155TokenReceiver` hook(s) on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard).
@param _from Source address
@param _to Target address
@param _ids IDs of each token type (order and length must match _values array)
@param _values Transfer amounts per token type (order and length must match _ids array)
@param _data Additional data with no specified format, MUST be sent unaltered in call to the `ERC1155TokenReceiver` hook(s) on `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external;

/**
@notice Get the balance of an account's tokens.
@param _owner The address of the token holder
@param _id ID of the token
@return The _owner's balance of the token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);

/**
@notice Get the balance of multiple account/token pairs
@param _owners The addresses of the token holders
@param _ids ID of the tokens
@return The _owner's balance of the token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);

/**
@notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens.
@dev MUST emit the ApprovalForAll event on success.
@param _operator Address to add to the set of authorized operators
@param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;

/**
@notice Queries the approval status of an operator for a given owner.
@param _owner The owner of the tokens
@param _operator Address of authorized operator
@return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}

/**
Note: The ERC-165 identifier for this interface is 0x0e89341c.
*/
interface ERC1155MetadataURI is ERC1155 {
/**
@notice A distinct Uniform Resource Identifier (URI) for a given token.
@dev URIs are defined in RFC 3986.
The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema".
@return URI string
*/
function uri(uint256 _id) external view returns (string memory);
}
150 changes: 150 additions & 0 deletions src/ercs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
// Autogenerated by `ercs.mjs`. DO NOT MODIFY
export default {
ERC1155: {
selectors: [
'00fdd58e',
'4e1273f4',
'e985e9c5',
'2eb2c2d6',
'f242432a',
'a22cb465',
'01ffc9a7'
],
topics: [
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31',
'4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb',
'c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
'6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b'
],
functions: {
'00fdd58e': 'function balanceOf(address _owner, uint256 _id) view returns (uint256)',
'4e1273f4': 'function balanceOfBatch(address[] _owners, uint256[] _ids) view returns (uint256[])',
e985e9c5: 'function isApprovedForAll(address _owner, address _operator) view returns (bool)',
'2eb2c2d6': 'function safeBatchTransferFrom(address _from, address _to, uint256[] _ids, uint256[] _values, bytes _data)',
f242432a: 'function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes _data)',
a22cb465: 'function setApprovalForAll(address _operator, bool _approved)',
'01ffc9a7': 'function supportsInterface(bytes4 interfaceID) view returns (bool)'
},
events: {
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31': 'event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)',
'4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb': 'event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values)',
c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62: 'event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value)',
'6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b': 'event URI(string _value, uint256 indexed _id)',
}
},
ERC1155MetadataURI: {
selectors: [
'00fdd58e',
'4e1273f4',
'e985e9c5',
'2eb2c2d6',
'f242432a',
'a22cb465',
'01ffc9a7',
'0e89341c'
],
topics: [
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31',
'4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb',
'c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',
'6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b'
],
functions: {
'00fdd58e': 'function balanceOf(address _owner, uint256 _id) view returns (uint256)',
'4e1273f4': 'function balanceOfBatch(address[] _owners, uint256[] _ids) view returns (uint256[])',
e985e9c5: 'function isApprovedForAll(address _owner, address _operator) view returns (bool)',
'2eb2c2d6': 'function safeBatchTransferFrom(address _from, address _to, uint256[] _ids, uint256[] _values, bytes _data)',
f242432a: 'function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes _data)',
a22cb465: 'function setApprovalForAll(address _operator, bool _approved)',
'01ffc9a7': 'function supportsInterface(bytes4 interfaceID) view returns (bool)',
'0e89341c': 'function uri(uint256 _id) view returns (string)'
},
events: {
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31': 'event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)',
'4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb': 'event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values)',
c3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62: 'event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value)',
'6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b': 'event URI(string _value, uint256 indexed _id)'
}
},
ERC165: {
selectors: ['01ffc9a7'],
topics: [],
Expand Down Expand Up @@ -123,4 +189,88 @@ export default {
'event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)',
},
},
ERC721Enumerable: {
selectors: [
'095ea7b3',
'70a08231',
'081812fc',
'e985e9c5',
'6352211e',
'42842e0e',
'b88d4fde',
'a22cb465',
'01ffc9a7',
'4f6ccce7',
'2f745c59',
'18160ddd',
'23b872dd',
],
topics: [
'8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925',
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31',
'ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
],
functions: {
'095ea7b3': 'function approve(address _approved, uint256 _tokenId) payable',
'70a08231': 'function balanceOf(address _owner) view returns (uint256)',
'081812fc': 'function getApproved(uint256 _tokenId) view returns (address)',
e985e9c5: 'function isApprovedForAll(address _owner, address _operator) view returns (bool)',
'6352211e': 'function ownerOf(uint256 _tokenId) view returns (address)',
'42842e0e': 'function safeTransferFrom(address _from, address _to, uint256 _tokenId) payable',
b88d4fde: 'function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) payable',
a22cb465: 'function setApprovalForAll(address _operator, bool _approved)',
'01ffc9a7': 'function supportsInterface(bytes4 interfaceID) view returns (bool)',
'4f6ccce7': 'function tokenByIndex(uint256 _index) view returns (uint256)',
'2f745c59': 'function tokenOfOwnerByIndex(address _owner, uint256 _index) view returns (uint256)',
'18160ddd': 'function totalSupply() view returns (uint256)',
'23b872dd': 'function transferFrom(address _from, address _to, uint256 _tokenId) payable'
},
events: {
'8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925': 'event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)',
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31': 'event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)',
ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef: 'event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)'
}
},
ERC721Metadata: {
selectors: [
'095ea7b3',
'70a08231',
'081812fc',
'e985e9c5',
'06fdde03',
'6352211e',
'42842e0e',
'b88d4fde',
'a22cb465',
'01ffc9a7',
'95d89b41',
'c87b56dd',
'23b872dd',
],
topics: [
'8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925',
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31',
'ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
],
functions: {
'095ea7b3': 'function approve(address _approved, uint256 _tokenId) payable',
'70a08231': 'function balanceOf(address _owner) view returns (uint256)',
'081812fc': 'function getApproved(uint256 _tokenId) view returns (address)',
e985e9c5: 'function isApprovedForAll(address _owner, address _operator) view returns (bool)',
'06fdde03': 'function name() view returns (string)',
'6352211e': 'function ownerOf(uint256 _tokenId) view returns (address)',
'42842e0e': 'function safeTransferFrom(address _from, address _to, uint256 _tokenId) payable',
b88d4fde: 'function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) payable',
a22cb465: 'function setApprovalForAll(address _operator, bool _approved)',
'01ffc9a7': 'function supportsInterface(bytes4 interfaceID) view returns (bool)',
'95d89b41': 'function symbol() view returns (string)',
c87b56dd: 'function tokenURI(uint256 _tokenId) view returns (string)',
'23b872dd': 'function transferFrom(address _from, address _to, uint256 _tokenId) payable'
},
events: {
'8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925': 'event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)',
'17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31': 'event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)',
ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef: 'event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)'
}
}
};

0 comments on commit 561c15e

Please sign in to comment.