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.
-
If time passed
deadline
, revert.
require(deadline >= block.timestamp, 'UniswapV2: EXPIRED');
-
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);
-
If address matches the
owner
approve it.
require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE'); _approve(owner, spender, value);
Top comments (0)