Kodiak Finance
  • OVERVIEW
    • 🐻‍❄️Introducing Kodiak
    • 🐻Kodiak x Berachain
    • ✉️Contact Us
    • 🍯Kodiak Contracts
  • 🅱️Kodiak-Boyco
  • PROTOCOL
    • 🔃DEX
      • Swaps
      • Liquidity Provision
      • Trading Fees
    • 🏝️Islands
      • Island Liquidity Provision
      • Sweetened Islands
      • Island Mechanics
        • Auto-BGT
        • Real-time Security
        • Rebalancing
        • Strategies
    • 🐼Panda Factory
  • 🪙Tokenomics
    • Kodiak Pre-TGE Rewards
  • 🧠User Guide
    • Launch a Token Launch on Panda Factory
    • Trading on Panda Factory
    • Swap
    • Create a V2 Position
    • Create a V3 Position
    • Add/Stake Islands Liquidity
    • Migrating to a Reward Vault
    • Deploying new Permissonless Islands
    • Deploying and Configuring a Kodiak Farm
    • Add your token
  • Add Your Project to the Ecosystem
  • 👨‍💻Developers
    • 🐼Panda
      • Technical Integration Guide
      • Subgraph
        • Entity Reference
        • Query Guide
        • Advanced Usage Guide
      • Smart Contract Reference
        • Panda Factory
        • Panda Pool
        • Panda Token
      • Api
    • Farms
      • Technical Integration Guide
      • Smart Contract Reference
    • 🌴Kodiak Islands
      • Technical Integration Guide
        • Understanding Token Deposit Ratio
      • Subgraph
        • Entity Reference
        • Query Guide
        • Advanced Usage Guide
      • Smart Contract Reference
        • Kodiak Island Factory
        • Kodiak Island
        • Kodiak Island Router
      • Api
    • 💰Pricing with Subgraph
    • 💱Quotes
    • Backend
  • 🛡️SECURITY
    • 🔍Audits
    • Page
  • ℹ️Informational
    • 📜Terms of Use
    • 🔏Privacy Policy
    • TradingView Advanced License
Powered by GitBook
On this page
  1. Developers
  2. Panda
  3. Smart Contract Reference

Panda Pool

Abstract base contract implementing bonding curve mechanics.

Functions

Trading

buyTokens

function buyTokens(
    uint256 amountIn,
    uint256 minAmountOut,
    address to
) external nonReentrant returns (uint256 amountOut, uint256 fee)

Purchase tokens with the base token.

Parameters:

  • amountIn: Amount of base tokens to spend

  • minAmountOut: Minimum tokens to receive

  • to: Recipient address

Returns:

  • amountOut: Amount of tokens received

  • fee: Fee paid in base tokens

Errors:

  • PandaPool: INSUFFICIENT_OUTPUT_AMOUNT - When amountOut is less than minAmountOut

  • PandaPool: TRADE_BELOW_MIN - When trade size is below minimum threshold

  • PandaPool: INVALID_TO - When recipient address is zero

  • PandaPool: GRADUATED - When pool has already graduated

buyTokensWithBera

function buyTokensWithBera(
    uint256 minAmountOut,
    address to
) external payable returns (uint256 amountOut, uint256 fee)

Purchase tokens using native BERA.

Parameters:

  • minAmountOut: Minimum tokens to receive

  • to: Recipient address

Returns:

  • amountOut: Amount of tokens received

  • fee: Fee paid in BERA

Errors:

  • PandaPool: NOT_BERA_PAIR - When base token is not WBERA

  • PandaPool: INSUFFICIENT_OUTPUT_AMOUNT - When amountOut is less than minAmountOut

  • PandaPool: INVALID_TO - When recipient address is zero

  • PandaPool: GRADUATED - When pool has already graduated

buyAllTokens

function buyAllTokens(
    address to
) external returns (uint256 amountOut, uint256 fee)

Purchase all remaining tokens in the pool.

Parameters:

  • to: Recipient address

Returns:

  • amountOut: Amount of tokens received

  • fee: Fee paid in base tokens

Errors:

  • PandaPool: INVALID_TO - When recipient address is zero

  • PandaPool: INSUFFICIENT_LIQUIDITY - When not enough liquidity for trade

  • PandaPool: GRADUATED - When pool has already graduated

sellTokens

function sellTokens(
    uint256 amountIn,
    uint256 minAmountOut,
    address to
) external nonReentrant returns (uint256 amountOut, uint256 fee)

Sell tokens for the base token.

Parameters:

  • amountIn: Amount of tokens to sell

  • minAmountOut: Minimum base tokens to receive

  • to: Recipient address

Returns:

  • amountOut: Amount of base tokens received

  • fee: Fee paid in base tokens

Errors:

  • PandaPool: INSUFFICIENT_BUYING - When selling more than bought

  • PandaPool: INSUFFICIENT_OUTPUT_AMOUNT - When amountOut is less than minAmountOut

  • PandaPool: INVALID_TO - When recipient address is zero

  • PandaPool: GRADUATED - When pool has already graduated

sellTokensForBera

function sellTokensForBera(
    uint256 amountIn,
    uint256 minAmountOut,
    address to
) external returns (uint256 amountOut, uint256 fee)

Sell tokens for native BERA.

Parameters:

  • amountIn: Amount of tokens to sell

  • minAmountOut: Minimum amount of BERA to receive

  • to: Recipient address for BERA

Returns:

  • amountOut: Amount of BERA received

  • fee: Fee paid in BERA

Errors:

  • PandaPool: NOT_BERA_PAIR - When base token is not WBERA

  • PandaPool: INSUFFICIENT_BUYING - When selling more than bought

  • PandaPool: INSUFFICIENT_OUTPUT_AMOUNT - When amountOut is less than minAmountOut

  • PandaPool: INVALID_TO - When recipient address is zero

Price Discovery Functions

getAmountOutBuy

function getAmountOutBuy(
    uint256 amountIn
) public view returns (
    uint256 amountOut,
    uint256 fee,
    uint256 sqrtP_new
)

Calculate expected output for buying tokens.

Returns:

  • amountOut: Expected amount of tokens to receive

  • fee: Expected fee in base tokens

  • sqrtP_new: New square root price after the trade

Errors:

  • PandaPool: TRADE_BELOW_MIN - When trade size is below minimum threshold

  • PandaPool: INSUFFICIENT_LIQUIDITY - When not enough liquidity for trade

  • PandaPool: GRADUATED - When pool has already graduated

getAmountOutSell

function getAmountOutSell(
    uint256 amountIn
) public view returns (
    uint256 amountOut,
    uint256 fee,
    uint256 sqrtP_new
)

Calculate expected output for selling tokens.

Parameters:

  • amountIn: Amount of tokens to sell

Returns:

  • amountOut: Expected amount of base tokens to receive

  • fee: Expected fee in base tokens

  • sqrtP_new: New square root price after the trade

Errors:

  • PandaPool: TRADE_BELOW_MIN - When trade size is below minimum threshold

  • PandaPool: INSUFFICIENT_LIQUIDITY - When not enough liquidity for trade

  • PandaPool: GRADUATED - When pool has already graduated

getAmountInBuy

function getAmountInBuy(
    uint256 amountOut
) public view returns (
    uint256 amountIn,
    uint256 fee,
    uint256 sqrtP_new
)

Calculate required input for desired token output.

Parameters:

  • amountOut: Desired amount of tokens to receive

Returns:

  • amountIn: Required amount of base tokens to spend

  • fee: Expected fee in base tokens

  • sqrtP_new: New square root price after the trade

Errors:

  • PandaPool: TRADE_BELOW_MIN - When trade size is below minimum threshold

  • PandaPool: INSUFFICIENT_LIQUIDITY - When not enough tokens available

  • PandaPool: GRADUATED - When pool has already graduated

getAmountInBuyRemainingTokens

getAmountInBuyRemainingTokens() 
public view returns (uint256 amountIn)

Calculate amount needed to buy all remaining tokens.

Returns:

  • amountIn: Amount of base tokens needed to buy all remaining tokens

Balance & Vesting Functions

totalBalanceOf

totalBalanceOf(
    address user
) external view returns (uint256)

Get total balance including unvested tokens.

Parameters:

  • user: Address to check balance for

Returns:

  • Total balance including both vested and unvested tokens

vestedBalanceOf

 vestedBalanceOf(
    address user
) external view returns (uint256)

Get available/vested balance.

Parameters:

  • user: Address to check vested balance for

Returns:

  • Currently vested token balance

claimableTokens

claimableTokens(
    address user
) public view returns (uint256)

Get amount of tokens available to claim.

Parameters:

  • user: Address to check claimable tokens for

Returns:

  • Amount of tokens currently available to claim

Errors:

  • PandaPool: VESTING_OFF - When vesting is not enabled

  • PandaPool: NOT_GRADUATED - When pool hasn't graduated yet

claimTokens

claimTokens(
    address user
) external returns (uint256)

Claim vested tokens.

Parameters:

  • user: Address to claim tokens for

Returns:

  • Amount of tokens claimed

Errors:

  • PandaPool: VESTING_OFF - When vesting is not enabled

  • PandaPool: NO_CLAIMABLE - When no tokens are available to claim

Pool State Functions

remainingTokensInPool

remainingTokensInPool()
public view returns (uint256)

Get remaining tokens available in pool.

Returns:

  • Amount of tokens remaining in the pool

viewExcessTokens

viewExcessTokens()
public view returns (
    uint256 excessPandaTokens,
    uint256 excessBaseTokens
)

View excess tokens in contract.

Returns:

  • excessPandaTokens: Amount of excess Panda tokens

  • excessBaseTokens: Amount of excess base tokens

collectExcessTokens

collectExcessTokens()
external

Transfer excess tokens to treasury.

Emits: ExcessCollected

Events

PoolInitialized(
    address pandaToken,
    address baseToken,
    uint256 sqrtPa,
    uint256 sqrtPb,
    uint256 vestingPeriod,
    address deployer,
    bytes data
)

Emitted when pool is initialized.

Swap(
    address indexed sender,
    uint amount0In,
    uint amount1In,
    uint amount0Out,
    uint amount1Out,
    address indexed to
)

Emitted on each swap operation.

Sync(
    uint256 pandaReserve,
    uint256 baseReserve,
    uint256 sqrtPrice
)

Emitted when pool reserves are synchronized.

TokensClaimed(
    address indexed user,
    uint256 amount
)

Emitted when tokens are claimed from vesting.

ExcessCollected(
    uint256 excessPandaTokens,
    uint256 excessBaseTokens
)

Emitted when excess tokens are collected.

PreviousPanda FactoryNextPanda Token

Last updated 3 months ago

👨‍💻
🐼