# Bonding Curve Stage Trading

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

<pre class="language-solidity"><code class="lang-solidity">// solidity interface 

<strong>/// @notice Buy maximum coin with specified collateral amount
</strong>///
/// @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 reward
function buyExactInWithCollateral(
    address _token,
    uint256 _collateralAmountIn,
    uint256 _amountOutMin,
    address _tradeReferrer
)
    external
    payable;
</code></pre>

**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.

```solidity
/// @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
);
```

***

## 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

<pre class="language-solidity"><code class="lang-solidity">// solidity interface 

<strong>/// @notice Buy maximum coin with specified collateral amount
</strong>///
/// @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;
</code></pre>

### Events

A `Buy` event will be emitted upon successful coin purchase.

```solidity
/// @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
);
```

***

## 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

```solidity
// 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;
```

### Events

A `Buy` event will be emitted upon successful coin purchase.

```solidity
/// @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
);
```

***

## 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).

```solidity
// 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;
```

### Events

A `Sell` event will be emitted upon successful coin sale.

```solidity
/// @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
);
```

***

## 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).

```solidity
// 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;
```

### Events

A `Sell` event will be emitted upon successful coin sale.

```solidity
/// @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
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.base.meme/for-developers/trading-coins/bonding-curve-stage-trading.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
