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 spendminAmountOut: Minimum tokens to receiveto: Recipient address
Returns:
amountOut: Amount of tokens receivedfee: Fee paid in base tokens
Errors:
PandaPool: INSUFFICIENT_OUTPUT_AMOUNT- When amountOut is less than minAmountOutPandaPool: TRADE_BELOW_MIN- When trade size is below minimum thresholdPandaPool: INVALID_TO- When recipient address is zeroPandaPool: 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 receiveto: Recipient address
Returns:
amountOut: Amount of tokens receivedfee: Fee paid in BERA
Errors:
PandaPool: NOT_BERA_PAIR- When base token is not WBERAPandaPool: INSUFFICIENT_OUTPUT_AMOUNT- When amountOut is less than minAmountOutPandaPool: INVALID_TO- When recipient address is zeroPandaPool: 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 receivedfee: Fee paid in base tokens
Errors:
PandaPool: INVALID_TO- When recipient address is zeroPandaPool: INSUFFICIENT_LIQUIDITY- When not enough liquidity for tradePandaPool: 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 sellminAmountOut: Minimum base tokens to receiveto: Recipient address
Returns:
amountOut: Amount of base tokens receivedfee: Fee paid in base tokens
Errors:
PandaPool: INSUFFICIENT_BUYING- When selling more than boughtPandaPool: INSUFFICIENT_OUTPUT_AMOUNT- When amountOut is less than minAmountOutPandaPool: INVALID_TO- When recipient address is zeroPandaPool: 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 sellminAmountOut: Minimum amount of BERA to receiveto: Recipient address for BERA
Returns:
amountOut: Amount of BERA receivedfee: Fee paid in BERA
Errors:
PandaPool: NOT_BERA_PAIR- When base token is not WBERAPandaPool: INSUFFICIENT_BUYING- When selling more than boughtPandaPool: INSUFFICIENT_OUTPUT_AMOUNT- When amountOut is less than minAmountOutPandaPool: 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 receivefee: Expected fee in base tokenssqrtP_new: New square root price after the trade
Errors:
PandaPool: TRADE_BELOW_MIN- When trade size is below minimum thresholdPandaPool: INSUFFICIENT_LIQUIDITY- When not enough liquidity for tradePandaPool: 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 receivefee: Expected fee in base tokenssqrtP_new: New square root price after the trade
Errors:
PandaPool: TRADE_BELOW_MIN- When trade size is below minimum thresholdPandaPool: INSUFFICIENT_LIQUIDITY- When not enough liquidity for tradePandaPool: 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 spendfee: Expected fee in base tokenssqrtP_new: New square root price after the trade
Errors:
PandaPool: TRADE_BELOW_MIN- When trade size is below minimum thresholdPandaPool: INSUFFICIENT_LIQUIDITY- When not enough tokens availablePandaPool: 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 enabledPandaPool: 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 enabledPandaPool: 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 tokensexcessBaseTokens: Amount of excess base tokens
collectExcessTokens
collectExcessTokens()
externalTransfer 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.
Last updated