title: How is uniswap assembly create2 function working?
body: <p>I was going through uniswap code trying to understand the code and most of it is pretty clear but I do have a few questions.</p>
  <p>in this function:</p>
  <pre><code>function createPair(address tokenA, address tokenB) external returns (address pair) {
      require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
      (address token0, address token1) = tokenA &lt; tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
      require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
      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));
      assembly {
          pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
      }
      IUniswapV2Pair(pair).initialize(token0, token1);
      getPair[token0][token1] = pair;
      getPair[token1][token0] = pair; // populate mapping in the reverse direction
      allPairs.push(pair);
      emit PairCreated(token0, token1, pair, allPairs.length);
  </code></pre>
  <p>There is the assembly line. According to solidity docs this deploys a new contract but I don't understand how it works where it gets the code from and so on.</p>
  <p>So is it possible to &quot;translate&quot; this into solidity somehow? Thanks a lot!</p>