Token existence and current issue with minting fungible tokens
wighawag opened this issue · comments
Hi,
Great to see an another implementation of fungible token, I especially like the fact that it support ERC721 too. We, at @pixowl started thinking going that route too.
On that note though, as you probably realised it leads to ambiguous functions. (ownerOf
in particular).
The way I like to see these tokens (both NFT and FT) in term of the ERC721x interface is that the tokenIds refers to tokenTypes and not token instances.
the NFT tokenTypes by having only one instance can technically have an owner since being unique there will only be one owner among all the tokenType instance (since there is only one instance)
On the other hand FT cannot have a specified owner since there will be multiple owner among all the instances. As such ownerOf
cannot return any of them.
In your implementation you chose to revert the transaction calling ownerOf
. Did you consider returning the ERC721x contract address itself instead ? or the zero address ? If so why did you chose the revert option ?
I am bringing that up since currently in your code, you use the function exists
to check various function including _mint
and tokenURI
. In that exists
function you check the owner. If it does not have one, you deem the token to not exist.
This seems a bit wrong to me since surely FT token can be definitely said to exist. This would also allow to check if a particular FT token type has been minted without calling individualSupply
This now brings me to one bug in the ERC721x _mint
function (which allow to specify a supply):
Since you do not check for existence there, we can keep minting the same tokenIds multiple times including an existing NFT ERC721 tokenType. While this could be correct for an FT to increase supply (you should not push it to the allTokens array though) but this would never be correct for NFT.
Overall, I like your approach but it would probably benefit to be submitted as EIP/ERC first to improve it.
Also a proper spec would be needed for adoption by others.
Are you planning to write a spec as opposed to simply an interface and publish it as an official EIP ?
Looking forward to have a standard for FT and NFT together.
in issue #6
I proposed a fix :
FT have the ERC721x contract address as owner, this way, the, the function exists
remain valid for both FT and NFT.
Then in the ERC721x _mint
function (the one with supply as parameter) you can check existance by calling exists
Fixed in #7, thanks for the find! Let me know if you notice something else, and yes I'll probably go for an EIP/ERC soon to standardize/improve this
Great!
By the way the message here should probably change too :
since now FT will also have an owner but this will be the contract itself