PancakeSwap has extended its powerful decentralized exchange (DEX) infrastructure to the Aptos blockchain with Router v2, a smart contract designed to streamline token swaps, liquidity provision, and multi-hop trading. Built on the Move programming language, this version delivers enhanced efficiency and flexibility for developers and users interacting with decentralized finance (DeFi) protocols on Aptos.
This comprehensive guide breaks down the core functionalities of the pancake::router contract, explains key parameters, and demonstrates how developers can leverage its entry and public functions for seamless DeFi interactions.
Contract Overview
The PancakeSwap Router v2 contract serves as the central interface for managing liquidity pools and executing token swaps across the Aptos network. It enables users to create trading pairs, add or remove liquidity, and perform both direct and multi-hop swaps with precision.
Core Contract Details
- Contract Name:
pancake::router - Contract Address:
c7efb4076dbe143cbcd98cfaaa929ecfc8f299203dfff63b95ccb6bfe19850fa::router - Admin Multisig Address:
b11ccaed0056a75472539c2b0d9511c82fc6a36622bec7578216af5fe550dd0d
Developers can inspect the full module on Aptos Explorer, though all external links have been removed per guidelines.
👉 Discover how to interact with DeFi protocols efficiently using advanced tools.
Key Function Types
The router supports two primary categories of functions: entry functions, which are called directly via transactions, and public functions, which can be used internally or by other smart contracts.
Each function is designed with slippage control, security, and gas efficiency in mind—critical factors in decentralized trading environments.
Entry Functions: User-Facing Operations
These functions are invoked through wallet-signed transactions and form the backbone of user interaction with PancakeSwap on Aptos.
Create Pair
Initiates a new liquidity pool for a token pair.
public entry fun create_pair(sender: &signer)- Purpose: Deploy a new trading pair if it doesn’t already exist.
- Parameters: Requires only the transaction sender’s signer reference.
Note: This function assumes both token types are valid and not already paired.
Add Liquidity
Contribute assets to an existing pool to earn trading fees.
public entry fun add_liquidity(
sender: &signer,
amount_x_desired: u64,
amount_y_desired: u64,
amount_x_min: u64,
amount_y_min: u64
)amount_x_desired,amount_y_desired: Target amounts of each token to deposit.amount_x_min,amount_y_min: Slippage thresholds—transaction reverts if market conditions change unfavorably.
This ensures protection against front-running and volatility during execution.
Remove Liquidity
Withdraw your share of pooled tokens.
public entry fun remove_liquidity(
sender: &signer,
liquidity: u64,
amount_x_min: u64,
amount_y_min: u64
)liquidity: Amount of LP (Liquidity Provider) tokens to burn.- Minimum output values prevent loss due to impermanent loss or sudden price shifts.
Swap Exact Input
Swap a fixed amount of input token for a variable output.
public entry fun swap_exact_input(
sender: &signer,
x_in: u64,
y_min_out: u64
)Useful when you know exactly how much you want to spend and need assurance on minimum output.
👉 Learn how to optimize your swap strategies with real-time market insights.
Swap Exact Output
Receive a precise amount of output token by spending up to a maximum input.
public entry fun swap_exact_output(
sender: &signer,
y_out: u64,
x_max_in: u64
)Ideal for price-sensitive operations like stablecoin exchanges or yield farming deposits.
Multi-Hop Swaps: Extending Trade Reach
When direct pairs don’t exist, PancakeSwap Router v2 enables cross-pool trades through intermediate tokens.
Double Hop Swaps
Trade from token X → Z via an intermediate Y (e.g., X → Y → Z).
swap_exact_input_doublehop(sender: &signer, x_in: u64, z_min_out: u64)Supports both exact input and exact output variants.
Triple & Quadruple Hop Swaps
Extend the path across three or four pools:
- Triple Hop: X → Y → Z → A
- Quadruple Hop: X → Y → Z → A → B
These enable highly flexible routing across fragmented liquidity while maintaining slippage controls.
While more hops increase routing possibilities, they also raise gas costs and execution risk—optimize paths carefully.
Public Functions: Programmatic Access
These functions are callable by other contracts or off-chain tools for deeper integration.
Swap Exact X to Y (Direct)
public fun swap_exact_x_to_y_direct_external(x_in: coin::Coin): coin::Coin- Input: Coin resource of token X.
- Output: Received coin resource of token Y.
- Best suited for embedded DeFi applications like aggregators or vaults.
Swap X to Exact Y
public fun swap_x_to_exact_y_direct_external(x_in: coin::Coin, y_out_amount: u64): (coin::Coin, coin::Coin)Returns both spent and received coins, useful for auditing and accounting in smart contract logic.
Get Amount In
Calculates required input for a desired output.
public fun get_amount_in(y_out_amount: u64): u64Helps estimate trade impact before execution—critical for building intuitive frontends or risk engines.
Core Keywords for SEO Optimization
To align with search intent and improve discoverability, these keywords are naturally integrated throughout:
- PancakeSwap Router v2
- Aptos DEX
- Token swap on Aptos
- Add liquidity Aptos
- Multi-hop swap
- Move language smart contract
- Decentralized exchange functions
- Liquidity pool creation
These terms reflect common queries from developers and traders exploring DeFi development on the Aptos blockchain.
Frequently Asked Questions (FAQ)
Q: What is PancakeSwap Router v2 used for?
A: It's a smart contract that facilitates token swaps, liquidity management, and multi-hop trading on the Aptos blockchain. Developers and users interact with it to create pairs, add liquidity, and execute efficient trades.
Q: Can I use Router v2 without writing code?
A: Yes—wallet interfaces and DeFi dashboards abstract these functions into simple buttons. However, understanding the underlying mechanics helps in optimizing trades and avoiding errors like slippage losses.
Q: How does multi-hop swapping work?
A: It routes your trade through multiple pools (e.g., WAPT → USDT → BTC) when no direct pair exists. The router automatically calculates the best path based on available liquidity and fees.
Q: Is there a fee for using the router?
A: There’s no direct fee from PancakeSwap for using the router, but each swap incurs a small protocol fee (typically 0.25%) distributed to liquidity providers. Gas fees also apply per transaction.
Q: How do I protect against slippage?
A: Always set conservative values for min_out or max_in parameters. Most wallets suggest default slippage (e.g., 0.5%-1%), but volatile markets may require adjustments.
Q: Where can I test these functions?
A: Use the Aptos Testnet with faucet-funded tokens. Deploy test pairs, simulate swaps, and debug logic before going live on mainnet.
👉 Access developer resources and testnet tools to start building today.
By combining robust functionality with developer-friendly design, PancakeSwap Router v2 empowers the next generation of DeFi applications on Aptos. Whether you're building a trading bot, yield optimizer, or wallet integration, mastering these functions is essential for success in the growing Aptos ecosystem.