DEV Community

Cover image for [UniswapV2] UniswapV2Factory.sol
MOYED
MOYED

Posted on

[UniswapV2] UniswapV2Factory.sol

Variables

feeTo

Accumulate liquidity token for protocol fee.

feeToSetter

Address that can change the feeTo .

getPair

To get the address of exchange pairs. Ex: getPair[<tokenA address>][<tokenB address>] .

allPairs

Array of exchange pairs created by this factory.


Functions

createPair

  1. Get consistent order of token addresses.

    (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
    
  2. Check if address of pair is zero. It means that there is not existing pool for token0 & token1 .

    require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
    
  3. Initialize the pair of token0 and token . Add pair to the allPairs array.

    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);
    

setFeeTo & setFeeToSetter

If msg.sender is feeToSetter , we can change and control the feeTo .

Top comments (0)