Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkContract added for check of non-destroyed deployed SC #163

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions contracts/UniswapV2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ contract UniswapV2Factory is IUniswapV2Factory {
mapping(address => mapping(address => address)) public getPair;
address[] public allPairs;

event PairCreated(address indexed token0, address indexed token1, address pair, uint);
event PairCreated(address indexed token0, address indexed token1, address pair, uint256);

constructor(address _feeToSetter) public {
feeToSetter = _feeToSetter;
}

function allPairsLength() external view returns (uint) {
function allPairsLength() external view returns (uint256) {
return allPairs.length;
}

function createPair(address tokenA, address tokenB) external returns (address pair) {
require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
// require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
_checkContract(token0);
_checkContract(token1);
require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
bytes memory bytecode = type(UniswapV2Pair).creationCode;
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
Expand All @@ -46,4 +48,21 @@ contract UniswapV2Factory is IUniswapV2Factory {
require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
feeToSetter = _feeToSetter;
}

// -- Utility function --
/**
* 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 returns (bool) {
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');
return true;
}
}