Merge branch 'main' into feature/getBalanceOther

This commit is contained in:
Damjan Dimitrov
2024-12-27 22:25:26 +01:00
committed by GitHub
54 changed files with 9079 additions and 58 deletions

View File

@@ -202,6 +202,23 @@ const price = await agent.pythFetchPrice(
console.log("Price in BTC/USD:", price);
```
## Examples
### LangGraph Multi-Agent System
The repository includes an advanced example of building a multi-agent system using LangGraph and Solana Agent Kit. Located in `examples/agent-kit-langgraph`, this example demonstrates:
- Multi-agent architecture using LangGraph's StateGraph
- Specialized agents for different tasks:
- General purpose agent for basic queries
- Transfer/Swap agent for transaction operations
- Read agent for blockchain data queries
- Manager agent for routing and orchestration
- Fully typed TypeScript implementation
- Environment-based configuration
Check out the [LangGraph example](examples/agent-kit-langgraph) for a complete implementation of an advanced Solana agent system.
## Dependencies
The toolkit relies on several key Solana and Metaplex libraries:

View File

@@ -1 +1 @@
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE42TwU7DMAyG3yXniooJJtTbRNUDDJigN8QhCi6JltpR40hMaO+OtiFYWebtkos/f7asP69fiuGTVaVeyGvUsw9AvnesChU0W1Up43WMEMtx/cJy71Whlg7fVXU5uVkXv6Zb8h4MO8IagqdVD7jnc8gwdNpALHPgWDy5nmbFT2HzxhPWH0pUDqCZhrxoV5PaG2BjF4Mz8AwxEEbImg4xSXqXgmMYWloC1pp1VvkfkoTz5GlmDCXkGlg7H8Vtj+PSkAeH/Hf6x6YVZxylpRGL1Icu4VwnNFbUZ8lT6ibh9pxSuDKcqF2xPTMjeVSSm00+YfcvWyK/t3GXcHvYWB5AY+P0av32DUTvPWMEBAAA"
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE42TwU7DMAyG3yXniooJJtTbRFUkGDCN3hCHEFwaNXWixBFMaO+O6BCsLPW45OIv3x/ZzuOHIHgnUYgHayTKxSsg3WgSmXCSWlEIZWQIEPJx/aSl3ohMdBpfRHE6u9hmP6ZLawwo0hZLcMZuesA9n0YC30gFIU+BY/HsfJ4U37uvMxyxflOs0oMk69OiXY27XgGpduW1gjUEZzFA0nSIcdIr/fxmfTfEQy1Dt4Zp9RTMBVxHpwl8bTvAUpJMiv9CnHAZjV0oZSNSCSS1CWw7pnEu5FYj/c72rqrZjEmai1jF3jURlzKiall9kjymriIO7eS2N8Gx2g21/1zCNMrJ1bBUu49fW2v2XtxEHBob8gNobJyfbZ8+AWWuiIJlBAAA"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,9 @@
<!DOCTYPE html><html class="default" lang="en"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>solana-agent-kit</title><meta name="description" content="Documentation for solana-agent-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">solana-agent-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>solana-agent-kit</h1></div><div class="tsd-panel tsd-typography"><div align="center">
<a id="md:solana-agent-kit" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Solana Agent Kit<a href="#md:solana-agent-kit" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1></div>
<p><img src="https://github.com/user-attachments/assets/cfa380f6-79d9-474d-9852-3e1976c6de70" alt="Solana Agent Kit Cover 1 (3)"></p>
<a id="md:solana-agent-kit" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Solana Agent Kit<a href="#md:solana-agent-kit" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p><img src="https://github.com/user-attachments/assets/cfa380f6-79d9-474d-9852-3e1976c6de70" alt="Solana Agent Kit Cover 1 (3)"></p>
<p><img src="https://img.shields.io/npm/dm/solana-agent-kit?style=for-the-badge" alt="NPM Downloads">
<img src="https://img.shields.io/github/forks/sendaifun/solana-agent-kit?style=for-the-badge" alt="GitHub forks">
<img src="https://img.shields.io/github/license/sendaifun/solana-agent-kit?style=for-the-badge" alt="GitHub License"></p>
</div>
<p>An open-source toolkit for connecting AI agents to Solana protocols. Now, any agent, using any model can autonomously perform 15+ Solana actions:</p>
<ul>
<li>Trade tokens</li>
@@ -38,21 +41,29 @@
<li>Jupiter Exchange swaps</li>
<li>Launch on Pump via PumpPortal</li>
<li>Raydium pool creation (CPMM, CLMM, AMMv4)</li>
<li>Orca whirlpool integration</li>
<li>Orca Whirlpool integration</li>
<li>Meteora Dynamic AMM, DLMM Pool, and Alpga Vault</li>
<li>Openbook market creation</li>
<li>Register and Resolve SNS</li>
<li>Jito Bundles</li>
<li>Pyth Price feeds for fetching Asset Prices</li>
<li>Register/resolve Alldomains</li>
</ul>
</li>
<li>
<p><strong>Solana Blinks</strong></p>
<ul>
<li>Lending by Lulo</li>
<li>Lending by Lulon (Best APR for USDC)</li>
<li>Send Arcade Games</li>
<li>JupSOL staking</li>
</ul>
</li>
<li>
<p><strong>Non-Financial Actions</strong></p>
<ul>
<li>Gib Work for registering bounties</li>
</ul>
</li>
</ul>
<a id="md:🤖-ai-integration-features" class="tsd-anchor"></a><h2 class="tsd-anchor-link">🤖 AI Integration Features<a href="#md:🤖-ai-integration-features" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
<li>
@@ -123,6 +134,6 @@
</ul>
<a id="md:contributing" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Contributing<a href="#md:contributing" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Contributions are welcome! Please feel free to submit a Pull Request.
Refer to <a href="media/CONTRIBUTING.md">CONTRIBUTING.md</a> for detailed guidelines on how to contribute to this project.</p>
<a id="md:license" class="tsd-anchor"></a><h2 class="tsd-anchor-link">License<a href="#md:license" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>MIT License</p>
<a id="md:license" class="tsd-anchor"></a><h2 class="tsd-anchor-link">License<a href="#md:license" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Apache-2 License</p>
<a id="md:security" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Security<a href="#md:security" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>This toolkit handles private keys and transactions. Always ensure you're using it in a secure environment and never share your private keys.</p>
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:solana-agent-kit"><span>Solana <wbr/>Agent <wbr/>Kit</span></a><ul><li><a href="#md:🔧-core-blockchain-features"><span>🔧 <wbr/>Core <wbr/>Blockchain <wbr/>Features</span></a></li><li><a href="#md:🤖-ai-integration-features"><span>🤖 AI <wbr/>Integration <wbr/>Features</span></a></li><li><a href="#md:📦-installation"><span>📦 <wbr/>Installation</span></a></li><li><a href="#md:quick-start"><span>Quick <wbr/>Start</span></a></li><li><a href="#md:usage-examples"><span>Usage <wbr/>Examples</span></a></li><li><ul><li><a href="#md:deploy-a-new-token"><span>Deploy a <wbr/>New <wbr/>Token</span></a></li><li><a href="#md:create-nft-collection"><span>Create NFT <wbr/>Collection</span></a></li><li><a href="#md:swap-tokens"><span>Swap <wbr/>Tokens</span></a></li><li><a href="#md:lend-tokens"><span>Lend <wbr/>Tokens</span></a></li><li><a href="#md:stake-sol"><span>Stake SOL</span></a></li><li><a href="#md:send-an-spl-token-airdrop-via-zk-compression"><span>Send an SPL <wbr/>Token <wbr/>Airdrop via ZK <wbr/>Compression</span></a></li><li><a href="#md:fetch-price-data-from-pyth"><span>Fetch <wbr/>Price <wbr/>Data from <wbr/>Pyth</span></a></li></ul></li><li><a href="#md:dependencies"><span>Dependencies</span></a></li><li><a href="#md:contributing"><span>Contributing</span></a></li><li><a href="#md:license"><span>License</span></a></li><li><a href="#md:security"><span>Security</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-1"></use></svg><span>solana-agent-kit</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -3,6 +3,7 @@
<a href="interfaces/CollectionOptions.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Collection<wbr/>Options</span></a>
<a href="interfaces/Creator.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Creator</span></a>
<a href="interfaces/FetchPriceResponse.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Fetch<wbr/>Price<wbr/>Response</span></a>
<a href="interfaces/GibworkCreateTaskReponse.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Gibwork<wbr/>Create<wbr/>Task<wbr/>Reponse</span></a>
<a href="interfaces/JupiterTokenData.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Jupiter<wbr/>Token<wbr/>Data</span></a>
<a href="interfaces/LuloAccountDetailsResponse.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Lulo<wbr/>Account<wbr/>Details<wbr/>Response</span></a>
<a href="interfaces/MintCollectionNFTResponse.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Mint<wbr/>CollectionNFTResponse</span></a>

View File

@@ -0,0 +1,4 @@
OPENAI_API_KEY=
RPC_URL=
SOLANA_PRIVATE_KEY=
TAVILY_API_KEY= #Optional: for search functionality

11
examples/agent-kit-langgraph/.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
# Dependencies
node_modules/
package-lock.json
# Environment variables
.env
.env.local
# Build output
dist/
build/

View File

@@ -0,0 +1,87 @@
# Agent Kit LangGraph Example
This example demonstrates how to build an advanced Solana agent using LangGraph and the Solana Agent Kit. It showcases a multi-agent system that can handle various Solana-related tasks through a directed workflow.
![Solana Agent Kit LangGraph Architecture](./assets/architecture.png)
## Features
- Multi-agent architecture using LangGraph's StateGraph
- Specialized agents for different tasks:
- General purpose agent for basic queries (with optional Tavily search integration)
- Transfer/Swap agent for transaction operations
- Read agent for blockchain data queries
- Manager agent for routing and orchestration
- Environment-based configuration
- TypeScript implementation with full type safety
## Prerequisites
- Node.js (v16 or higher)
- pnpm package manager
- Solana development environment
## Installation
1. Clone the repository and navigate to the example directory:
```bash
cd examples/agent-kit-langgraph
```
2. Install dependencies:
```bash
pnpm install
```
3. Configure environment variables:
```bash
cp .env.example .env
```
Edit the `.env` file with your configuration:
- Add your OpenAI API key
- Add your Tavily API key (optional, enables web search capabilities)
- Configure any other required environment variables
## Project Structure
```
src/
├── agents/ # Individual agent implementations
├── helper/ # Helper utilities and examples
├── prompts/ # Agent prompts and templates
├── tools/ # Custom tools for agents
└── utils/ # Utility functions and configurations
```
## Usage
To run the example:
```bash
pnpm dev src/index.ts
```
The example demonstrates a workflow where:
1. The manager agent receives the initial query
2. Based on the query type, it routes to the appropriate specialized agent:
- General queries → Generalist Agent
- Transfer/Swap operations → TransferSwap Agent
- Blockchain data queries → Read Agent
## Dependencies
- `@langchain/community`: LangChain community tools and utilities
- Includes Tavily search integration for enhanced query responses
- `@langchain/core`: Core LangChain functionality
- `@langchain/langgraph`: Graph-based agent workflows
- `solana-agent-kit`: Solana Agent Kit for blockchain interactions
- `zod`: Runtime type checking
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
ISC License

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

View File

@@ -0,0 +1,9 @@
{
"node_version": "20",
"dockerfile_lines": [],
"dependencies": ["."],
"graphs": {
"solanaAgent": "./src/index.ts:graph"
},
"env": ".env"
}

View File

@@ -0,0 +1,31 @@
{
"name": "agent-kit-langgraph",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "tsx"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@langchain/community": "^0.3.20",
"@langchain/core": "^0.3.26",
"@langchain/langgraph": "^0.2.36",
"dotenv": "^16.4.7",
"solana-agent-kit": "^1.3.0",
"zod": "^3.24.1"
},
"devDependencies": {
"ts-node": "^10.9.2",
"tsx": "^4.19.2",
"typescript": "^5.0.0"
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
}

4462
examples/agent-kit-langgraph/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { gpt4o } from "../utils/model";
import { solanaAgentState } from "../utils/state";
import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
// Initialize tools array
const searchTools = [];
// Only add Tavily search if API key is available
if (process.env.TAVILY_API_KEY) {
searchTools.push(new TavilySearchResults());
}
const generalAgent = createReactAgent({
llm: gpt4o,
tools: searchTools,
});
export const generalistNode = async (state: typeof solanaAgentState.State) => {
const { messages } = state;
const result = await generalAgent.invoke({ messages });
return { messages: [...result.messages] };
};

View File

@@ -0,0 +1,23 @@
import { prompt, parser } from "../prompts/manager";
import { RunnableSequence } from "@langchain/core/runnables";
import { solanaAgentState } from "../utils/state";
import { gpt4o } from "../utils/model";
const chain = RunnableSequence.from([prompt, gpt4o, parser]);
export const managerNode = async (state: typeof solanaAgentState.State) => {
const { messages } = state;
const result = await chain.invoke({
formatInstructions: parser.getFormatInstructions(),
messages: messages,
});
const { isSolanaReadQuery, isSolanaWriteQuery, isGeneralQuery } = result;
return {
isSolanaReadQuery,
isSolanaWriteQuery,
isGeneralQuery,
};
};

View File

@@ -0,0 +1,22 @@
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { gpt4o } from "../utils/model";
import { solanaAgentState } from "../utils/state";
import { HumanMessage } from "@langchain/core/messages";
import { agentKit } from "../utils/solanaAgent";
import {
SolanaBalanceTool,
SolanaFetchPriceTool,
} from "solana-agent-kit/dist/langchain";
const readAgent = createReactAgent({
llm: gpt4o,
tools: [new SolanaBalanceTool(agentKit), new SolanaFetchPriceTool(agentKit)],
});
export const readNode = async (state: typeof solanaAgentState.State) => {
const { messages } = state;
const result = await readAgent.invoke({ messages });
return { messages: [...result.messages] };
};

View File

@@ -0,0 +1,25 @@
import { gpt4o } from "../utils/model";
import { agentKit } from "../utils/solanaAgent";
import { solanaAgentState } from "../utils/state";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { SolanaTransferTool } from "solana-agent-kit/dist/langchain";
import { transferSwapPrompt } from "../prompts/transferSwap";
import { swapTool } from "../tools/swap";
const transferOrSwapAgent = createReactAgent({
stateModifier: transferSwapPrompt,
llm: gpt4o,
tools: [new SolanaTransferTool(agentKit), swapTool],
});
export const transferSwapNode = async (
state: typeof solanaAgentState.State,
) => {
const { messages } = state;
const result = await transferOrSwapAgent.invoke({
messages,
});
return result;
};

View File

@@ -0,0 +1,9 @@
import { HumanMessage } from "@langchain/core/messages";
export const generalQuestion = [
new HumanMessage("Who is the president of Ecuador?"),
];
export const solanaReadQuery = [new HumanMessage("what is the price of SOL")];
export const solanaWriteQuery = [new HumanMessage("swap 0.1 usdc to sol")];

View File

@@ -0,0 +1,50 @@
export const tokenList = [
{
name: "USDC",
ticker: "USDC",
decimal: 6,
mintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
},
{
name: "USDT",
ticker: "USDT",
decimal: 6,
mintAddress: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
},
{
name: "USDS",
ticker: "USDS",
decimal: 6,
mintAddress: "USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA",
},
{
name: "SOL",
ticker: "SOL",
decimal: 9,
mintAddress: "So11111111111111111111111111111111111111112",
},
{
name: "jitoSOL",
ticker: "jitoSOL",
decimal: 9,
mintAddress: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
},
{
name: "bSOL",
ticker: "bSOL",
decimal: 9,
mintAddress: "bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1",
},
{
name: "mSOL",
ticker: "mSOL",
decimal: 9,
mintAddress: "mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
},
{
name: "BONK",
ticker: "BONK",
decimal: 9,
mintAddress: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
},
];

View File

@@ -0,0 +1,28 @@
import { StateGraph } from "@langchain/langgraph";
import { solanaAgentState } from "./utils/state";
import { generalistNode } from "./agents/generalAgent";
import { transferSwapNode } from "./agents/transferOrSwap";
import { managerNode } from "./agents/manager";
import { readNode } from "./agents/readAgent";
import { START, END } from "@langchain/langgraph";
import { managerRouter } from "./utils/route";
import { HumanMessage } from "@langchain/core/messages";
const workflow = new StateGraph(solanaAgentState)
.addNode("generalist", generalistNode)
.addNode("manager", managerNode)
.addNode("transferSwap", transferSwapNode)
.addNode("read", readNode)
.addEdge(START, "manager")
.addConditionalEdges("manager", managerRouter)
.addEdge("generalist", END)
.addEdge("transferSwap", END)
.addEdge("read", END);
export const graph = workflow.compile();
const result = await graph.invoke({
messages: [new HumanMessage("what is the price of SOL")],
});
console.log(result);

View File

@@ -0,0 +1,48 @@
import { StructuredOutputParser } from "@langchain/core/output_parsers";
import { z } from "zod";
import { PromptTemplate } from "@langchain/core/prompts";
export const parser = StructuredOutputParser.fromZodSchema(
z.object({
isSolanaReadQuery: z
.boolean()
.describe("Query requires reading data from Solana blockchain"),
isSolanaWriteQuery: z
.boolean()
.describe("Query requires writing/modifying data on Solana blockchain"),
isGeneralQuery: z
.boolean()
.describe("Query is about non-blockchain topics"),
}),
);
export const prompt = PromptTemplate.fromTemplate(
`
You are the Chief Routing Officer for a multi-blockchain agent network. Your role is to:
1. Analyze and classify incoming queries
2. Determine if the query requires Solana read operations, write operations, or is general
Format your response according to:
{formatInstructions}
Classification Guidelines:
- Solana Read Operations include:
* Checking account balances
* Viewing NFT metadata
* Getting program data
* Querying transaction history
* Checking token prices or holdings
- Solana Write Operations include:
* Creating or updating programs
* Sending tokens or SOL
* Minting NFTs
* Creating accounts
* Any transaction that modifies blockchain state
- General queries include:
* Non-blockchain topics
* Internet searches
* General knowledge questions
\n {messages} \n
`,
);

View File

@@ -0,0 +1,43 @@
import {
ChatPromptTemplate,
MessagesPlaceholder,
} from "@langchain/core/prompts";
import { tokenList } from "../helper/tokenList";
// Convert token list to a more readable format for the prompt
const formattedTokenList = tokenList
.map(
(token) =>
`- ${token.name} (${token.ticker}) - Decimals: ${token.decimal} - Address: ${token.mintAddress}`,
)
.join("\n ");
export const transferSwapPrompt = ChatPromptTemplate.fromMessages([
[
"system",
`You are an agent that is an expert in Solana transactions, specialized in token transfers and swaps. You can execute these transactions using the available tools based on user input.
When processing token amounts:
1. Use EXACTLY the decimal amount specified by the user without any modifications
2. Do not round or adjust the numbers
3. Maintain precise decimal places as provided in the user input
For transfers:
- User must specify the token, amount, and recipient address
- The same token will be used for input and output
For swaps:
- User must specify the input token, output token, and amount to swap
- Input and output tokens must be different
- Select tokens from this list of supported tokens:
${formattedTokenList}
Example amounts:
If you say "0.01 SOL", I will use exactly 0.01 (not 0.010 or 0.0100)
If you say "1.234 USDC", I will use exactly 1.234 (not 1.23 or 1.2340)
For swaps, have the slippage be 200 bps
`,
],
new MessagesPlaceholder("messages"),
]);

View File

@@ -0,0 +1,45 @@
import { agentKit } from "../utils/solanaAgent";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
import { PublicKey } from "@solana/web3.js";
export const swapTool = tool(
async ({ outputMint, inputAmount, inputMint, inputDecimal }) => {
try {
const inputAmountWithDecimals = inputAmount * 10 ** inputDecimal;
const outputMintAddress = new PublicKey(outputMint);
const inputMintAddress = new PublicKey(inputMint);
console.log(inputAmountWithDecimals, outputMintAddress, inputMintAddress);
const tx = await agentKit.trade(
outputMintAddress,
inputAmountWithDecimals,
inputMintAddress,
200,
);
return tx;
} catch (error) {
console.error(error);
return "error";
}
},
{
name: "swap",
description:
"call to swap/trade tokens from one token to the other using Jupiter exchange",
schema: z.object({
outputMint: z
.string()
.describe("The mint address of destination token to be swapped to"),
inputAmount: z
.number()
.describe(
"the input amount of the token to be swapped without adding any decimals",
),
inputMint: z.string().describe("The mint address of the origin token "),
inputDecimal: z
.number()
.describe("The decimal of the input token that is being traded"),
}),
},
);

View File

@@ -0,0 +1,12 @@
import { ChatOpenAI } from "@langchain/openai";
import "dotenv/config";
export const gpt4o = new ChatOpenAI({
modelName: "gpt-4o",
apiKey: process.env.OPENAI_API_KEY!,
});
export const gpt4oMini = new ChatOpenAI({
modelName: "gpt-4o-mini",
apiKey: process.env.OPENAI_API_KEY!,
});

View File

@@ -0,0 +1,16 @@
import { solanaAgentState } from "./state";
import { END } from "@langchain/langgraph";
export const managerRouter = (state: typeof solanaAgentState.State) => {
const { isSolanaReadQuery, isSolanaWriteQuery, isGeneralQuery } = state;
if (isGeneralQuery) {
return "generalist";
} else if (isSolanaWriteQuery) {
return "transferSwap";
} else if (isSolanaReadQuery) {
return "read";
} else {
return END;
}
};

View File

@@ -0,0 +1,9 @@
import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
export const agentKit = new SolanaAgentKit(
process.env.SOLANA_PRIVATE_KEY!,
process.env.RPC_URL!,
process.env.OPENAI_API_KEY!,
);
export const solanaTools = createSolanaTools(agentKit);

View File

@@ -0,0 +1,25 @@
import { Annotation } from "@langchain/langgraph";
import { BaseMessage } from "@langchain/core/messages";
import { messagesStateReducer } from "@langchain/langgraph";
export const solanaAgentState = Annotation.Root({
messages: Annotation<BaseMessage[]>({
reducer: messagesStateReducer,
default: () => [],
}),
isSolanaReadQuery: Annotation<boolean>({
reducer: (x, y) => y ?? x ?? false,
default: () => false,
}),
isSolanaWriteQuery: Annotation<boolean>({
reducer: (x, y) => y ?? x ?? false,
default: () => false,
}),
isGeneralQuery: Annotation<boolean>({
reducer: (x, y) => y ?? x ?? false,
default: () => false,
}),
});

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"outDir": "./dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}

View File

@@ -0,0 +1,4 @@
OPENAI_API_KEY=
RPC_URL=
SOLANA_PRIVATE_KEY=
POSTGRES_DB_URL=

View File

@@ -0,0 +1,66 @@
# Persistent Agent with PostgreSQL
This example showcases a persistent agent that retains memory across sessions using a PostgreSQL database. It ensures that the agent can remember previous conversations even after being restarted, enhancing the user experience in applications requiring long-term context retention.
[Reference](https://langchain-ai.github.io/langgraphjs/reference/classes/checkpoint_postgres.PostgresSaver.html)
## Key Features
- **Persistent Memory**: The agent stores chat history in a PostgreSQL database, allowing it to remember past interactions across sessions.
- **Seamless Integration**: Designed to integrate smoothly with existing setups.
- **Scalable Solution**: Ideal for applications requiring long-term memory capabilities.
## Prerequisites
To use this feature, ensure you have the following:
1. **PostgreSQL Database URL**: Create and host ur PostgreSQL databse and enter the URL. It will be of the format "postgresql://user:password@localhost:5432/db"
## Before applying persistance
```
Available modes:
1. chat
- Interactive chat mode
2. auto
- Autonomous action mode
Choose a mode (enter number or name: 1
Starting chat mode... Type 'exit' to end.
Prompt: i am arpit
Hello Arpit! How can I assist you today?
Prompt: ^С
® arpitsingh Mac persistance-agent & ts-node index.ts
Starting Agent...
Available modes:
1. chat
- Interactive chat mode
2. auto
- Autonomous action mode
Choose a mode (enter number or name): 1
Starting chat mode... Type 'exit' to end.
Prompt: do u know my name
I don't know your name yet. If you'd like, you can share it.
```
## After applying persistence
```
Available modes:
1. chat
- Interactive chat mode
2. auto
- Autonomous action mode
Choose a mode (enter number or name: 1
Starting chat mode... Type 'exit' to end.
Prompt: i am arpit
Hello Arpit! How can I assist you today?
Prompt: ^С
® arpitsingh Mac persistance-agent & ts-node index.ts
Starting Agent...
Available modes:
1. chat
- Interactive chat mode
2. auto
- Autonomous action mode
Choose a mode (enter number or name): 1
Starting chat mode... Type 'exit' to end.
Prompt: do u know my name
Yes, you mentioned that your name is Arpit. How can I help you today?
```

View File

@@ -0,0 +1,220 @@
import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
import { HumanMessage } from "@langchain/core/messages";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatOpenAI } from "@langchain/openai";
import * as dotenv from "dotenv";
import * as fs from "fs";
import * as readline from "readline";
import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
dotenv.config();
const checkpointer = PostgresSaver.fromConnString(
process.env.POSTGRES_DB_URL!
);
function validateEnvironment(): void {
const missingVars: string[] = [];
const requiredVars = ["OPENAI_API_KEY", "RPC_URL", "SOLANA_PRIVATE_KEY", "POSTGRES_DB_URL"];
requiredVars.forEach((varName) => {
if (!process.env[varName]) {
missingVars.push(varName);
}
});
if (missingVars.length > 0) {
console.error("Error: Required environment variables are not set");
missingVars.forEach((varName) => {
console.error(`${varName}=your_${varName.toLowerCase()}_here`);
});
process.exit(1);
}
}
validateEnvironment();
const WALLET_DATA_FILE = "wallet_data.txt";
async function initializeAgent() {
try {
const llm = new ChatOpenAI({
modelName: "gpt-4o-mini",
temperature: 0.7,
});
let walletDataStr: string | null = null;
if (fs.existsSync(WALLET_DATA_FILE)) {
try {
walletDataStr = fs.readFileSync(WALLET_DATA_FILE, "utf8");
} catch (error) {
console.error("Error reading wallet data:", error);
}
}
const solanaAgent = new SolanaAgentKit(
process.env.SOLANA_PRIVATE_KEY!,
process.env.RPC_URL,
process.env.OPENAI_API_KEY!,
);
const tools = createSolanaTools(solanaAgent);
await checkpointer.setup();
const config = { configurable: { thread_id: "Solana Agent Kit!" } };
const agent = createReactAgent({
llm,
tools,
checkpointSaver: checkpointer,
messageModifier: `
You are a helpful agent that can interact onchain using the Solana Agent Kit. You are
empowered to interact onchain using your tools. If you ever need funds, you can request them from the
faucet. If not, you can provide your wallet details and request funds from the user. If there is a 5XX
(internal) HTTP error code, ask the user to try again later. If someone asks you to do something you
can't do with your currently available tools, you must say so, and encourage them to implement it
themselves using the Solana Agent Kit, recommend they go to https://www.solanaagentkit.xyz for more information. Be
concise and helpful with your responses. Refrain from restating your tools' descriptions unless it is explicitly requested.
`,
});
if (walletDataStr) {
fs.writeFileSync(WALLET_DATA_FILE, walletDataStr);
}
return { agent, config };
} catch (error) {
console.error("Failed to initialize agent:", error);
throw error;
}
}
async function runAutonomousMode(agent: any, config: any, interval = 10) {
console.log("Starting autonomous mode...");
while (true) {
try {
const thought =
"Be creative and do something interesting on the blockchain. " +
"Choose an action or set of actions and execute it that highlights your abilities.";
const stream = await agent.stream(
{ messages: [new HumanMessage(thought)] },
config,
);
for await (const chunk of stream) {
if ("agent" in chunk) {
console.log(chunk.agent.messages[0].content);
} else if ("tools" in chunk) {
console.log(chunk.tools.messages[0].content);
}
console.log("-------------------");
}
await new Promise((resolve) => setTimeout(resolve, interval * 1000));
} catch (error) {
if (error instanceof Error) {
console.error("Error:", error.message);
}
process.exit(1);
}
}
}
async function runChatMode(agent: any, config: any) {
console.log("Starting chat mode... Type 'exit' to end.");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const question = (prompt: string): Promise<string> =>
new Promise((resolve) => rl.question(prompt, resolve));
try {
while (true) {
const userInput = await question("\nPrompt: ");
if (userInput.toLowerCase() === "exit") {
break;
}
const stream = await agent.stream(
{ messages: [new HumanMessage(userInput)] },
config,
);
for await (const chunk of stream) {
if ("agent" in chunk) {
console.log(chunk.agent.messages[0].content);
} else if ("tools" in chunk) {
console.log(chunk.tools.messages[0].content);
}
console.log("-------------------");
}
}
} catch (error) {
if (error instanceof Error) {
console.error("Error:", error.message);
}
process.exit(1);
} finally {
rl.close();
}
}
async function chooseMode(): Promise<"chat" | "auto"> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const question = (prompt: string): Promise<string> =>
new Promise((resolve) => rl.question(prompt, resolve));
while (true) {
console.log("\nAvailable modes:");
console.log("1. chat - Interactive chat mode");
console.log("2. auto - Autonomous action mode");
const choice = (await question("\nChoose a mode (enter number or name): "))
.toLowerCase()
.trim();
rl.close();
if (choice === "1" || choice === "chat") {
return "chat";
} else if (choice === "2" || choice === "auto") {
return "auto";
}
console.log("Invalid choice. Please try again.");
}
}
async function main() {
try {
console.log("Starting Agent...");
const { agent, config } = await initializeAgent();
const mode = await chooseMode();
if (mode === "chat") {
await runChatMode(agent, config);
} else {
await runAutonomousMode(agent, config);
}
} catch (error) {
if (error instanceof Error) {
console.error("Error:", error.message);
}
process.exit(1);
}
}
if (require.main === module) {
main().catch((error) => {
console.error("Fatal error:", error);
process.exit(1);
});
}

View File

@@ -0,0 +1,16 @@
{
"name": "persistance-agent",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@langchain/langgraph-checkpoint-postgres": "^0.0.2",
"solana-agent-kit": "^1.3.0"
}
}

3095
examples/persistance-agent/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,7 @@ Extending the **Solana Agent Kit** with custom tools allows you to add specializ
Create a new TypeScript file in the `src/tools/` directory for your tool (e.g., `custom_tool.ts`).
### 2. Implement the Tool Class
> `src/langchain/index.ts`
```typescript:src/langchain/index.ts
import { Tool } from "langchain/tools";
import { SolanaAgentKit } from "../agent";
@@ -51,7 +51,7 @@ export class CustomTool extends Tool {
```
### 3. Add Supporting Functions to SolanaAgentKit
> `src/agent/index.ts`
```typescript:src/agent/index.ts
export class SolanaAgentKit {
// ... existing code ...
@@ -64,7 +64,7 @@ export class SolanaAgentKit {
```
### 4. Export the Tool
> `src/tools/index.ts`
```typescript:src/tools/index.ts
export * from "./request_faucet_funds";
export * from "./deploy_token";
@@ -72,7 +72,7 @@ export * from "./custom_tool"; // Add your new tool
```
### 5. Integrate with Agent
> `src/langchain/index.ts`
```typescript:src/langchain/index.ts
import { CustomTool } from "../tools/custom_tool";
@@ -104,6 +104,10 @@ if (customTool) {
const result = await customTool._call("your-input");
console.log(result);
}
// or alternatively
const result = await agent.customFunction("your-input"); // assuming you have a `customFunction` method in SolanaAgentKit
console.log(result);
```
## Best Practices
@@ -117,7 +121,7 @@ if (customTool) {
## Example: Token Price Fetching Tool
Here's a complete example of implementing a tool to fetch token prices:
> `src/tools/fetch_token_price.ts`
```typescript:src/tools/fetch_token_price.ts
import { Tool } from "langchain/tools";
import { SolanaAgentKit } from "../agent";
@@ -150,7 +154,7 @@ export class FetchTokenPriceTool extends Tool {
```
Add the supporting function to SolanaAgentKit:
> `src/agent/index.ts`
```typescript:src/agent/index.ts
export class SolanaAgentKit {
async getTokenPrice(tokenSymbol: string): Promise<number> {
@@ -170,6 +174,21 @@ export class SolanaAgentKit {
}
```
Then it can be used as such:
```typescript
import { SolanaAgentKit } from "solana-agent-kit";
const agent = new SolanaAgentKit(
"your-wallet-private-key-as-base58",
"https://api.mainnet-beta.solana.com",
"your-openai-api-key"
);
const result = await agent.getTokenPrice("SOL");
console.log(result);
```
## Need Help?
If you encounter any issues while implementing your custom tool:

View File

@@ -49,12 +49,12 @@ The project includes a test script located at `test/index.ts`. To execute the te
### Token Deployment
```typescript
import { deploy_token } from "solana-agent-kit";
import { SolanaAgentKit } from "solana-agent-kit";
const result = await deploy_token(
agent,
9, // decimals
1000000 // initial supply
const agent = new SolanaAgentKit("your_private_key");
const result = await agent.deployToken(
9, // decimals
);
console.log("Token Mint Address:", result.mint.toString());
@@ -62,9 +62,11 @@ console.log("Token Mint Address:", result.mint.toString());
### NFT Collection Creation
```typescript
import { deploy_collection } from "solana-agent-kit";
import { SolanaAgentKit } from "solana-agent-kit";
const collection = await deploy_collection(agent, {
const agent = new SolanaAgentKit("your_private_key");
const collection = await agent.deployCollection({
name: "My NFT Collection",
uri: "https://arweave.net/metadata.json",
royaltyBasisPoints: 500, // 5%

View File

@@ -23,9 +23,9 @@
"dependencies": {
"@bonfida/spl-name-service": "^3.0.7",
"@coral-xyz/anchor": "0.29",
"@langchain/core": "^0.3.18",
"@langchain/core": "^0.3.26",
"@langchain/groq": "^0.1.2",
"@langchain/langgraph": "^0.2.27",
"@langchain/langgraph": "^0.2.34",
"@langchain/openai": "^0.3.13",
"@lightprotocol/compressed-token": "^0.17.1",
"@lightprotocol/stateless.js": "^0.17.1",
@@ -42,6 +42,7 @@
"@raydium-io/raydium-sdk-v2": "0.1.95-alpha",
"@solana/spl-token": "^0.4.9",
"@solana/web3.js": "^1.95.4",
"@tiplink/api": "^0.3.1",
"bn.js": "^5.2.1",
"bs58": "^6.0.0",
"chai": "^5.1.2",
@@ -56,13 +57,13 @@
"@types/bn.js": "^5.1.5",
"@types/chai": "^5.0.1",
"@types/node": "^22.9.0",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"prettier": "^3.2.5"
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
}
}

217
pnpm-lock.yaml generated
View File

@@ -15,13 +15,13 @@ importers:
specifier: '0.29'
version: 0.29.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@langchain/core':
specifier: ^0.3.18
specifier: ^0.3.26
version: 0.3.26(openai@4.77.0(zod@3.24.1))
'@langchain/groq':
specifier: ^0.1.2
version: 0.1.2(@langchain/core@0.3.26(openai@4.77.0(zod@3.24.1)))
'@langchain/langgraph':
specifier: ^0.2.27
specifier: ^0.2.34
version: 0.2.34(@langchain/core@0.3.26(openai@4.77.0(zod@3.24.1)))
'@langchain/openai':
specifier: ^0.3.13
@@ -71,6 +71,9 @@ importers:
'@solana/web3.js':
specifier: ^1.95.4
version: 1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@tiplink/api':
specifier: ^0.3.1
version: 0.3.1(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(sodium-native@3.4.1)(utf-8-validate@5.0.10)
bn.js:
specifier: ^5.2.1
version: 5.2.1
@@ -578,6 +581,12 @@ packages:
peerDependencies:
'@solana/web3.js': ^1.95.3
'@solana/spl-token@0.3.11':
resolution: {integrity: sha512-bvohO3rIMSVL24Pb+I4EYTJ6cL82eFpInEXD/I8K8upOGjpqHsKUoAempR/RnUlI1qSFNyFlWJfu6MNUgfbCQQ==}
engines: {node: '>=16'}
peerDependencies:
'@solana/web3.js': ^1.88.0
'@solana/spl-token@0.4.6':
resolution: {integrity: sha512-1nCnUqfHVtdguFciVWaY/RKcQz1IF4b31jnKgAmjU9QVN1q7dRUkTEWJZgTYIEtsULjVnC9jRqlhgGN39WbKKA==}
engines: {node: '>=16'}
@@ -609,6 +618,9 @@ packages:
'@swc/helpers@0.5.15':
resolution: {integrity: sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==}
'@tiplink/api@0.3.1':
resolution: {integrity: sha512-HjnXethjKOHTYT0IP1BewlMS7wZJ+hsoDgRa6jA1cNvxvwQjE1WHOyvOUPpAi+DJDw4P4/omFtyHr7dwLfnB/g==}
'@tsconfig/node10@1.0.11':
resolution: {integrity: sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==}
@@ -822,6 +834,10 @@ packages:
base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
big-integer@1.6.52:
resolution: {integrity: sha512-QxD8cf2eVqJOOz63z6JIN9BzvVs/dlySa5HGSBH5xtR8dPteIRQnBxxKqkNTiT6jbDTF6jAfrd4oMcND9RGbQg==}
engines: {node: '>=0.6'}
big.js@6.2.2:
resolution: {integrity: sha512-y/ie+Faknx7sZA5MfGA2xKlu0GDv8RWrXGsmlteyJQ2lvoKv9GBK/fpRMc2qlSoBAgNxrixICFCBefIq8WCQpQ==}
@@ -870,6 +886,9 @@ packages:
resolution: {integrity: sha512-kWSuLN694+KTk8SrYvCqwP2WcgQjoRCiF5b4QDvkkz8EmgD+aWAIceGFKMIAdmF/pH+vpgNV3d3kAKorcdAmWA==}
engines: {node: '>=4.5'}
buffer@5.7.1:
resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==}
buffer@6.0.3:
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
@@ -1352,6 +1371,9 @@ packages:
resolution: {integrity: sha512-p3EcsicXjit7SaskXHs1hA91QxgTw46Fv6EFKKGS5DRFLD8yKnohjF3hxoju94b/OcMZoQukzpPpBE9uLVKzgQ==}
engines: {node: '>= 0.4'}
is-typedarray@1.0.0:
resolution: {integrity: sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==}
isexe@2.0.0:
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
@@ -1464,6 +1486,18 @@ packages:
resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==}
engines: {node: '>= 0.8.0'}
libsodium-sumo@0.7.15:
resolution: {integrity: sha512-5tPmqPmq8T8Nikpm1Nqj0hBHvsLFCXvdhBFV7SGOitQPZAA6jso8XoL0r4L7vmfKXr486fiQInvErHtEvizFMw==}
libsodium-wrappers-sumo@0.7.15:
resolution: {integrity: sha512-aSWY8wKDZh5TC7rMvEdTHoyppVq/1dTSAeAR7H6pzd6QRT3vQWcT5pGwCotLcpPEOLXX6VvqihSPkpEhYAjANA==}
libsodium-wrappers@0.7.15:
resolution: {integrity: sha512-E4anqJQwcfiC6+Yrl01C1m8p99wEhLmJSs0VQqST66SbQXXBoaJY0pF4BNjRYa/sOQAxx6lXAaAFIlx+15tXJQ==}
libsodium@0.7.15:
resolution: {integrity: sha512-sZwRknt/tUpE2AwzHq3jEyUU5uvIZHtSssktXq7owd++3CSgn8RGrv6UZJJBpP7+iBghBqe7Z06/2M31rI2NKw==}
linkify-it@5.0.0:
resolution: {integrity: sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==}
@@ -1554,6 +1588,11 @@ packages:
resolution: {integrity: sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==}
hasBin: true
nanoid@3.3.8:
resolution: {integrity: sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==}
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
natural-compare@1.4.0:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
@@ -1669,6 +1708,9 @@ packages:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'}
poly1305-js@0.4.4:
resolution: {integrity: sha512-5B6/S+vg5AOr66wJDkh5LOpU/F3EKANDy4VXKsNZLXea1uCy6CiOWOZ3VhcC0nYdhE7vJUMcLxqcVlrv2g/+Rg==}
possible-typed-array-names@1.0.0:
resolution: {integrity: sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==}
engines: {node: '>= 0.4'}
@@ -1768,6 +1810,14 @@ packages:
snake-case@3.0.4:
resolution: {integrity: sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==}
sodium-native@3.4.1:
resolution: {integrity: sha512-PaNN/roiFWzVVTL6OqjzYct38NSXewdl2wz8SRB51Br/MLIJPrbM3XexhVWkq7D3UWMysfrhKVf1v1phZq6MeQ==}
sodium-plus@0.9.0:
resolution: {integrity: sha512-WWKxrd81qDL7C1A10yxNmZ135yovEZuIRnZ/BIf/FcajYBupbKbPdgzwlusPHLVxkMDDamcarq9PxxRBUSqpCw==}
peerDependencies:
sodium-native: ^3.2.0
space-separated-tokens@2.0.2:
resolution: {integrity: sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==}
@@ -1862,6 +1912,9 @@ packages:
tslib@2.8.1:
resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==}
tweetnacl-util@0.15.1:
resolution: {integrity: sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==}
tweetnacl@1.0.3:
resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==}
@@ -1873,6 +1926,9 @@ packages:
resolution: {integrity: sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==}
engines: {node: '>=10'}
typedarray-to-buffer@3.1.5:
resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==}
typedoc@0.26.11:
resolution: {integrity: sha512-sFEgRRtrcDl2FxVP58Ze++ZK2UQAEvtvvH8rRlig1Ja3o7dDaMHmaBfvJmdGnNEFaLTpQsN8dpvZaTqJSu/Ugw==}
engines: {node: '>= 18'}
@@ -1880,6 +1936,11 @@ packages:
peerDependencies:
typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x
typescript@4.9.5:
resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==}
engines: {node: '>=4.2.0'}
hasBin: true
typescript@5.7.2:
resolution: {integrity: sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==}
engines: {node: '>=14.17'}
@@ -2001,6 +2062,9 @@ packages:
utf-8-validate:
optional: true
xsalsa20@1.2.0:
resolution: {integrity: sha512-FIr/DEeoHfj7ftfylnoFt3rAIRoWXpx2AoDfrT2qD2wtp7Dp+COajvs/Icb7uHqRW9m60f5iXZwdsJJO3kvb7w==}
yaml@2.6.1:
resolution: {integrity: sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg==}
engines: {node: '>= 14'}
@@ -2514,6 +2578,11 @@ snapshots:
'@solana/errors': 2.0.0-preview.4(typescript@5.7.2)
typescript: 5.7.2
'@solana/codecs-core@2.0.0-rc.1(typescript@4.9.5)':
dependencies:
'@solana/errors': 2.0.0-rc.1(typescript@4.9.5)
typescript: 4.9.5
'@solana/codecs-core@2.0.0-rc.1(typescript@5.7.2)':
dependencies:
'@solana/errors': 2.0.0-rc.1(typescript@5.7.2)
@@ -2532,6 +2601,13 @@ snapshots:
'@solana/errors': 2.0.0-preview.4(typescript@5.7.2)
typescript: 5.7.2
'@solana/codecs-data-structures@2.0.0-rc.1(typescript@4.9.5)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-numbers': 2.0.0-rc.1(typescript@4.9.5)
'@solana/errors': 2.0.0-rc.1(typescript@4.9.5)
typescript: 4.9.5
'@solana/codecs-data-structures@2.0.0-rc.1(typescript@5.7.2)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@5.7.2)
@@ -2550,6 +2626,12 @@ snapshots:
'@solana/errors': 2.0.0-preview.4(typescript@5.7.2)
typescript: 5.7.2
'@solana/codecs-numbers@2.0.0-rc.1(typescript@4.9.5)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@4.9.5)
'@solana/errors': 2.0.0-rc.1(typescript@4.9.5)
typescript: 4.9.5
'@solana/codecs-numbers@2.0.0-rc.1(typescript@5.7.2)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@5.7.2)
@@ -2571,6 +2653,14 @@ snapshots:
fastestsmallesttextencoderdecoder: 1.0.22
typescript: 5.7.2
'@solana/codecs-strings@2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-numbers': 2.0.0-rc.1(typescript@4.9.5)
'@solana/errors': 2.0.0-rc.1(typescript@4.9.5)
fastestsmallesttextencoderdecoder: 1.0.22
typescript: 4.9.5
'@solana/codecs-strings@2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@5.7.2)
@@ -2600,6 +2690,17 @@ snapshots:
transitivePeerDependencies:
- fastestsmallesttextencoderdecoder
'@solana/codecs@2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-data-structures': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-numbers': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-strings': 2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)
'@solana/options': 2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)
typescript: 4.9.5
transitivePeerDependencies:
- fastestsmallesttextencoderdecoder
'@solana/codecs@2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@5.7.2)
@@ -2622,6 +2723,12 @@ snapshots:
commander: 12.1.0
typescript: 5.7.2
'@solana/errors@2.0.0-rc.1(typescript@4.9.5)':
dependencies:
chalk: 5.4.0
commander: 12.1.0
typescript: 4.9.5
'@solana/errors@2.0.0-rc.1(typescript@5.7.2)':
dependencies:
chalk: 5.4.0
@@ -2644,6 +2751,17 @@ snapshots:
transitivePeerDependencies:
- fastestsmallesttextencoderdecoder
'@solana/options@2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-data-structures': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-numbers': 2.0.0-rc.1(typescript@4.9.5)
'@solana/codecs-strings': 2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)
'@solana/errors': 2.0.0-rc.1(typescript@4.9.5)
typescript: 4.9.5
transitivePeerDependencies:
- fastestsmallesttextencoderdecoder
'@solana/options@2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)':
dependencies:
'@solana/codecs-core': 2.0.0-rc.1(typescript@5.7.2)
@@ -2688,6 +2806,14 @@ snapshots:
- fastestsmallesttextencoderdecoder
- typescript
'@solana/spl-token-metadata@0.1.6(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)':
dependencies:
'@solana/codecs': 2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)
'@solana/web3.js': 1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
transitivePeerDependencies:
- fastestsmallesttextencoderdecoder
- typescript
'@solana/spl-token-metadata@0.1.6(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)':
dependencies:
'@solana/codecs': 2.0.0-rc.1(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)
@@ -2696,6 +2822,20 @@ snapshots:
- fastestsmallesttextencoderdecoder
- typescript
'@solana/spl-token@0.3.11(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)(utf-8-validate@5.0.10)':
dependencies:
'@solana/buffer-layout': 4.0.1
'@solana/buffer-layout-utils': 0.2.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@solana/spl-token-metadata': 0.1.6(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)
'@solana/web3.js': 1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
buffer: 6.0.3
transitivePeerDependencies:
- bufferutil
- encoding
- fastestsmallesttextencoderdecoder
- typescript
- utf-8-validate
'@solana/spl-token@0.4.6(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.7.2)(utf-8-validate@5.0.10)':
dependencies:
'@solana/buffer-layout': 4.0.1
@@ -2793,6 +2933,26 @@ snapshots:
dependencies:
tslib: 2.8.1
'@tiplink/api@0.3.1(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(sodium-native@3.4.1)(utf-8-validate@5.0.10)':
dependencies:
'@coral-xyz/anchor': 0.29.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
'@solana/spl-token': 0.3.11(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@4.9.5)(utf-8-validate@5.0.10)
'@solana/web3.js': 1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)
bs58: 5.0.0
libsodium: 0.7.15
libsodium-wrappers-sumo: 0.7.15
nanoid: 3.3.8
sodium-plus: 0.9.0(sodium-native@3.4.1)
tweetnacl: 1.0.3
tweetnacl-util: 0.15.1
typescript: 4.9.5
transitivePeerDependencies:
- bufferutil
- encoding
- fastestsmallesttextencoderdecoder
- sodium-native
- utf-8-validate
'@tsconfig/node10@1.0.11': {}
'@tsconfig/node12@1.0.11': {}
@@ -3026,6 +3186,8 @@ snapshots:
base64-js@1.5.1: {}
big-integer@1.6.52: {}
big.js@6.2.2: {}
bigint-buffer@1.1.5:
@@ -3077,6 +3239,11 @@ snapshots:
buffer-layout@1.2.2: {}
buffer@5.7.1:
dependencies:
base64-js: 1.5.1
ieee754: 1.2.1
buffer@6.0.3:
dependencies:
base64-js: 1.5.1
@@ -3572,6 +3739,8 @@ snapshots:
dependencies:
which-typed-array: 1.1.18
is-typedarray@1.0.0: {}
isexe@2.0.0: {}
isomorphic-ws@4.0.1(ws@7.5.10(bufferutil@4.0.8)(utf-8-validate@5.0.10)):
@@ -3672,6 +3841,18 @@ snapshots:
prelude-ls: 1.2.1
type-check: 0.4.0
libsodium-sumo@0.7.15: {}
libsodium-wrappers-sumo@0.7.15:
dependencies:
libsodium-sumo: 0.7.15
libsodium-wrappers@0.7.15:
dependencies:
libsodium: 0.7.15
libsodium@0.7.15: {}
linkify-it@5.0.0:
dependencies:
uc.micro: 2.1.0
@@ -3765,6 +3946,8 @@ snapshots:
mustache@4.2.0: {}
nanoid@3.3.8: {}
natural-compare@1.4.0: {}
no-case@3.0.4:
@@ -3778,8 +3961,7 @@ snapshots:
dependencies:
whatwg-url: 5.0.0
node-gyp-build@4.8.4:
optional: true
node-gyp-build@4.8.4: {}
object-is@1.1.6:
dependencies:
@@ -3876,6 +4058,10 @@ snapshots:
picomatch@2.3.1: {}
poly1305-js@0.4.4:
dependencies:
big-integer: 1.6.52
possible-typed-array-names@1.0.0: {}
prelude-ls@1.2.1: {}
@@ -3970,6 +4156,19 @@ snapshots:
dot-case: 3.0.4
tslib: 2.8.1
sodium-native@3.4.1:
dependencies:
node-gyp-build: 4.8.4
sodium-plus@0.9.0(sodium-native@3.4.1):
dependencies:
buffer: 5.7.1
libsodium-wrappers: 0.7.15
poly1305-js: 0.4.4
sodium-native: 3.4.1
typedarray-to-buffer: 3.1.5
xsalsa20: 1.2.0
space-separated-tokens@2.0.2: {}
stringify-entities@4.0.4:
@@ -4052,6 +4251,8 @@ snapshots:
tslib@2.8.1: {}
tweetnacl-util@0.15.1: {}
tweetnacl@1.0.3: {}
type-check@0.4.0:
@@ -4060,6 +4261,10 @@ snapshots:
type-fest@0.20.2: {}
typedarray-to-buffer@3.1.5:
dependencies:
is-typedarray: 1.0.0
typedoc@0.26.11(typescript@5.7.2):
dependencies:
lunr: 2.3.9
@@ -4069,6 +4274,8 @@ snapshots:
typescript: 5.7.2
yaml: 2.6.1
typescript@4.9.5: {}
typescript@5.7.2: {}
uc.micro@2.1.0: {}
@@ -4180,6 +4387,8 @@ snapshots:
bufferutil: 4.0.8
utf-8-validate: 5.0.10
xsalsa20@1.2.0: {}
yaml@2.6.1: {}
yn@3.1.1: {}

View File

@@ -36,6 +36,8 @@ import {
getOwnedAllDomains,
resolveAllDomains,
create_gibwork_task,
rock_paper_scissor,
create_TipLink,
} from "../tools";
import {
CollectionDeployment,
@@ -345,4 +347,14 @@ export class SolanaAgentKit {
payer ? new PublicKey(payer) : undefined,
);
}
async rockPaperScissors(
amount: number,
choice: "rock" | "paper" | "scissors",
) {
return rock_paper_scissor(this, amount, choice);
}
async createTiplink(amount: number, splmintAddress?: PublicKey) {
return create_TipLink(this, amount, splmintAddress);
}
}

View File

@@ -1272,6 +1272,103 @@ export class SolanaCreateGibworkTask extends Tool {
}
}
export class SolanaRockPaperScissorsTool extends Tool {
name = "rock_paper_scissors";
description = `Play rock paper scissors to win SEND coins.
Inputs (input is a JSON string):
choice: string, either "rock", "paper", or "scissors" (required)
amount: number, amount of SOL to play with - must be 0.1, 0.01, or 0.005 SOL (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
private validateInput(input: any): void {
if (input.choice !== undefined) {
throw new Error("choice is required.");
}
if (
input.amount !== undefined &&
(typeof input.spaceKB !== "number" || input.spaceKB <= 0)
) {
throw new Error("amount must be a positive number when provided");
}
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = toJSON(input);
this.validateInput(parsedInput);
const result = await this.solanaKit.rockPaperScissors(
Number(parsedInput['"amount"']),
parsedInput['"choice"'].replace(/^"|"$/g, "") as
| "rock"
| "paper"
| "scissors",
);
return JSON.stringify({
status: "success",
message: result,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaTipLinkTool extends Tool {
name = "solana_tiplink";
description = `Create a TipLink for transferring SOL or SPL tokens.
Input is a JSON string with:
- amount: number (required) - Amount to transfer
- splmintAddress: string (optional) - SPL token mint address`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
if (!parsedInput.amount) {
throw new Error("Amount is required");
}
const amount = parseFloat(parsedInput.amount);
const splmintAddress = parsedInput.splmintAddress
? new PublicKey(parsedInput.splmintAddress)
: undefined;
const { url, signature } = await this.solanaKit.createTiplink(
amount,
splmintAddress,
);
return JSON.stringify({
status: "success",
url,
signature,
amount,
tokenType: splmintAddress ? "SPL" : "SOL",
message: `TipLink created successfully`,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export function createSolanaTools(solanaKit: SolanaAgentKit) {
return [
new SolanaBalanceTool(solanaKit),
@@ -1307,5 +1404,7 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaGetMainDomain(solanaKit),
new SolanaResolveAllDomainsTool(solanaKit),
new SolanaCreateGibworkTask(solanaKit),
new SolanaRockPaperScissorsTool(solanaKit),
new SolanaTipLinkTool(solanaKit),
];
}

View File

@@ -0,0 +1,112 @@
import { TipLink } from "@tiplink/api";
import {
Transaction,
SystemProgram,
LAMPORTS_PER_SOL,
sendAndConfirmTransaction,
PublicKey,
ComputeBudgetProgram,
} from "@solana/web3.js";
import {
getAssociatedTokenAddress,
createTransferInstruction,
getMint,
createAssociatedTokenAccountInstruction,
} from "@solana/spl-token";
import { SolanaAgentKit } from "../index";
const MINIMUM_SOL_BALANCE = 0.003 * LAMPORTS_PER_SOL;
export async function create_TipLink(
agent: SolanaAgentKit,
amount: number,
splmintAddress?: PublicKey,
): Promise<{ url: string; signature: string }> {
try {
const tiplink = await TipLink.create();
if (!splmintAddress) {
const transaction = new Transaction();
transaction.add(
SystemProgram.transfer({
fromPubkey: agent.wallet_address,
toPubkey: tiplink.keypair.publicKey,
lamports: amount * LAMPORTS_PER_SOL,
}),
);
const signature = await sendAndConfirmTransaction(
agent.connection,
transaction,
[agent.wallet],
{ commitment: "confirmed" },
);
return {
url: tiplink.url.toString(),
signature,
};
} else {
const fromAta = await getAssociatedTokenAddress(
splmintAddress,
agent.wallet_address,
);
const toAta = await getAssociatedTokenAddress(
splmintAddress,
tiplink.keypair.publicKey,
);
const mintInfo = await getMint(agent.connection, splmintAddress);
const adjustedAmount = amount * Math.pow(10, mintInfo.decimals);
const transaction = new Transaction();
transaction.add(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 5000,
}),
);
transaction.add(
SystemProgram.transfer({
fromPubkey: agent.wallet_address,
toPubkey: tiplink.keypair.publicKey,
lamports: MINIMUM_SOL_BALANCE,
}),
);
transaction.add(
createAssociatedTokenAccountInstruction(
agent.wallet_address,
toAta,
tiplink.keypair.publicKey,
splmintAddress,
),
);
transaction.add(
createTransferInstruction(
fromAta,
toAta,
agent.wallet_address,
adjustedAmount,
),
);
const signature = await sendAndConfirmTransaction(
agent.connection,
transaction,
[agent.wallet],
{ commitment: "confirmed" },
);
return {
url: tiplink.url.toString(),
signature,
};
}
} catch (error: any) {
console.error("Error creating TipLink or sending funds:", error.message);
throw new Error(`Failed to create TipLink: ${error.message}`);
}
}

View File

@@ -38,3 +38,6 @@ export * from "./openbook_create_market";
export * from "./pyth_fetch_price";
export * from "./create_gibwork_task";
export * from "./rock_paper_scissor";
export * from "./create_tiplinks";

View File

@@ -0,0 +1,132 @@
import { sendAndConfirmTransaction, Transaction } from "@solana/web3.js";
import { SolanaAgentKit } from "../agent";
export async function rock_paper_scissor(
agent: SolanaAgentKit,
amount: number,
choice: "rock" | "paper" | "scissors",
) {
try {
const res = await fetch(
`https://rps.sendarcade.fun/api/actions/bot?amount=${amount}&choice=${choice}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
account: agent.wallet.publicKey.toBase58(),
}),
},
);
const data = await res.json();
if (data.transaction) {
const txn = Transaction.from(Buffer.from(data.transaction, "base64"));
txn.sign(agent.wallet);
txn.recentBlockhash = (
await agent.connection.getLatestBlockhash()
).blockhash;
const sig = await sendAndConfirmTransaction(
agent.connection,
txn,
[agent.wallet],
{ commitment: "confirmed" },
);
const href = data.links?.next?.href;
return await outcome(agent, sig, href);
} else {
return "failed";
}
} catch (error: any) {
console.error(error);
throw new Error(`RPS game failed: ${error.message}`);
}
}
async function outcome(
agent: SolanaAgentKit,
sig: string,
href: string,
): Promise<string> {
try {
const res = await fetch(
"https://rps.sendarcade.fun" + href, // href = /api/actions/outcome?id=...
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
account: agent.wallet.publicKey.toBase58(),
signature: sig,
}),
},
);
const data: any = await res.json();
const title = data.title;
if (title.startsWith("You lost")) {
return title;
}
const next_href = data.links?.actions?.[0]?.href;
return title + "\n" + (await won(agent, next_href));
} catch (error: any) {
console.error(error);
throw new Error(`RPS outcome failed: ${error.message}`);
}
}
async function won(agent: SolanaAgentKit, href: string): Promise<string> {
try {
const res = await fetch(
"https://rps.sendarcade.fun" + href, // href = /api/actions/won?id=...
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
account: agent.wallet.publicKey.toBase58(),
}),
},
);
const data: any = await res.json();
if (data.transaction) {
const txn = Transaction.from(Buffer.from(data.transaction, "base64"));
txn.partialSign(agent.wallet);
await agent.connection.sendRawTransaction(txn.serialize(), {
preflightCommitment: "confirmed",
});
} else {
return "Failed to claim prize.";
}
const next_href = data.links?.next?.href;
return await postWin(agent, next_href);
} catch (error: any) {
console.error(error);
throw new Error(`RPS outcome failed: ${error.message}`);
}
}
async function postWin(agent: SolanaAgentKit, href: string): Promise<string> {
try {
const res = await fetch(
"https://rps.sendarcade.fun" + href, // href = /api/actions/postwin?id=...
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
account: agent.wallet.publicKey.toBase58(),
}),
},
);
const data: any = await res.json();
const title = data.title;
return "Prize claimed Successfully" + "\n" + title;
} catch (error: any) {
console.error(error);
throw new Error(`RPS outcome failed: ${error.message}`);
}
}