# Pumpfun Object

## Pumpfun Object Documentation

The `Pumpfun` class provides methods to interact with the Pump.fun decentralized trading service on the Solana blockchain. It supports watching for pool creation and trade events, as well as buying and selling tokens. This class extends the `Subscribable` class, enabling subscription to Pump.fun-related events.

### Methods

#### watchCreatePools

**Description** Watches for the creation of new liquidity pools on Pump.fun and invokes a callback when an event occurs.

**Signature**

```typescript
public async watchCreatePools(
  callback: (event: PumpfunCreatePool) => void
): Promise<SubscriptionResult>
```

**Parameters**

* `callback` (`(event: PumpfunCreatePool) => void`): The callback function to handle pool creation events.

**Returns**

* `Promise<SubscriptionResult>`: The result of the subscription operation.

**Example Usage**

```typescript
pumpfun.watchCreatePools((event) => {
  console.log("New pool created:", event);
});
```

***

#### watchTrades

**Description** Watches for trade events (buy or sell) on Pump.fun and invokes a callback when a trade occurs.

**Signature**

```typescript
public async watchTrades(
  callback: (event: PumpfunTrade) => void
): Promise<SubscriptionResult>
```

**Parameters**

* `callback` (`(event: PumpfunTrade) => void`): The callback function to handle trade events.

**Returns**

* `Promise<SubscriptionResult>`: The result of the subscription operation.

**Example Usage**

```typescript
pumpfun.watchTrades((event) => {
  console.log("Trade event:", event);
});
```

***

#### buyTokens

**Description** Buys tokens on Pump.fun by specifying the mint address, amount of SOL, slippage tolerance, and an optional priority fee.

**Signature**

```typescript
public async buyTokens({
  mint,
  amount,
  slippage,
  priorityFee,
  createATA,
}: PumpfunBuyRequest): Promise<Transaction>
```

**Parameters**

* `mint` (`PublicKeyOrString`): The mint address of the token to buy.
* `amount` (`string | number`): The amount of SOL to spend.
* `slippage` (`number`): Optional. The slippage tolerance (in percentage).
* `priorityFee` (`string | number`): Optional. The priority fee in lamports for faster transaction processing.
* `createATA` (`boolean`): Optional. Whether to create an associated token account. Default is `true`.

**Returns**

* `Promise<Transaction>`: The deserialized transaction object representing the buy operation.

**Example Usage**

```typescript
const buyTx = await pumpfun.buyTokens({
  mint: "TokenMintAddress",
  amount: 1, // 1 SOL
  slippage: 0.5, // 0.5% slippage tolerance
  priorityFee: 10000, // 10,000 lamports priority fee
});
console.log("Buy transaction:", buyTx);
```

***

#### sellTokens

**Description** Sells tokens on Pump.fun by specifying the mint address and the amount of tokens to sell.

**Signature**

```typescript
public async sellTokens({
  mint,
  amount,
}: PumpfunSellRequest): Promise<Transaction>
```

**Parameters**

* `mint` (`PublicKeyOrString`): The mint address of the token to sell.
* `amount` (`string | number`): The amount of tokens to sell.

**Returns**

* `Promise<Transaction>`: The deserialized transaction object representing the sell operation.

**Example Usage**

```typescript
const sellTx = await pumpfun.sellTokens({
  mint: "TokenMintAddress",
  amount: 1000, // Amount of tokens to sell
});
console.log("Sell transaction:", sellTx);
```

***

### Types

#### Trade

Represents a trade event (buy or sell).

```typescript
type Trade = {
  side: "buy" | "sell";
  mint: string;
  user: string;
  sol: {
    amount: string;
    uiAmount: string;
  };
  token: {
    amount: string;
    decimals?: number;
    uiAmount?: string;
  };
};
```

***

#### PumpfunBuyRequest

Request type for buying tokens on Pump.fun.

```typescript
type PumpfunBuyRequest = {
  mint: PublicKeyOrString;
  amount: string | number;
  slippage?: number;
  priorityFee?: string | number;
  createATA?: boolean;
};
```

***

#### PumpfunSellRequest

Request type for selling tokens on Pump.fun.

```typescript
type PumpfunSellRequest = {
  mint: PublicKeyOrString;
  amount: string | number;
};
```

***

#### PumpfunTrade

Represents a Pump.fun trade event.

```typescript
type PumpfunTrade = {
  service: "pumpfun";
  event: "trade";
  transaction: VersionedTransactionResponse;
  trade: Trade;
};
```

***

#### PumpfunCreatePool

Represents a Pump.fun pool creation event.

```typescript
type PumpfunCreatePool = {
  service: "pumpfun";
  event: "create-pool";
  transaction: VersionedTransactionResponse;
  pool?: {
    bondingCurve: string;
    associatedBondingCurve: string;
    user: string;
    mint: string;
    metadata: string;
  };
};
```


---

# 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://gitbook.roboqo.com/global-objects/integrations.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.
