> ## Documentation Index
> Fetch the complete documentation index at: https://docs.saucerswap.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a new pool (V1)

> Create new SaucerSwap V1 liquidity pools with addLiquidityETHNewPool and addLiquidityNewPool, including the pool creation fee and auto-association setup.

Create a new HBAR/token or token/token liquidity pool.

There are two methods to add a new liquidity pool:

* [Creating a new HBAR-token liquidity pool](#creating-a-new-hbar-token-liquidity-pool)

* [Creating a new token-token liquidity pool](#creating-a-new-token-token-liquidity-pool)

> [!NOTE]
>
> Contract ID: [SaucerSwapV1RouterV3](https://hashscan.io/mainnet/contract/0.0.3045981)

> [!TIP]
>
> See [Pool creation fee](https://docs.saucerswap.finance/developers/v1/liquidity/pool-creation-fee.md) to get the current pool creation fee.

> [!TIP]
>
> Ensure that the liquidity pool does not exist on-chain prior to creation of the new pool. See [Check for an existing pool](https://docs.saucerswap.finance/developers/v1/liquidity/check-if-a-pool-exists.md).

> [!NOTE]
>
> Increase the client's max token auto-association by one to receive the incoming LP token.

> [!NOTE]
>
> To add liquidity to an existing pool, see [Adding liquidity](https://docs.saucerswap.finance/developers/v1/liquidity/adding-liquidity.md).

> [!TIP]
>
> Both methods support HTS tokens with custom fees.

***

## Creating a new HBAR-token liquidity pool

Create a new HBAR/token liquidity pool and provide it with initial liquidity.

Function name: `addLiquidityETHNewPool`

Recommended gas limit: 3,200,000

| Parameter Name | Description |
| - | - |
| *address token* | EVM address of the token to pair with HBAR |
| *uint amountTokenDesired* | The maximum token amount in its smallest unit |
| *uint amountTokenMin* | The minimum token amount in its smallest unit |
| *uint amountETHMin* | The minimum HBAR amount in its smallest unit (tinybar) |
| *address to* | EVM address to receive the new liquidity tokens |
| *uint deadline* | Deadline in Unix seconds |

```solidity IUniswapV2Router01.sol theme={"dark"}
function addLiquidityETHNewPool(
  address token,
  uint amountTokenDesired,
  uint amountTokenMin,
  uint amountETHMin,
  address to,
  uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
```

```solidity UniswapV2Router02.sol theme={"dark"}
function addLiquidityETHNewPool(
  address token,
  uint amountTokenDesired,
  uint amountTokenMin,
  uint amountETHMin,
  address to,
  uint deadline
) external virtual payable override ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) {
  require (IUniswapV2Factory(factory).getPair(token, whbar) == address(0), "UniswapV2Router: POOL ALREADY EXISTS");
  uint256 feeInTinybars = tinycentsToTinybars(IUniswapV2Factory(factory).pairCreateFee());
  require(msg.value > feeInTinybars, 'UniswapV2Router: MSG.VALUE');
  IUniswapV2Factory(factory).createPair{value: feeInTinybars}(token, whbar);

  (amountToken, amountETH) = _addLiquidity(token, whbar, amountTokenDesired, msg.value - feeInTinybars, amountTokenMin, amountETHMin);
  address pair = UniswapV2Library.pairFor(factory, token, whbar);

  safeTransferToken(
    token, msg.sender, pair, amountToken
  );
  IWHBAR(WHBAR).deposit{value: amountETH}(msg.sender, pair);
  liquidity = IUniswapV2Pair(pair).mint(to);
  if (msg.value - feeInTinybars > amountETH) TransferHelper.safeTransferETH(msg.sender, msg.value - feeInTinybars - amountETH);
}
```

> [!NOTE]
>
> A spender allowance for the router is required for the HTS token.

> [!NOTE]
>
> The `addLiquidityETHNewPool` function operates in HBAR but derives its name from Uniswap on Ethereum. This name was kept to simplify integration for developers versed in Uniswap tools.

### Code overview

> [tab] JavaScript SDK
>
> Resources:
>
> * [SaucerSwap deployed contract IDs](https://docs.saucerswap.finance/developers/contracts.md)
> * [Hedera JavaScript SDK](https://github.com/hashgraph/hedera-sdk-js)
> * [Token approve allowance](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/approve-an-allowance)
> * [Token auto-association](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/update-an-account)
> * [Calling a smart contract function](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/call-a-smart-contract-function)
>
> ```typescript theme={"dark"}
> import {
>   ContractFunctionParameters,
>   ContractExecuteTransaction,
>   AccountAllowanceApproveTransaction,
>   AccountUpdateTransaction, //for token auto-association
> } from '@hashgraph/sdk';
>
> //Client pre-checks:
> // - Max auto-association increased by one
> // - Router contract has spender allowance for the input token
>
> const params = new ContractFunctionParameters();
> params.addAddress(tokenAddress); //address token
> params.addUint256(amountTokenDesired); //uint amountTokenDesired
> params.addUint256(amountTokenMin); //uint amountTokenMin
> params.addUint256(amountHBARMin); //uint amountETHMin
> params.addAddress(toAddress); //address to
> params.addUint256(deadline); //uint deadline
>
> const response = await new ContractExecuteTransaction()
>  .setPayableAmount(inputHbarAndPoolCreationFeeHbar) //input hbar + pool creation fee
>  .setContractId(routerContractId)
>  .setGas(gasLim)
>  .setFunction('addLiquidityETHNewPool', params)
>  .execute(client);
>
> const record = await response.getRecord(client);
> const result = record.contractFunctionResult!;
> const values = result.getResult(['uint','uint','uint']);
> const amountToken = values[0]; //uint amountToken
> const amountHBAR = values[1]; //uint amountETH
> const liquidity = values[2]; //uint liquidity
> ```

***

## Creating a new token-token liquidity pool

Create a new token/token liquidity pool and provide it with initial liquidity.

Function name: `addLiquidityNewPool`

Recommended gas limit: 3,200,000

| Parameter Name | Description |
| - | - |
| *address tokenA* | EVM address of the first HTS token |
| *address tokenB* | EVM address of the second HTS token |
| *uint amountADesired* | The maximum amount for the first token in its smallest unit |
| *uint amountBDesired* | The maximum amount for the second token in its smallest unit |
| *uint amountAMin* | The minimum amount for the first token in its smallest unit |
| *uint amountBMin* | The minimum amount for the second token in its smallest unit |
| *address to* | EVM address to receive the new liquidity tokens |
| *uint deadline* | Deadline in Unix seconds |

```solidity IUniswapV2Router01.sol theme={"dark"}
function addLiquidityNewPool(
  address tokenA,
  address tokenB,
  uint amountADesired,
  uint amountBDesired,
  uint amountAMin,
  uint amountBMin,
  address to,
  uint deadline
) external payable returns (uint amountA, uint amountB, uint liquidity);
```

```solidity UniswapV2Router02.sol theme={"dark"}
function addLiquidityNewPool(
  address tokenA,
  address tokenB,
  uint amountADesired,
  uint amountBDesired,
  uint amountAMin,
  uint amountBMin,
  address to,
  uint deadline
) external virtual payable override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {

  require (IUniswapV2Factory(factory).getPair(tokenA, tokenB) == address(0), "UniswapV2Router: POOL ALREADY EXISTS");
  address pair = IUniswapV2Factory(factory).createPair{value: msg.value}(tokenA, tokenB);

  (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);

  safeTransferToken(
    tokenA, msg.sender, pair, amountA
  );
  safeTransferToken(
    tokenB, msg.sender, pair, amountB
  );
  liquidity = IUniswapV2Pair(pair).mint(to);
}
```

> [!NOTE]
>
> A spender allowance for the router is required for both HTS tokens.

### Code overview

> [tab] JavaScript SDK
>
> Resources:
>
> * [SaucerSwap deployed contract IDs](https://docs.saucerswap.finance/developers/contracts.md)
> * [Hedera JavaScript SDK](https://github.com/hashgraph/hedera-sdk-js)
> * [Token approve allowance](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/approve-an-allowance)
> * [Token auto-association](https://docs.hedera.com/hedera/sdks-and-apis/sdks/cryptocurrency/update-an-account)
> * [Calling a smart contract function](https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/call-a-smart-contract-function)
>
> ```typescript theme={"dark"}
> import {
>   ContractFunctionParameters,
>   ContractExecuteTransaction,
>   AccountAllowanceApproveTransaction,
>   AccountUpdateTransaction, //for token auto-association
> } from '@hashgraph/sdk';
>
> //Client pre-checks:
> // - Max auto-association increased by one
> // - Router contract has spender allowance for the input tokens
>
> const params = new ContractFunctionParameters();
> params.addAddress(tokenAEvmAddress); //address tokenA
> params.addAddress(tokenBEvmAddress); //address tokenB
> params.addUint256(amountADesired); //uint amountADesired
> params.addUint256(amountBDesired); //uint amountBDesired
> params.addUint256(amountAMin); //uint amountAMin
> params.addUint256(amountBMin); //uint amountBMin
> params.addAddress(toEvmAddress); //address to
> params.addUint256(deadline); //uint deadline
>
> const response = await new ContractExecuteTransaction()
>  .setPayableAmount(poolCreationFeeHbar)
>  .setContractId(routerContractId)
>  .setGas(gasLim)
>  .setFunction('addLiquidityNewPool', params)
>  .execute(client);
>
> const record = await response.getRecord(client);
> const result = record.contractFunctionResult!;
> const values = result.getResult(['uint','uint','uint']);
> const amountA = values[0]; //uint amountA - in its smallest unit
> const amountB = values[1]; //uint amountB - in its smallest unit
> const liquidity = values[2]; //uint liquidity
> ```

## Next steps

> [card] [Pool creation fee (V1)](https://docs.saucerswap.finance/developers/v1/liquidity/pool-creation-fee.md)
>
> Fetch the current fee before creating a pool.

> [card] [Check if a pool exists (V1)](https://docs.saucerswap.finance/developers/v1/liquidity/check-if-a-pool-exists.md)
>
> Verify the pool is not already on-chain.

> [card] [Adding liquidity (V1)](https://docs.saucerswap.finance/developers/v1/liquidity/adding-liquidity.md)
>
> Add to the pool once it exists.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.