> For the complete documentation index, see [llms.txt](https://docs-new.klayswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-new.klayswap.com/developers/contract/factory.md).

# V2Factory

The Factory smart contract oversees the full functionality of token pair registration and transactions in KLAYswap. It is also a token contract for KLAYswap's KSP governance token that complies with the KIP7 standard, and a smart contract that implements all functions related to KSP mining.

## Code

Github Link: (Will be updated after official launch)

## Address

* Cypress : [0xb2ad0f20d54177916721c6b6466bce1eb1a56eef](https://klaytnscope.com/account/0xB2AD0f20D54177916721c6B6466bce1eB1a56eef?tabId=txList)

## Events, Read-Only Functions, and State-Changing Functions

{% tabs %}
{% tab title="Events" %}

## Events

**CreatePool**

```solidity
event CreatePool(
    address token0,
    uint256 amount0,
    address token1,
    uint256 amount1,
    uint256 fee,
    address exchange,
    uint256 exid
);
```

* Event to create new liquidity pool&#x20;
* parameters&#x20;
  * `token0` : token0 address in pair
  * `amount0` : token0 amount in pool
  * `token1` : token1 address in pair
  * `amount1` : token1 amount in pool&#x20;
  * `fee` : pool fee rate exchange :&#x20;
  * `exchange` : contract address of this pool&#x20;
  * `exid` : exchange id

{% endtab %}

{% tab title="Read-Only Functions" %}

## Read-Only Functions

#### owner

* Governance Contract Address

#### pools

* List of liquidity pool pairings&#x20;
* Each item saves the smart contract address of the liquidity pool

#### poolExist

* Returns if the contract for the given liquidiy pool pair exists

#### tokenToPool

* When the addresses of tokenA and tokenB are inputted, this returns the contract address of the corresponding pairing
* Returns the  same contract address regardless of the order of the liquidity pool pairing tokens:

  tokenToPool\[tokenA]\[tokenB] == tokenToPool\[tokenB]\[tokenA]

#### createFee

* The amount of KSP that must be paired to create a new liquidity pool pair
* deprecated

#### getPoolCount

```solidity
function getPoolCount() public view returns (uint)
```

* Returns the current number of registered liquidity pools.&#x20;

#### getPoolAddress

```solidity
function getPoolAddress(uint idx) public view returns (address)
```

* Returns the liquidity pair contract address of the pair's index.
  {% endtab %}

{% tab title="State-Changing Functions" %}

## State-Changing Functions

#### createKlayPool

```solidity
function createETHPool(address token, uint256 amount, uint256 fee) public payable
```

* A method called to add a liquidity pair with one side as KLAY
* Token for when the KLAY-KIP7 pair to be registered has never been registered before
* Parameters
  * `token` : KIP7 token address to add liquidity
  * `amount` : the amount of tokens (KIP7) to be provided for the initial liquidity
  * `fee` : Sets the initial fee value for liquidity pairs
    * A value between 30 and 100
    * Meaning: 30 -> 0.3%, 100 -> 1%
  * `msg.value` : KLAY quantity to initially supply liquidity&#x20;
    * Delivers the transaction value without specifying otherwise

#### createTokenPool

```solidity
function createTokenPool(address token0, uint256 amount0, address token1, uint256 amount1, uint256 fee) public
```

* A method called to add a liquidity pair with both ERC20&#x20;
* Token for when the ERC20-ERC20 pair to be registered has never been registered before
* parameter
  * `token0` : The address of the first token
  * `amount0` : The quantity of the first token that supplies the initial liquidity
  * `token1` : The address of the second token
  * `amount1` : The quantity of the second token that supplies the initial liquidity
  * `fee` : Sets the initial fee value for liquidity pairs
    {% endtab %}
    {% endtabs %}
