Merge branch 'main' into calintje/main

This commit is contained in:
aryan
2024-12-20 19:16:08 +05:30
37 changed files with 1798 additions and 568 deletions

View File

@@ -1,3 +1,3 @@
OPENAI_API_KEY=
HELIUS_API_KEY=
SOLANA_PRIVATE_KEY=
RPC_URL=
SOLANA_PRIVATE_KEY=

View File

@@ -44,9 +44,9 @@ import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
// Initialize with private key and optional RPC URL
const agent = new SolanaAgentKit(
"your-wallet-private-key-as-base58",
"https://api.mainnet-beta.solana.com",
"your-openai-api-key"
"your-wallet-private-key-as-base58",
"https://api.mainnet-beta.solana.com",
"your-openai-api-key"
);
// Create LangChain tools
@@ -61,9 +61,9 @@ const tools = createSolanaTools(agent);
import { deploy_token } from "solana-agent-kit";
const result = await deploy_token(
agent,
9, // decimals
1000000 // initial supply
agent,
9, // decimals
1000000 // initial supply
);
console.log("Token Mint Address:", result.mint.toString());
@@ -75,15 +75,15 @@ console.log("Token Mint Address:", result.mint.toString());
import { deploy_collection } from "solana-agent-kit";
const collection = await deploy_collection(agent, {
name: "My NFT Collection",
uri: "https://arweave.net/metadata.json",
royaltyBasisPoints: 500, // 5%
creators: [
{
address: "creator-wallet-address",
percentage: 100,
},
],
name: "My NFT Collection",
uri: "https://arweave.net/metadata.json",
royaltyBasisPoints: 500, // 5%
creators: [
{
address: "creator-wallet-address",
percentage: 100,
},
],
});
```
@@ -94,11 +94,11 @@ import { trade } from "solana-agent-kit";
import { PublicKey } from "@solana/web3.js";
const signature = await trade(
agent,
new PublicKey("target-token-mint"),
100, // amount
new PublicKey("source-token-mint"),
300 // 3% slippage
agent,
new PublicKey("target-token-mint"),
100, // amount
new PublicKey("source-token-mint"),
300 // 3% slippage
);
```
@@ -109,8 +109,8 @@ import { lendAsset } from "solana-agent-kit";
import { PublicKey } from "@solana/web3.js";
const signature = await lendAsset(
agent,
100 // amount
agent,
100 // amount
);
```
@@ -120,8 +120,8 @@ const signature = await lendAsset(
import { stakeWithJup } from "solana-agent-kit";
const signature = await stakeWithJup(
agent,
1 // amount in SOL
agent,
1 // amount in SOL
);
```
@@ -131,20 +131,51 @@ const signature = await stakeWithJup(
import { fetchPrice } from "solana-agent-kit";
const price = await fetchPrice(
agent,
"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN" // Token mint address
agent,
"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN" // Token mint address
);
console.log("Price in USDC:", price);
```
### Send an SPL Token Airdrop via ZK Compression
```typescript
import {
sendCompressedAirdrop,
getAirdropCostEstimate,
} from "solana-agent-kit";
import { PublicKey } from "@solana/web3.js";
(async () => {
console.log(
"~Airdrop cost estimate:",
getAirdropCostEstimate(
1000, // recipients
30_000 // priority fee in lamports
)
);
const signature = await sendCompressedAirdrop(
agent,
new PublicKey("JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"), // mint
42, // amount per recipient
[
new PublicKey("1nc1nerator11111111111111111111111111111111"),
// ... add more recipients
],
30_000 // priority fee in lamports
);
})();
```
## API Reference
### Core Functions
#### `deploy_token(agent, decimals?, initialSupply?)`
#### `deploy_token(agent, decimals?, name, uri, symbol, initialSupply?)`
Deploy a new SPL token with optional initial supply.
Deploy a new SPL token with optional initial supply. If not specified, decimals default to 9.
#### `deploy_collection(agent, options)`
@@ -174,6 +205,10 @@ Lend idle assets to earn interest with Lulo.
Stake SOL with Jupiter to earn rewards.
#### `sendCompressedAirdrop(agent, mintAddress, amount, recipients, priorityFeeInLamports?, shouldLog?)`
Send an SPL token airdrop to many recipients at low cost via ZK Compression.
## Dependencies
The toolkit relies on several key Solana and Metaplex libraries:
@@ -181,7 +216,10 @@ The toolkit relies on several key Solana and Metaplex libraries:
- @solana/web3.js
- @solana/spl-token
- @metaplex-foundation/mpl-token-metadata
- @metaplex-foundation/mpl-core
- @metaplex-foundation/umi
- @lightprotocol/compressed-token
- @lightprotocol/stateless.js
## Contributing

View File

@@ -1 +0,0 @@
solanaagentkit.xyz

View File

@@ -1 +1 @@
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE4XSTUsDQQwG4P+S8+Ji0SJ7K5ZerB/o3sTDMGbdodlk2GRAkf53qRXt4nR6mUveeUJInj/B8N2ggSchx27xhmw3waCC6KyHBjw5VdR6Wj/rbSCoYBP4FZrz2dW2+pWuhQi9BeElRpKPAfnAC2w4ds6j1rngFJ5dzrPwfdy9ekL9SRXJEZ3JmIf2tdL3dSJZeC+JbYnmAukjahRWzIrH46Umt4Htb6i7VVvscTRdavGQhtglXrvEvi/y2eQpepW4lQ0W15bJlVi/Ww7uj7IVoQO0S/w9u9b/QlNxfrF9+QJeMbLbAQMAAA=="
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE4XTQUvDMBTA8e+Sc7E4dEhvw9KDzm1ob+IhxNc1LH0vJC+gyL67bBNdXfZ26SX//l4T0tcvxfDBqlIv5DTq2RqQHy2rQnnNvaqUcTpGiOV4/arnwalCbSy+q+p6crctfqV7cg4MW8IavKPPAfDIs8gQOm0glrlwDE9up1l46XfPeEH9qUQygGYKeeiwJr3eAJt+FayBZ4ieMEJWOs0k9CF5yxBa2gDWmnWW/B9J4Dw5mhlDCbkG1tZF8WvP59KQJ4v8d/SLphVnnK2lEas0+C7hXCc0vchny0t0k3B/nNLlynQSa3ZXCA6/TkvkjtAu4X7vsTyJxuL0Zvv2DYU9ByOnAwAA"

View File

@@ -1 +1 @@
window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE7Wb227jNhCG34W+FbLhQU7su2y3AYpu20U37Y0RBIxEe4XIkipRmwZB3r2gDtbQHDmUtb1KYHP+GXI+DSmSfiVl/lyR9eaVPCVZTNaUXQckk3tF1uRrnspM3uxUpn9NNAlIXaZkTaJUVpWqPthfX3zT+5QE/bdkTchb0KuGlB1UozyrdFlHOi99JBd2eyAfkEKWKtNupINjeskE9JypSCd55ut4aD7H77NMU+U1fotD0/n+HmQcl6qqJvgFJnP854XKZPIgi+Th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ylOoyME4c7+B7rfYVbfFDkYc9FL4ibU30Ir2oMSBgAI2qR+b5gqf7K7wASEBhPxYSOs0l+0mXdxu0pWHAxnQZQ667JfY4doASANglftVql6muYYEAgKICD9Eui3LstmyBLCBmEK/MWvPBUG3QDCctkbCs3tJpocKk201NvocTI3cb6Y1utnWipICFeqn0u62giIKMGB+o358cx0MPBh3P6n2QAJAAEpW6DdhwRuBoF8ggcxTqDuL3yo7VSAk7ldGu6rQlgj04QOJE36Jg5UGWXhwkEful8f+ZE8WVhIFKF3Cbybs71nH3T1rQCh4FKnf89P9KGHb/Chh2/4oYRAEwfmV1e6q4aO5alh0Vw0BJgBZ5sfscPwIxgxMRsKPEXAXAoQDWGOrruz40dtfaHm0528OljXcL5vt2k+aK8xPiVVvALV+0HZ3pQEPYKCo30Q73KECvQJp435pa479v7fH/iBxYHoVfkB1t/tBn8CjR/0eveEnEUAGLtX9cn643gZGBnSI+819R/MwAwrMT6H/DRcIA0QxQeIBeeuDGfKT6i+9gXBA2eAeab4PSJEUKk0yRdab+7e3/wDIrU8JNjgAAA==";
window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE7WcXXOcuBKG/wu+nXKiT2zf5eO4Kufk7KY22b2ZSrkwyBOOGWBBk+xsKv/9lGAYWqNm3JjsVVJjdfcr6VFLCInvUVN9a6Ob9ffoMS+z6Ibxq1VUJlsT3UQfqyIpk1cbU9r/5DZaRbumiG6itEja1rQv/D9ffrHbIloNf41uoujHavCqGD96Tauytc0utVVDcXnhlwfuV1GdNKa0odIxMHvJJYxcmtTmVUkNPBZfEvdbUhSG1H4Xx6LL490lWdaYtp0RF5gsiV/Vpkzyu6TO7x7NnhQ/MJkZn7+UI7eN+XNnWnub7FJjb3dlRmsD1GyJjszURbX/VD0aGnB++eWR31RFMYN3xGiJho2xr5MiKVNDiu4VXxJ3m5f2l9tPpKBj2SURbZOU7YOhpTNQeBnjm7y1pnlbbZOc1r+BybL4bVV8NR+rYpaCwGghYR+afJs0+xkaEKO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i+y0fvCozMHwYDav+lToYgYBMfnV4QKBlitOvpIDeBJ1Jc9UfJgYewFSkaCMR3uYF9QNUcLKj4HgVIAI4jGlt3q0q8nLXZqk3nEG2iWmgDld8HoyfXkBrSdrEfcjIfXpGUxboREnrRZjlkYcWAVATtGwxXBhIap8vsCRXtOeD4XMjyKoHdAOjkX/4Ns9D922eh/7bPIAQkDKI7roPkbRVgagDOZ8Rq9pfiL53F6Lrw4Vo0AsgZwgav+6rBenxqwXJ8NUCMMjgYyStCceLF6BbgRtFwxjcAgNVBMNByMNMQOuK4Srfvb9alKAXJK0X+kfbxH284TH3sjboAGL799+sAO0N+Oe0x5vhbB5IP0BHTBvgw7lv0GVgLa5pDdMfpgbDBVRG03SMV2FBF4HqSFq7donK30uKgZiYhkx3B+xrfwcMyAENo2hddPgkDxj7IAUzYsscv+cE3MDNGaKU4a4zGFSgQoK2EjpZLXLggdM8DB+gAzKAihku7pBHUzhp0lwNN6CBD9C2ktC2n1dRndemyEsT3aw///jxf5ujh0DzUAAA";

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

File diff suppressed because one or more lines are too long

View File

@@ -2,6 +2,8 @@
</div></section><section class="tsd-index-section"><h3 class="tsd-index-heading">Interfaces</h3><div class="tsd-index-list"><a href="interfaces/CollectionDeployment.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/>Deployment</span></a>
<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/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>
<a href="interfaces/PumpfunLaunchResponse.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>Pumpfun<wbr/>Launch<wbr/>Response</span></a>

179
guides/add_your_own_tool.md Normal file
View File

@@ -0,0 +1,179 @@
# How to Add Your Own Tool
Extending the **Solana Agent Kit** with custom tools allows you to add specialized functionalities tailored to your needs. This guide walks you through creating and integrating a new tool into the existing framework.
## Overview
1. Create a new tool file
2. Implement the tool class
3. Implement supporting functions in SolanaAgentKit
4. Export the new tool
5. Integrate the tool into the agent
6. Use the custom tool
## Implementation Guide
### 1. Create a New Tool File
Create a new TypeScript file in the `src/tools/` directory for your tool (e.g., `custom_tool.ts`).
### 2. Implement the Tool Class
```typescript:src/tools/custom_tool.ts
import { Tool } from "langchain/tools";
import { SolanaAgentKit } from "../agent";
export class CustomTool extends Tool {
name = "custom_tool";
description = "Description of what the custom tool does.";
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const result = await this.solanaKit.customFunction(input);
return JSON.stringify({
status: "success",
message: "Custom tool executed successfully",
data: result,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
```
### 3. Add Supporting Functions to SolanaAgentKit
```typescript:src/agent/index.ts
export class SolanaAgentKit {
// ... existing code ...
async customFunction(input: string): Promise<string> {
// Implement your custom functionality
return `Processed input: ${input}`;
}
}
```
### 4. Export the Tool
```typescript:src/tools/index.ts
export * from "./request_faucet_funds";
export * from "./deploy_token";
export * from "./custom_tool"; // Add your new tool
```
### 5. Integrate with Agent
```typescript:src/langchain/index.ts
import { CustomTool } from "../tools/custom_tool";
export function createSolanaTools(agent: SolanaAgentKit) {
return [
// ... existing tools ...
new CustomTool(agent),
];
}
```
### 6. Usage Example
```typescript
import { SolanaAgentKit, createSolanaTools } 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 tools = createSolanaTools(agent);
const customTool = tools.find(tool => tool.name === "custom_tool");
if (customTool) {
const result = await customTool._call("your-input");
console.log(result);
}
```
## Best Practices
- Implement robust error handling
- Add security checks for sensitive operations
- Document your tool's purpose and usage
- Write tests for reliability
- Keep tools focused on single responsibilities
## Example: Token Price Fetching Tool
Here's a complete example of implementing a tool to fetch token prices:
```typescript:src/tools/fetch_token_price.ts
import { Tool } from "langchain/tools";
import { SolanaAgentKit } from "../agent";
export class FetchTokenPriceTool extends Tool {
name = "fetch_token_price";
description = "Fetches the current price of a specified token.";
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(tokenSymbol: string): Promise<string> {
try {
const price = await this.solanaKit.getTokenPrice(tokenSymbol);
return JSON.stringify({
status: "success",
message: `Price fetched successfully for ${tokenSymbol}.`,
data: { token: tokenSymbol, price },
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
```
Add the supporting function to SolanaAgentKit:
```typescript:src/agent/index.ts
export class SolanaAgentKit {
async getTokenPrice(tokenSymbol: string): Promise<number> {
const mockPrices: { [key: string]: number } = {
SOL: 150,
USDC: 1,
USDT: 1,
BONK: 0.5,
};
if (!mockPrices[tokenSymbol.toUpperCase()]) {
throw new Error(`Price for token symbol ${tokenSymbol} not found.`);
}
return mockPrices[tokenSymbol.toUpperCase()];
}
}
```
## Need Help?
If you encounter any issues while implementing your custom tool:
- Open an issue in the repository
- Contact the maintainer
- Check existing tools for implementation examples
---

83
guides/setup_locally.md Normal file
View File

@@ -0,0 +1,83 @@
# How to Setup Locally
Setting up the **Solana Agent Kit** on your local machine involves cloning the repository, installing dependencies, configuring environment variables, and building the project. Follow the steps below to get started.
## Prerequisites
- **Node**: Ensure you have Node version 23.x or higher installed. You can download it from [Node Official Website](https://nodejs.org/).
- **Package Manager**: Node's package manager comes bundled with Node. Verify installation by running `npm -v`.
- **Git**: Ensure Git is installed and configured. Download from [Git Official Website](https://git-scm.com/).
## Step-by-Step Guide
1. **Clone the Repository**
```bash
git clone https://github.com/yourusername/solana-agent-kit.git
```
2. **Navigate to the Project Directory**
```bash
cd solana-agent-kit
```
3. **Install Dependencies**
The project uses `pnpm` for package management. Install all necessary dependencies by running:
```bash
pnpm install
```
4. **Configure Environment Variables**
Create a `.env` file in the root directory of the project to store your environment variables securely. This file should include the following variables:
```env
OPENAI_API_KEY=your_openai_api_key_here
RPC_URL=your_rpc_url
SOLANA_PRIVATE_KEY=your_solana_private_key_here
```
- **OPENAI_API_KEY**: Your OpenAI API key for generating images and interacting with OpenAI services.
- **RPC_URL**: Your RPC_URL for Solana blockchain interactions.
- **SOLANA_PRIVATE_KEY**: Your Solana wallet's private key in base58 format.
**Note:** Ensure that the `.env` file is added to `.gitignore` to prevent exposing sensitive information.
5. **Build the Project**
Compile the TypeScript code to JavaScript using the build script:
```bash
pnpm run build
```
This will generate the compiled files in the `dist/` directory.
6. **Generate Documentation (Optional)**
If you wish to generate the project documentation, use the following command:
```bash
pnpm run docs
```
The documentation will be available in the `docs/` directory.
---
**Additional Information:**
- **Git Configuration:** Ensure that Git is properly configured with your user name and email. You can set them using:
```bash
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
```
- **Verifying Installation:**
After installing dependencies and building the project, you can verify the installation by running:
```bash
pnpm run build
pnpm run test
```
Ensure that all tests pass successfully.
---

107
guides/test_it_out.md Normal file
View File

@@ -0,0 +1,107 @@
# How to Test It Out
Testing the **Solana Agent Kit** ensures that all functionalities are working as expected. You can run automated tests or interact with the agent in different modes to verify its operations.
## Running Automated Tests
The project includes a test script located at `test/index.ts`. To execute the tests:
1. **Ensure Dependencies are Installed**
- If you haven't installed the dependencies yet, refer to the [Setup Locally](./setup_locally.md) guide.
2. **Run the Test Script**
```bash
pnpm run test
```
This will run the `test/index.ts` script using `ts-node`. Ensure that your environment variables are correctly set in the `.env` file before running the tests.
## Interactive Modes
### Available Modes
1. **Chat Mode**
- Allows you to interact with the agent in a conversational manner.
2. **Autonomous Mode**
- Enables the agent to perform actions on the blockchain autonomously at regular intervals.
### Starting the Agent
1. **Launch the Agent**
```bash
pnpm start
```
2. **Select Your Mode**
- For Chat Mode: Enter `1` or `chat`
- For Autonomous Mode: Enter `2` or `auto`
### Using Each Mode
#### Chat Mode
- Start chatting by entering prompts after the `Prompt:` indicator
- Type `exit` to end the chat session
#### Autonomous Mode
- The agent executes predefined actions every 10 seconds
- Actions and outputs are displayed in the console
## Code Examples
### Token Deployment
```typescript
import { deploy_token } from "solana-agent-kit";
const result = await deploy_token(
agent,
9, // decimals
1000000 // initial supply
);
console.log("Token Mint Address:", result.mint.toString());
```
### NFT Collection Creation
```typescript
import { deploy_collection } from "solana-agent-kit";
const collection = await deploy_collection(agent, {
name: "My NFT Collection",
uri: "https://arweave.net/metadata.json",
royaltyBasisPoints: 500, // 5%
creators: [
{
address: "creator-wallet-address",
percentage: 100,
},
],
});
```
## Best Practices
### Environment Setup
- Verify `.env` file contains correct and secure values
- Ensure all required environment variables are set
### Testing
- Maintain comprehensive test coverage
- Monitor console logs during testing
- Clean up test assets after deployment
## Troubleshooting
### Test Failures
#### Missing Environment Variables
- **Issue:** Tests fail due to missing environment variables
- **Solution:** Check `.env` file for all required variables
#### Network Problems
- **Issue:** Network-related errors
- **Solution:** Verify internet connection and Solana RPC endpoint accessibility
### Agent Issues
#### Startup Problems
- **Issue:** Agent doesn't prompt for mode selection
- **Solution:** Verify successful build and dependency installation

View File

@@ -20,6 +20,8 @@
"@langchain/groq": "^0.1.2",
"@langchain/langgraph": "^0.2.27",
"@langchain/openai": "^0.3.13",
"@lightprotocol/compressed-token": "^0.17.1",
"@lightprotocol/stateless.js": "^0.17.1",
"@metaplex-foundation/mpl-core": "^1.1.1",
"@metaplex-foundation/mpl-token-metadata": "^3.3.0",
"@metaplex-foundation/umi": "^0.9.2",
@@ -39,6 +41,7 @@
},
"devDependencies": {
"@types/node": "^22.9.0",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
}
}
}

823
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -9,10 +9,15 @@ import {
transfer,
trade,
registerDomain,
resolveSolDomain,
getPrimaryDomain,
launchPumpFunToken,
lendAsset,
getTPS,
getTokenDataByAddress,
getTokenDataByTicker,
stakeWithJup,
sendCompressedAirdrop,
createOrcaSingleSidedWhirlpool,
FEE_TIERS
} from "../tools";
@@ -39,7 +44,7 @@ export class SolanaAgentKit {
constructor(
private_key: string,
rpc_url = "https://api.mainnet-beta.solana.com",
openai_api_key: string,
openai_api_key: string
) {
this.connection = new Connection(rpc_url);
this.wallet = Keypair.fromSecretKey(bs58.decode(private_key));
@@ -53,10 +58,13 @@ export class SolanaAgentKit {
}
async deployToken(
name: string,
uri: string,
symbol: string,
decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS,
// initialSupply?: number
initialSupply?: number
) {
return deploy_token(this, decimals);
return deploy_token(this, name, uri, symbol, decimals, initialSupply);
}
async deployCollection(options: CollectionOptions) {
@@ -70,7 +78,7 @@ export class SolanaAgentKit {
async mintNFT(
collectionMint: PublicKey,
metadata: Parameters<typeof mintCollectionNFT>[2],
recipient?: PublicKey,
recipient?: PublicKey
) {
return mintCollectionNFT(this, collectionMint, metadata, recipient);
}
@@ -83,11 +91,19 @@ export class SolanaAgentKit {
return registerDomain(this, name, spaceKB);
}
async resolveSolDomain(domain: string) {
return resolveSolDomain(this, domain);
}
async getPrimaryDomain(account: PublicKey) {
return getPrimaryDomain(this, account);
}
async trade(
outputMint: PublicKey,
inputAmount: number,
inputMint?: PublicKey,
slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS,
slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS
) {
return trade(this, outputMint, inputAmount, inputMint, slippageBps);
}
@@ -100,12 +116,20 @@ export class SolanaAgentKit {
return getTPS(this);
}
async getTokenDataByAddress(mint: string) {
return getTokenDataByAddress(new PublicKey(mint));
}
async getTokenDataByTicker(ticker: string) {
return getTokenDataByTicker(ticker);
}
async launchPumpFunToken(
tokenName: string,
tokenTicker: string,
description: string,
imageUrl: string,
options?: PumpFunTokenOptions,
options?: PumpFunTokenOptions
) {
return launchPumpFunToken(
this,
@@ -113,16 +137,33 @@ export class SolanaAgentKit {
tokenTicker,
description,
imageUrl,
options,
options
);
}
async stake(
amount: number,
) {
async stake(amount: number) {
return stakeWithJup(this, amount);
}
async sendCompressedAirdrop(
mintAddress: string,
amount: number,
decimals: number,
recipients: string[],
priorityFeeInLamports: number,
shouldLog: boolean
): Promise<string[]> {
return await sendCompressedAirdrop(
this,
new PublicKey(mintAddress),
amount,
decimals,
recipients.map((recipient) => new PublicKey(recipient)),
priorityFeeInLamports,
shouldLog
);
}
async createOrcaSingleSidedWhirlpool(
depositTokenAmount: BN,
depositTokenMint: PublicKey,

View File

@@ -90,38 +90,30 @@ export class SolanaTransferTool extends Tool {
export class SolanaDeployTokenTool extends Tool {
name = "solana_deploy_token";
description =
"Deploy a new SPL token. Input should be JSON string with: {decimals?: number, initialSupply?: number}";
description = `Deploy a new token on Solana blockchain.
Inputs (input is a JSON string):
name: string, eg "My Token" (required)
uri: string, eg "https://example.com/token.json" (required)
symbol: string, eg "MTK" (required)
decimals?: number, eg 9 (optional, defaults to 9)
initialSupply?: number, eg 1000000 (optional)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
private validateInput(input: any): void {
if (
input.decimals !== undefined &&
(typeof input.decimals !== "number" ||
input.decimals < 0 ||
input.decimals > 9)
) {
throw new Error(
"decimals must be a number between 0 and 9 when provided"
);
}
if (
input.initialSupply !== undefined &&
(typeof input.initialSupply !== "number" || input.initialSupply <= 0)
) {
throw new Error("initialSupply must be a positive number when provided");
}
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = toJSON(input);
this.validateInput(parsedInput);
const parsedInput = JSON.parse(input);
const result = await this.solanaKit.deployToken(parsedInput.decimals);
const result = await this.solanaKit.deployToken(
parsedInput.name,
parsedInput.uri,
parsedInput.symbol,
parsedInput.decimals,
parsedInput.initialSupply
);
return JSON.stringify({
status: "success",
@@ -141,57 +133,20 @@ export class SolanaDeployTokenTool extends Tool {
export class SolanaDeployCollectionTool extends Tool {
name = "solana_deploy_collection";
description =
"Deploy a new NFT collection. Input should be JSON with: {name: string, uri: string, royaltyBasisPoints?: number, creators?: Array<{address: string, percentage: number}>}";
description = `Deploy a new NFT collection on Solana blockchain.
Inputs (input is a JSON string):
name: string, eg "My Collection" (required)
uri: string, eg "https://example.com/collection.json" (required)
royaltyBasisPoints?: number, eg 500 for 5% (optional)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
private validateInput(input: any): void {
if (!input.name || typeof input.name !== "string") {
throw new Error("name is required and must be a string");
}
if (!input.uri || typeof input.uri !== "string") {
throw new Error("uri is required and must be a string");
}
if (
input.royaltyBasisPoints !== undefined &&
(typeof input.royaltyBasisPoints !== "number" ||
input.royaltyBasisPoints < 0 ||
input.royaltyBasisPoints > 10000)
) {
throw new Error(
"royaltyBasisPoints must be a number between 0 and 10000 when provided"
);
}
if (input.creators) {
if (!Array.isArray(input.creators)) {
throw new Error("creators must be an array when provided");
}
input.creators.forEach((creator: any, index: number) => {
if (!creator.address || typeof creator.address !== "string") {
throw new Error(
`creator[${index}].address is required and must be a string`
);
}
if (
typeof creator.percentage !== "number" ||
creator.percentage < 0 ||
creator.percentage > 100
) {
throw new Error(
`creator[${index}].percentage must be a number between 0 and 100`
);
}
});
}
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = toJSON(input);
this.validateInput(parsedInput);
const parsedInput = JSON.parse(input);
const result = await this.solanaKit.deployCollection(parsedInput);
@@ -213,50 +168,42 @@ export class SolanaDeployCollectionTool extends Tool {
export class SolanaMintNFTTool extends Tool {
name = "solana_mint_nft";
description =
"Mint a new NFT in a collection. Input should be JSON with: {collectionMint: string, metadata: {name: string, symbol: string, uri: string}, recipient?: string}";
description = `Mint a new NFT in a collection on Solana blockchain.
Inputs (input is a JSON string):
collectionMint: string, eg "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w" (required) - The address of the collection to mint into
name: string, eg "My NFT" (required)
uri: string, eg "https://example.com/nft.json" (required)
recipient?: string, eg "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u" (optional) - The wallet to receive the NFT, defaults to agent's wallet which is ${this.solanaKit.wallet_address.toString()}`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
private validateInput(input: any): void {
if (!input.collectionMint || typeof input.collectionMint !== "string") {
throw new Error("collectionMint is required and must be a string");
}
if (!input.metadata || typeof input.metadata !== "object") {
throw new Error("metadata is required and must be an object");
}
if (!input.metadata.name || typeof input.metadata.name !== "string") {
throw new Error("metadata.name is required and must be a string");
}
if (!input.metadata.symbol || typeof input.metadata.symbol !== "string") {
throw new Error("metadata.symbol is required and must be a string");
}
if (!input.metadata.uri || typeof input.metadata.uri !== "string") {
throw new Error("metadata.uri is required and must be a string");
}
if (input.recipient !== undefined && typeof input.recipient !== "string") {
throw new Error("recipient must be a string when provided");
}
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = toJSON(input);
this.validateInput(parsedInput);
const parsedInput = JSON.parse(input);
const result = await this.solanaKit.mintNFT(
new PublicKey(parsedInput.collectionMint),
parsedInput.metadata,
parsedInput.recipient ? new PublicKey(parsedInput.recipient) : undefined
{
name: parsedInput.name,
uri: parsedInput.uri,
},
parsedInput.recipient
? new PublicKey(parsedInput.recipient)
: this.solanaKit.wallet_address
);
return JSON.stringify({
status: "success",
message: "NFT minted successfully",
mintAddress: result.mint.toString(),
name: parsedInput.metadata.name,
metadata: {
name: parsedInput.name,
symbol: parsedInput.symbol,
uri: parsedInput.uri,
},
recipient: parsedInput.recipient || result.mint.toString(),
});
} catch (error: any) {
@@ -393,6 +340,70 @@ export class SolanaRegisterDomainTool extends Tool {
}
}
export class SolanaResolveDomainTool extends Tool {
name = "solana_resolve_domain";
description = `Resolve a .sol domain to a Solana PublicKey.
Inputs:
domain: string, eg "pumpfun.sol" or "pumpfun"(required)
`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const domain = input.trim();
const publicKey = await this.solanaKit.resolveSolDomain(domain);
return JSON.stringify({
status: "success",
message: "Domain resolved successfully",
publicKey: publicKey.toBase58(),
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaGetDomainTool extends Tool {
name = "solana_get_domain";
description = `Retrieve the .sol domain associated for a given account address.
Inputs:
account: string, eg "4Be9CvxqHW6BYiRAxW9Q3xu1ycTMWaL5z8NX4HR3ha7t" (required)
`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const account = new PublicKey(input.trim());
const domain = await this.solanaKit.getPrimaryDomain(account);
return JSON.stringify({
status: "success",
message: "Primary domain retrieved successfully",
domain,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaGetWalletAddressTool extends Tool {
name = "solana_get_wallet_address";
description = `Get the wallet address of the agent`;
@@ -634,6 +645,110 @@ export class SolanaFetchPriceTool extends Tool {
}
}
export class SolanaTokenDataTool extends Tool {
name = "solana_token_data";
description = `Get the token data for a given token mint address
Inputs: mintAddress is required.
mintAddress: string, eg "So11111111111111111111111111111111111111112" (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = input.trim();
const tokenData = await this.solanaKit.getTokenDataByAddress(parsedInput);
return JSON.stringify({
status: "success",
tokenData: tokenData,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaTokenDataByTickerTool extends Tool {
name = "solana_token_data_by_ticker";
description = `Get the token data for a given token ticker
Inputs: ticker is required.
ticker: string, eg "USDC" (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const ticker = input.trim();
const tokenData = await this.solanaKit.getTokenDataByTicker(ticker);
return JSON.stringify({
status: "success",
tokenData: tokenData,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaCompressedAirdropTool extends Tool {
name = "solana_compressed_airdrop";
description = `Airdrop SPL tokens with ZK Compression (also called as airdropping tokens)
Inputs (input is a JSON string):
mintAddress: string, the mint address of the token, e.g., "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN" (required)
amount: number, the amount of tokens to airdrop per recipient, e.g., 42 (required)
decimals: number, the decimals of the token, e.g., 6 (required)
recipients: string[], the recipient addresses, e.g., ["1nc1nerator11111111111111111111111111111111"] (required)
priorityFeeInLamports: number, the priority fee in lamports. Default is 30_000. (optional)
shouldLog: boolean, whether to log progress to stdout. Default is false. (optional)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
const txs = await this.solanaKit.sendCompressedAirdrop(
parsedInput.mintAddress,
parsedInput.amount,
parsedInput.decimals,
parsedInput.recipients,
parsedInput.priorityFeeInLamports || 30_000,
parsedInput.shouldLog || false
);
return JSON.stringify({
status: "success",
message: `Airdropped ${parsedInput.amount} tokens to ${parsedInput.recipients.length} recipients.`,
transactionHashes: txs,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaCreateSingleSidedWhirlpoolTool extends Tool {
name = "create_orca_single_sided_whirlpool";
description = `Create a single-sided Whirlpool with liquidity.
@@ -706,5 +821,10 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaTPSCalculatorTool(solanaKit),
new SolanaStakeTool(solanaKit),
new SolanaFetchPriceTool(solanaKit),
new SolanaResolveDomainTool(solanaKit),
new SolanaGetDomainTool(solanaKit),
new SolanaTokenDataTool(solanaKit),
new SolanaTokenDataByTickerTool(solanaKit),
new SolanaCompressedAirdropTool(solanaKit),
];
}

View File

@@ -243,7 +243,7 @@ export async function createOrcaSingleSidedWhirlpool(
const tickUpperInitializableIndex = TickUtil.getInitializableTickIndex(tickUpperIndex, tickSpacing);
if (!TickUtil.checkTickInBounds(tickLowerInitializableIndex) || !TickUtil.checkTickInBounds(tickUpperInitializableIndex)) throw Error('Prices out of bounds');
const increasLiquidityQuoteParam: IncreaseLiquidityQuoteParam = {
inputTokenAmount: BN(depositTokenAmount),
inputTokenAmount: new BN(depositTokenAmount),
inputTokenMint: depositTokenMint,
tokenMintA: mintA,
tokenMintB: mintB,

View File

@@ -1,9 +1,9 @@
import { SolanaAgentKit } from "../index";
import { createUmi, generateSigner, publicKey } from "@metaplex-foundation/umi";
import { createCollection, ruleSet } from "@metaplex-foundation/mpl-core";
import { mplTokenMetadata } from "@metaplex-foundation/mpl-token-metadata";
import { generateSigner, keypairIdentity, publicKey } from "@metaplex-foundation/umi";
import { createCollection, mplCore, ruleSet } from "@metaplex-foundation/mpl-core";
import { CollectionOptions, CollectionDeployment } from "../types";
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
import { fromWeb3JsKeypair, toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
/**
* Deploy a new NFT collection
@@ -17,7 +17,8 @@ export async function deploy_collection(
): Promise<CollectionDeployment> {
try {
// Initialize Umi
const umi = createUmi().use(mplTokenMetadata());
const umi = createUmi(agent.connection.rpcEndpoint).use(mplCore());
umi.use(keypairIdentity(fromWeb3JsKeypair(agent.wallet)));
// Generate collection signer
const collectionSigner = generateSigner(umi);
@@ -27,11 +28,11 @@ export async function deploy_collection(
address: publicKey(creator.address),
percentage: creator.percentage,
})) || [
{
address: publicKey(agent.wallet_address.toString()),
percentage: 100,
},
];
{
address: publicKey(agent.wallet_address.toString()),
percentage: 100,
},
];
// Create collection
const tx = await createCollection(umi, {

View File

@@ -1,57 +1,66 @@
import { SolanaAgentKit } from "../index";
import {
createInitializeMint2Instruction,
MINT_SIZE,
getMinimumBalanceForRentExemptAccount,
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import { Keypair, SystemProgram, Transaction } from "@solana/web3.js";
import { sendTx } from "../utils/send_tx";
import { PublicKey } from "@solana/web3.js";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { generateSigner, keypairIdentity } from "@metaplex-foundation/umi";
import { createFungible, mintV1, TokenStandard } from "@metaplex-foundation/mpl-token-metadata";
import { fromWeb3JsKeypair, fromWeb3JsPublicKey, toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
/**
* Deploy a new SPL token
* @param agent SolanaAgentKit instance
* @param name Name of the token
* @param uri URI for the token metadata
* @param symbol Symbol of the token
* @param decimals Number of decimals for the token (default: 9)
* @param initialSupply Initial supply to mint (optional)
* @returns Object containing token mint address and initial account (if supply was minted)
*/
export async function deploy_token(
agent: SolanaAgentKit,
decimals: number = 9
// initialSupply?: number
) {
name: string,
uri: string,
symbol: string,
decimals: number = 9,
initialSupply?: number
): Promise<{ mint: PublicKey }> {
try {
// Create new token mint
const lamports = await getMinimumBalanceForRentExemptAccount(
agent.connection
);
// Create UMI instance from agent
const umi = createUmi(agent.connection.rpcEndpoint)
umi.use(keypairIdentity(fromWeb3JsKeypair(agent.wallet)));
const mint = Keypair.generate();
let account_create_ix = SystemProgram.createAccount({
fromPubkey: agent.wallet_address,
newAccountPubkey: mint.publicKey,
lamports,
space: MINT_SIZE,
programId: TOKEN_PROGRAM_ID,
// Create new token mint
const mint = generateSigner(umi);
let builder = createFungible(umi, {
name,
uri,
symbol,
sellerFeeBasisPoints: {
basisPoints: 0n,
identifier: "%",
decimals: 2,
},
decimals,
mint,
});
let create_mint_ix = createInitializeMint2Instruction(
mint.publicKey,
decimals,
agent.wallet_address,
agent.wallet_address,
TOKEN_PROGRAM_ID
);
if (initialSupply) {
builder = builder.add(
mintV1(umi, {
mint: mint.publicKey,
tokenStandard: TokenStandard.Fungible,
tokenOwner: fromWeb3JsPublicKey(agent.wallet_address),
amount: initialSupply,
})
);
}
let tx = new Transaction().add(account_create_ix, create_mint_ix);
let hash = await sendTx(agent, tx, [mint]);
builder.sendAndConfirm(umi, { confirm: { commitment: 'finalized' } });
return {
mint: mint.publicKey,
mint: toWeb3JsPublicKey(mint.publicKey),
};
} catch (error: any) {
console.log(error);
throw new Error(`Token deployment failed: ${error.message}`);
}
}

View File

@@ -0,0 +1,37 @@
import { getPrimaryDomain as _getPrimaryDomain } from "@bonfida/spl-name-service";
import { PublicKey } from "@solana/web3.js";
import { SolanaAgentKit } from "../index";
/**
* Retrieves the primary .sol domain associated with a given Solana public key.
*
* This function queries the Bonfida SPL Name Service to get the primary .sol domain for
* a specified Solana public key. If the primary domain is stale or an error occurs during
* the resolution, it throws an error.
*
* @param agent SolanaAgentKit instance
* @param account The Solana public key for which to retrieve the primary domain
* @returns A promise that resolves to the primary .sol domain as a string
* @throws Error if the domain is stale or if the domain resolution fails
*/
export async function getPrimaryDomain(
agent: SolanaAgentKit,
account: PublicKey
): Promise<string> {
try {
const { reverse, stale } = await _getPrimaryDomain(
agent.connection,
account
);
if (stale) {
throw new Error(
`Primary domain is stale for account: ${account.toBase58()}`
);
}
return reverse;
} catch (error) {
throw new Error(
`Failed to get primary domain for account: ${account.toBase58()}`
);
}
}

View File

@@ -0,0 +1,68 @@
import { PublicKey } from "@solana/web3.js";
import { JupiterTokenData } from "../types";
export async function getTokenDataByAddress(
mint: PublicKey,
): Promise<JupiterTokenData | undefined> {
try {
if (!mint) {
throw new Error("Mint address is required");
}
const response = await fetch("https://tokens.jup.ag/tokens?tags=verified", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
const data = (await response.json()) as JupiterTokenData[];
const token = data.find((token: JupiterTokenData) => {
return token.address === mint.toBase58();
});
return token;
} catch (error: any) {
throw new Error(`Error fetching token data: ${error.message}`);
}
}
export async function getTokenAddressFromTicker(
ticker: string
): Promise<string | null> {
try {
const response = await fetch(
`https://api.dexscreener.com/latest/dex/search?q=${ticker}`
);
const data = await response.json();
if (!data.pairs || data.pairs.length === 0) {
return null;
}
// Filter for Solana pairs only and sort by FDV
let solanaPairs = data.pairs
.filter((pair: any) => pair.chainId === "solana")
.sort((a: any, b: any) => (b.fdv || 0) - (a.fdv || 0));
solanaPairs = solanaPairs.filter(
(pair: any) =>
pair.baseToken.symbol.toLowerCase() === ticker.toLowerCase()
);
// Return the address of the highest FDV Solana pair
return solanaPairs[0].baseToken.address;
} catch (error) {
console.error("Error fetching token address from DexScreener:", error);
return null;
}
}
export async function getTokenDataByTicker(
ticker: string
): Promise<JupiterTokenData | undefined> {
const address = await getTokenAddressFromTicker(ticker);
if (!address) {
throw new Error(`Token address not found for ticker: ${ticker}`);
}
return getTokenDataByAddress(new PublicKey(address));
}

View File

@@ -6,9 +6,14 @@ export * from "./mint_nft";
export * from "./transfer";
export * from "./trade";
export * from "./register_domain";
export * from "./resolve_sol_domain";
export * from "./get_primary_domain";
export * from "./launch_pumpfun_token";
export * from "./lend";
export * from "./get_tps";
export * from './stake_with_jup';
export * from "./get_token_data";
export * from "./stake_with_jup";
export * from "./fetch_price";
export * from "./send_compressed_airdrop";
export * from "./create_orca_single_sided_whirlpool";

View File

@@ -1,9 +1,9 @@
import { SolanaAgentKit } from "../index";
import { generateSigner } from '@metaplex-foundation/umi';
import { create } from '@metaplex-foundation/mpl-core';
import { generateSigner, keypairIdentity } from '@metaplex-foundation/umi';
import { create, mplCore } from '@metaplex-foundation/mpl-core';
import { fetchCollection } from '@metaplex-foundation/mpl-core';
import { PublicKey } from "@solana/web3.js";
import { fromWeb3JsPublicKey, toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
import { fromWeb3JsKeypair, fromWeb3JsPublicKey, toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { MintCollectionNFTResponse } from '../types';
@@ -20,7 +20,6 @@ export async function mintCollectionNFT(
collectionMint: PublicKey,
metadata: {
name: string;
symbol: string;
uri: string;
sellerFeeBasisPoints?: number;
creators?: Array<{
@@ -32,11 +31,12 @@ export async function mintCollectionNFT(
): Promise<MintCollectionNFTResponse> {
try {
// Create UMI instance from agent
const umi = createUmi(agent.connection)
const umi = createUmi(agent.connection.rpcEndpoint).use(mplCore());
umi.use(keypairIdentity(fromWeb3JsKeypair(agent.wallet)));
// Convert collection mint to UMI format
const umiCollectionMint = fromWeb3JsPublicKey(collectionMint);
// Fetch the existing collection
const collection = await fetchCollection(umi, umiCollectionMint);
@@ -48,8 +48,8 @@ export async function mintCollectionNFT(
asset: assetSigner,
collection: collection,
name: metadata.name,
uri: metadata.uri,
owner: fromWeb3JsPublicKey(recipient!)
uri: metadata.uri,
owner: fromWeb3JsPublicKey(recipient ?? agent.wallet.publicKey)
}).sendAndConfirm(umi);
return {

View File

@@ -0,0 +1,30 @@
import { resolve } from "@bonfida/spl-name-service";
import { PublicKey } from "@solana/web3.js";
import { SolanaAgentKit } from "../index";
/**
* Resolves a .sol domain to a Solana PublicKey.
*
* This function uses the Bonfida SPL Name Service to resolve a given .sol domain
* to the corresponding Solana PublicKey. The domain can be provided with or without
* the .sol suffix.
*
* @param agent SolanaAgentKit instance
* @param domain The .sol domain to resolve. This can be provided with or without the .sol TLD suffix
* @returns A promise that resolves to the corresponding Solana PublicKey
* @throws Error if the domain resolution fails
*/
export async function resolveSolDomain(
agent: SolanaAgentKit,
domain: string
): Promise<PublicKey> {
if (!domain || typeof domain !== "string") {
throw new Error("Invalid domain. Expected a non-empty string.");
}
try {
return await resolve(agent.connection, domain);
} catch (error) {
throw new Error(`Failed to resolve domain: ${domain}`);
}
}

View File

@@ -0,0 +1,306 @@
import {
AddressLookupTableAccount,
ComputeBudgetProgram,
Connection,
Keypair,
PublicKey,
TransactionInstruction,
} from "@solana/web3.js";
import { SolanaAgentKit } from "../agent/index.js";
import {
buildAndSignTx,
calculateComputeUnitPrice,
createRpc,
Rpc,
sendAndConfirmTx,
sleep,
} from "@lightprotocol/stateless.js";
import {
CompressedTokenProgram,
createTokenPool,
} from "@lightprotocol/compressed-token";
import { Account, getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
// arbitrary
const MAX_AIRDROP_RECIPIENTS = 1000;
const MAX_CONCURRENT_TXS = 30;
/**
* Estimate the cost of an airdrop in lamports.
* @param numberOfRecipients Number of recipients
* @param priorityFeeInLamports Priority fee in lamports
* @returns Estimated cost in lamports
*/
export const getAirdropCostEstimate = (
numberOfRecipients: number,
priorityFeeInLamports: number
) => {
const baseFee = 5000;
const perRecipientCompressedStateFee = 300;
const txsNeeded = Math.ceil(numberOfRecipients / 15);
const totalPriorityFees = txsNeeded * (baseFee + priorityFeeInLamports);
return (
perRecipientCompressedStateFee * numberOfRecipients + totalPriorityFees
);
};
/**
* Send airdrop with ZK Compressed Tokens.
* @param agent Agent
* @param mintAddress SPL Mint address
* @param amount Amount to send per recipient
* @param decimals Decimals of the token
* @param recipients Recipient wallet addresses (no ATAs)
* @param priorityFeeInLamports Priority fee in lamports
* @param shouldLog Whether to log progress to stdout. Defaults to false.
*/
export async function sendCompressedAirdrop(
agent: SolanaAgentKit,
mintAddress: PublicKey,
amount: number,
decimals: number,
recipients: PublicKey[],
priorityFeeInLamports: number,
shouldLog: boolean = false
): Promise<string[]> {
if (recipients.length > MAX_AIRDROP_RECIPIENTS) {
throw new Error(
`Max airdrop can be ${MAX_AIRDROP_RECIPIENTS} recipients at a time. For more scale, use open source ZK Compression airdrop tools such as https://github.com/helius-labs/airship.`
);
}
const url = agent.connection.rpcEndpoint;
if (url.includes("devnet")) {
throw new Error("Devnet is not supported for airdrop. Please use mainnet.");
}
if (!url.includes("helius")) {
console.warn(
"Warning: Must use RPC with ZK Compression support. Double check with your RPC provider if in doubt."
);
}
let sourceTokenAccount: Account;
try {
sourceTokenAccount = await getOrCreateAssociatedTokenAccount(
agent.connection,
agent.wallet,
mintAddress,
agent.wallet.publicKey
);
} catch (error) {
throw new Error(
"Source token account not found and failed to create it. Please add funds to your wallet and try again."
);
}
try {
await createTokenPool(
agent.connection as unknown as Rpc,
agent.wallet,
mintAddress
);
} catch (error: any) {
if (error.message.includes("already in use")) {
// skip
} else {
throw error;
}
}
return await processAll(
agent,
amount * 10 ** decimals,
mintAddress,
recipients,
priorityFeeInLamports,
shouldLog
);
}
async function processAll(
agent: SolanaAgentKit,
amount: number,
mint: PublicKey,
recipients: PublicKey[],
priorityFeeInLamports: number,
shouldLog: boolean
): Promise<string[]> {
const mintAddress = mint;
const payer = agent.wallet;
const sourceTokenAccount = await getOrCreateAssociatedTokenAccount(
agent.connection,
agent.wallet,
mintAddress,
agent.wallet.publicKey
);
const maxRecipientsPerInstruction = 5;
const maxIxs = 3; // empirically determined (as of 12/15/2024)
const lookupTableAddress = new PublicKey(
"9NYFyEqPkyXUhkerbGHXUXkvb4qpzeEdHuGpgbgpH1NJ"
);
const lookupTableAccount = (
await agent.connection.getAddressLookupTable(lookupTableAddress)
).value!;
const batches: PublicKey[][] = [];
for (
let i = 0;
i < recipients.length;
i += maxRecipientsPerInstruction * maxIxs
) {
batches.push(recipients.slice(i, i + maxRecipientsPerInstruction * maxIxs));
}
const instructionSets = await Promise.all(
batches.map(async (recipientBatch) => {
const instructions: TransactionInstruction[] = [
ComputeBudgetProgram.setComputeUnitLimit({ units: 500_000 }),
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: calculateComputeUnitPrice(
priorityFeeInLamports,
500_000
),
}),
];
const compressIxPromises = [];
for (
let i = 0;
i < recipientBatch.length;
i += maxRecipientsPerInstruction
) {
const batch = recipientBatch.slice(i, i + maxRecipientsPerInstruction);
compressIxPromises.push(
CompressedTokenProgram.compress({
payer: payer.publicKey,
owner: payer.publicKey,
source: sourceTokenAccount.address,
toAddress: batch,
amount: batch.map(() => amount),
mint: mintAddress,
})
);
}
const compressIxs = await Promise.all(compressIxPromises);
return [...instructions, ...compressIxs];
})
);
const url = agent.connection.rpcEndpoint;
const rpc = createRpc(url, url, url);
const results = [];
let confirmedCount = 0;
const totalBatches = instructionSets.length;
const renderProgressBar = (current: number, total: number) => {
const percentage = Math.floor((current / total) * 100);
const filled = Math.floor((percentage / 100) * 20);
const empty = 20 - filled;
const bar = "█".repeat(filled) + "░".repeat(empty);
return `Airdropped to ${Math.min(current * 15, recipients.length)}/${
recipients.length
} recipients [${bar}] ${percentage}%`;
};
const log = (message: string) => {
if (shouldLog && typeof process !== "undefined" && process.stdout) {
process.stdout.write(message);
}
};
for (let i = 0; i < instructionSets.length; i += MAX_CONCURRENT_TXS) {
const batchPromises = instructionSets
.slice(i, i + MAX_CONCURRENT_TXS)
.map((instructions, idx) =>
sendTransactionWithRetry(
rpc,
instructions,
payer,
lookupTableAccount,
i + idx
).then((signature) => {
confirmedCount++;
log("\r" + renderProgressBar(confirmedCount, totalBatches));
return signature;
})
);
const batchResults = await Promise.allSettled(batchPromises);
results.push(...batchResults);
}
log("\n");
const failures = results
.filter((r) => r.status === "rejected")
.map((r, idx) => ({
index: idx,
error: (r as PromiseRejectedResult).reason,
}));
if (failures.length > 0) {
throw new Error(
`Failed to process ${failures.length} batches: ${failures
.map((f) => f.error)
.join(", ")}`
);
}
return results.map((r) => (r as PromiseFulfilledResult<string>).value);
}
async function sendTransactionWithRetry(
connection: Rpc,
instructions: TransactionInstruction[],
payer: Keypair,
lookupTableAccount: AddressLookupTableAccount,
batchIndex: number
): Promise<string> {
const MAX_RETRIES = 3;
const INITIAL_BACKOFF = 500; // ms
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
try {
const { blockhash } = await connection.getLatestBlockhash();
const tx = buildAndSignTx(
instructions,
payer,
blockhash,
[],
[lookupTableAccount]
);
const signature = await sendAndConfirmTx(connection, tx);
return signature;
} catch (error: any) {
const isRetryable =
error.message?.includes("blockhash not found") ||
error.message?.includes("timeout") ||
error.message?.includes("rate limit") ||
error.message?.includes("too many requests");
if (!isRetryable || attempt === MAX_RETRIES - 1) {
throw new Error(
`Batch ${batchIndex} failed after ${attempt + 1} attempts: ${
error.message
}`
);
}
const backoff =
INITIAL_BACKOFF * Math.pow(2, attempt) * (0.5 + Math.random());
await sleep(backoff);
}
}
throw new Error("Unreachable");
}

View File

@@ -39,7 +39,6 @@ export interface PumpfunLaunchResponse {
error?: string;
}
/**
* Lulo Account Details response format
*/
@@ -55,6 +54,22 @@ export interface LuloAccountDetailsResponse {
};
}
export interface JupiterTokenData {
address: string;
name: string;
symbol: string;
decimals: number;
tags: string[];
logoURI: string;
daily_volume: number;
freeze_authority: string | null;
mint_authority: string | null;
permanent_delegate: string | null;
extensions: {
coingeckoId?: string;
};
}
export interface FetchPriceResponse {
status: "success" | "error";
tokenId?: string;

View File

@@ -41,7 +41,7 @@ export async function getPriorityFees(connection: Connection): Promise<{
const median =
sortedFees.length % 2 === 0
? ((sortedFees[mid - 1] ?? 0) + (sortedFees[mid] ?? 0)) / 2
: (sortedFees[mid] ?? 0);
: sortedFees[mid] ?? 0;
// Helper to create priority fee IX based on chosen strategy
const createPriorityFeeIx = (fee: number) => {
@@ -76,7 +76,7 @@ export async function getPriorityFees(connection: Connection): Promise<{
export async function sendTx(
agent: SolanaAgentKit,
tx: Transaction,
otherKeypairs?: Keypair[],
otherKeypairs?: Keypair[]
) {
tx.recentBlockhash = (await agent.connection.getLatestBlockhash()).blockhash;
tx.feePayer = agent.wallet_address;
@@ -90,8 +90,9 @@ export async function sendTx(
await agent.connection.confirmTransaction({
signature: txid,
blockhash: (await agent.connection.getLatestBlockhash()).blockhash,
lastValidBlockHeight: (await agent.connection.getLatestBlockhash())
.lastValidBlockHeight,
lastValidBlockHeight: (
await agent.connection.getLatestBlockhash()
).lastValidBlockHeight,
});
return txid;
}

View File

@@ -12,8 +12,8 @@ dotenv.config();
function validateEnvironment(): void {
const missingVars: string[] = [];
const requiredVars = ["OPENAI_API_KEY", "HELIUS_API_KEY", "SOLANA_PRIVATE_KEY"];
const requiredVars = ["OPENAI_API_KEY", "RPC_URL", "SOLANA_PRIVATE_KEY"];
requiredVars.forEach(varName => {
if (!process.env[varName]) {
missingVars.push(varName);
@@ -52,7 +52,7 @@ async function initializeAgent() {
const solanaKit = new SolanaAgentKit(
process.env.SOLANA_PRIVATE_KEY!,
`https://mainnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`,
process.env.RPC_URL,
process.env.OPENAI_API_KEY!
);
@@ -176,7 +176,7 @@ async function chooseMode(): Promise<"chat" | "auto"> {
.trim();
rl.close();
if (choice === "1" || choice === "chat") {
return "chat";
} else if (choice === "2" || choice === "auto") {