Skip to main content

Factory

Address

The UniswapV2Factory contract is located at 0xAdD2FC2189dA02E4122E6D734094bF1474516AD0 on the Rails Network mainnet.

Events

PairCreated

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

Triggered whenever a new pair is established through the createPair method.

  • token0 will always be sorted before token1.
  • The sequence number of the pair creation is recorded in the last uint (1 for the first pair, 2 for the second, and so on).

Read-Only Functions

getPair

function getPair(address tokenA, address tokenB) external view returns (address pair);

Fetches the pair address for tokenA and tokenB, returning address(0) if the pair does not exist.

  • The order of tokenA and tokenB does not matter.
  • Pair addresses can be determined through the SDK as well.

allPairs

function allPairs(uint) external view returns (address pair);

Retrieves the address of the nth pair created by the factory, returning address(0) if the index exceeds the total pairs count.

  • Input 0 for the first pair's address, 1 for the second, and so forth.

allPairsLength

function allPairsLength() external view returns (uint);

Indicates the cumulative count of pairs generated by the factory.

feeTo

function feeTo() external view returns (address);

Refer to Protocol Charge Calculation for details.

feeToSetter

function feeToSetter() external view returns (address);

The authorized address to modify feeTo.

State-Changing Functions

createPair

function createPair(address tokenA, address tokenB) external returns (address pair);

Initiates a pair for tokenA and tokenB if it does not yet exist.

  • Both tokenA and tokenB are interchangeable.
  • Triggers a PairCreated event.

Interface

Incorporate the Uniswap V2 Factory interface as follows:

import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol';

Solidity interface definition:

pragma solidity >=0.5.0;

interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);

function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);

function feeTo() external view returns (address);
function feeToSetter() external view returns (address);

function createPair(address tokenA, address tokenB) external returns (address pair);
}

ABI

The ABI for the Uniswap V2 Factory can be included as follows:

import IUniswapV2Factory from '@uniswap/v2-core/build/IUniswapV2Factory.json'

Access the ABI directly at Uniswap V2 Core ABI.