This guide covers coin trading during the Bonding Curve stage which is executed through the Basememe Factory contract.
Coins can be configured with different collateral pairs on Base (ETH / USDC / SOL). The trading flow depends on whether a coin uses native ETH collateral (tokenToCollateralToken(token) == address(0)) or an ERC20 collateral token.
Buy Coins with Exact Collateral Value
The buyExactInWithCollateral method accepts a specified collateral amount and buys the maximum possible number of coins for that input.
Method Interface
// solidity interface /// @notice Buy maximum coin with specified collateral amount////// @param_token The token contract address/// @param_collateralAmountIn The amount of collateral to spend on buying token/// @param_amountOutMin The minimum amount of token expected to receive for collateral amount sending in/// @param_tradeReferrer The Trade Referrer address to receive rewardfunctionbuyExactInWithCollateral(address_token,uint256_collateralAmountIn,uint256_amountOutMin,address_tradeReferrer)externalpayable;
Payment notes
For ETH-collateral coins, send msg.value == _collateralAmountIn.
For ERC20-collateral coins (e.g. USDC / SOL), msg.value must be 0 and the caller must approve the Factory to spend _collateralAmountIn of the collateral token.
Events
A Buy event will be emitted upon successful coin purchase.
Buy Coins with Exact Collateral Value (ETH Pair Only)
The buyExactIn method is the legacy ETH-only exact-in entrypoint. It only works for coins whose collateral pair is native ETH and will revert for coins that use ERC20 collateral (e.g. USDC / SOL). For multi-collateral support, use buyExactInWithCollateral.
Method Interface
Events
A Buy event will be emitted upon successful coin purchase.
Buy Exact Coin Amount
The buyExactOut method allows the buyer to specify the exact number of coins to purchase, while setting a maximum collateral amount willing to spend.
Payment notes
For ETH-collateral coins, send your max as msg.value and set _maxCollateralAmount accordingly.
For ERC20-collateral coins (e.g. USDC / SOL), do not send ETH (msg.value should be 0) and approve the Factory to spend up to _maxCollateralAmount of the collateral token.
Method Interface
Events
A Buy event will be emitted upon successful coin purchase.
Sell Exact Coin Amount
The sellExactIn method accepts the exact number of coins to sell and receives at least the minimum expected collateral amount in return. The collateral received depends on the coin's selected collateral pair (ETH / USDC / SOL).
Events
A Sell event will be emitted upon successful coin sale.
Sell Coins for Exact Collateral Value
The sellExactOut method accepts the exact collateral amount to receive upon coin sale, with the required coin amount (up to a maximum) specified. The collateral received depends on the coin's selected collateral pair (ETH / USDC / SOL).
Events
A Sell event will be emitted upon successful coin sale.
/// @notice emitted upon successful token purchase during Bonding Curve stage
///
/// @param buyer The token buyer address
/// @param token The purchased token address
/// @param tokenAmount The amount of token purhased
/// @param collateralAmount The amount of collateral used to purchase token (depends on the coin's selected collateral pair)
/// @param refund The amount of collateral refunded to buyer if there's leftover
/// @param tradeFee The amount of fee collected by platform for token purchase
/// @param curveProgressBps The updated Bonding Curve progress basis points for token
/// @param virtualCollateralReserves The updated virtual collateral reserves amount in Bonding Curve stage
/// @param virtualTokenReserves The updated virtual token reserves amount in Bonding Curve stage
/// @param collateralReserves The updated real collateral reserves amount in Bonding Curve stage
/// @param tokenReserves The updated real token reserves amount in Bonding Curve stage
event Buy(
address indexed buyer,
address indexed token,
uint256 tokenAmount,
uint256 collateralAmount,
uint256 refund,
uint256 tradeFee,
uint256 curveProgressBps,
uint256 virtualCollateralReserves,
uint256 virtualTokenReserves,
uint256 collateralReserves,
uint256 tokenReserves
);
// solidity interface
/// @notice Buy maximum coin with specified collateral amount
///
/// @param _token The token contract address
/// @param _amountOutMin The minimum amount of token expected to receive for collateral amount sending in
/// @param _tradeReferrer The Trade Referrer address to receive reward
function buyExactIn(
address _token,
uint256 _amountOutMin,
address _tradeReferrer
)
external
payable;
/// @notice emitted upon successful token purchase during Bonding Curve stage
///
/// @param buyer The token buyer address
/// @param token The purchased token address
/// @param tokenAmount The amount of token purhased
/// @param collateralAmount The amount of collateral used to purchase token (depends on the coin's selected collateral pair)
/// @param refund The amount of collateral refunded to buyer if there's leftover
/// @param tradeFee The amount of fee collected by platform for token purchase
/// @param curveProgressBps The updated Bonding Curve progress basis points for token
/// @param virtualCollateralReserves The updated virtual collateral reserves amount in Bonding Curve stage
/// @param virtualTokenReserves The updated virtual token reserves amount in Bonding Curve stage
/// @param collateralReserves The updated real collateral reserves amount in Bonding Curve stage
/// @param tokenReserves The updated real token reserves amount in Bonding Curve stage
event Buy(
address indexed buyer,
address indexed token,
uint256 tokenAmount,
uint256 collateralAmount,
uint256 refund,
uint256 tradeFee,
uint256 curveProgressBps,
uint256 virtualCollateralReserves,
uint256 virtualTokenReserves,
uint256 collateralReserves,
uint256 tokenReserves
);
// solidity interface
/// @notice Buy exact amount of coin
///
/// @param _token The token contract address
/// @param _tokenAmount The amount of token expect to receive
/// @param _maxCollateralAmount The maximum amount of collateral expected to spent
/// @param _tradeReferrer The Trade Referrer address to receive reward
function buyExactOut(
address _token,
uint256 _tokenAmount,
uint256 _maxCollateralAmount,
address _tradeReferrer
)
external
payable;
/// @notice emitted upon successful token purchase during Bonding Curve stage
///
/// @param buyer The token buyer address
/// @param token The purchased token address
/// @param tokenAmount The amount of token purhased
/// @param collateralAmount The amount of collateral used to purchase token (depends on the coin's selected collateral pair)
/// @param refund The amount of collateral refunded to buyer if there's leftover
/// @param tradeFee The amount of fee collected by platform for token purchase
/// @param curveProgressBps The updated Bonding Curve progress basis points for token
/// @param virtualCollateralReserves The updated virtual collateral reserves amount in Bonding Curve stage
/// @param virtualTokenReserves The updated virtual token reserves amount in Bonding Curve stage
/// @param collateralReserves The updated real collateral reserves amount in Bonding Curve stage
/// @param tokenReserves The updated real token reserves amount in Bonding Curve stage
event Buy(
address indexed buyer,
address indexed token,
uint256 tokenAmount,
uint256 collateralAmount,
uint256 refund,
uint256 tradeFee,
uint256 curveProgressBps,
uint256 virtualCollateralReserves,
uint256 virtualTokenReserves,
uint256 collateralReserves,
uint256 tokenReserves
);
// solidity interface
/// @notice Sell exact amount of coin
///
/// @param _token The token contract address
/// @param _tokenAmount The amount of token to sell
/// @param _amountCollateralMin The minimum amount of collateral expected in return
/// @param _traderReferrer The Trade Referrer address to receive reward
function sellExactIn(
address _token,
uint256 _tokenAmount,
uint256 _amountCollateralMin,
address _tradeReferrer
)
external;
/// @notice emitted upon successful token sale during Bonding Curve stage
///
/// @param seller The token seller address
/// @param token The sold token address
/// @param tokenAmount The amount of token sold
/// @param collateralAmount The amount of collateral received upon token sale
/// @param tradeFee The amount of fee collected by platform for token sale
/// @param curveProgressBps The updated Bonding Curve progress basis points for token
/// @param virtualCollateralReserves The updated virtual collateral reserves amount in Bonding Curve stage
/// @param virtualTokenReserves The updated virtual token reserves amount in Bonding Curve stage
/// @param collateralReserves The updated real collateral reserves amount in Bonding Curve stage
/// @param tokenReserves The updated real token reserves amount in Bonding Curve stage
event Sell(
address indexed seller,
address indexed token,
uint256 tokenAmount,
uint256 collateralAmount,
uint256 tradeFee,
uint256 curveProgressBps,
uint256 virtualCollateralReserves,
uint256 virtualTokenReserves,
uint256 collateralReserves,
uint256 tokenReserves
);
// solidity interface
/// @notice Sell token for exact amount of collateral
///
/// @param _token The token contract address
/// @param _tokenAmountMax The maximum amount of token to sell
/// @param _amountCollateral The exact amount of collateral expected in return
/// @param _traderReferrer The Trade Referrer address to receive reward
function sellExactOut(
address _token,
uint256 _tokenAmountMax,
uint256 _amountCollateral,
address _tradeReferrer
)
external;
/// @notice emitted upon successful token sale during Bonding Curve stage
///
/// @param seller The token seller address
/// @param token The sold token address
/// @param tokenAmount The amount of token sold
/// @param collateralAmount The amount of collateral received upon token sale
/// @param tradeFee The amount of fee collected by platform for token sale
/// @param curveProgressBps The updated Bonding Curve progress basis points for token
/// @param virtualCollateralReserves The updated virtual collateral reserves amount in Bonding Curve stage
/// @param virtualTokenReserves The updated virtual token reserves amount in Bonding Curve stage
/// @param collateralReserves The updated real collateral reserves amount in Bonding Curve stage
/// @param tokenReserves The updated real token reserves amount in Bonding Curve stage
event Sell(
address indexed seller,
address indexed token,
uint256 tokenAmount,
uint256 collateralAmount,
uint256 tradeFee,
uint256 curveProgressBps,
uint256 virtualCollateralReserves,
uint256 virtualTokenReserves,
uint256 collateralReserves,
uint256 tokenReserves
);