@suwappu/langchain-suwappu
v0.1.0
Published
LangChain-compatible tools for the Suwappu DEX API — cross-chain swaps, prices, and portfolio tracking for AI agents
Downloads
12
Maintainers
Readme
langchain-suwappu
LangChain-compatible tools for the Suwappu DEX API. Gives AI agents the ability to get swap quotes, token prices, and portfolio balances across 7+ chains.
Install
npm install langchain-suwappu @langchain/core zodTools
| 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
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
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
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
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.30Portfolio Balances
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):
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
