DEV Community

Cover image for [UniswapV2] UniswapV2ERC20.sol
MOYED
MOYED

Posted on

3 3

[UniswapV2] UniswapV2ERC20.sol

This is quite similar to OpenZepplin’s ERC20.sol, but with some unique features.


Variables

nonces

To prevent replay attack.

constructor

Having problem understanding it...

Functions

permit

Give permission.

  1. If time passed deadline, revert.

    require(deadline >= block.timestamp, 'UniswapV2: EXPIRED');
    
  2. Recover address from digest and signature. (Honestly, I don’t get it.)

    bytes32 digest = keccak256(
                abi.encodePacked(
                    '\x19\x01',
                    DOMAIN_SEPARATOR,
                    keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
                )
            );
    address recoveredAddress = ecrecover(digest, v, r, s);
    
  3. If address matches the owner approve it.

    require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE');
    _approve(owner, spender, value);
    

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay