I wish to propose ERC1003 to be included into OpenZeppelin-solidity library.
Pros:
- no checks required on client side: just get tokens from
msg.sender
and spend as arguments describe - full compatibility with ERC20
approve
+transferFrom
mechanism, even compatible with some existing smart contracts including DEXes
Cons:
- any tokens mistakenly sent to the ERC1003-compatible smart contract helper contract became available for everyone to be stolen.
Example Implementation:
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
contract ERC1003Caller is Ownable {
function makeCall(address target, bytes calldata data) external payable onlyOwner returns (bool success) {
(success,) = target.call.value(msg.value)(data);
}
}
contract ERC1003Token is ERC20 {
ERC1003Caller public caller_ = new ERC1003Caller();
address[] internal sendersStack_;
function transferToContract(address to, uint256 value, bytes memory data) public payable returns (bool) {
sendersStack_.push(msg.sender);
approve(to, value);
require(caller_.makeCall.value(msg.value)(to, data));
sendersStack_.pop();
return true;
}
function transferFrom(address from, address to, uint256 value) public returns (bool) {
address source = (from != address(caller_)) ? from : sendersStack_[sendersStack_.length - 1];
return super.transferFrom(source, to, value);
}
}