BlockchainAppMaker Get a quote

DeFi

PancakeSwap Clone Script Guide: What to Copy, What to Change, What to Avoid

A PancakeSwap clone script is a packaged copy of PancakeSwap's swap, liquidity pool and farm contracts with a branded front end, ready to deploy on BNB Smart Chain or another EVM chain. This guide explains what such a script contains, which PancakeSwap version it copies, where clones fail and how to check a script before you deploy it.

Forking the contracts is the easy part. The harder parts are attracting liquidity, designing incentives that last and changing the code without opening a security hole.

Where PancakeSwap's code comes from

PancakeSwap launched in 2020 as a fork of Uniswap v2 on Binance Smart Chain, which is now called BNB Smart Chain. It added the CAKE token and MasterChef farms copied from SushiSwap, and later concentrated-liquidity pools based on Uniswap v3.

PancakeSwap's newest architecture, Infinity, follows a design similar to Uniswap v4. The Infinity documentation lists these features:

  • All pools live in one PoolManager contract, so creating a pool is a state update rather than a new contract.
  • Hook contracts can change swap parameters, fees and pricing curves.
  • Flash accounting tracks net balances during a transaction and settles once at the end.
  • Pools can hold native BNB without wrapping it.

PancakeSwap's documentation now lists eleven chains, including BNB Chain, Ethereum, Base, Arbitrum, Solana and Aptos. Its site also runs perpetuals, a lottery and price-prediction games.

What a PancakeSwap clone script contains

ComponentOriginJob
Factory and pair contracts (v2)Uniswap v2 forkCreate constant-product pools and mint LP tokens
RouterUniswap v2 forkRuns multi-hop swaps and adds or removes liquidity, with slippage and deadline checks
Concentrated-liquidity pools (v3)Uniswap v3 forkLet LPs provide liquidity in a price range. Each position is an NFT.
MasterChef farmsSushiSwap patternPay the native token to users who stake LP tokens. Each pool's allocation points set its share of the rewards.
Native tokenCustomFunds farm rewards and can carry governance or fee sharing
Front end and routingPancakeSwap's open-source interface or custom codeConnects wallets, finds the best route and shows charts

A first version needs v2 or v3 pools, a router and a modest incentive program, and perpetuals, lotteries and Infinity-style hooks are not required at launch.

Any wallet that supports the standard EVM provider interface or WalletConnect works with the front end, which covers MetaMask, Trust Wallet, Binance Wallet, SafePal, TokenPocket and most others without code for each wallet.

v2, v3 or Infinity pools

DesignHow liquidity worksStrengthsCosts
v2 (constant product)Liquidity covers all pricesSimple math that is easy to audit. LP tokens are ERC-20s that farms can stake directly.Poor capital efficiency for stable pairs
v3 (concentrated liquidity)LPs choose a price rangeMuch deeper liquidity near the current price for the same capitalPositions are NFTs, so farms need a different staking contract. LPs must manage ranges. The price-range math, based on units called ticks, is hard to change safely.
Infinity (singleton with hooks)One PoolManager with several pool types and optional hooksCheap pool creation, cheaper multi-hop swaps and custom pool logicNewest and most complex code. Each hook needs its own audit.

A team that changes v3 or Infinity internals, rather than deploying them unchanged, needs a full audit of those changes.

Licenses: what you may deploy

Each repository has its own license, so check every contract you copy:

  • Uniswap v2 contracts use the GPL-3.0 license.
  • Uniswap v3 core used the Business Source License 1.1 until April 2023 and then converted to GPL-2.0-or-later.
  • PancakeSwap's v3 pool contracts carry a GPL-2.0-or-later header, and the Infinity core repository lists GPL-2.0.
  • Uniswap v4 core mixes BUSL-1.1 and MIT files, so an Infinity-style design copied from Uniswap v4 needs a license check per file.

GPL code can be forked, but derivative code must keep the same license when you distribute it. A lawyer should confirm what you may deploy and what you must publish.

The farm contract is where clones go wrong

The MasterChef pattern tracks an accumulated reward per share for each pool. When a staker deposits, withdraws or claims, the contract multiplies the staker's LP amount by the growth in the pool's reward per share since that staker's last action, and pays the result. Forks have added dangerous changes to this contract many times:

  • Migrator functions: the original SushiSwap MasterChef let the owner move all staked LP tokens to a new contract. With a single-key owner, that function lets the owner take every user's funds. Remove it or put it behind a long timelock.
  • Unbounded minting: a farm that can mint the reward token without a cap lets a stolen owner key inflate the supply. Fix emissions in code and cap the total supply.
  • Allocation changes without updates: the contract must settle each pool's rewards at the old allocation points before the points change, or it pays the wrong rewards.
  • Fee-on-transfer and rebasing tokens: a token that charges a transfer fee, or a rebasing token whose balances change by themselves, breaks the farm's balance accounting. Measure balances before and after each transfer, or reject such tokens.

PancakeSwap itself changed its incentive model in 2025. Under Tokenomics 3.0, it retired two systems on April 23, 2025: veCAKE, which gave voting power for locked CAKE, and gauge voting, which let veCAKE holders direct farm rewards. PancakeSwap also moved the 5% of trading fees that went to veCAKE holders into its program that buys and destroys CAKE, according to its veCAKE sunset page. The DeFi yield farming guide covers emission design in depth.

How to check a PancakeSwap clone script before you buy

Vendors often sell clone scripts without a public audit of their changes. Run these checks before you deploy one:

  1. Diff against the source: compare every contract with the original PancakeSwap or Uniswap repository. Each changed line needs an explanation and a review.
  2. List every owner function: look for migrators, uncapped mint functions, fee-recipient changes, pause functions and upgradeable proxies.
  3. Check the router for hidden fees: some scripts add a fee transfer to a vendor address inside the swap path.
  4. Check key custody: owner and admin roles go to your multisig at deployment, never to the vendor.
  5. Ask for the audit: an audit of the original protocol does not cover the vendor's changes, which need their own audit.
  6. Check the front end: the interface must load from your own hosting, with no vendor scripts that can change transactions.

Liquidity decides whether a clone works

A new DEX with shallow pools quotes worse prices than PancakeSwap, so aggregators route no trades to it and traders do not come. These strategies address that problem:

  1. Pick a niche the large DEXs serve poorly: a newer chain, one token ecosystem, or a pair type such as stablecoins or liquid-staking tokens.
  2. Seed the main pools with treasury or partner liquidity instead of relying on emissions alone.
  3. List the pools on DEX aggregators, so routed volume arrives once your prices compete.
  4. Share real fee revenue with LPs and token holders instead of high APYs paid in new tokens.

Cost, timeline and risk

These figures are estimates based on the scope described, not quotes. An unchanged v2 fork with a branded front end and a standard farm takes one or two Solidity engineers and one front-end engineer four to eight weeks, plus an audit of any changed code. Changes to v3 math, custom pool types, hooks or deployment on several chains extend the work to several months.

A DEX token whose only use is farming often follows this sequence: high APY, inflows, selling from emissions, a falling price and outflows. Plan the token's role and the emission schedule before writing code.

The decentralized exchange development guide covers DEX design from first principles, without copying one product. The Uniswap clone guide covers the Ethereum original, and the BNB Smart Chain overview covers chain details.

Frequently asked questions

What is a PancakeSwap clone script?

A PancakeSwap clone script is a copy of PancakeSwap's open-source contracts and interface, rebranded and set up for a new DEX. It usually includes v2 or v3 pools, a router, MasterChef farms and a token.

Is it legal to fork PancakeSwap?

PancakeSwap's v3 pools and Infinity core carry GPL licenses, which allow forks under the same license. Some code copied from Uniswap v4 uses the Business Source License. Check each file's license and have counsel confirm before deployment.

Does a PancakeSwap clone have to run on BNB Smart Chain?

No. The contracts are standard EVM Solidity and deploy to any EVM chain. Teams usually choose the chain where their users and liquidity already are.

How much does a PancakeSwap clone cost?

Cost follows engineering time and audit fees. An unchanged fork with a custom front end takes a small team four to eight weeks, plus audit fees for any changed code. Custom pool math, perpetuals or deployment on several chains raise the cost quickly.

Do I need my own token?

No. A DEX can charge swap fees and pay LPs without a native token. A token adds incentive and governance tools, but it also brings regulatory questions and selling pressure from emissions.