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

