> For the complete documentation index, see [llms.txt](https://zealous-swap.gitbook.io/zealous-swap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zealous-swap.gitbook.io/zealous-swap/developers/liquidity.md).

# Liquidity

## 💧 Providing Liquidity

Adding liquidity through a smart contract on Zealous Swap requires careful consideration of token ratios to avoid unnecessary loss due to arbitrage. This guide explains how to safely add liquidity using the router.

***

### 📘 Understanding Price Ratios

When liquidity is added at a price that doesn't match the current pool ratio, the difference is exploitable by arbitrageurs.

**Example:**\
If the KAS/USDT pool has a ratio of `10 KAS : 20 USDT` (i.e. price is 1 KAS = 2 USDT), and you provide liquidity at `10 KAS : 30 USDT`, you're effectively implying a different price (1 KAS = 3 USDT).\
The pool will accept your deposit, issue you fewer LP tokens (fair value at the *true* pool price), and the imbalance you introduced creates an opportunity for someone else to profit — at your expense.

To prevent this, always add liquidity based on the **current market price**, not arbitrary values.

***

### 🛠️ Using the Router

The Zealous Swap Router includes helper functions to simplify safe liquidity provisioning:

* `addLiquidity` — for token/token pairs (e.g. USDT/KAS) (KAS is treated as WKAS)
* `addLiquidityKAS` — for KAS/token pairs (KAS is treated as native)

Both methods require:

* A **desired amount** of each token (your target contribution)
* A **minimum amount** for each token (your slippage tolerance)
* Approval of tokens to the router
* Sufficient token/KAS balance in your contract

***

### 🧪 Example: Add Liquidity to a USDT/KAS Pool

Let’s say the KAS/USDT pool ratio is 1 KAS = 2 USDT, and you want to add liquidity accordingly.

```solidity
uint amountKASDesired = 1 ether;
uint amountUSDTDesired = 2 * 10 ** USDT.decimals();

// Set slippage tolerance (e.g., 1%)
uint amountKASMin = amountKASDesired * 99 / 100;
uint amountUSDTMin = amountUSDTDesired * 99 / 100;

// Transfer USDT to your contract
require(USDT.transferFrom(msg.sender, address(this), amountUSDTDesired), "USDT transfer failed");

// Approve the router to spend USDT
require(USDT.approve(address(ZealousSwapRouter), amountUSDTDesired), "Approval failed");

// Add liquidity (KAS sent as msg.value)
ZealousSwapRouter.addLiquidityKAS{ value: amountKASDesired }(
    address(USDT),
    amountUSDTDesired,
    amountUSDTMin,
    amountKASMin,
    msg.sender,
    block.timestamp
);
```

### 📌 Notes

* `amountKASDesired` and `amountUSDTDesired` reflect your price belief. You must calculate these off-chain before submitting the transaction.
* `amountKASMin` and `amountUSDTMin` are protection thresholds. If the pool's price shifts beyond your tolerance, the transaction reverts.
* Don't fetch pool prices on-chain during the same transaction — the reserves can be manipulated within a block.

***

### ✅ Best Practices

* Use a trusted external price feed to determine token ratios before submitting.
* Always pre-approve the exact token amount you intend to deposit.
* Avoid extremely tight slippage unless you're certain the transaction will confirm quickly.
* Monitor liquidity pool reserves and price volatility when deploying automated contracts.
