thesis / solidity-contracts

MIT License
2 stars 1 forks source link

ERC20WithPermit token #3

Closed pdyraga closed 3 years ago

pdyraga commented 3 years ago

Generic implementation of ERC20 token with permit functionality, used already in keep-network/tbtc-v2 and keep-network/coverage-pools.

User can authorize a transfer of their token with a signature conforming EIP712 standard instead of an on-chain transaction from their address. Anyone can submit this signature on the user's behalf by calling permit function, as specified in EIP2612, paying gas fees, and possibly performing other actions in the same transaction.

By the time of implementing this contract, to my knowledge, there is no other audited EP2612 token implementation other than Uniswap V2 on which this code is based on. OpenZeppelin has quite recently added permit to their ERC20 but this code is still in a draft state, was released in the most recent version of the library, and to my understanding was not audited yet by another firm, and could have breaking change in the future.

The implementation mostly mirrors UniswapV2ERC20. It adds some tweaks from OpenZeppelin ERC20 implementation such as more meaningful revert messages and Approval event emitted on calls to transferFrom. This allows applications to reconstruct the allowance for all accounts just by listening to the event. Additionally, this token implements approveAndCall pattern.

Unit tests were based on OpenZeppelin ERC20 unit tests with our own tests implementation for EIP2612 and EIP712. The token code in
keep-network/tbtc-v2 this is is a ctrlc/ctrlv was audited by ToB.

nkuba commented 3 years ago

Oh boy, I'm sorry for spamming. I was using VSC plugin for the review and I was 100% sure the comments are being added to the pending review so I will submit them all at once 🤦🏻

pdyraga commented 3 years ago

Let's open a separate issue for test improvements. All tests but permit-related were ported from OpenZeppelin and already reviewed in coverage-pools PR. If we want to do some modifications, let's not hold PRs that wait for this one.