# PTokenFactory

## Introduction

The PTokenFactory contract is for creating new pools.

## Create pToken

Before creating a new pToken, the factory will check the conditions necessary to create a new pool, and if the asset meets all the conditions, the pToken will be create&#x64;**,** otherwise, the function will return an error.

#### PTokenFactory

```
function createPToken(address underlying_) external returns (uint)
```

* `underlying_`: The underlying asset address.
* `RETURN`: 0 on success, otherwise an Error code

#### **Solidity**

```
Erc20 underlying = Erc20(0xToken...);
PTokenFactory factory = PTokenFactory(0xABCD...);
require(factory.createPToken(address(underlying)) == 0, "something went wrong");
```

#### **Web3 1.0**

```
const underlying = "0xToken..."
const factory = PTokenFactory.at(0x3FDB...);
factory.methods.createPToken(underlying).send({from: ...});
```

## Checking asset liquidity

One of the main requirements for creating a new pToken is the availability of sufficient liquidity on Uniswap v2 or other DEX (clones Uniswap v2). This function checks liquidity and returns `true` if it is greater than or equal to the `minUniswapLiquidity` parameter.

#### PTokenFactory

```
function checkPair(address asset) public view returns (bool)
```

* asset: The underlying asset address.
* `RETURN`: true or false

#### **Solidity**

```
Erc20 underlying = Erc20(0xToken...);
PTokenFactory factory = PTokenFactory(0xABCD...);
require(factory.checkPair(address(underlying)) == 0, "not enough liquidity");
```

#### **Web3 1.0**

```
const underlying = "0xToken..."
const factory = PTokenFactory.at(0x3FDB...);
factory.methods.checkPair(underlying).call();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.defipie.com/ptokenfactory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
