PancakeSwap
Launch App
English
English
  • Welcome to PancakeSwap
    • Product Overview
    • ✨How-to Guides
      • Get Started (BSC)
        • Create a Wallet
        • Get BEP20 Tokens
        • Using PancakeSwap without Centralized Exchanges
        • Connect Your Wallet to PancakeSwap
      • Get Started (Aptos)
        • Create a Wallet
        • Get Aptos Coins
        • CAKE Bridging Guide
        • Connect Your Wallet to PancakeSwap
        • Aptos FAQ
      • V3/V2 Migration
        • How to migrate
        • How v3 APR is calculated
        • FAQ
        • V2 Migration
          • Migrate Your Stakings
          • MasterChef v2
            • List of Farms
          • CAKE Syrup Pool
    • 🗺️Roadmap
    • veCAKE Sunset
      • Staked Cake Redemption
      • 🔷[Archive] veCAKE
        • What is veCAKE?
        • How to get veCAKE?
        • Migrate from CAKE Pool
        • veCAKE Managers
        • Bridge your veCAKE
        • Earn CAKE Weekly
          • FAQ
    • 📈Analytics (Info Page)
    • ✅Audits
    • 🤙Contact Us
      • Social Accounts
      • Telegram & Discord Communities
      • 💼Business Partnerships
        • ⛽veCAKE / Gauges
        • 🧑‍🌾Initial Farm Offerings - IFOs
        • 🥞Syrup Pools and Farms
        • 🖼️NFT Marketplace
        • ❓Commonly Asked Business Partnerships Questions
      • Ambassador Program
        • What can you do as an Ambassador?
        • Benefits of a PancakeSwap Ambassador
        • Want to be an Ambassador?
        • ❓ FAQs Page
      • General FAQ
        • I need help
        • Troubleshooting Errors
        • What is an Approval Transaction?
        • Fixing Stuck Pending Transactions on MetaMask
    • 👨‍👨‍👦About Us
      • Team
        • The Kitchen Team
        • Become a Chef
          • Brand / Graphics Designer
          • Motion / Interaction Designer
          • Social Media & Content Manager
          • Developer Relations Manager
          • Product Designer (UX/I)
          • Business Development Manager
          • Senior Backend Engineer
      • Brand & Logos
  • 👴Archive
    • 📂Legacy Products
      • 🖼️[Archived] NFT Marketplace
      • 🎮[Archived] Gaming Platform
        • 📒Brand Kit
        • 🎓Pancake Mayor
        • 🛡️Pancake Protectors
          • FAQ
      • 🍯[Archived] Pottery
        • How to Play Pottery
        • Pottery FAQ
      • 🧈[Archived] Trading Reward
        • How to Participate
          • Top Traders Campaign
          • CAKE Stakers Campaign
        • FAQ
      • 🤝[Archived] Simple Staking
        • How to start Simple Staking
        • FAQ
        • Terms & Conditions
      • 🎯[Archived] PancakeSwap Quest
        • Getting Started
        • How to Join and Complete a Quest
        • Rewards
      • 💧[Archived] Liquid Staking Integration
        • How To Liquid Stake
        • WBETH
          • WBETH FAQ
        • SnBNB
          • SnBNB FAQ
      • 💸[Archived] Options
        • Options Primer
        • CLAMM Options
        • Options FAQ
      • [Archived] CAKE Syrup Pool
        • How to use the Flexible Staking option
        • How to use the Fixed-Term Staking option
    • Old Tokenomics
      • CAKE Tokenomics v1
      • Controlling CAKE supply v1
    • How to Use Farms with BscScan
    • [Archived] Affiliate Program
      • Dashboard & Link
      • Commission Structure and Payment
      • Program Rules & Guidelines
      • Terms & Conditions
  • Trade
    • 🔄Swap
      • Token Swaps
      • How to Trade
      • Fees and Routes
      • Market Maker Integration
      • Smart Router (V2)
        • How to trade using Smart Router
    • ♾️PancakeSwap Infinity
      • Key Features
      • Hooks
        • Dynamic Fee Hook
      • Pool Types
      • Farms
    • 🎯Limit Orders and Twap
      • How to use Limit Orders
      • How to use TWAP
    • 📈Perpetual Trading
      • What is Perpetual Trading?
      • Perpetual Trading V2
        • How can I use it?
        • Dumb Mode
          • Dumb Mode Guide
        • Degen Mode
          • Degen Mode Dynamic Fee
        • MADBTCUSD
          • MADBTCUSD FAQ
        • Perpetuals V2 Glossary
        • Forex
        • Perpetual Trading FAQ
          • Arbitrum
            • ALP Syrup Pool (Arbitrum)
              • ALP Buying & Selling Fees
        • Trading Rewards Program
          • Arbitrum
        • Supported Chains, Modes & Markets
      • Perpetual Trading V1
        • Perpetuals V1 Glossary
        • How can I use it?
        • V1 Perpetual Trading FAQ
    • 🏦Stableswap
      • How to StableSwap
    • 💳Buy Crypto
    • ❓Trading FAQ
      • Swap FAQ
      • v4 FAQ
      • Limit Orders and TWAP FAQ
  • Trading Tools
    • 🛡️PancakeSwap MEV Guard
    • PancakeSwap Auto Slippage
      • How to Set Slippage on PancakeSwap
    • 🔔Notifications
    • ❓Trading Tools FAQ
      • MEV Guard FAQ
  • Bridge
    • 🌉Bridging
      • Between EVMs
      • Between EVM and Aptos
      • Wormhole Bridge Guide
    • ❓Bridging FAQ
      • Wormhole Bridge FAQ
  • Earn
    • 🌊Liquidity Pools
      • How to Add/Remove Liquidity
      • ⛏️Pancake Picks
      • Zap
        • Zap (V2)
    • 🚜Yield Farming
      • How to Use Farms
        • How to Use Farms (Legacy)
      • APR/ROI/IL Calculator
      • Farming on Aptos
        • FAQ
      • Crosschain Farming
        • FAQ
    • 🥩Cake Staking
      • 🍯Syrup Pools - Stake CAKE
        • Syrup Pools
    • 🛍️IFO (Initial Farm Offering)
      • How to Participate in an IFO
      • How to Participate in CrossChain IFOs
      • FAQ
      • NFT Profile System
        • How to Set Up an NFT Profile
        • Teams
      • Contract Details
    • ❓Earn FAQ
      • Cake Staking FAQ
        • Syrup Pool FAQ & Troubleshooting
  • Play
    • 🔮Prediction
      • How to Use Prediction
      • AI Prediction
      • Prediction FAQ
      • Prediction Troubleshooting
      • Prediction Mini App
    • 🎟️Lottery
      • How to Play Lottery
      • Lottery FAQ
  • ❓Play FAQ
  • Protocol
    • 🍰CAKE Tokenomics
    • 📔Governance
      • How to Vote
        • How to Vote with SafePal Wallet
    • 💻Developers
      • Developer Docs
      • Contributing
        • Codebase Overview
Powered by GitBook
On this page
  • Contract info
  • Types
  • Entry Functions
  • Create Pair
  • Add Liquidity
  • Remove Liquidity
  • Swap Exact Input
  • Swap Exact Output
  • Swap Exact Input Double Hop
  • Swap Exact Output Double Hop
  • Swap Exact Input Triple Hop
  • Swap Exact Output Triple Hop
  • Swap Exact Input Quadruple Hop
  • Swap Exact Output Quadruple Hop
  • Public Functions
  • Get Amount In

Was this helpful?

  1. To Delete
  2. Smart Contracts (Aptos)
  3. PancakeSwap Exchange
  4. v2

Router v2

Last updated 2 years ago

Was this helpful?

Contract info

Contract name: pancake::router Contract address: c7efb4076dbe143cbcd98cfaaa929ecfc8f299203dfff63b95ccb6bfe19850fa::router

Admin Multi Sig: b11ccaed0056a75472539c2b0d9511c82fc6a36622bec7578216af5fe550dd0d

Types

Name
Type
Description

X

type address

The coin type address of token X in the pair.

Y

type address

The coin type address of token Y in the pair.

Entry Functions

Create Pair

Create the pool pair for swap.

public entry fun create_pair<X, Y>(sender: &signer)

Params

Name
Type
Descripton

sender

signer

The sender's signer when calling the function.

Add Liquidity

Add liquidity to the pool.

public entry fun add_liquidity<X, Y>(
    sender: &signer,
    amount_x_desired: u64,
    amount_y_desired: u64,
    amount_x_min: u64,
    amount_y_min: u64,
)

Params

Name
Type
Description

sender

signer

The sender's signer when calling the function.

amount_x_desired

u64

The amount of tokenX you'd like to provide as liquidity.

amount_y_desired

u64

The amount of tokenY you'd like to provide as liquidity.

amount_x_min

u64

The minimum amount of tokenX to provide (slippage impact).

amount_y_min

u64

The minimum amount of tokenY to provide (slippage impact).

Remove Liquidity

Remove liquidity from the pool.

public entry fun remove_liquidity<X, Y>(
    sender: &signer,
    liquidity: u64,
    amount_x_min: u64,
    amount_y_min: u64
)

Params

Name
Type
Description

sender

signer

The sender's signer when calling the function.

liquidity

u64

The amount of LP Tokens to remove.

amount_x_min

u64

The minimum amount of tokenX to remove (slippage impact).

amount_y_min

u64

The minimum amount of tokenY to remove (slippage impact).

Swap Exact Input

Swap exact amount of tokenX to tokenY.

public entry fun swap_exact_input<X, Y>(
    sender: &signer,
    x_in: u64,
    y_min_out: u64,
)

Params

Name
Type
Description

sender

signer

The sender's signer when calling the function.

x_in

u64

Payable amount of input tokenX.

y_min_out

u64

The minimum amount tokenY to receive.

Swap Exact Output

Swap tokenX to exact amount of tokenY.

public entry fun swap_exact_output<X, Y>(
    sender: &signer,
    y_out: u64,
    x_max_in: u64,
)

Params

Name
Type
Description

sender

signer

The sender's signer when calling the function.

y_out

u64

Payable amount of output tokenY.

x_max_in

u64

The maximum amount tokenX to input.

Swap Exact Input Double Hop

Swap exact amount of tokenX to tokenZ using 2 pools (Pool XY and Pool YZ).

public entry fun swap_exact_input_doublehop<X, Y, Z>(
    sender: &signer,
    x_in: u64,
    z_min_out: u64,
)

Params

Name
Type
Description

sender

signer

The sender's signer when calling the function.

x_in

u64

Payable amount of input tokenX.

z_min_out

u64

The minimum amount tokenZ to receive.

Swap Exact Output Double Hop

Swap tokenX to exact amount of tokenZ using 2 pools (Pool XY and Pool YZ).

public entry fun swap_exact_output_doublehop<X, Y, Z>(
    sender: &signer,
    z_out: u64,
    x_max_in: u64,
)

Params

Name
Type
Description

sender

signer

The sender's signer when calling the function.

z_out

u64

Payable amount of output tokenZ.

x_max_in

u64

The maximum amount tokenX to input.

Swap Exact Input Triple Hop

Swap exact amount of tokenX to tokenA using 3 pools (Pool XY, Pool YZ and Pool ZA).

public entry fun swap_exact_input_triplehop<X, Y, Z, A>(
    sender: &signer,
    x_in: u64,
    a_min_out: u64,
) 

Params

Name
Type
Description

sender

signer

The sender's signer when calling the function.

x_in

u64

Payable amount of input tokenX.

a_min_out

u64

The minimum amount tokenA to receive.

Swap Exact Output Triple Hop

Swap tokenX to exact amount of tokenA using 3 pools (Pool XY, Pool YZ and Pool ZA).

public entry fun swap_exact_output_triplehop<X, Y, Z, A>(
    sender: &signer,
    a_out: u64,
    x_max_in: u64,
) 
Name
Type
Description

sender

signer

The sender's signer when calling the function.

a_out

u64

Payable amount of output tokenA.

x_max_in

u64

The maximum amount tokenX to input.

Swap Exact Input Quadruple Hop

Swap exact amount of tokenX to tokenB using 3 pools (Pool XY, Pool YZ, Pool ZA and Pool AB).

public entry fun swap_exact_input_quadruplehop<X, Y, Z, A, B>(
    sender: &signer,
    x_in: u64,
    b_min_out: u64,
)
Name
Type
Description

sender

signer

The sender's signer when calling the function.

x_in

u64

Payable amount of input tokenX.

b_min_out

u64

The minimum amount tokenB to receive.

Swap Exact Output Quadruple Hop

Swap tokenX to exact amount of tokenB using 3 pools (Pool XY, Pool YZ, Pool ZA and Pool AB).

public entry fun swap_exact_output_quadruplehop<X, Y, Z, A, B>(
    sender: &signer,
    b_out: u64,
    x_max_in: u64,
)
Name
Type
Description

sender

signer

The sender's signer when calling the function.

b_out

u64

Payable amount of output tokenB.

x_max_in

u64

The maximum amount tokenX to input.

Public Functions

Swap Exact X to Y

Swap exact amount of tokenX to tokenY.

public fun swap_exact_x_to_y_direct_external<X, Y>(x_in: coin::Coin<X>): coin::Coin<Y> 

Input Values

Name
Type
Description

x_in

coin::Coin

The coin resource of tokenX that the user will swap.

Return Values

Type
Description

coin::Coin

The coin resource of tokenY that the user will receive.

Swap X to Exact Y

Swap tokenX to the exact amount of tokenY.

public fun swap_x_to_exact_y_direct_external<X, Y>(x_in: coin::Coin<X>, y_out_amount:u64): (coin::Coin<X>, coin::Coin<Y>)

Input Values

Name
Type
Description

x_in

coin::Coin

The coin resource of tokenX that the user will swap.

y_out_amount

u64

The expected amount of tokenY that user will receive.

Return Values

Position
Type
Description

0

coin::Coin

The coin resource of tokenX that the user will swap.

1

coin::Coin

The coin resource of tokenY that user will receive.

Get Amount In

The amount required in order to the the output amount.

public fun get_amount_in<X, Y>(y_out_amount: u64): u64

Input Values

Name
Type
Description

y_out_amount

u64

The amount of tokenY that user will receive.

Return Values

Type

u64

The amount of tokenX required to get the amount of tokenY.

View on Aptos Explorer