Book a free call

How to Implement a Liquidity Pool Step by Step

A liquidity pool is a smart contract holding two tokens so traders can swap without a counterparty. To build one, pick a design, set the first price and deploy.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Implement a Liquidity Pool Step by Step
On this page

Short answer

A liquidity pool is a smart contract that holds reserves of two tokens and lets anyone swap one for the other at a price set by the ratio of the reserves. To implement one, you choose a pool design, seed it with both tokens at your chosen starting price, deploy the contract, and add the safety checks that protect depositors.

What is a liquidity pool?

A liquidity pool is a smart contract that holds two tokens and lets traders swap between them without waiting for another trader. Instead of matching buyers and sellers, the contract uses a formula: the price of each token depends on how much of it the pool holds. When someone buys a token from the pool, that token becomes scarcer in the pool, so its price rises.

People who deposit tokens into the pool are called liquidity providers. In return they receive LP tokens, which represent their share of the pool. When traders pay swap fees, those fees are added to the pool, so each LP token slowly becomes worth more. Providers can burn their LP tokens later to withdraw their share.

Pools are the core of decentralised exchanges. Without them, a new token would have no market at all, because there would be nobody willing to trade it. A liquidity pool is therefore often the first piece of infrastructure a token project needs.

Which pool design fits your token?

The pool design decides how the price moves and how much capital sits idle. The oldest design, the constant product pool, keeps the product of the two reserves fixed and works for any pair, but it spreads capital across every possible price, including prices the token will never reach.

Stablecoin pairs usually use a different design that keeps prices near one-to-one and wastes less capital on tiny price moves. Concentrated liquidity pools let providers pick a price range, which earns more fees per token deposited but requires active management when the price leaves that range.

Design Best for Capital use Management
Constant product New or volatile pairs Spread across all prices Set and forget
Stable swap Stablecoin pairs Tight around 1:1 Set and forget
Concentrated liquidity Established pairs Focused on a range Active rebalancing
Weighted pool Unequal value pairs Custom ratio Occasional review

For a first pool, the constant product design is usually the right choice. It needs no active management, it is the most tested design, and it works even when the token has no trading history. Move to a concentrated design only once the token has steady volume and someone is assigned to manage the range.

How do you set the first price?

The first price is set by the ratio of the two tokens you deposit when you create the pool. If you deposit 10,000 of your token and 5,000 of a stablecoin, the starting price is $0.50 per token. That ratio is your decision, and it should match the price the token already trades at elsewhere, or the price your launch plan promises.

Setting the first price wrong is expensive. If you price the token far below its real value, traders will buy it from the pool immediately and drain the cheaper side. If you price it far above, nobody will buy, and the pool will sit empty. Check the price on other venues first, and seed the pool with enough of both tokens that a single trade cannot move the price by a large amount.

Most teams seed with a stablecoin as the second token, because it gives traders a clear dollar price. Seeding with a volatile token as the pair makes the price harder to read and harder to defend. Keep the initial deposit large enough that the pool can absorb the first day of trading without wild swings.

How do you build and deploy the pool?

You build and deploy a pool by writing or reusing a tested contract, checking it, and then launching it in stages. Reusing a well-audited contract from an established exchange is safer than writing one from scratch, because the edge cases have already been found by other teams.

  1. Pick the design and the chain. Choose the pool design from the table above and the chain where your users already hold wallets.
  2. Deploy the factory and pair contracts. Use the established exchange's contracts, or fork them with no changes to the pricing logic.
  3. Seed the pool. Deposit both tokens at your chosen starting ratio, and keep a record of the exact amounts and the resulting price.
  4. Set the fee tier. A common starting point is 0.3% per swap for a volatile pair and 0.05% for a stable pair.
  5. Test on a testnet. Run swaps, deposits and withdrawals with small amounts and check that LP tokens and fee balances match your expectations.
  6. Get an audit. Have an independent auditor review any code you changed, and fix every finding before launch.
  7. Launch with limits. Start with a deposit cap and a monitoring alert, then raise the cap once the first week of trading looks normal.

Do not skip the testnet step. A pool contract handles real money, and a bug in the pricing logic can drain it in a single trade. A liquidity pool cost breakdown helps you budget the audit, deployment and seeding alongside the build.

How do fees and rewards work?

Every swap in the pool pays a fee, usually a percentage of the trade, which is added to the pool's reserves. Liquidity providers earn their share of those fees in proportion to their LP tokens. If you hold 10% of the LP tokens, you earn 10% of the fees collected while you hold them.

Some pools add extra rewards, such as distributing a project token to providers. Rewards can attract deposits quickly, but they also attract providers who leave as soon as the rewards stop. Fees from real trading volume are the durable income; rewards are a launch tool, not a business model.

Providers also face impermanent loss: if the price of one token moves a long way from the starting ratio, withdrawing can return less value than simply holding both tokens. This is not a bug; it is the cost of providing the service. Explain it to providers before they deposit, and show the calculation, so nobody is surprised.

Example: a token project launches its first pool

Example (hypothetical): a project launches a token and seeds a constant product pool with 100,000 tokens and 50,000 stablecoins, setting the starting price at $0.50 per token. The fee is 0.3% per swap.

In the first week, traders swap $200,000 of volume through the pool. Fees of 0.3% on that volume come to $600, which is added to the pool's reserves. The project's own deposit is 60% of the pool, so it earns about $360 of those fees, and outside providers share the remaining $240 in proportion to their deposits.

One large trade of $10,000 moves the price noticeably, because the pool is still small. The team decides to double the seed to 200,000 tokens and 100,000 stablecoins, which halves the price impact of the same trade. The lesson is that pool depth, not the fee tier, is what makes a pool usable for larger traders.

What are the common mistakes?

The most common mistakes are pricing the pool badly, skipping the audit, and promising returns that the fees cannot support.

  • Seeding at the wrong price. A starting ratio that ignores the market price invites arbitrage traders to drain one side on day one.
  • Seeding too thin. A small pool swings wildly on normal trades, which scares away the traders it was built for.
  • Skipping the audit. A pool contract holds real funds. Any changed code should be reviewed by an independent auditor before launch.
  • Promising fixed returns. Fee income depends on trading volume, which you cannot guarantee. Never quote a return figure to providers.
  • No monitoring. Without alerts for large swaps, price moves and withdrawals, a problem can run for hours before anyone notices.
  • Forgetting the exit. Providers need a clear way to withdraw. Test the full withdrawal path on testnet before launch.

Liquidity matters for every exchange, centralised or not, and the same depth and price-impact logic applies.

If you are building the exchange around the pool, DEX development covers the full setup.

Key takeaways

  • A liquidity pool is a smart contract holding two tokens, priced by the ratio of its reserves
  • The pool design decides how capital is used and how much management it needs
  • The first price is set by your seed ratio, so it must match the market price
  • Fees go to liquidity providers in proportion to their LP tokens
  • Pool depth, not the fee tier, decides how much a large trade moves the price

Frequently asked questions

Do I need my own contract to launch a pool?

Usually not. Established exchanges provide factory contracts you can deploy unchanged, which is safer than writing pricing logic from scratch. You only need custom code if your pool has features the standard design does not offer.

How much money do I need to seed a pool?

Enough that a normal trade moves the price by only a small amount. A pool seeded with a few thousand dollars will swing wildly on a single trade, while a deeper pool absorbs the same trade with barely a move.

What are LP tokens?

LP tokens are receipts for your deposit. They represent your share of the pool, including accumulated fees. Burning them returns your share of both tokens at the current ratio when you withdraw.

What is impermanent loss?

It is the difference between holding two tokens and depositing them in a pool, when the price ratio moves. If the ratio moves far, withdrawing can return less value than holding. Fees can offset it, but they are not guaranteed.

Can a pool run out of one token?

In a constant product pool, no. As one token gets scarcer its price rises, which makes buying more of it expensive. The pool approaches zero of a token but never quite reaches it.

Do pools work for stablecoins?

Yes, and stablecoin pairs usually use a dedicated design that keeps the price near one-to-one. A constant product pool wastes capital on stable pairs because it spreads funds across prices that never occur.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a token launch and need a pool traders can rely on? Talk to Hertiv.

A senior engineer replies within one business day. Or see our DEX Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call