npm package: @suwappu/langchain-suwappu
Description: LangChain-compatible tools for the Suwappu DEX API — cross-chain swaps, prices, and portfolio tracking for AI agents
Latest version: 0.1.0

# langchain-suwappu

LangChain-compatible tools for the [Suwappu DEX API](https://api.suwappu.bot). Gives AI agents the ability to get swap quotes, token prices, and portfolio balances across 7+ chains.

## Install

```bash
npm install langchain-suwappu @langchain/core zod
```

## Tools

| Tool | Description |
|------|-------------|
| `SuwappuSwapTool` | Get quotes and execute cross-chain token swaps |
| `SuwappuPriceTool` | Get current token prices in USD |
| `SuwappuPortfolioTool` | Get wallet token balances and portfolio value |

## Quick Start

```typescript
import { SuwappuSwapTool, SuwappuPriceTool, SuwappuPortfolioTool } from "langchain-suwappu";

const config = { apiKey: process.env.SUWAPPU_API_KEY! };

const tools = [
  new SuwappuSwapTool(config),
  new SuwappuPriceTool(config),
  new SuwappuPortfolioTool(config),
];
```

## LangChain Agent Integration

```typescript
import { ChatOpenAI } from "@langchain/openai";
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { SuwappuSwapTool, SuwappuPriceTool, SuwappuPortfolioTool } from "langchain-suwappu";

const config = { apiKey: process.env.SUWAPPU_API_KEY! };

const tools = [
  new SuwappuSwapTool(config),
  new SuwappuPriceTool(config),
  new SuwappuPortfolioTool(config),
];

const llm = new ChatOpenAI({ model: "gpt-4o", temperature: 0 });

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a DeFi assistant that can look up prices, get swap quotes, and check portfolio balances."],
  ["human", "{input}"],
  ["placeholder", "{agent_scratchpad}"],
]);

const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });

const result = await executor.invoke({
  input: "What's the current price of ETH and get me a quote to swap 1 ETH to USDC on Base",
});

console.log(result.output);
```

## Using Individual Tools

### Swap Quotes

```typescript
import { SuwappuSwapTool } from "langchain-suwappu";

const swap = new SuwappuSwapTool({ apiKey: "your-api-key" });

const quote = await swap.invoke({
  from_token: "ETH",
  to_token: "USDC",
  amount: "1.0",
  chain: "base",
});

console.log(quote);
// Swap Quote (base)
//   1.0 ETH -> 3245.50 USDC
//   Rate: 3245.50
//   Price impact: 0.02%
```

### Token Prices

```typescript
import { SuwappuPriceTool } from "langchain-suwappu";

const prices = new SuwappuPriceTool({ apiKey: "your-api-key" });

const result = await prices.invoke({ symbols: "ETH,BTC,SOL" });

console.log(result);
// Token Prices (USD)
//   ETH: $3245.50
//   BTC: $67890.00
//   SOL: $142.30
```

### Portfolio Balances

```typescript
import { SuwappuPortfolioTool } from "langchain-suwappu";

const portfolio = new SuwappuPortfolioTool({ apiKey: "your-api-key" });

const result = await portfolio.invoke({
  wallet_address: "0x1234...abcd",
});

console.log(result);
// Portfolio for 0x1234...abcd
//   Total value: $12345.67
//   ETH: 2.5 ($8113.75)
//   USDC: 4231.92 ($4231.92)
```

## Custom Base URL

Point to a different API endpoint (useful for staging/testing):

```typescript
const swap = new SuwappuSwapTool({
  apiKey: "your-api-key",
  baseUrl: "https://staging-api.suwappu.bot",
});
```

## Supported Chains

Ethereum, Base, Arbitrum, Polygon, BSC, Optimism, Solana

## License

MIT