Uniswap / v2-core

🦄 🦄 Core smart contracts of Uniswap V2
https://uniswap.org/docs
GNU General Public License v3.0
2.95k stars 3.16k forks source link

`CheckContract` for token contracts #162

Open abhi3700 opened 2 years ago

abhi3700 commented 2 years ago

Instead of this line, the check contract logic can be written by introducing a function like this:

/**
 * Check that the account is an already deployed non-destroyed contract.
 * See: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol#L12
 */
function _checkContract(address _account) private view {
    require(_account != address(0), "Account cannot be zero address");

    uint256 size;
    // solhint-disable-next-line no-inline-assembly
    assembly {
        size := extcodesize(_account)
    }
    require(size != 0, "Account code size cannot be zero");
}
hacklili commented 1 year ago

what

abhi3700 commented 1 year ago

this is to check whether the parsed contract address has some ERC20 code.

ghost commented 9 months ago

this is not recommended because

  1. It blocks developers creating a pair before deploying a token contract ( some may find this useful )

  2. Every pair liquidity is dedicated so if the pair token isn't deployed or doesn't fulfill ERC20 standard core functionality wouldn't work including providing liquidity, etc. so it doesn't matter.