HIP-404: The Mixed FT/NFT Standard

Introduction

HIP-404 is derived from ERC-404 v2, which was originally created by Pandora Labs. It's an experimental token standard that merges fungible tokens (FT, ERC-20) and non-fungible tokens (NFT, ERC-721) while incorporating native liquidity and fractionalization.

This standard enables the creation of digital assets that can function both as fungible tokens for use cases such as staking or trading, and as unique non-fungible token to represent unique ownership.

When a user buys a certain amount of HIP-404 tokens or receives them from another wallet, the contract not only updates the balance of fungible tokens but can also mint a unique NFT to the recipient. This NFT could represent a special right, membership, or ownership over a part of a unique asset associated with the fungible tokens. Conversely, selling or transferring the fungible tokens could trigger the transfer of associated NFTs, ensuring that ownership rights are correctly maintained and transferred alongside the fungible token balances.

Key features

  • Hybrid Nature: While ERC-20 focuses on fungible tokens (identical and interchangeable) and ERC-721 on non-fungible (unique and not interchangeable), HIP-404 utilizes both types of token standards, allowing both fungible and non-fungible functionalities within the same smart contract. This functionality is similar to the already existing ERC-1155 standard, which also enables the same type of token operations from a single contract.

  • Native Fractionalization of NFTs: Unlike standard ERC-721, where an NFT represents a whole, indivisible asset, HIP-404 introduces native support for fractional ownership of NFTs. This means users can own a part of an NFT, enhancing liquidity and accessibility for high-value assets.

  • Enhanced Liquidity: By allowing fractional ownership, HIP-404 overcomes one of the main limitations of traditional NFTs—their lack of liquidity. It enables smaller investors to participate in the ownership of high-value assets and facilitates easier trading on exchanges.

  • Dynamic Functionality: HIP-404 tokens can act as either fungible or non-fungible assets depending on the transaction context. For example, when buying or receiving tokens from another user, the contract can automatically allocate ERC-721 NFTs to represent specific ownership rights or achievements while also handling fungible token transactions seamlessly.

Specification

Events

  • ERC20Transfer: Emitted when a fungible token transfer occurs.

  • Approval: Indicates approval of a spender to withdraw tokens on behalf of the owner.

  • Transfer: Emitted for both ERC-20 and ERC-721 transfers, indicating a token's transfer.

  • ERC721Approval: Similar to Approval, but specifically for ERC-721 token IDs.

  • ApprovalForAll: Emitted when an owner approves an operator to manage all their tokens.

Errors

  • NotFound: Indicates a query for a non-existent token ID owner.

  • InvalidTokenId: Indicates a query for a non-existent token ID.

  • AlreadyExists: Thrown if attempting to mint a token with an ID that already exists.

  • InvalidRecipient: Thrown if the recipient is zero address.

  • InvalidSender: Thrown if the sender is zero address.

  • InvalidSpender: Thrown if the spender is zero address.

  • InvalidOperator: Thrown if the operator is zero address.

  • UnsafeRecipient: Indicates that a recipient contract cannot handle ERC-721 tokens.

  • RecipientIsERC721TransferExempt: Throw when transfer ERC-721 to transfer exempt address.

  • Unauthorized: Throw when msg.sender is neither the NFT owner nor authorized.

  • InsufficientAllowance: Throw when operator has insufficient allowance.

  • DecimalsTooLow: Throw when ERC-20 Tokens deciamls to low.

  • OwnedIndexOverflow: Throw when owned index overflow.

  • InvalidExemption: Throw when set zero address is set to ERC-721 transfer exempt.

Metadata

  • name: The name of the token.

  • symbol: The symbol of the token.

  • decimals: Used for fungible tokens to define the smallest unit.

  • Units: units between non-fungible tokens and fungible tokens.

  • totalSupply: The total supply of fungible tokens.

  • minted: Counter for minted tokens, ensuring unique IDs for NFTs.

Mappings

  • balanceOf: Maps an address to its balance of fungible tokens.

  • allowance: Maps an owner to an operator and the number of tokens they're allowed to spend.

  • getApproved: Maps a token ID to an approved address for that specific token.

  • isApprovedForAll: Maps an owner to an operator for approval across all tokens.

  • _ownedData: Packed representation of ownerOf and owned indices

  • _owned: Maps an address to an array of token IDs they own.

  • _erc721TransferExempt: Addresses that are exempt from ERC-721 transfer, typically for gas savings (pairs, routers, etc).

Constructor

Initializes the contract with the name, symbol, units and decimals.

Functions

  • erc20BalanceOf: Returns the owner owned fungible tokens num.

  • erc721BalanceOf: Returns the owner owned non-fungible tokens num.

  • erc20TotalSupply: Returns fungible tokens supply.

  • erc721TotalSupply: Returns non-fungible tokens supply.

  • ownerOf: Returns the owner of a specified token ID.

  • tokenURI: (Abstract Function) Should be implemented to return the URI for a token's metadata.

  • approve: Allows a token owner to approve another address to spend a specific amount or token ID on their behalf.

  • erc20Approve: Allows a token owner to approve another address to spend a specific amount on their behalf.

  • erc721Approve: Allows a token owner to approve another address to spend token ID on their behalf.

  • setApprovalForAll: Enables or disables approval for an operator to manage all of the caller's tokens.

  • transferFrom: Facilitates the transfer of fungible tokens or a specific NFT from one address to another.

  • erc20TransferFrom: Facilitates the transfer of fungible tokens from one address to another.

  • erc721TransferFrom: Facilitates the transfer of a specific NFT from one address to another.

  • transfer: Allows for the transfer of fungible tokens from the caller's address to another.

  • safeTransferFrom (with and without data): Similar to transferFrom but includes checks to ensure the recipient can safely receive NFTs.

  • _transfer: Internal function that handles the logic of transferring fungible tokens, including potential minting or burning of NFTs based on the transferred amount.

  • _setERC721TransferExempt: function to set pairs / etc, saving gas by avoiding mint / burn on unnecessary targets.

Implementation

TBD

References

Last updated

Was this helpful?