Hi there,
I created an ERC for namespacing function and events ABI so otherwise conflicting function signatures from different contract interface standard could coexist in one smart contract
Would love to get feedback so we can move that forward and implement it in solidity / vyper …
from : https://github.com/ethereum/EIPs/issues/1407
Namespacing ABI interface
Abstract
Currently function and event ABI are entirely defined with their name and type signature.
It would be great to include an extra data to allow namespacing the interfaces.
Solidity and other smart contract languages could add the possibility to annotate function to use different namespace so a contract is not required to support only one namespace.
The default one could be the empty namespace ‘’ for backward compatibility. Or alternatively every new contract would need to declare the default namespace for all functions (the default could be the contract name). Then annotations could be used to specify each function namespace if the one desired is different than the default.
Motivation
This would allow a contract to support multiple conflicting interfaces at the same time.
For example, let say you plan to use an ERC20 token but would like it to be part of the same contract as an ERC721. (this could allow you to avoid calling external contract to transfer balances for example). When the contract is used as an ERC20 “balanceOf” would return the balance of the ERC20 token represented by that contract and when used as an ERC721 it would return how many NFT you own. The namespacing would simply result in different ABI, so even though the function has the same signature, both can be used.
Currently this is not possible (and won’t be for this particular case even after this EIP get implemented in smart contract languages since the ERC721 and ERC20 ABI has already been decided) but as more smart contract interface standards come into being, the likeliness of interface conflict will increase. The usefulness of combining two conflicting interfaces into one contract will probably rise too.
Potential Specification
Here is a potential way to achieve that in solidity.
Suggestion are more than welcome. The idea behind creating that issue to find a sensible specification for solving that problem elegantly.
contract ERC721 {
function totalSupply() public view returns (uint256) { // use default namespace, that of the Contract Name
....
}
function balanceOf(address who) public view returns (uint256){
}
function test() {
this.balanceOf(msg.sender);
this.@ERC20.balanceOf(msg.sender); // could be a way to access namespaced function
}
@namespace('ERC20') function totalSupply() public view returns (uint256) { // use namespace ERC20
....
}
@namespace('ERC20') function balanceOf(address who) public view returns (uint256){
}
@namespace('ERC20') event Transfer(address indexed from, address indexed to, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
}
The ABI for each function could then be
sha3("<namespace><canonical function signature>")
instead of
sha3("<canonical function signature>)"