# Buy and Sell

For Buys and Sells the corresponding function are

```solidity
function buy(uint256 id, uint256 amountOutMin) public payable returns (uint256 amountOut)
```

Where id is the tokenId (or you could also say it's the poolId or curveId), and the amountOutMin the minimum amount of tokens we want to receive (i.e. slippage).

Platform fees (in ETH/BNB) are taken before the actual amountOut is calculated.

```solidity
function sell(uint256 id, uint256 amountIn, uint256 amountOutMin) public returns (uint256 amountOut)
```

TokenId is the token we want to sell, amountIn is the amount of tokens we want to sell, and amountOutMin is the minimum amount of ETH we want to receive.

Platform fees (in ETH/BNB) are taken after the amountOut has been calculated.

### Refund

Should a buy be the last buy and trigger migration, an automatic refund is triggered for too much ETH provided.

For example, if there are only 2,000,000 tokens left to be sold and you make a buy with 1 ETH, only the value of the actual tokens amount sold in ETH will be subtracted from the provided ETH (plus platform fees), the rest will be refunded in the same transaction. So lets sat the 2,000,000 tokens are worth 0.15 ETH, then the platform fee (1% maximum) will be 0.0015 ETH, therefor 0.1515 ETH are subtracted and 0.8485 ETH are refunded.

To accurately calculate slippage this refunding process needs to be taken into account.


---

# 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://lfg-club.gitbook.io/lfgclub/bonding-curve/buy-and-sell.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.
