> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inkyswap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trading

> buy, sell, and the referral variants on the InkyPump V2 hook.

Trades on the bonding curve go through the InkyPump V2 hook at `0x4cC8F6d5B7cE150CCC0A9B7664532B1283b96AC4`. There are four write functions: `buy`, `buyWithReferral`, `sell`, and `sellWithReferral`. The referral variants emit an extra `Referral` event.

After a token bonds, trades route through the Uniswap Universal Router instead. See [Post-Bond Pool](/trading/post-bond-pool) for that path.

## buy

```solidity theme={null}
function buy(
    uint256 launchId,
    uint256 minTokensOut,
    InkyPumpTypes.CaptchaAuth calldata captcha
) external payable returns (uint256 tokensOut);
```

| Param          | Meaning                                                       |
| -------------- | ------------------------------------------------------------- |
| `launchId`     | The launch ID returned by `createLaunch`                      |
| `minTokensOut` | Slippage floor. Reverts if fewer tokens would be sent         |
| `captcha`      | Captcha signature, required only during the anti-snipe window |

`msg.value` is the ETH you spend. Must be at least `MIN_BUY_ETH` (`0.00001 ether`).

Returns `tokensOut`, the number of tokens credited to `msg.sender`.

## buyWithReferral

```solidity theme={null}
function buyWithReferral(
    uint256 launchId,
    uint256 minTokensOut,
    InkyPumpTypes.CaptchaAuth calldata captcha,
    string calldata referralCode
) external payable returns (uint256 tokensOut);
```

Same as `buy`, plus emits `Referral(launchId, msg.sender, referralCode)` if `referralCode` is non empty. No fee impact.

## sell

```solidity theme={null}
function sell(
    uint256 launchId,
    uint128 tokenAmount,
    uint256 minEthOut,
    InkyPumpTypes.CaptchaAuth calldata captcha
) external returns (uint256 payout);
```

| Param         | Meaning                                                                  |
| ------------- | ------------------------------------------------------------------------ |
| `launchId`    | The launch ID                                                            |
| `tokenAmount` | Tokens to sell. Must be at least `MIN_SELL_TOKENS` (`1 ether` = 1 token) |
| `minEthOut`   | Slippage floor on the ETH payout                                         |
| `captcha`     | Captcha signature, required only during the anti-snipe window            |

The contract pulls `tokenAmount` from `msg.sender` (you need to approve the hook first, or the token's `transferFrom` allowance has to cover the trade).

Returns the net ETH payout.

## sellWithReferral

```solidity theme={null}
function sellWithReferral(
    uint256 launchId,
    uint128 tokenAmount,
    uint256 minEthOut,
    InkyPumpTypes.CaptchaAuth calldata captcha,
    string calldata referralCode
) external returns (uint256 payout);
```

Same as `sell`, plus emits `Referral`. No fee impact.

## Captcha auth

The anti-snipe captcha is an off chain ECDSA signature from the InkyPump signer.

```solidity theme={null}
struct CaptchaAuth {
    uint256 deadline;   // expiration timestamp for this signature
    bytes signature;    // ECDSA signature from the authorized captcha signer
}
```

If the anti-snipe window has ended for the launch (`block.timestamp > launchTimestamp + antiSnipeDuration`), the captcha is not checked. You can pass empty fields.

If the window is still active, you must provide a valid signature. Otherwise the call reverts with `CaptchaRequired()`. The InkyPump UI fetches the signature automatically from its backend.

For direct integrations that need to trade during the anti-snipe window, contact InkyPump for backend signing access.

## Fees

The hook splits the input (on buy) or the gross payout (on sell) before processing:

```solidity theme={null}
protocolFee  = amount * PROTOCOL_FEE_BPS / BPS_DENOMINATOR;  // 1 percent
variableFee  = amount * VARIABLE_FEE_BPS / BPS_DENOMINATOR;  // 1 percent
creatorFee   = variableFee * creatorFeeSplitBps / BPS_DENOMINATOR;
buybackFee   = variableFee - creatorFee;
netAmount    = amount - protocolFee - variableFee;
```

`creatorFee` accrues to the launch creator. `buybackFee` accrues to a buyback module that periodically buys and burns the token.

## Events emitted

Every successful trade emits:

```solidity theme={null}
event Trade(
    uint256 indexed launchId,
    address indexed trader,
    TradeType tradeType,    // BUY or SELL
    PriceData priceData,
    TradeData tradeData,
    uint256 refund
);

event FeeAccrued(address indexed recipient, uint256 amount);
```

The `*WithReferral` variants additionally emit:

```solidity theme={null}
event Referral(
    uint256 indexed launchId,
    address indexed trader,
    string referralCode
);
```

## Common errors

| Revert             | Cause                                                                            |
| ------------------ | -------------------------------------------------------------------------------- |
| `CaptchaRequired`  | In the anti-snipe window without a valid signature                               |
| `InvalidCaptcha`   | Signature does not verify against the configured signer or `deadline` has passed |
| `SlippageExceeded` | Output below `minTokensOut` (buy) or `minEthOut` (sell)                          |
| `BelowMinBuy`      | `msg.value` is below `MIN_BUY_ETH`                                               |
| `BelowMinSell`     | `tokenAmount` is below `MIN_SELL_TOKENS`                                         |
| `LaunchFinalized`  | The token has bonded. Use the V4 pool instead                                    |
| `LaunchNotStarted` | `launchTimestamp` is in the future (scheduled launch)                            |
