Hello,
I have ERC20 Token contract it has implemented ERC20Permit and ERC20Burnable. I'm using only both mint and burn function with signature. This function name is withSignature
. I have created simple IToken interface it like this following;
interface IToken is IERC20, IERC20Permit {
enum OP {MINT, BURN}
function withSignature(
OP op,
address to,
uint256 amount,
uint256 deadline,
uint8 v, bytes32 r, bytes32 s
) external;
}
This function correctly call from Token
contract. But I want to call from my another contract this name is OtherContract
. This other contract implemented ERC1155, Ownable, ERC1155Burnable, ERC1155Supply, EIP712
. OtherContract has mintWithSignature
like Token.withSignature
, following this code;
function mintWithSignature(
address to,
uint256[] memory ids,
uint256[] memory amounts,
uint256 deadline,
// 0 -> OtherContract
// 1 -> IToken
uint8[] memory v,
bytes32[] memory r,
bytes32[] memory s
) public {
require(msg.sender == to && block.timestamp <= deadline, "EA22");
bytes32 functionSelector = keccak256("mintWithSignature(address to,uint256[] ids,uint256[] amounts,uint256 nonce,uint256 deadline)");
bytes32 structHash = keccak256( abi.encode(functionSelector, to, keccak256(abi.encodePacked(ids)), keccak256(abi.encodePacked(amounts)), _useNonce(to), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer_ = ECDSA.recover(hash, v[0], r[0], s[0]);
// E44: ERC1155Permit: invalid signature && ECDSA: invalid signature
require(signer_ == secretSigner && signer_ != address(0), "E44");
if(ids.length > 0 || amounts.length > 0) {
IToken token = IToken(tokenAddress);
require(token.balanceOf(to) >= DESTROY_TOKEN * 10 ** 18, "E33");
_mintBatch(msg.sender, ids, amounts, "");
// Doesn't work "only below"
tokenAddress.delegatecall(
abi.encodeWithSignature(
"withSignature(uint8,address,uint256,uint256,uint8,bytes32,bytes32)",
IToken.OP.BURN, msg.sender, DESTROY_TOKEN * 10 ** 18, deadline, v[1], r[1], s[1]
)
);
}
}
OtherContract.mintWithSignature
function just only work If you need destroy Token amount, works.
Exactly what I want to do is as I said last. Everything works but delegatecall
does not work. I couldn't understand why. You know any other alternative solution please guide me.
Solidity version is ^0.8.7
, environment is Hardhat@2.8.4
Thank you,
Good work.