0

I came across __ERC20Permit_init while reviewing some code. What purpose of this? I googled and found it out in the Initializable.sol of Oppenzeppelin's contract. But example codes in contract were used in different contracts. The code I reviewed was used in one contract. Is there any difference?

[Code snippet of the project]

contract LPToken is ILPTokenInit, ILiquidStakingManagerChildContract, Initializable, ERC20PermitUpgradeable {
    //...
    constructor() initializer {}

    function init(
            address _deployer,
            address _transferHookProcessor,
            string calldata _tokenSymbol,
            string calldata _tokenName
         ) external override initializer {
            deployer = _deployer;
            transferHookProcessor = ITransferHookProcessor(_transferHookProcessor);
            __ERC20_init(_tokenName, _tokenSymbol);
            __ERC20Permit_init(_tokenName);
    }
}

2 Answers 2

1

No, I don't think there is a difference. __ERC20Permit_init initializes the {EIP712} domain separator using the name parameter, and setting version to "1". A domain separator helps to prevent a signature meant for one dApp from working in another.

  • The name is the name of the dApp or protocol name.

  • The current version is the version what the EIP712 standard calls a “signing domain”. This can be the version number of your dApp or platform. It prevents signatures from one dApp version from working with those of others.

See:

https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol

https://medium.com/metamask/eip712-is-coming-what-to-expect-and-how-to-use-it-bb92fd1a7a26

0

I found this in the ERC20Permit.sol file under /contracts/token/ERC20/extensions/ERC20Permit.sol

* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.

so it looks like enables an allowance function on the ERC20 contract that you can change by signing a message instead of sending a transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.