diff --git a/contracts/RMRK/extension/tokenHolder/ERC1155Holder.sol b/contracts/RMRK/extension/tokenHolder/ERC1155Holder.sol new file mode 100644 index 00000000..c06cfe1f --- /dev/null +++ b/contracts/RMRK/extension/tokenHolder/ERC1155Holder.sol @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; + +import "./IERC1155Holder.sol"; +import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; + +error InvalidValueForERC1155(); +error InvalidAddressForERC1155(); +error InsufficientBalance(); + +abstract contract ERC1155Holder is IERC1155Holder { + mapping(uint256 tokenHolderId => mapping(address erc1155Address => mapping(uint256 tokenHeldId => uint256 balance))) + private _balances; + + /** + * @inheritdoc IERC1155Holder + */ + function balanceOfERC1155( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenHeldId + ) external view returns (uint256) { + return _balances[tokenHolderId][erc1155Contract][tokenHeldId]; + } + + /** + * @notice Transfer ERC-1155 tokens from a specific token + * @dev The balance MUST be transferred from this smart contract. + * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this. + * @param erc1155Contract The ERC-1155 contract + * @param tokenHolderId The token to transfer from + * @param tokenToTransferId The ID of the held token being sent + * @param amount The number of ERC-1155 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _transferHeldERC1155FromToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + uint256 amount, + bytes memory data + ) internal { + if (amount == 0) { + revert InvalidValueForERC1155(); + } + if (to == address(0) || erc1155Contract == address(0)) { + revert InvalidAddressForERC1155(); + } + if ( + _balances[tokenHolderId][erc1155Contract][tokenToTransferId] < + amount + ) { + revert InsufficientBalance(); + } + _beforeTransferHeldERC1155FromToken( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + to, + amount, + data + ); + _balances[tokenHolderId][erc1155Contract][tokenToTransferId] -= amount; + + IERC1155(erc1155Contract).safeTransferFrom( + address(this), + to, + tokenToTransferId, + amount, + data + ); + + emit TransferredERC1155( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + to, + amount + ); + _afterTransferHeldERC1155FromToken( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + to, + amount, + data + ); + } + + /** + * @inheritdoc IERC1155Holder + */ + function transferERC1155ToToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + uint256 amount, + bytes memory data + ) external { + if (amount == 0) { + revert InvalidValueForERC1155(); + } + if (erc1155Contract == address(0)) { + revert InvalidAddressForERC1155(); + } + _beforeTransferERC1155ToToken( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + msg.sender, + amount, + data + ); + IERC1155(erc1155Contract).safeTransferFrom( + msg.sender, + address(this), + tokenToTransferId, + amount, + data + ); + _balances[tokenHolderId][erc1155Contract][tokenToTransferId] += amount; + + emit ReceivedERC1155( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + msg.sender, + amount + ); + _afterTransferERC1155ToToken( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + msg.sender, + amount, + data + ); + } + + /** + * @notice Hook that is called before any transfer of ERC-1155 tokens from a token + * @param tokenHolderId The token to transfer from + * @param tokenToTransferId The ID of the held token being sent + * @param to The address to send the ERC-1155 tokens to + * @param erc1155Contract The ERC-1155 contract + * @param amount The number of ERC-1155 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _beforeTransferHeldERC1155FromToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + uint256 amount, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called after any transfer of ERC-1155 tokens from a token + * @param tokenHolderId The token to transfer from + * @param tokenToTransferId The ID of the held token being sent + * @param to The address to send the ERC-1155 tokens to + * @param erc1155Contract The ERC-1155 contract + * @param amount The number of ERC-1155 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _afterTransferHeldERC1155FromToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + uint256 amount, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called before any transfer of ERC-1155 tokens to a token + * @param tokenHolderId The token to transfer to + * @param tokenToTransferId The ID of the held token being received + * @param from The address to send the ERC-1155 tokens from + * @param erc1155Contract The ERC-1155 contract + * @param amount The number of ERC-1155 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _beforeTransferERC1155ToToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address from, + uint256 amount, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called after any transfer of ERC-1155 tokens to a token + * @param tokenHolderId The token to transfer to + * @param tokenToTransferId The ID of the held token being received + * @param from The address to send the ERC-1155 tokens from + * @param erc1155Contract The ERC-1155 contract + * @param amount The number of ERC-1155 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _afterTransferERC1155ToToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address from, + uint256 amount, + bytes memory data + ) internal virtual {} + + function supportsInterface( + bytes4 interfaceId + ) public view virtual override returns (bool) { + return type(IERC1155Holder).interfaceId == interfaceId; + } + + function onERC1155Received( + address, + address, + uint256, + uint256, + bytes memory + ) public pure virtual returns (bytes4) { + return this.onERC1155Received.selector; + } +} diff --git a/contracts/RMRK/extension/tokenHolder/ERC20Holder.sol b/contracts/RMRK/extension/tokenHolder/ERC20Holder.sol new file mode 100644 index 00000000..d10f2989 --- /dev/null +++ b/contracts/RMRK/extension/tokenHolder/ERC20Holder.sol @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; + +import "./IERC20Holder.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +error InvalidValueForERC20(); +error InvalidAddressForERC20(); +error InsufficientBalanceForERC20(); + +abstract contract ERC20Holder is IERC20Holder { + mapping(uint256 tokenId => mapping(address erc20Address => uint256 balance)) + private _balances; + + /** + * @inheritdoc IERC20Holder + */ + function balanceOfERC20( + address erc20Contract, + uint256 tokenId + ) external view returns (uint256) { + return _balances[tokenId][erc20Contract]; + } + + /** + * @notice Transfer ERC-20 tokens from a specific token + * @dev The balance MUST be transferred from this smart contract. + * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this. + * @param erc20Contract The ERC-20 contract + * @param tokenId The token to transfer from + * @param amount The number of ERC-20 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _transferHeldERC20FromToken( + address erc20Contract, + uint256 tokenId, + address to, + uint256 amount, + bytes memory data + ) internal { + if (amount == 0) { + revert InvalidValueForERC20(); + } + if (to == address(0) || erc20Contract == address(0)) { + revert InvalidAddressForERC20(); + } + if (_balances[tokenId][erc20Contract] < amount) { + revert InsufficientBalanceForERC20(); + } + _beforeTransferHeldERC20FromToken( + erc20Contract, + tokenId, + to, + amount, + data + ); + _balances[tokenId][erc20Contract] -= amount; + + IERC20(erc20Contract).transfer(to, amount); + + emit TransferredERC20(erc20Contract, tokenId, to, amount); + _afterTransferHeldERC20FromToken( + erc20Contract, + tokenId, + to, + amount, + data + ); + } + + /** + * @inheritdoc IERC20Holder + */ + function transferERC20ToToken( + address erc20Contract, + uint256 tokenId, + uint256 amount, + bytes memory data + ) external { + if (amount == 0) { + revert InvalidValueForERC20(); + } + if (erc20Contract == address(0)) { + revert InvalidAddressForERC20(); + } + _beforeTransferERC20ToToken( + erc20Contract, + tokenId, + msg.sender, + amount, + data + ); + IERC20(erc20Contract).transferFrom(msg.sender, address(this), amount); + _balances[tokenId][erc20Contract] += amount; + + emit ReceivedERC20(erc20Contract, tokenId, msg.sender, amount); + _afterTransferERC20ToToken( + erc20Contract, + tokenId, + msg.sender, + amount, + data + ); + } + + /** + * @notice Hook that is called before any transfer of ERC-20 tokens from a token + * @param tokenId The token to transfer from + * @param to The address to send the ERC-20 tokens to + * @param erc20Contract The ERC-20 contract + * @param amount The number of ERC-20 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _beforeTransferHeldERC20FromToken( + address erc20Contract, + uint256 tokenId, + address to, + uint256 amount, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called after any transfer of ERC-20 tokens from a token + * @param tokenId The token to transfer from + * @param to The address to send the ERC-20 tokens to + * @param erc20Contract The ERC-20 contract + * @param amount The number of ERC-20 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _afterTransferHeldERC20FromToken( + address erc20Contract, + uint256 tokenId, + address to, + uint256 amount, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called before any transfer of ERC-20 tokens to a token + * @param tokenId The token to transfer from + * @param from The address to send the ERC-20 tokens from + * @param erc20Contract The ERC-20 contract + * @param amount The number of ERC-20 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _beforeTransferERC20ToToken( + address erc20Contract, + uint256 tokenId, + address from, + uint256 amount, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called after any transfer of ERC-20 tokens to a token + * @param tokenId The token to transfer from + * @param from The address to send the ERC-20 tokens from + * @param erc20Contract The ERC-20 contract + * @param amount The number of ERC-20 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function _afterTransferERC20ToToken( + address erc20Contract, + uint256 tokenId, + address from, + uint256 amount, + bytes memory data + ) internal virtual {} + + function supportsInterface( + bytes4 interfaceId + ) public view virtual override returns (bool) { + return type(IERC20Holder).interfaceId == interfaceId; + } +} diff --git a/contracts/RMRK/extension/tokenHolder/ERC721Holder.sol b/contracts/RMRK/extension/tokenHolder/ERC721Holder.sol new file mode 100644 index 00000000..c94c34e5 --- /dev/null +++ b/contracts/RMRK/extension/tokenHolder/ERC721Holder.sol @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; + +import "./IERC721Holder.sol"; +import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; + +error InvalidAddressForERC721(); +error TokenNotHeldForERC721(); + +abstract contract ERC721Holder is IERC721Holder { + mapping(uint256 tokenHolderId => mapping(address erc721Address => mapping(uint256 tokenHeldId => uint256 balance))) + private _balances; + + /** + * @inheritdoc IERC721Holder + */ + function balanceOfERC721( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenHeldId + ) external view returns (uint256) { + return _balances[tokenHolderId][erc721Contract][tokenHeldId]; + } + + /** + * @notice Transfer ERC-721 tokens from a specific token + * @dev The balance MUST be transferred from this smart contract. + * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this. + * @param erc721Contract The ERC-721 contract + * @param tokenHolderId The token to transfer from + * @param tokenToTransferId The ID of the held token being sent + * @param data Additional data with no specified format, to allow for custom logic + */ + function _transferHeldERC721FromToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + bytes memory data + ) internal { + if (to == address(0) || erc721Contract == address(0)) { + revert InvalidAddressForERC721(); + } + if (_balances[tokenHolderId][erc721Contract][tokenToTransferId] == 0) { + revert TokenNotHeldForERC721(); + } + _beforeTransferHeldERC721FromToken( + erc721Contract, + tokenHolderId, + tokenToTransferId, + to, + data + ); + _balances[tokenHolderId][erc721Contract][tokenToTransferId] = 0; + + IERC721(erc721Contract).safeTransferFrom( + address(this), + to, + tokenToTransferId, + data + ); + + emit TransferredERC721( + erc721Contract, + tokenHolderId, + tokenToTransferId, + to + ); + _afterTransferHeldERC721FromToken( + erc721Contract, + tokenHolderId, + tokenToTransferId, + to, + data + ); + } + + /** + * @inheritdoc IERC721Holder + */ + function transferERC721ToToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + bytes memory data + ) external { + if (erc721Contract == address(0)) { + revert InvalidAddressForERC721(); + } + _beforeTransferERC721ToToken( + erc721Contract, + tokenHolderId, + tokenToTransferId, + msg.sender, + data + ); + IERC721(erc721Contract).safeTransferFrom( + msg.sender, + address(this), + tokenToTransferId, + data + ); + _balances[tokenHolderId][erc721Contract][tokenToTransferId] = 1; + + emit ReceivedERC721( + erc721Contract, + tokenHolderId, + tokenToTransferId, + msg.sender + ); + _afterTransferERC721ToToken( + erc721Contract, + tokenHolderId, + tokenToTransferId, + msg.sender, + data + ); + } + + /** + * @notice Hook that is called before any transfer of ERC-721 tokens from a token + * @param tokenHolderId The token to transfer from + * @param tokenToTransferId The ID of the held token being sent + * @param to The address to send the ERC-721 tokens to + * @param erc721Contract The ERC-721 contract + * @param data Additional data with no specified format, to allow for custom logic + */ + function _beforeTransferHeldERC721FromToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called after any transfer of ERC-721 tokens from a token + * @param tokenHolderId The token to transfer from + * @param tokenToTransferId The ID of the held token being sent + * @param to The address to send the ERC-721 tokens to + * @param erc721Contract The ERC-721 contract + * @param data Additional data with no specified format, to allow for custom logic + */ + function _afterTransferHeldERC721FromToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called before any transfer of ERC-721 tokens to a token + * @param tokenHolderId The token to transfer to + * @param tokenToTransferId The ID of the held token being received + * @param from The address to send the ERC-721 tokens from + * @param erc721Contract The ERC-721 contract + * @param data Additional data with no specified format, to allow for custom logic + */ + function _beforeTransferERC721ToToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address from, + bytes memory data + ) internal virtual {} + + /** + * @notice Hook that is called after any transfer of ERC-721 tokens to a token + * @param tokenHolderId The token to transfer to + * @param tokenToTransferId The ID of the held token being received + * @param from The address to send the ERC-721 tokens from + * @param erc721Contract The ERC-721 contract + * @param data Additional data with no specified format, to allow for custom logic + */ + function _afterTransferERC721ToToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address from, + bytes memory data + ) internal virtual {} + + function supportsInterface( + bytes4 interfaceId + ) public view virtual override returns (bool) { + return type(IERC721Holder).interfaceId == interfaceId; + } + + function onERC721Received( + address, + address, + uint256, + bytes memory + ) public pure virtual returns (bytes4) { + return this.onERC721Received.selector; + } +} diff --git a/contracts/RMRK/extension/tokenHolder/IERC1155Holder.sol b/contracts/RMRK/extension/tokenHolder/IERC1155Holder.sol new file mode 100644 index 00000000..c5a78b1f --- /dev/null +++ b/contracts/RMRK/extension/tokenHolder/IERC1155Holder.sol @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; + +import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; + +interface IERC1155Holder is IERC165 { + /** + * @notice Used to notify listeners that the token received ERC-1155 tokens. + * @param erc1155Contract The address of the ERC-1155 smart contract + * @param tokenHolderId The ID of the token receiving the ERC-1155 tokens + * @param tokenTransferredId The ID of the received token + * @param from The address of the account from which the tokens are being transferred + * @param amount The number of ERC-1155 tokens received + */ + event ReceivedERC1155( + address indexed erc1155Contract, + uint256 indexed tokenHolderId, + uint256 tokenTransferredId, + address indexed from, + uint256 amount + ); + + /** + * @notice Used to notify the listeners that the ERC-1155 tokens have been transferred. + * @param erc1155Contract The address of the ERC-1155 smart contract + * @param tokenHolderId The ID of the token from which the ERC-1155 tokens have been transferred + * @param tokenTransferredId The ID of the transferred token + * @param to The address receiving the ERC-1155 tokens + * @param amount The number of ERC-1155 tokens transferred + */ + event TransferredERC1155( + address indexed erc1155Contract, + uint256 indexed tokenHolderId, + uint256 tokenTransferredId, + address indexed to, + uint256 amount + ); + + /** + * @notice Used to retrieve the given token's specific ERC-1155 balance + * @param erc1155Contract The address of the ERC-1155 smart contract + * @param tokenHolderId The ID of the token being checked for ERC-1155 balance + * @param tokenHeldId The ID of the held token + * @return The amount of the specified ERC-1155 tokens owned by a given token + */ + function balanceOfERC1155( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenHeldId + ) external view returns (uint256); + + /** + * @notice Transfer ERC-1155 tokens from a specific token. + * @dev The balance MUST be transferred from this smart contract. + * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this. + * @param erc1155Contract The address of the ERC-1155 smart contract + * @param tokenHolderId The ID of the token to transfer the ERC-1155 tokens from + * @param tokenToTransferId The ID of the held token being sent + * @param amount The number of ERC-1155 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function transferHeldERC1155FromToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + uint256 amount, + bytes memory data + ) external; + + /** + * @notice Transfer ERC-1155 tokens to a specific token. + * @dev The ERC-1155 smart contract must have approval for this contract to transfer the ERC-1155 tokens. + * @dev The balance MUST be transferred from the `msg.sender`. + * @param erc1155Contract The address of the ERC-1155 smart contract + * @param tokenHolderId The ID of the token to transfer ERC-1155 tokens to + * @param tokenToTransferId The ID of the held token being received + * @param amount The number of ERC-1155 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function transferERC1155ToToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + uint256 amount, + bytes memory data + ) external; +} diff --git a/contracts/RMRK/extension/tokenHolder/IERC20Holder.sol b/contracts/RMRK/extension/tokenHolder/IERC20Holder.sol new file mode 100644 index 00000000..155151ce --- /dev/null +++ b/contracts/RMRK/extension/tokenHolder/IERC20Holder.sol @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; + +import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; + +interface IERC20Holder is IERC165 { + /** + * @notice Used to notify listeners that the token received ERC-20 tokens. + * @param erc20Contract The address of the ERC-20 smart contract + * @param toTokenId The ID of the token receiving the ERC-20 tokens + * @param from The address of the account from which the tokens are being transferred + * @param amount The number of ERC-20 tokens received + */ + event ReceivedERC20( + address indexed erc20Contract, + uint256 indexed toTokenId, + address indexed from, + uint256 amount + ); + + /** + * @notice Used to notify the listeners that the ERC-20 tokens have been transferred. + * @param erc20Contract The address of the ERC-20 smart contract + * @param fromTokenId The ID of the token from which the ERC-20 tokens have been transferred + * @param to The address receiving the ERC-20 tokens + * @param amount The number of ERC-20 tokens transferred + */ + event TransferredERC20( + address indexed erc20Contract, + uint256 indexed fromTokenId, + address indexed to, + uint256 amount + ); + + /** + * @notice Used to retrieve the given token's specific ERC-20 balance + * @param erc20Contract The address of the ERC-20 smart contract + * @param tokenId The ID of the token being checked for ERC-20 balance + * @return The amount of the specified ERC-20 tokens owned by a given token + */ + function balanceOfERC20( + address erc20Contract, + uint256 tokenId + ) external view returns (uint256); + + /** + * @notice Transfer ERC-20 tokens from a specific token. + * @dev The balance MUST be transferred from this smart contract. + * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this. + * @param erc20Contract The address of the ERC-20 smart contract + * @param tokenId The ID of the token to transfer the ERC-20 tokens from + * @param amount The number of ERC-20 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function transferHeldERC20FromToken( + address erc20Contract, + uint256 tokenId, + address to, + uint256 amount, + bytes memory data + ) external; + + /** + * @notice Transfer ERC-20 tokens to a specific token. + * @dev The ERC-20 smart contract must have approval for this contract to transfer the ERC-20 tokens. + * @dev The balance MUST be transferred from the `msg.sender`. + * @param erc20Contract The address of the ERC-20 smart contract + * @param tokenId The ID of the token to transfer ERC-20 tokens to + * @param amount The number of ERC-20 tokens to transfer + * @param data Additional data with no specified format, to allow for custom logic + */ + function transferERC20ToToken( + address erc20Contract, + uint256 tokenId, + uint256 amount, + bytes memory data + ) external; +} diff --git a/contracts/RMRK/extension/tokenHolder/IERC721Holder.sol b/contracts/RMRK/extension/tokenHolder/IERC721Holder.sol new file mode 100644 index 00000000..c014b9f9 --- /dev/null +++ b/contracts/RMRK/extension/tokenHolder/IERC721Holder.sol @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; + +import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; + +interface IERC721Holder is IERC165 { + /** + * @notice Used to notify listeners that the token received ERC-721 tokens. + * @param erc721Contract The address of the ERC-721 smart contract + * @param tokenHolderId The ID of the token receiving the ERC-721 tokens + * @param tokenTransferredId The ID of the received token + * @param from The address of the account from which the tokens are being transferred + */ + event ReceivedERC721( + address indexed erc721Contract, + uint256 indexed tokenHolderId, + uint256 tokenTransferredId, + address indexed from + ); + + /** + * @notice Used to notify the listeners that the ERC-721 tokens have been transferred. + * @param erc721Contract The address of the ERC-721 smart contract + * @param tokenHolderId The ID of the token from which the ERC-721 tokens have been transferred + * @param tokenTransferredId The ID of the transferred token + * @param to The address receiving the ERC-721 tokens + */ + event TransferredERC721( + address indexed erc721Contract, + uint256 indexed tokenHolderId, + uint256 tokenTransferredId, + address indexed to + ); + + /** + * @notice Used to retrieve the given token's specific ERC-721 balance + * @param erc721Contract The address of the ERC-721 smart contract + * @param tokenHolderId The ID of the token being checked for ERC-721 balance + * @param tokenHeldId The ID of the held token + */ + function balanceOfERC721( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenHeldId + ) external view returns (uint256); + + /** + * @notice Transfer ERC-721 tokens from a specific token. + * @dev The balance MUST be transferred from this smart contract. + * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this. + * @param erc721Contract The address of the ERC-721 smart contract + * @param tokenHolderId The ID of the token to transfer the ERC-721 tokens from + * @param tokenToTransferId The ID of the held token being sent + * @param data Additional data with no specified format, to allow for custom logic + */ + function transferHeldERC721FromToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + bytes memory data + ) external; + + /** + * @notice Transfer ERC-721 tokens to a specific token. + * @dev The ERC-721 smart contract must have approval for this contract to transfer the ERC-721 tokens. + * @dev The balance MUST be transferred from the `msg.sender`. + * @param erc721Contract The address of the ERC-721 smart contract + * @param tokenHolderId The ID of the token to transfer ERC-721 tokens to + * @param tokenToTransferId The ID of the held token being received + * @param data Additional data with no specified format, to allow for custom logic + */ + function transferERC721ToToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + bytes memory data + ) external; +} diff --git a/contracts/RMRK/extension/tokenHolder/IRMRKTokenHolder.sol b/contracts/RMRK/extension/tokenHolder/IRMRKTokenHolder.sol index 4644b1d3..3b9816b0 100644 --- a/contracts/RMRK/extension/tokenHolder/IRMRKTokenHolder.sol +++ b/contracts/RMRK/extension/tokenHolder/IRMRKTokenHolder.sol @@ -18,12 +18,12 @@ interface IRMRKTokenHolder is IERC165 { /** * @notice Used to notify listeners that the token received held tokens. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST equal `0` + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0` * @dev If the token type is `ERC-721`, the `amount` MUST equal `1`. * @param tokenContract The address of the held token's smart contract * @param tokenType The type of the held token being received * @param toTokenId The ID of the token receiving the held tokens - * @param heldTokenId The ID of the held token being received + * @param tokenToTransferId The ID of the held token being received * @param from The address of the account from which the tokens are being transferred * @param amount The amount of held tokens received */ @@ -31,19 +31,19 @@ interface IRMRKTokenHolder is IERC165 { address indexed tokenContract, TokenType tokenType, uint256 indexed toTokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, address indexed from, uint256 amount ); /** * @notice Used to notify the listeners that the ERC-20 tokens have been transferred. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST equal `0` + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0` * @dev If the token type is `ERC-721`, the `amount` MUST equal `1`. * @param tokenContract The address of the smart contract of the token being transferred * @param tokenType The type of the token being transferred * @param fromTokenId The ID of the token from which the held tokens have been transferred - * @param heldTokenId The Id of the held token being transferred + * @param tokenToTransferId The Id of the held token being transferred * @param to The address receiving the ERC-20 tokens * @param amount The amount of held tokens transferred */ @@ -51,25 +51,25 @@ interface IRMRKTokenHolder is IERC165 { address indexed tokenContract, TokenType tokenType, uint256 indexed fromTokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, address indexed to, uint256 amount ); /** * @notice Used to retrieve the given token's balance of given token - * @dev When retrieving the balance of an ERC-20 token, the `heldTokenId` parameter MUST be ignored. + * @dev When retrieving the balance of an ERC-20 token, the `tokenToTransferId` parameter MUST be ignored. * @param tokenContract The address of the held token's smart contract * @param tokenType The type of the token being checked for balance * @param tokenId The ID of the token being checked for balance - * @param heldTokenId The ID of the held token of which the balance is being retrieved + * @param tokenToTransferId The ID of the held token of which the balance is being retrieved * @return The amount of the specified ERC-20 tokens owned by a given token */ function balanceOfToken( address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId + uint256 tokenToTransferId ) external view returns (uint256); /** @@ -77,12 +77,12 @@ interface IRMRKTokenHolder is IERC165 { * @dev The balance MUST be transferred from this smart contract. * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before * calling this. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST be ignored. + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored. * @dev IF the token type is `ERC-721`, the `amount` MUST be ignored. * @param tokenContract The address of the held token's smart contract * @param tokenType The type of the token being transferred * @param tokenId The ID of the token to transfer the held token from - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param amount The number of held tokens to transfer * @param to The address to transfer the held tokens to * @param data Additional data with no specified format, to allow for custom logic @@ -91,7 +91,7 @@ interface IRMRKTokenHolder is IERC165 { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, uint256 amount, address to, bytes memory data @@ -101,12 +101,12 @@ interface IRMRKTokenHolder is IERC165 { * @notice Transfer tokens to a specific holder token. * @dev The token smart contract must have approval for this contract to transfer the tokens. * @dev The balance MUST be transferred from the `msg.sender`. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST be ignored. + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored. * @dev If the token type is `ERC-721`, the `amount` MUST be ignored. * @param tokenContract The address of the token smart contract * @param tokenType The type of the token being transferred * @param tokenId The ID of the token to transfer the tokens to - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param amount The number of ERC-20 tokens to transfer * @param data Additional data with no specified format, to allow for custom logic */ @@ -114,7 +114,7 @@ interface IRMRKTokenHolder is IERC165 { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, uint256 amount, bytes memory data ) external; diff --git a/contracts/RMRK/extension/tokenHolder/RMRKTokenHolder.sol b/contracts/RMRK/extension/tokenHolder/RMRKTokenHolder.sol index e2d3e816..ec4cec9a 100644 --- a/contracts/RMRK/extension/tokenHolder/RMRKTokenHolder.sol +++ b/contracts/RMRK/extension/tokenHolder/RMRKTokenHolder.sol @@ -20,7 +20,7 @@ error InsufficientBalance(); * @dev The RMRKTokenHolder extension is capable of holding ERC-20, ERC-721, and ERC-1155 tokens. */ abstract contract RMRKTokenHolder is IRMRKTokenHolder { - mapping(uint256 tokenId => mapping(address tokenAddress => mapping(TokenType tokenType => mapping(uint256 heldTokenId => uint256 balance)))) + mapping(uint256 tokenId => mapping(address tokenAddress => mapping(TokenType tokenType => mapping(uint256 tokenToTransferId => uint256 balance)))) private _balances; /** @@ -30,12 +30,13 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId + uint256 tokenToTransferId ) external view returns (uint256) { if (tokenType == TokenType.ERC20) { return _balances[tokenId][tokenContract][tokenType][0]; } else { - return _balances[tokenId][tokenContract][tokenType][heldTokenId]; + return + _balances[tokenId][tokenContract][tokenType][tokenToTransferId]; } } @@ -44,12 +45,12 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { * @dev The balance MUST be transferred from this smart contract. * @dev Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before * calling this. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST be ignored. + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored. * @dev IF the token type is `ERC-721`, the `amount` MUST be ignored. * @param tokenContract The address of the held token's smart contract * @param tokenType The type of the token being transferred * @param tokenId The ID of the token to transfer the held token from - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param amount The number of held tokens to transfer * @param to The address to transfer the held tokens to * @param data Additional data with no specified format, to allow for custom logic @@ -58,13 +59,13 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, uint256 amount, address to, bytes memory data ) internal { if (tokenType == TokenType.ERC20) { - heldTokenId = 0; + tokenToTransferId = 0; } else if (tokenType == TokenType.ERC721) { amount = 1; } @@ -76,7 +77,8 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { revert InvalidAddress(); } if ( - _balances[tokenId][tokenContract][tokenType][heldTokenId] < amount + _balances[tokenId][tokenContract][tokenType][tokenToTransferId] < + amount ) { revert InsufficientBalance(); } @@ -85,13 +87,15 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, to, amount, data ); - _balances[tokenId][tokenContract][tokenType][heldTokenId] -= amount; + _balances[tokenId][tokenContract][tokenType][ + tokenToTransferId + ] -= amount; if (tokenType == TokenType.ERC20) { IERC20(tokenContract).transfer(to, amount); @@ -99,14 +103,14 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { IERC721(tokenContract).safeTransferFrom( address(this), to, - heldTokenId, + tokenToTransferId, data ); } else { IERC1155(tokenContract).safeTransferFrom( address(this), to, - heldTokenId, + tokenToTransferId, amount, data ); @@ -116,7 +120,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, to, amount ); @@ -125,7 +129,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, to, amount, data @@ -136,12 +140,12 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { * @notice Transfer tokens to a specific holder token. * @dev The token smart contract must have approval for this contract to transfer the tokens. * @dev The balance MUST be transferred from the `msg.sender`. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST be ignored. + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored. * @dev If the token type is `ERC-721`, the `amount` MUST be ignored. * @param tokenContract The address of the token smart contract * @param tokenType The type of the token being transferred * @param tokenId The ID of the token to transfer the tokens to - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param amount The number of ERC-20 tokens to transfer * @param data Additional data with no specified format, to allow for custom logic */ @@ -149,12 +153,12 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, uint256 amount, bytes memory data ) internal { if (tokenType == TokenType.ERC20) { - heldTokenId = 0; + tokenToTransferId = 0; } else if (tokenType == TokenType.ERC721) { amount = 1; } @@ -170,13 +174,15 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, msg.sender, amount, data ); - _balances[tokenId][tokenContract][tokenType][heldTokenId] += amount; + _balances[tokenId][tokenContract][tokenType][ + tokenToTransferId + ] += amount; if (tokenType == TokenType.ERC20) { IERC20(tokenContract).transferFrom( @@ -188,14 +194,14 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { IERC721(tokenContract).safeTransferFrom( msg.sender, address(this), - heldTokenId, + tokenToTransferId, data ); } else { IERC1155(tokenContract).safeTransferFrom( msg.sender, address(this), - heldTokenId, + tokenToTransferId, amount, data ); @@ -205,7 +211,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, msg.sender, amount ); @@ -214,7 +220,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, msg.sender, amount, data @@ -223,12 +229,12 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { /** * @notice Hook that is called before any transfer of held tokens from a given token. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST equal `0` + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0` * @dev If the token type is `ERC-721`, the `amount` MUST equal `1`. * @param tokenContract The address of the held token smart contract * @param tokenType The type of the held token being transferred * @param tokenId The ID of the token to transfer from - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param to The address to send the held tokens to * @param amount The amount of held tokens to transfer * @param data Additional data with no specified format, to allow for custom logic @@ -237,7 +243,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, address to, uint256 amount, bytes memory data @@ -245,12 +251,12 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { /** * @notice Hook that is called after any transfer of held tokens from a token. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST equal `0` + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0` * @dev If the token type is `ERC-721`, the `amount` MUST equal `1`. * @param tokenContract The address of the held token smart contract * @param tokenType The type of the held token being transferred * @param tokenId The ID of the token to transfer from - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param to The address to send the held tokens to * @param amount The amount of held tokens to transfer * @param data Additional data with no specified format, to allow for custom logic @@ -259,7 +265,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, address to, uint256 amount, bytes memory data @@ -267,12 +273,12 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { /** * @notice Hook that is called before any transfer of held tokens to a token. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST equal `0` + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0` * @dev If the token type is `ERC-721`, the `amount` MUST equal `1`. * @param tokenContract The address of the held token's smart contract * @param tokenType The type of the token being transferred * @param tokenId The ID of the token to transfer the held tokens to - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param from The address to send the held tokens from * @param amount The number of held tokens to transfer * @param data Additional data with no specified format, to allow for custom logic @@ -281,7 +287,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, address from, uint256 amount, bytes memory data @@ -289,12 +295,12 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { /** * @notice Hook that is called after any transfer of held tokens to a token. - * @dev If the token type is `ERC-20`, the `heldTokenId` MUST equal `0` + * @dev If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0` * @dev If the token type is `ERC-721`, the `amount` MUST equal `1`. * @param tokenContract The address of the held token's smart contract contract * @param tokenType The type of the token being transferred * @param tokenId The ID of the token to transfer from - * @param heldTokenId The ID of the held token to transfer + * @param tokenToTransferId The ID of the held token to transfer * @param from The address to send the held tokens from * @param amount The amount of held tokens to transfer * @param data Additional data with no specified format, to allow for custom logic @@ -303,7 +309,7 @@ abstract contract RMRKTokenHolder is IRMRKTokenHolder { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, address from, uint256 amount, bytes memory data diff --git a/contracts/mocks/extensions/tokenHolder/RMRKERC1155HolderMock.sol b/contracts/mocks/extensions/tokenHolder/RMRKERC1155HolderMock.sol new file mode 100644 index 00000000..1388d5c8 --- /dev/null +++ b/contracts/mocks/extensions/tokenHolder/RMRKERC1155HolderMock.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; +import "../../../RMRK/extension/tokenHolder/ERC1155Holder.sol"; +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; + +error OnlyNFTOwnerCanTransferTokensFromIt(); + +/** + * @title RMRKERC1155HolderMock + * @author RMRK team + * @notice Smart contract of the RMRK ERC1155 Holder module. + */ +contract RMRKERC1155HolderMock is ERC1155Holder, ERC721 { + constructor( + string memory name, + string memory symbol + ) ERC721(name, symbol) {} + + function mint(address to, uint256 tokenId) public { + _mint(to, tokenId); + } + + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(ERC1155Holder, ERC721) returns (bool) { + return + ERC1155Holder.supportsInterface(interfaceId) || + super.supportsInterface(interfaceId); + } + + /** + * @inheritdoc IERC1155Holder + */ + function transferHeldERC1155FromToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + uint256 amount, + bytes memory data + ) external { + if (msg.sender != ownerOf(tokenHolderId)) { + revert OnlyNFTOwnerCanTransferTokensFromIt(); + } + _transferHeldERC1155FromToken( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + to, + amount, + data + ); + } +} diff --git a/contracts/mocks/extensions/tokenHolder/RMRKERC20HolderMock.sol b/contracts/mocks/extensions/tokenHolder/RMRKERC20HolderMock.sol new file mode 100644 index 00000000..7afe8b77 --- /dev/null +++ b/contracts/mocks/extensions/tokenHolder/RMRKERC20HolderMock.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; +import "../../../RMRK/extension/tokenHolder/ERC20Holder.sol"; +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; + +error OnlyNFTOwnerCanTransferTokensFromIt(); + +/** + * @title RMRKERC20HolderMock + * @author RMRK team + * @notice Smart contract of the RMRK ERC20 Holder module. + */ +contract RMRKERC20HolderMock is ERC20Holder, ERC721 { + constructor( + string memory name, + string memory symbol + ) ERC721(name, symbol) {} + + function mint(address to, uint256 tokenId) public { + _mint(to, tokenId); + } + + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(ERC20Holder, ERC721) returns (bool) { + return + ERC20Holder.supportsInterface(interfaceId) || + super.supportsInterface(interfaceId); + } + + /** + * @inheritdoc IERC20Holder + */ + function transferHeldERC20FromToken( + address erc20Contract, + uint256 tokenHolderId, + address to, + uint256 amount, + bytes memory data + ) external { + if (msg.sender != ownerOf(tokenHolderId)) { + revert OnlyNFTOwnerCanTransferTokensFromIt(); + } + _transferHeldERC20FromToken( + erc20Contract, + tokenHolderId, + to, + amount, + data + ); + } +} diff --git a/contracts/mocks/extensions/tokenHolder/RMRKERC721HolderMock.sol b/contracts/mocks/extensions/tokenHolder/RMRKERC721HolderMock.sol new file mode 100644 index 00000000..c4e22396 --- /dev/null +++ b/contracts/mocks/extensions/tokenHolder/RMRKERC721HolderMock.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; +import "../../../RMRK/extension/tokenHolder/ERC721Holder.sol"; +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; + +error OnlyNFTOwnerCanTransferTokensFromIt(); + +/** + * @title RMRKERC721HolderMock + * @author RMRK team + * @notice Smart contract of the RMRK ERC721 Holder module. + */ +contract RMRKERC721HolderMock is ERC721Holder, ERC721 { + constructor( + string memory name, + string memory symbol + ) ERC721(name, symbol) {} + + function mint(address to, uint256 tokenId) public { + _mint(to, tokenId); + } + + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(ERC721Holder, ERC721) returns (bool) { + return + ERC721Holder.supportsInterface(interfaceId) || + super.supportsInterface(interfaceId); + } + + /** + * @inheritdoc IERC721Holder + */ + function transferHeldERC721FromToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + bytes memory data + ) external { + if (msg.sender != ownerOf(tokenHolderId)) { + revert OnlyNFTOwnerCanTransferTokensFromIt(); + } + _transferHeldERC721FromToken( + erc721Contract, + tokenHolderId, + tokenToTransferId, + to, + data + ); + } +} diff --git a/contracts/mocks/extensions/tokenHolder/RMRKTokenHolderMock.sol b/contracts/mocks/extensions/tokenHolder/RMRKTokenHolderMock.sol index 9d6d61ce..d68dee85 100644 --- a/contracts/mocks/extensions/tokenHolder/RMRKTokenHolderMock.sol +++ b/contracts/mocks/extensions/tokenHolder/RMRKTokenHolderMock.sol @@ -5,7 +5,6 @@ import "../../../RMRK/extension/tokenHolder/RMRKTokenHolder.sol"; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; error OnlyNFTOwnerCanTransferTokensFromIt(); -error OnlyNFTOwnerCanTransferTokensToIt(); /** * @title RMRKTokenHolderMock @@ -37,7 +36,7 @@ contract RMRKTokenHolderMock is RMRKTokenHolder, ERC721 { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, uint256 amount, bytes memory data ) external { @@ -45,7 +44,7 @@ contract RMRKTokenHolderMock is RMRKTokenHolder, ERC721 { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, amount, data ); @@ -58,7 +57,7 @@ contract RMRKTokenHolderMock is RMRKTokenHolder, ERC721 { address tokenContract, TokenType tokenType, uint256 tokenId, - uint256 heldTokenId, + uint256 tokenToTransferId, uint256 amount, address to, bytes memory data @@ -70,7 +69,7 @@ contract RMRKTokenHolderMock is RMRKTokenHolder, ERC721 { tokenContract, tokenType, tokenId, - heldTokenId, + tokenToTransferId, amount, to, data diff --git a/contracts/mocks/extensions/tokenHolder/RMRKUniversalHolderMock.sol b/contracts/mocks/extensions/tokenHolder/RMRKUniversalHolderMock.sol new file mode 100644 index 00000000..b1df5110 --- /dev/null +++ b/contracts/mocks/extensions/tokenHolder/RMRKUniversalHolderMock.sol @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.18; +import "../../../RMRK/extension/tokenHolder/ERC20Holder.sol"; +import "../../../RMRK/extension/tokenHolder/ERC721Holder.sol"; +import "../../../RMRK/extension/tokenHolder/ERC1155Holder.sol"; +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; + +error OnlyNFTOwnerCanTransferTokensFromIt(); + +/** + * @title RMRKUniversalHolderMock + * @author RMRK team + * @notice Smart contract of the RMRK ERC1155 Holder module. + */ +contract RMRKUniversalHolderMock is + ERC20Holder, + ERC721Holder, + ERC1155Holder, + ERC721 +{ + constructor( + string memory name, + string memory symbol + ) ERC721(name, symbol) {} + + function supportsInterface( + bytes4 interfaceId + ) + public + view + virtual + override(ERC20Holder, ERC721Holder, ERC1155Holder, ERC721) + returns (bool) + { + return + ERC20Holder.supportsInterface(interfaceId) || + ERC721Holder.supportsInterface(interfaceId) || + ERC1155Holder.supportsInterface(interfaceId) || + ERC721.supportsInterface(interfaceId); + } + + /** + * @inheritdoc IERC20Holder + */ + function transferHeldERC20FromToken( + address erc20Contract, + uint256 tokenHolderId, + address to, + uint256 amount, + bytes memory data + ) external { + if (msg.sender != ownerOf(tokenHolderId)) { + revert OnlyNFTOwnerCanTransferTokensFromIt(); + } + _transferHeldERC20FromToken( + erc20Contract, + tokenHolderId, + to, + amount, + data + ); + } + + /** + * @inheritdoc IERC721Holder + */ + function transferHeldERC721FromToken( + address erc721Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + bytes memory data + ) external { + if (msg.sender != ownerOf(tokenHolderId)) { + revert OnlyNFTOwnerCanTransferTokensFromIt(); + } + _transferHeldERC721FromToken( + erc721Contract, + tokenHolderId, + tokenToTransferId, + to, + data + ); + } + + /** + * @inheritdoc IERC1155Holder + */ + function transferHeldERC1155FromToken( + address erc1155Contract, + uint256 tokenHolderId, + uint256 tokenToTransferId, + address to, + uint256 amount, + bytes memory data + ) external { + if (msg.sender != ownerOf(tokenHolderId)) { + revert OnlyNFTOwnerCanTransferTokensFromIt(); + } + _transferHeldERC1155FromToken( + erc1155Contract, + tokenHolderId, + tokenToTransferId, + to, + amount, + data + ); + } +} diff --git a/docs/RMRK/extension/tokenHolder/ERC1155Holder.md b/docs/RMRK/extension/tokenHolder/ERC1155Holder.md new file mode 100644 index 00000000..66ff1192 --- /dev/null +++ b/docs/RMRK/extension/tokenHolder/ERC1155Holder.md @@ -0,0 +1,196 @@ +# ERC1155Holder + + + + + + + + + +## Methods + +### balanceOfERC1155 + +```solidity +function balanceOfERC1155(address erc1155Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-1155 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-1155 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-1155 tokens owned by a given token | + +### onERC1155Received + +```solidity +function onERC1155Received(address, address, uint256, uint256, bytes) external pure returns (bytes4) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | +| _1 | address | undefined | +| _2 | uint256 | undefined | +| _3 | uint256 | undefined | +| _4 | bytes | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes4 | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### transferERC1155ToToken + +```solidity +function transferERC1155ToToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens to a specific token. + +*The ERC-1155 smart contract must have approval for this contract to transfer the ERC-1155 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-1155 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC1155FromToken + +```solidity +function transferHeldERC1155FromToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-1155 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### ReceivedERC1155 + +```solidity +event ReceivedERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-1155 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-1155 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-1155 tokens received | + +### TransferredERC1155 + +```solidity +event TransferredERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-1155 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-1155 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-1155 tokens | +| amount | uint256 | The number of ERC-1155 tokens transferred | + + + +## Errors + +### InvalidAddressForERC1155 + +```solidity +error InvalidAddressForERC1155() +``` + + + + + + +### InvalidValueForERC1155 + +```solidity +error InvalidValueForERC1155() +``` + + + + + + + diff --git a/docs/RMRK/extension/tokenHolder/ERC20Holder.md b/docs/RMRK/extension/tokenHolder/ERC20Holder.md new file mode 100644 index 00000000..feaed415 --- /dev/null +++ b/docs/RMRK/extension/tokenHolder/ERC20Holder.md @@ -0,0 +1,165 @@ +# ERC20Holder + + + + + + + + + +## Methods + +### balanceOfERC20 + +```solidity +function balanceOfERC20(address erc20Contract, uint256 tokenId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-20 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token being checked for ERC-20 balance | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-20 tokens owned by a given token | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### transferERC20ToToken + +```solidity +function transferERC20ToToken(address erc20Contract, uint256 tokenId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens to a specific token. + +*The ERC-20 smart contract must have approval for this contract to transfer the ERC-20 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token to transfer ERC-20 tokens to | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC20FromToken + +```solidity +function transferHeldERC20FromToken(address erc20Contract, uint256 tokenId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token to transfer the ERC-20 tokens from | +| to | address | undefined | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### ReceivedERC20 + +```solidity +event ReceivedERC20(address indexed erc20Contract, uint256 indexed toTokenId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-20 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| toTokenId `indexed` | uint256 | The ID of the token receiving the ERC-20 tokens | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-20 tokens received | + +### TransferredERC20 + +```solidity +event TransferredERC20(address indexed erc20Contract, uint256 indexed fromTokenId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-20 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| fromTokenId `indexed` | uint256 | The ID of the token from which the ERC-20 tokens have been transferred | +| to `indexed` | address | The address receiving the ERC-20 tokens | +| amount | uint256 | The number of ERC-20 tokens transferred | + + + +## Errors + +### InvalidAddressForERC20 + +```solidity +error InvalidAddressForERC20() +``` + + + + + + +### InvalidValueForERC20 + +```solidity +error InvalidValueForERC20() +``` + + + + + + + diff --git a/docs/RMRK/extension/tokenHolder/ERC721Holder.md b/docs/RMRK/extension/tokenHolder/ERC721Holder.md new file mode 100644 index 00000000..26bf3a18 --- /dev/null +++ b/docs/RMRK/extension/tokenHolder/ERC721Holder.md @@ -0,0 +1,180 @@ +# ERC721Holder + + + + + + + + + +## Methods + +### balanceOfERC721 + +```solidity +function balanceOfERC721(address erc721Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-721 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-721 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### onERC721Received + +```solidity +function onERC721Received(address, address, uint256, bytes) external pure returns (bytes4) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | +| _1 | address | undefined | +| _2 | uint256 | undefined | +| _3 | bytes | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes4 | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### transferERC721ToToken + +```solidity +function transferERC721ToToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens to a specific token. + +*The ERC-721 smart contract must have approval for this contract to transfer the ERC-721 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-721 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC721FromToken + +```solidity +function transferHeldERC721FromToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-721 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### ReceivedERC721 + +```solidity +event ReceivedERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from) +``` + +Used to notify listeners that the token received ERC-721 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-721 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | + +### TransferredERC721 + +```solidity +event TransferredERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to) +``` + +Used to notify the listeners that the ERC-721 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-721 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-721 tokens | + + + +## Errors + +### InvalidAddressForERC721 + +```solidity +error InvalidAddressForERC721() +``` + + + + + + + diff --git a/docs/RMRK/extension/tokenHolder/IERC1155Holder.md b/docs/RMRK/extension/tokenHolder/IERC1155Holder.md new file mode 100644 index 00000000..f6abc2cc --- /dev/null +++ b/docs/RMRK/extension/tokenHolder/IERC1155Holder.md @@ -0,0 +1,145 @@ +# IERC1155Holder + + + + + + + + + +## Methods + +### balanceOfERC1155 + +```solidity +function balanceOfERC1155(address erc1155Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-1155 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-1155 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-1155 tokens owned by a given token | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### transferERC1155ToToken + +```solidity +function transferERC1155ToToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens to a specific token. + +*The ERC-1155 smart contract must have approval for this contract to transfer the ERC-1155 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-1155 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC1155FromToken + +```solidity +function transferHeldERC1155FromToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-1155 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### ReceivedERC1155 + +```solidity +event ReceivedERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-1155 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-1155 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-1155 tokens received | + +### TransferredERC1155 + +```solidity +event TransferredERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-1155 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-1155 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-1155 tokens | +| amount | uint256 | The number of ERC-1155 tokens transferred | + + + diff --git a/docs/RMRK/extension/tokenHolder/IERC20Holder.md b/docs/RMRK/extension/tokenHolder/IERC20Holder.md new file mode 100644 index 00000000..bda7b8ba --- /dev/null +++ b/docs/RMRK/extension/tokenHolder/IERC20Holder.md @@ -0,0 +1,140 @@ +# IERC20Holder + + + + + + + + + +## Methods + +### balanceOfERC20 + +```solidity +function balanceOfERC20(address erc20Contract, uint256 tokenId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-20 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token being checked for ERC-20 balance | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-20 tokens owned by a given token | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### transferERC20ToToken + +```solidity +function transferERC20ToToken(address erc20Contract, uint256 tokenId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens to a specific token. + +*The ERC-20 smart contract must have approval for this contract to transfer the ERC-20 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token to transfer ERC-20 tokens to | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC20FromToken + +```solidity +function transferHeldERC20FromToken(address erc20Contract, uint256 tokenId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token to transfer the ERC-20 tokens from | +| to | address | undefined | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### ReceivedERC20 + +```solidity +event ReceivedERC20(address indexed erc20Contract, uint256 indexed toTokenId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-20 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| toTokenId `indexed` | uint256 | The ID of the token receiving the ERC-20 tokens | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-20 tokens received | + +### TransferredERC20 + +```solidity +event TransferredERC20(address indexed erc20Contract, uint256 indexed fromTokenId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-20 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| fromTokenId `indexed` | uint256 | The ID of the token from which the ERC-20 tokens have been transferred | +| to `indexed` | address | The address receiving the ERC-20 tokens | +| amount | uint256 | The number of ERC-20 tokens transferred | + + + diff --git a/docs/RMRK/extension/tokenHolder/IERC721Holder.md b/docs/RMRK/extension/tokenHolder/IERC721Holder.md new file mode 100644 index 00000000..4a9f31bb --- /dev/null +++ b/docs/RMRK/extension/tokenHolder/IERC721Holder.md @@ -0,0 +1,141 @@ +# IERC721Holder + + + + + + + + + +## Methods + +### balanceOfERC721 + +```solidity +function balanceOfERC721(address erc721Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-721 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-721 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + +*Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### transferERC721ToToken + +```solidity +function transferERC721ToToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens to a specific token. + +*The ERC-721 smart contract must have approval for this contract to transfer the ERC-721 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-721 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC721FromToken + +```solidity +function transferHeldERC721FromToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-721 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### ReceivedERC721 + +```solidity +event ReceivedERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from) +``` + +Used to notify listeners that the token received ERC-721 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-721 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | + +### TransferredERC721 + +```solidity +event TransferredERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to) +``` + +Used to notify the listeners that the ERC-721 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-721 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-721 tokens | + + + diff --git a/docs/RMRK/extension/tokenHolder/IRMRKTokenHolder.md b/docs/RMRK/extension/tokenHolder/IRMRKTokenHolder.md index 4c45c321..dff4c152 100644 --- a/docs/RMRK/extension/tokenHolder/IRMRKTokenHolder.md +++ b/docs/RMRK/extension/tokenHolder/IRMRKTokenHolder.md @@ -13,12 +13,12 @@ Interface smart contract of the RMRKTokenHolder extension. ### balanceOfToken ```solidity -function balanceOfToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId) external view returns (uint256) +function balanceOfToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId) external view returns (uint256) ``` Used to retrieve the given token's balance of given token -*When retrieving the balance of an ERC-20 token, the `heldTokenId` parameter MUST be ignored.* +*When retrieving the balance of an ERC-20 token, the `tokenToTransferId` parameter MUST be ignored.* #### Parameters @@ -27,7 +27,7 @@ Used to retrieve the given token's balance of given token | tokenContract | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being checked for balance | | tokenId | uint256 | The ID of the token being checked for balance | -| heldTokenId | uint256 | The ID of the held token of which the balance is being retrieved | +| tokenToTransferId | uint256 | The ID of the held token of which the balance is being retrieved | #### Returns @@ -60,12 +60,12 @@ function supportsInterface(bytes4 interfaceId) external view returns (bool) ### transferHeldTokenFromToken ```solidity -function transferHeldTokenFromToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId, uint256 amount, address to, bytes data) external nonpayable +function transferHeldTokenFromToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId, uint256 amount, address to, bytes data) external nonpayable ``` Transfer held tokens from a specific token. -*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.If the token type is `ERC-20`, the `heldTokenId` MUST be ignored.IF the token type is `ERC-721`, the `amount` MUST be ignored.* +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored.IF the token type is `ERC-721`, the `amount` MUST be ignored.* #### Parameters @@ -74,7 +74,7 @@ Transfer held tokens from a specific token. | tokenContract | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | tokenId | uint256 | The ID of the token to transfer the held token from | -| heldTokenId | uint256 | The ID of the held token to transfer | +| tokenToTransferId | uint256 | The ID of the held token to transfer | | amount | uint256 | The number of held tokens to transfer | | to | address | The address to transfer the held tokens to | | data | bytes | Additional data with no specified format, to allow for custom logic | @@ -82,12 +82,12 @@ Transfer held tokens from a specific token. ### transferHeldTokenToToken ```solidity -function transferHeldTokenToToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId, uint256 amount, bytes data) external nonpayable +function transferHeldTokenToToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId, uint256 amount, bytes data) external nonpayable ``` Transfer tokens to a specific holder token. -*The token smart contract must have approval for this contract to transfer the tokens.The balance MUST be transferred from the `msg.sender`.If the token type is `ERC-20`, the `heldTokenId` MUST be ignored.If the token type is `ERC-721`, the `amount` MUST be ignored.* +*The token smart contract must have approval for this contract to transfer the tokens.The balance MUST be transferred from the `msg.sender`.If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored.If the token type is `ERC-721`, the `amount` MUST be ignored.* #### Parameters @@ -96,7 +96,7 @@ Transfer tokens to a specific holder token. | tokenContract | address | The address of the token smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | tokenId | uint256 | The ID of the token to transfer the tokens to | -| heldTokenId | uint256 | The ID of the held token to transfer | +| tokenToTransferId | uint256 | The ID of the held token to transfer | | amount | uint256 | The number of ERC-20 tokens to transfer | | data | bytes | Additional data with no specified format, to allow for custom logic | @@ -107,12 +107,12 @@ Transfer tokens to a specific holder token. ### ReceivedToken ```solidity -event ReceivedToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed toTokenId, uint256 heldTokenId, address indexed from, uint256 amount) +event ReceivedToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed toTokenId, uint256 tokenToTransferId, address indexed from, uint256 amount) ``` Used to notify listeners that the token received held tokens. -*If the token type is `ERC-20`, the `heldTokenId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* +*If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* #### Parameters @@ -121,19 +121,19 @@ Used to notify listeners that the token received held tokens. | tokenContract `indexed` | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the held token being received | | toTokenId `indexed` | uint256 | The ID of the token receiving the held tokens | -| heldTokenId | uint256 | The ID of the held token being received | +| tokenToTransferId | uint256 | The ID of the held token being received | | from `indexed` | address | The address of the account from which the tokens are being transferred | | amount | uint256 | The amount of held tokens received | ### TransferredToken ```solidity -event TransferredToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed fromTokenId, uint256 heldTokenId, address indexed to, uint256 amount) +event TransferredToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed fromTokenId, uint256 tokenToTransferId, address indexed to, uint256 amount) ``` Used to notify the listeners that the ERC-20 tokens have been transferred. -*If the token type is `ERC-20`, the `heldTokenId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* +*If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* #### Parameters @@ -142,7 +142,7 @@ Used to notify the listeners that the ERC-20 tokens have been transferred. | tokenContract `indexed` | address | The address of the smart contract of the token being transferred | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | fromTokenId `indexed` | uint256 | The ID of the token from which the held tokens have been transferred | -| heldTokenId | uint256 | The Id of the held token being transferred | +| tokenToTransferId | uint256 | The Id of the held token being transferred | | to `indexed` | address | The address receiving the ERC-20 tokens | | amount | uint256 | The amount of held tokens transferred | diff --git a/docs/RMRK/extension/tokenHolder/RMRKTokenHolder.md b/docs/RMRK/extension/tokenHolder/RMRKTokenHolder.md index 1e7e8fef..524195ec 100644 --- a/docs/RMRK/extension/tokenHolder/RMRKTokenHolder.md +++ b/docs/RMRK/extension/tokenHolder/RMRKTokenHolder.md @@ -13,12 +13,12 @@ Smart contract of a token holder RMRK extension. ### balanceOfToken ```solidity -function balanceOfToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId) external view returns (uint256) +function balanceOfToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId) external view returns (uint256) ``` Used to retrieve the given token's balance of given token -*When retrieving the balance of an ERC-20 token, the `heldTokenId` parameter MUST be ignored.* +*When retrieving the balance of an ERC-20 token, the `tokenToTransferId` parameter MUST be ignored.* #### Parameters @@ -27,7 +27,7 @@ Used to retrieve the given token's balance of given token | tokenContract | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being checked for balance | | tokenId | uint256 | The ID of the token being checked for balance | -| heldTokenId | uint256 | The ID of the held token of which the balance is being retrieved | +| tokenToTransferId | uint256 | The ID of the held token of which the balance is being retrieved | #### Returns @@ -111,12 +111,12 @@ function supportsInterface(bytes4 interfaceId) external view returns (bool) ### transferHeldTokenFromToken ```solidity -function transferHeldTokenFromToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId, uint256 amount, address to, bytes data) external nonpayable +function transferHeldTokenFromToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId, uint256 amount, address to, bytes data) external nonpayable ``` Transfer held tokens from a specific token. -*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.If the token type is `ERC-20`, the `heldTokenId` MUST be ignored.IF the token type is `ERC-721`, the `amount` MUST be ignored.* +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored.IF the token type is `ERC-721`, the `amount` MUST be ignored.* #### Parameters @@ -125,7 +125,7 @@ Transfer held tokens from a specific token. | tokenContract | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | tokenId | uint256 | The ID of the token to transfer the held token from | -| heldTokenId | uint256 | The ID of the held token to transfer | +| tokenToTransferId | uint256 | The ID of the held token to transfer | | amount | uint256 | The number of held tokens to transfer | | to | address | The address to transfer the held tokens to | | data | bytes | Additional data with no specified format, to allow for custom logic | @@ -133,12 +133,12 @@ Transfer held tokens from a specific token. ### transferHeldTokenToToken ```solidity -function transferHeldTokenToToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId, uint256 amount, bytes data) external nonpayable +function transferHeldTokenToToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId, uint256 amount, bytes data) external nonpayable ``` Transfer tokens to a specific holder token. -*The token smart contract must have approval for this contract to transfer the tokens.The balance MUST be transferred from the `msg.sender`.If the token type is `ERC-20`, the `heldTokenId` MUST be ignored.If the token type is `ERC-721`, the `amount` MUST be ignored.* +*The token smart contract must have approval for this contract to transfer the tokens.The balance MUST be transferred from the `msg.sender`.If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored.If the token type is `ERC-721`, the `amount` MUST be ignored.* #### Parameters @@ -147,7 +147,7 @@ Transfer tokens to a specific holder token. | tokenContract | address | The address of the token smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | tokenId | uint256 | The ID of the token to transfer the tokens to | -| heldTokenId | uint256 | The ID of the held token to transfer | +| tokenToTransferId | uint256 | The ID of the held token to transfer | | amount | uint256 | The number of ERC-20 tokens to transfer | | data | bytes | Additional data with no specified format, to allow for custom logic | @@ -158,12 +158,12 @@ Transfer tokens to a specific holder token. ### ReceivedToken ```solidity -event ReceivedToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed toTokenId, uint256 heldTokenId, address indexed from, uint256 amount) +event ReceivedToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed toTokenId, uint256 tokenToTransferId, address indexed from, uint256 amount) ``` Used to notify listeners that the token received held tokens. -*If the token type is `ERC-20`, the `heldTokenId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* +*If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* #### Parameters @@ -172,19 +172,19 @@ Used to notify listeners that the token received held tokens. | tokenContract `indexed` | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the held token being received | | toTokenId `indexed` | uint256 | The ID of the token receiving the held tokens | -| heldTokenId | uint256 | The ID of the held token being received | +| tokenToTransferId | uint256 | The ID of the held token being received | | from `indexed` | address | The address of the account from which the tokens are being transferred | | amount | uint256 | The amount of held tokens received | ### TransferredToken ```solidity -event TransferredToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed fromTokenId, uint256 heldTokenId, address indexed to, uint256 amount) +event TransferredToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed fromTokenId, uint256 tokenToTransferId, address indexed to, uint256 amount) ``` Used to notify the listeners that the ERC-20 tokens have been transferred. -*If the token type is `ERC-20`, the `heldTokenId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* +*If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* #### Parameters @@ -193,7 +193,7 @@ Used to notify the listeners that the ERC-20 tokens have been transferred. | tokenContract `indexed` | address | The address of the smart contract of the token being transferred | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | fromTokenId `indexed` | uint256 | The ID of the token from which the held tokens have been transferred | -| heldTokenId | uint256 | The Id of the held token being transferred | +| tokenToTransferId | uint256 | The Id of the held token being transferred | | to `indexed` | address | The address receiving the ERC-20 tokens | | amount | uint256 | The amount of held tokens transferred | diff --git a/docs/mocks/extensions/tokenHolder/RMRKERC1155HolderMock.md b/docs/mocks/extensions/tokenHolder/RMRKERC1155HolderMock.md new file mode 100644 index 00000000..c306097d --- /dev/null +++ b/docs/mocks/extensions/tokenHolder/RMRKERC1155HolderMock.md @@ -0,0 +1,523 @@ +# RMRKERC1155HolderMock + +*RMRK team* + +> RMRKERC1155HolderMock + +Smart contract of the RMRK ERC1155 Holder module. + + + +## Methods + +### approve + +```solidity +function approve(address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-approve}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | undefined | +| tokenId | uint256 | undefined | + +### balanceOf + +```solidity +function balanceOf(address owner) external view returns (uint256) +``` + + + +*See {IERC721-balanceOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### balanceOfERC1155 + +```solidity +function balanceOfERC1155(address erc1155Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-1155 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-1155 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-1155 tokens owned by a given token | + +### getApproved + +```solidity +function getApproved(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-getApproved}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### isApprovedForAll + +```solidity +function isApprovedForAll(address owner, address operator) external view returns (bool) +``` + + + +*See {IERC721-isApprovedForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | +| operator | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### mint + +```solidity +function mint(address to, uint256 tokenId) external nonpayable +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | undefined | +| tokenId | uint256 | undefined | + +### name + +```solidity +function name() external view returns (string) +``` + + + +*See {IERC721Metadata-name}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### onERC1155Received + +```solidity +function onERC1155Received(address, address, uint256, uint256, bytes) external pure returns (bytes4) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | +| _1 | address | undefined | +| _2 | uint256 | undefined | +| _3 | uint256 | undefined | +| _4 | bytes | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes4 | undefined | + +### ownerOf + +```solidity +function ownerOf(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-ownerOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | +| data | bytes | undefined | + +### setApprovalForAll + +```solidity +function setApprovalForAll(address operator, bool approved) external nonpayable +``` + + + +*See {IERC721-setApprovalForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| operator | address | undefined | +| approved | bool | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### symbol + +```solidity +function symbol() external view returns (string) +``` + + + +*See {IERC721Metadata-symbol}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### tokenURI + +```solidity +function tokenURI(uint256 tokenId) external view returns (string) +``` + + + +*See {IERC721Metadata-tokenURI}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### transferERC1155ToToken + +```solidity +function transferERC1155ToToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens to a specific token. + +*The ERC-1155 smart contract must have approval for this contract to transfer the ERC-1155 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-1155 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferFrom + +```solidity +function transferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-transferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### transferHeldERC1155FromToken + +```solidity +function transferHeldERC1155FromToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-1155 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### Approval + +```solidity +event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId) +``` + + + +*Emitted when `owner` enables `approved` to manage the `tokenId` token.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| approved `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### ApprovalForAll + +```solidity +event ApprovalForAll(address indexed owner, address indexed operator, bool approved) +``` + + + +*Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| operator `indexed` | address | undefined | +| approved | bool | undefined | + +### ReceivedERC1155 + +```solidity +event ReceivedERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-1155 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-1155 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-1155 tokens received | + +### Transfer + +```solidity +event Transfer(address indexed from, address indexed to, uint256 indexed tokenId) +``` + + + +*Emitted when `tokenId` token is transferred from `from` to `to`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from `indexed` | address | undefined | +| to `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### TransferredERC1155 + +```solidity +event TransferredERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-1155 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-1155 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-1155 tokens | +| amount | uint256 | The number of ERC-1155 tokens transferred | + + + +## Errors + +### InsufficientBalance + +```solidity +error InsufficientBalance() +``` + + + + + + +### InvalidAddressForERC1155 + +```solidity +error InvalidAddressForERC1155() +``` + + + + + + +### InvalidValueForERC1155 + +```solidity +error InvalidValueForERC1155() +``` + + + + + + +### OnlyNFTOwnerCanTransferTokensFromIt + +```solidity +error OnlyNFTOwnerCanTransferTokensFromIt() +``` + + + + + + + diff --git a/docs/mocks/extensions/tokenHolder/RMRKERC20HolderMock.md b/docs/mocks/extensions/tokenHolder/RMRKERC20HolderMock.md new file mode 100644 index 00000000..372e98c1 --- /dev/null +++ b/docs/mocks/extensions/tokenHolder/RMRKERC20HolderMock.md @@ -0,0 +1,492 @@ +# RMRKERC20HolderMock + +*RMRK team* + +> RMRKERC20HolderMock + +Smart contract of the RMRK ERC20 Holder module. + + + +## Methods + +### approve + +```solidity +function approve(address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-approve}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | undefined | +| tokenId | uint256 | undefined | + +### balanceOf + +```solidity +function balanceOf(address owner) external view returns (uint256) +``` + + + +*See {IERC721-balanceOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### balanceOfERC20 + +```solidity +function balanceOfERC20(address erc20Contract, uint256 tokenId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-20 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token being checked for ERC-20 balance | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-20 tokens owned by a given token | + +### getApproved + +```solidity +function getApproved(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-getApproved}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### isApprovedForAll + +```solidity +function isApprovedForAll(address owner, address operator) external view returns (bool) +``` + + + +*See {IERC721-isApprovedForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | +| operator | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### mint + +```solidity +function mint(address to, uint256 tokenId) external nonpayable +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | undefined | +| tokenId | uint256 | undefined | + +### name + +```solidity +function name() external view returns (string) +``` + + + +*See {IERC721Metadata-name}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### ownerOf + +```solidity +function ownerOf(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-ownerOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | +| data | bytes | undefined | + +### setApprovalForAll + +```solidity +function setApprovalForAll(address operator, bool approved) external nonpayable +``` + + + +*See {IERC721-setApprovalForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| operator | address | undefined | +| approved | bool | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### symbol + +```solidity +function symbol() external view returns (string) +``` + + + +*See {IERC721Metadata-symbol}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### tokenURI + +```solidity +function tokenURI(uint256 tokenId) external view returns (string) +``` + + + +*See {IERC721Metadata-tokenURI}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### transferERC20ToToken + +```solidity +function transferERC20ToToken(address erc20Contract, uint256 tokenId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens to a specific token. + +*The ERC-20 smart contract must have approval for this contract to transfer the ERC-20 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token to transfer ERC-20 tokens to | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferFrom + +```solidity +function transferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-transferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### transferHeldERC20FromToken + +```solidity +function transferHeldERC20FromToken(address erc20Contract, uint256 tokenHolderId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenHolderId | uint256 | undefined | +| to | address | undefined | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### Approval + +```solidity +event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId) +``` + + + +*Emitted when `owner` enables `approved` to manage the `tokenId` token.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| approved `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### ApprovalForAll + +```solidity +event ApprovalForAll(address indexed owner, address indexed operator, bool approved) +``` + + + +*Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| operator `indexed` | address | undefined | +| approved | bool | undefined | + +### ReceivedERC20 + +```solidity +event ReceivedERC20(address indexed erc20Contract, uint256 indexed toTokenId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-20 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| toTokenId `indexed` | uint256 | The ID of the token receiving the ERC-20 tokens | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-20 tokens received | + +### Transfer + +```solidity +event Transfer(address indexed from, address indexed to, uint256 indexed tokenId) +``` + + + +*Emitted when `tokenId` token is transferred from `from` to `to`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from `indexed` | address | undefined | +| to `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### TransferredERC20 + +```solidity +event TransferredERC20(address indexed erc20Contract, uint256 indexed fromTokenId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-20 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| fromTokenId `indexed` | uint256 | The ID of the token from which the ERC-20 tokens have been transferred | +| to `indexed` | address | The address receiving the ERC-20 tokens | +| amount | uint256 | The number of ERC-20 tokens transferred | + + + +## Errors + +### InsufficientBalanceForERC20 + +```solidity +error InsufficientBalanceForERC20() +``` + + + + + + +### InvalidAddressForERC20 + +```solidity +error InvalidAddressForERC20() +``` + + + + + + +### InvalidValueForERC20 + +```solidity +error InvalidValueForERC20() +``` + + + + + + +### OnlyNFTOwnerCanTransferTokensFromIt + +```solidity +error OnlyNFTOwnerCanTransferTokensFromIt() +``` + + + + + + + diff --git a/docs/mocks/extensions/tokenHolder/RMRKERC721HolderMock.md b/docs/mocks/extensions/tokenHolder/RMRKERC721HolderMock.md new file mode 100644 index 00000000..25f9c072 --- /dev/null +++ b/docs/mocks/extensions/tokenHolder/RMRKERC721HolderMock.md @@ -0,0 +1,507 @@ +# RMRKERC721HolderMock + +*RMRK team* + +> RMRKERC721HolderMock + +Smart contract of the RMRK ERC721 Holder module. + + + +## Methods + +### approve + +```solidity +function approve(address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-approve}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | undefined | +| tokenId | uint256 | undefined | + +### balanceOf + +```solidity +function balanceOf(address owner) external view returns (uint256) +``` + + + +*See {IERC721-balanceOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### balanceOfERC721 + +```solidity +function balanceOfERC721(address erc721Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-721 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-721 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### getApproved + +```solidity +function getApproved(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-getApproved}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### isApprovedForAll + +```solidity +function isApprovedForAll(address owner, address operator) external view returns (bool) +``` + + + +*See {IERC721-isApprovedForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | +| operator | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### mint + +```solidity +function mint(address to, uint256 tokenId) external nonpayable +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | undefined | +| tokenId | uint256 | undefined | + +### name + +```solidity +function name() external view returns (string) +``` + + + +*See {IERC721Metadata-name}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### onERC721Received + +```solidity +function onERC721Received(address, address, uint256, bytes) external pure returns (bytes4) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | +| _1 | address | undefined | +| _2 | uint256 | undefined | +| _3 | bytes | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes4 | undefined | + +### ownerOf + +```solidity +function ownerOf(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-ownerOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | +| data | bytes | undefined | + +### setApprovalForAll + +```solidity +function setApprovalForAll(address operator, bool approved) external nonpayable +``` + + + +*See {IERC721-setApprovalForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| operator | address | undefined | +| approved | bool | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### symbol + +```solidity +function symbol() external view returns (string) +``` + + + +*See {IERC721Metadata-symbol}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### tokenURI + +```solidity +function tokenURI(uint256 tokenId) external view returns (string) +``` + + + +*See {IERC721Metadata-tokenURI}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### transferERC721ToToken + +```solidity +function transferERC721ToToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens to a specific token. + +*The ERC-721 smart contract must have approval for this contract to transfer the ERC-721 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-721 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferFrom + +```solidity +function transferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-transferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### transferHeldERC721FromToken + +```solidity +function transferHeldERC721FromToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-721 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### Approval + +```solidity +event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId) +``` + + + +*Emitted when `owner` enables `approved` to manage the `tokenId` token.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| approved `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### ApprovalForAll + +```solidity +event ApprovalForAll(address indexed owner, address indexed operator, bool approved) +``` + + + +*Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| operator `indexed` | address | undefined | +| approved | bool | undefined | + +### ReceivedERC721 + +```solidity +event ReceivedERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from) +``` + +Used to notify listeners that the token received ERC-721 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-721 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | + +### Transfer + +```solidity +event Transfer(address indexed from, address indexed to, uint256 indexed tokenId) +``` + + + +*Emitted when `tokenId` token is transferred from `from` to `to`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from `indexed` | address | undefined | +| to `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### TransferredERC721 + +```solidity +event TransferredERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to) +``` + +Used to notify the listeners that the ERC-721 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-721 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-721 tokens | + + + +## Errors + +### InvalidAddressForERC721 + +```solidity +error InvalidAddressForERC721() +``` + + + + + + +### OnlyNFTOwnerCanTransferTokensFromIt + +```solidity +error OnlyNFTOwnerCanTransferTokensFromIt() +``` + + + + + + +### TokenNotHeldForERC721 + +```solidity +error TokenNotHeldForERC721() +``` + + + + + + + diff --git a/docs/mocks/extensions/tokenHolder/RMRKTokenHolderMock.md b/docs/mocks/extensions/tokenHolder/RMRKTokenHolderMock.md index 0b1d8cf2..8f288483 100644 --- a/docs/mocks/extensions/tokenHolder/RMRKTokenHolderMock.md +++ b/docs/mocks/extensions/tokenHolder/RMRKTokenHolderMock.md @@ -52,12 +52,12 @@ function balanceOf(address owner) external view returns (uint256) ### balanceOfToken ```solidity -function balanceOfToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId) external view returns (uint256) +function balanceOfToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId) external view returns (uint256) ``` Used to retrieve the given token's balance of given token -*When retrieving the balance of an ERC-20 token, the `heldTokenId` parameter MUST be ignored.* +*When retrieving the balance of an ERC-20 token, the `tokenToTransferId` parameter MUST be ignored.* #### Parameters @@ -66,7 +66,7 @@ Used to retrieve the given token's balance of given token | tokenContract | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being checked for balance | | tokenId | uint256 | The ID of the token being checked for balance | -| heldTokenId | uint256 | The ID of the held token of which the balance is being retrieved | +| tokenToTransferId | uint256 | The ID of the held token of which the balance is being retrieved | #### Returns @@ -362,12 +362,12 @@ function transferFrom(address from, address to, uint256 tokenId) external nonpay ### transferHeldTokenFromToken ```solidity -function transferHeldTokenFromToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId, uint256 amount, address to, bytes data) external nonpayable +function transferHeldTokenFromToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId, uint256 amount, address to, bytes data) external nonpayable ``` Transfer held tokens from a specific token. -*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.If the token type is `ERC-20`, the `heldTokenId` MUST be ignored.IF the token type is `ERC-721`, the `amount` MUST be ignored.* +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored.IF the token type is `ERC-721`, the `amount` MUST be ignored.* #### Parameters @@ -376,7 +376,7 @@ Transfer held tokens from a specific token. | tokenContract | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | tokenId | uint256 | The ID of the token to transfer the held token from | -| heldTokenId | uint256 | The ID of the held token to transfer | +| tokenToTransferId | uint256 | The ID of the held token to transfer | | amount | uint256 | The number of held tokens to transfer | | to | address | The address to transfer the held tokens to | | data | bytes | Additional data with no specified format, to allow for custom logic | @@ -384,12 +384,12 @@ Transfer held tokens from a specific token. ### transferHeldTokenToToken ```solidity -function transferHeldTokenToToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 heldTokenId, uint256 amount, bytes data) external nonpayable +function transferHeldTokenToToken(address tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 tokenId, uint256 tokenToTransferId, uint256 amount, bytes data) external nonpayable ``` Transfer tokens to a specific holder token. -*The token smart contract must have approval for this contract to transfer the tokens.The balance MUST be transferred from the `msg.sender`.If the token type is `ERC-20`, the `heldTokenId` MUST be ignored.If the token type is `ERC-721`, the `amount` MUST be ignored.* +*The token smart contract must have approval for this contract to transfer the tokens.The balance MUST be transferred from the `msg.sender`.If the token type is `ERC-20`, the `tokenToTransferId` MUST be ignored.If the token type is `ERC-721`, the `amount` MUST be ignored.* #### Parameters @@ -398,7 +398,7 @@ Transfer tokens to a specific holder token. | tokenContract | address | The address of the token smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | tokenId | uint256 | The ID of the token to transfer the tokens to | -| heldTokenId | uint256 | The ID of the held token to transfer | +| tokenToTransferId | uint256 | The ID of the held token to transfer | | amount | uint256 | The number of ERC-20 tokens to transfer | | data | bytes | Additional data with no specified format, to allow for custom logic | @@ -445,12 +445,12 @@ event ApprovalForAll(address indexed owner, address indexed operator, bool appro ### ReceivedToken ```solidity -event ReceivedToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed toTokenId, uint256 heldTokenId, address indexed from, uint256 amount) +event ReceivedToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed toTokenId, uint256 tokenToTransferId, address indexed from, uint256 amount) ``` Used to notify listeners that the token received held tokens. -*If the token type is `ERC-20`, the `heldTokenId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* +*If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* #### Parameters @@ -459,7 +459,7 @@ Used to notify listeners that the token received held tokens. | tokenContract `indexed` | address | The address of the held token's smart contract | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the held token being received | | toTokenId `indexed` | uint256 | The ID of the token receiving the held tokens | -| heldTokenId | uint256 | The ID of the held token being received | +| tokenToTransferId | uint256 | The ID of the held token being received | | from `indexed` | address | The address of the account from which the tokens are being transferred | | amount | uint256 | The amount of held tokens received | @@ -484,12 +484,12 @@ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId ### TransferredToken ```solidity -event TransferredToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed fromTokenId, uint256 heldTokenId, address indexed to, uint256 amount) +event TransferredToken(address indexed tokenContract, enum IRMRKTokenHolder.TokenType tokenType, uint256 indexed fromTokenId, uint256 tokenToTransferId, address indexed to, uint256 amount) ``` Used to notify the listeners that the ERC-20 tokens have been transferred. -*If the token type is `ERC-20`, the `heldTokenId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* +*If the token type is `ERC-20`, the `tokenToTransferId` MUST equal `0`If the token type is `ERC-721`, the `amount` MUST equal `1`.* #### Parameters @@ -498,7 +498,7 @@ Used to notify the listeners that the ERC-20 tokens have been transferred. | tokenContract `indexed` | address | The address of the smart contract of the token being transferred | | tokenType | enum IRMRKTokenHolder.TokenType | The type of the token being transferred | | fromTokenId `indexed` | uint256 | The ID of the token from which the held tokens have been transferred | -| heldTokenId | uint256 | The Id of the held token being transferred | +| tokenToTransferId | uint256 | The Id of the held token being transferred | | to `indexed` | address | The address receiving the ERC-20 tokens | | amount | uint256 | The amount of held tokens transferred | diff --git a/docs/mocks/extensions/tokenHolder/RMRKUniversalHolderMock.md b/docs/mocks/extensions/tokenHolder/RMRKUniversalHolderMock.md new file mode 100644 index 00000000..f70a975d --- /dev/null +++ b/docs/mocks/extensions/tokenHolder/RMRKUniversalHolderMock.md @@ -0,0 +1,787 @@ +# RMRKUniversalHolderMock + +*RMRK team* + +> RMRKUniversalHolderMock + +Smart contract of the RMRK ERC1155 Holder module. + + + +## Methods + +### approve + +```solidity +function approve(address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-approve}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| to | address | undefined | +| tokenId | uint256 | undefined | + +### balanceOf + +```solidity +function balanceOf(address owner) external view returns (uint256) +``` + + + +*See {IERC721-balanceOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### balanceOfERC1155 + +```solidity +function balanceOfERC1155(address erc1155Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-1155 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-1155 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-1155 tokens owned by a given token | + +### balanceOfERC20 + +```solidity +function balanceOfERC20(address erc20Contract, uint256 tokenId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-20 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token being checked for ERC-20 balance | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | The amount of the specified ERC-20 tokens owned by a given token | + +### balanceOfERC721 + +```solidity +function balanceOfERC721(address erc721Contract, uint256 tokenHolderId, uint256 tokenHeldId) external view returns (uint256) +``` + +Used to retrieve the given token's specific ERC-721 balance + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token being checked for ERC-721 balance | +| tokenHeldId | uint256 | The ID of the held token | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | uint256 | undefined | + +### getApproved + +```solidity +function getApproved(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-getApproved}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### isApprovedForAll + +```solidity +function isApprovedForAll(address owner, address operator) external view returns (bool) +``` + + + +*See {IERC721-isApprovedForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner | address | undefined | +| operator | address | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### name + +```solidity +function name() external view returns (string) +``` + + + +*See {IERC721Metadata-name}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### onERC1155Received + +```solidity +function onERC1155Received(address, address, uint256, uint256, bytes) external pure returns (bytes4) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | +| _1 | address | undefined | +| _2 | uint256 | undefined | +| _3 | uint256 | undefined | +| _4 | bytes | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes4 | undefined | + +### onERC721Received + +```solidity +function onERC721Received(address, address, uint256, bytes) external pure returns (bytes4) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | +| _1 | address | undefined | +| _2 | uint256 | undefined | +| _3 | bytes | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bytes4 | undefined | + +### ownerOf + +```solidity +function ownerOf(uint256 tokenId) external view returns (address) +``` + + + +*See {IERC721-ownerOf}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | address | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### safeTransferFrom + +```solidity +function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) external nonpayable +``` + + + +*See {IERC721-safeTransferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | +| data | bytes | undefined | + +### setApprovalForAll + +```solidity +function setApprovalForAll(address operator, bool approved) external nonpayable +``` + + + +*See {IERC721-setApprovalForAll}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| operator | address | undefined | +| approved | bool | undefined | + +### supportsInterface + +```solidity +function supportsInterface(bytes4 interfaceId) external view returns (bool) +``` + + + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| interfaceId | bytes4 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | bool | undefined | + +### symbol + +```solidity +function symbol() external view returns (string) +``` + + + +*See {IERC721Metadata-symbol}.* + + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### tokenURI + +```solidity +function tokenURI(uint256 tokenId) external view returns (string) +``` + + + +*See {IERC721Metadata-tokenURI}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| tokenId | uint256 | undefined | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| _0 | string | undefined | + +### transferERC1155ToToken + +```solidity +function transferERC1155ToToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens to a specific token. + +*The ERC-1155 smart contract must have approval for this contract to transfer the ERC-1155 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-1155 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferERC20ToToken + +```solidity +function transferERC20ToToken(address erc20Contract, uint256 tokenId, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens to a specific token. + +*The ERC-20 smart contract must have approval for this contract to transfer the ERC-20 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenId | uint256 | The ID of the token to transfer ERC-20 tokens to | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferERC721ToToken + +```solidity +function transferERC721ToToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens to a specific token. + +*The ERC-721 smart contract must have approval for this contract to transfer the ERC-721 tokens.The balance MUST be transferred from the `msg.sender`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer ERC-721 tokens to | +| tokenToTransferId | uint256 | The ID of the held token being received | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferFrom + +```solidity +function transferFrom(address from, address to, uint256 tokenId) external nonpayable +``` + + + +*See {IERC721-transferFrom}.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from | address | undefined | +| to | address | undefined | +| tokenId | uint256 | undefined | + +### transferHeldERC1155FromToken + +```solidity +function transferHeldERC1155FromToken(address erc1155Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-1155 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract | address | The address of the ERC-1155 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-1155 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| amount | uint256 | The number of ERC-1155 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC20FromToken + +```solidity +function transferHeldERC20FromToken(address erc20Contract, uint256 tokenHolderId, address to, uint256 amount, bytes data) external nonpayable +``` + +Transfer ERC-20 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract | address | The address of the ERC-20 smart contract | +| tokenHolderId | uint256 | undefined | +| to | address | undefined | +| amount | uint256 | The number of ERC-20 tokens to transfer | +| data | bytes | Additional data with no specified format, to allow for custom logic | + +### transferHeldERC721FromToken + +```solidity +function transferHeldERC721FromToken(address erc721Contract, uint256 tokenHolderId, uint256 tokenToTransferId, address to, bytes data) external nonpayable +``` + +Transfer ERC-721 tokens from a specific token. + +*The balance MUST be transferred from this smart contract.Implementers should validate that the `msg.sender` is either the token owner or approved to manage it before calling this.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract | address | The address of the ERC-721 smart contract | +| tokenHolderId | uint256 | The ID of the token to transfer the ERC-721 tokens from | +| tokenToTransferId | uint256 | The ID of the held token being sent | +| to | address | undefined | +| data | bytes | Additional data with no specified format, to allow for custom logic | + + + +## Events + +### Approval + +```solidity +event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId) +``` + + + +*Emitted when `owner` enables `approved` to manage the `tokenId` token.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| approved `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### ApprovalForAll + +```solidity +event ApprovalForAll(address indexed owner, address indexed operator, bool approved) +``` + + + +*Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| owner `indexed` | address | undefined | +| operator `indexed` | address | undefined | +| approved | bool | undefined | + +### ReceivedERC1155 + +```solidity +event ReceivedERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-1155 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-1155 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-1155 tokens received | + +### ReceivedERC20 + +```solidity +event ReceivedERC20(address indexed erc20Contract, uint256 indexed toTokenId, address indexed from, uint256 amount) +``` + +Used to notify listeners that the token received ERC-20 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| toTokenId `indexed` | uint256 | The ID of the token receiving the ERC-20 tokens | +| from `indexed` | address | The address of the account from which the tokens are being transferred | +| amount | uint256 | The number of ERC-20 tokens received | + +### ReceivedERC721 + +```solidity +event ReceivedERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed from) +``` + +Used to notify listeners that the token received ERC-721 tokens. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token receiving the ERC-721 tokens | +| tokenTransferredId | uint256 | The ID of the received token | +| from `indexed` | address | The address of the account from which the tokens are being transferred | + +### Transfer + +```solidity +event Transfer(address indexed from, address indexed to, uint256 indexed tokenId) +``` + + + +*Emitted when `tokenId` token is transferred from `from` to `to`.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| from `indexed` | address | undefined | +| to `indexed` | address | undefined | +| tokenId `indexed` | uint256 | undefined | + +### TransferredERC1155 + +```solidity +event TransferredERC1155(address indexed erc1155Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-1155 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc1155Contract `indexed` | address | The address of the ERC-1155 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-1155 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-1155 tokens | +| amount | uint256 | The number of ERC-1155 tokens transferred | + +### TransferredERC20 + +```solidity +event TransferredERC20(address indexed erc20Contract, uint256 indexed fromTokenId, address indexed to, uint256 amount) +``` + +Used to notify the listeners that the ERC-20 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc20Contract `indexed` | address | The address of the ERC-20 smart contract | +| fromTokenId `indexed` | uint256 | The ID of the token from which the ERC-20 tokens have been transferred | +| to `indexed` | address | The address receiving the ERC-20 tokens | +| amount | uint256 | The number of ERC-20 tokens transferred | + +### TransferredERC721 + +```solidity +event TransferredERC721(address indexed erc721Contract, uint256 indexed tokenHolderId, uint256 tokenTransferredId, address indexed to) +``` + +Used to notify the listeners that the ERC-721 tokens have been transferred. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| erc721Contract `indexed` | address | The address of the ERC-721 smart contract | +| tokenHolderId `indexed` | uint256 | The ID of the token from which the ERC-721 tokens have been transferred | +| tokenTransferredId | uint256 | The ID of the transferred token | +| to `indexed` | address | The address receiving the ERC-721 tokens | + + + +## Errors + +### InsufficientBalance + +```solidity +error InsufficientBalance() +``` + + + + + + +### InsufficientBalanceForERC20 + +```solidity +error InsufficientBalanceForERC20() +``` + + + + + + +### InvalidAddressForERC1155 + +```solidity +error InvalidAddressForERC1155() +``` + + + + + + +### InvalidAddressForERC20 + +```solidity +error InvalidAddressForERC20() +``` + + + + + + +### InvalidAddressForERC721 + +```solidity +error InvalidAddressForERC721() +``` + + + + + + +### InvalidValueForERC1155 + +```solidity +error InvalidValueForERC1155() +``` + + + + + + +### InvalidValueForERC20 + +```solidity +error InvalidValueForERC20() +``` + + + + + + +### OnlyNFTOwnerCanTransferTokensFromIt + +```solidity +error OnlyNFTOwnerCanTransferTokensFromIt() +``` + + + + + + +### TokenNotHeldForERC721 + +```solidity +error TokenNotHeldForERC721() +``` + + + + + + +