DEV Community

Cover image for [UniswapV2] UniswapV2Factory.sol
MOYED
MOYED

Posted on

4 3

[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 .

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay