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

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

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

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

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

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

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

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

Calculate amount needed to buy all remaining tokens.

Returns:

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

Balance & Vesting Functions

totalBalanceOf

Get total balance including unvested tokens.

Parameters:

  • user: Address to check balance for

Returns:

  • Total balance including both vested and unvested tokens

vestedBalanceOf

Get available/vested balance.

Parameters:

  • user: Address to check vested balance for

Returns:

  • Currently vested token balance

claimableTokens

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

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

Get remaining tokens available in pool.

Returns:

  • Amount of tokens remaining in the pool

viewExcessTokens

View excess tokens in contract.

Returns:

  • excessPandaTokens: Amount of excess Panda tokens

  • excessBaseTokens: Amount of excess base tokens

collectExcessTokens

Transfer excess tokens to treasury.

Emits: ExcessCollected

Events

Emitted when pool is initialized.

Emitted on each swap operation.

Emitted when pool reserves are synchronized.

Emitted when tokens are claimed from vesting.

Emitted when excess tokens are collected.

Last updated