mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-13 23:16:55 +00:00
wip: langchain
This commit is contained in:
@@ -4,102 +4,101 @@ import { z } from "zod";
|
||||
import { sendCompressedAirdrop } from "../tools";
|
||||
|
||||
const compressedAirdropAction: Action = {
|
||||
name: "solana_compressed_airdrop",
|
||||
similes: [
|
||||
"ZK Compressed airdrop",
|
||||
"Airdrop tokens with compression",
|
||||
"Send compressed SPL airdrop",
|
||||
"Airdrop to multiple recipients",
|
||||
name: "solana_compressed_airdrop",
|
||||
similes: [
|
||||
"ZK Compressed airdrop",
|
||||
"Airdrop tokens with compression",
|
||||
"Send compressed SPL airdrop",
|
||||
"Airdrop to multiple recipients",
|
||||
],
|
||||
description:
|
||||
"Airdrop SPL tokens with ZK Compression (also known as airdropping tokens) to multiple recipients",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mintAddress: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
|
||||
amount: 42,
|
||||
decimals: 6,
|
||||
recipients: [
|
||||
"1nc1nerator11111111111111111111111111111111",
|
||||
"BrFndAe111111111111111111111111111111111",
|
||||
],
|
||||
priorityFeeInLamports: 30000,
|
||||
shouldLog: true,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Airdropped 42 tokens to 2 recipients.",
|
||||
transactionHashes: ["4uyfBN...", "9XsF2N..."],
|
||||
},
|
||||
explanation:
|
||||
"Airdrops 42 tokens (with 6 decimals) to 2 recipients, optionally logging progress to stdout.",
|
||||
},
|
||||
],
|
||||
description:
|
||||
"Airdrop SPL tokens with ZK Compression (also known as airdropping tokens) to multiple recipients",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mintAddress: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
|
||||
amount: 42,
|
||||
decimals: 6,
|
||||
recipients: [
|
||||
"1nc1nerator11111111111111111111111111111111",
|
||||
"BrFndAe111111111111111111111111111111111",
|
||||
],
|
||||
priorityFeeInLamports: 30000,
|
||||
shouldLog: true,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message:
|
||||
"Airdropped 42 tokens to 2 recipients.",
|
||||
transactionHashes: ["4uyfBN...", "9XsF2N..."],
|
||||
},
|
||||
explanation:
|
||||
"Airdrops 42 tokens (with 6 decimals) to 2 recipients, optionally logging progress to stdout.",
|
||||
},
|
||||
],
|
||||
],
|
||||
// Validate inputs with zod
|
||||
schema: z.object({
|
||||
mintAddress: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("Mint address of the token, e.g., 'JUPy...'"),
|
||||
amount: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Number of tokens to airdrop per recipient, e.g., 42"),
|
||||
decimals: z
|
||||
.number()
|
||||
.nonnegative()
|
||||
.int()
|
||||
.describe("Decimals of the token, e.g., 6"),
|
||||
recipients: z
|
||||
.array(z.string())
|
||||
.nonempty()
|
||||
.describe("Array of recipient addresses, e.g., ['1nc1n...']"),
|
||||
priorityFeeInLamports: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe("Priority fee in lamports (default is 30_000)"),
|
||||
shouldLog: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Whether to log progress to stdout (default is false)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const {
|
||||
mintAddress,
|
||||
amount,
|
||||
decimals,
|
||||
recipients,
|
||||
priorityFeeInLamports,
|
||||
shouldLog,
|
||||
} = input;
|
||||
],
|
||||
// Validate inputs with zod
|
||||
schema: z.object({
|
||||
mintAddress: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("Mint address of the token, e.g., 'JUPy...'"),
|
||||
amount: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Number of tokens to airdrop per recipient, e.g., 42"),
|
||||
decimals: z
|
||||
.number()
|
||||
.nonnegative()
|
||||
.int()
|
||||
.describe("Decimals of the token, e.g., 6"),
|
||||
recipients: z
|
||||
.array(z.string())
|
||||
.nonempty()
|
||||
.describe("Array of recipient addresses, e.g., ['1nc1n...']"),
|
||||
priorityFeeInLamports: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe("Priority fee in lamports (default is 30_000)"),
|
||||
shouldLog: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Whether to log progress to stdout (default is false)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const {
|
||||
mintAddress,
|
||||
amount,
|
||||
decimals,
|
||||
recipients,
|
||||
priorityFeeInLamports,
|
||||
shouldLog,
|
||||
} = input;
|
||||
|
||||
// Call your airdrop method on the SolanaAgentKit
|
||||
const txs = await sendCompressedAirdrop(
|
||||
mintAddress,
|
||||
amount,
|
||||
decimals,
|
||||
recipients,
|
||||
priorityFeeInLamports || 30_000,
|
||||
shouldLog || false,
|
||||
);
|
||||
// Call your airdrop method on the SolanaAgentKit
|
||||
const txs = await sendCompressedAirdrop(
|
||||
mintAddress,
|
||||
amount,
|
||||
decimals,
|
||||
recipients,
|
||||
priorityFeeInLamports || 30_000,
|
||||
shouldLog || false,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: `Airdropped ${amount} tokens to ${recipients.length} recipients.`,
|
||||
transactionHashes: txs,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to airdrop tokens: ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
return {
|
||||
status: "success",
|
||||
message: `Airdropped ${amount} tokens to ${recipients.length} recipients.`,
|
||||
transactionHashes: txs,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to airdrop tokens: ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default compressedAirdropAction;
|
||||
export default compressedAirdropAction;
|
||||
|
||||
@@ -7,70 +7,70 @@ import Decimal from "decimal.js";
|
||||
import { raydiumCreateClmm } from "../tools";
|
||||
|
||||
const raydiumCreateClmmAction: Action = {
|
||||
name: "raydium_create_clmm",
|
||||
similes: [
|
||||
"create clmm pool",
|
||||
"create concentrated liquidity pool",
|
||||
"raydium clmm setup",
|
||||
"launch concentrated liquidity market maker",
|
||||
name: "raydium_create_clmm",
|
||||
similes: [
|
||||
"create clmm pool",
|
||||
"create concentrated liquidity pool",
|
||||
"raydium clmm setup",
|
||||
"launch concentrated liquidity market maker",
|
||||
],
|
||||
description: `Create a Raydium Concentrated Liquidity Market Maker (CLMM) pool with custom ranges, providing increased capital efficiency`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mint1: "9xU1vzz456... (PublicKey)",
|
||||
mint2: "EfrsBcG98... (PublicKey)",
|
||||
configId: "D6yTTr... (Config PublicKey)",
|
||||
initialPrice: 123.12,
|
||||
startTime: 0, // or current UNIX timestamp
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Create raydium clmm pool successfully",
|
||||
transaction: "3skCN8... (transaction signature)",
|
||||
},
|
||||
explanation:
|
||||
"Creates a CLMM pool between mint1 and mint2 at an initial price of 123.12 and start time of 0.",
|
||||
},
|
||||
],
|
||||
description: `Create a Raydium Concentrated Liquidity Market Maker (CLMM) pool with custom ranges, providing increased capital efficiency`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mint1: "9xU1vzz456... (PublicKey)",
|
||||
mint2: "EfrsBcG98... (PublicKey)",
|
||||
configId: "D6yTTr... (Config PublicKey)",
|
||||
initialPrice: 123.12,
|
||||
startTime: 0, // or current UNIX timestamp
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Create raydium clmm pool successfully",
|
||||
transaction: "3skCN8... (transaction signature)",
|
||||
},
|
||||
explanation:
|
||||
"Creates a CLMM pool between mint1 and mint2 at an initial price of 123.12 and start time of 0.",
|
||||
},
|
||||
],
|
||||
],
|
||||
// Validate tool inputs using zod
|
||||
schema: z.object({
|
||||
mint1: z.string().min(1).describe("First token mint address (public key)"),
|
||||
mint2: z.string().min(1).describe("Second token mint address (public key)"),
|
||||
configId: z.string().min(1).describe("Raydium configId (public key)"),
|
||||
initialPrice: z.number().describe("Initial price for the CLMM pool"),
|
||||
startTime: z.number().describe(
|
||||
"Start time in seconds (UNIX timestamp or zero)",
|
||||
),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const { mint1, mint2, configId, initialPrice, startTime } = input;
|
||||
],
|
||||
// Validate tool inputs using zod
|
||||
schema: z.object({
|
||||
mint1: z.string().min(1).describe("First token mint address (public key)"),
|
||||
mint2: z.string().min(1).describe("Second token mint address (public key)"),
|
||||
configId: z.string().min(1).describe("Raydium configId (public key)"),
|
||||
initialPrice: z.number().describe("Initial price for the CLMM pool"),
|
||||
startTime: z
|
||||
.number()
|
||||
.describe("Start time in seconds (UNIX timestamp or zero)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const { mint1, mint2, configId, initialPrice, startTime } = input;
|
||||
|
||||
const tx = await raydiumCreateClmm(
|
||||
agent,
|
||||
new PublicKey(mint1),
|
||||
new PublicKey(mint2),
|
||||
new PublicKey(configId),
|
||||
new Decimal(initialPrice),
|
||||
new BN(startTime),
|
||||
);
|
||||
const tx = await raydiumCreateClmm(
|
||||
agent,
|
||||
new PublicKey(mint1),
|
||||
new PublicKey(mint2),
|
||||
new PublicKey(configId),
|
||||
new Decimal(initialPrice),
|
||||
new BN(startTime),
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Create raydium clmm pool successfully",
|
||||
transaction: tx,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create CLMM pool: ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
return {
|
||||
status: "success",
|
||||
message: "Create raydium clmm pool successfully",
|
||||
transaction: tx,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create CLMM pool: ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default raydiumCreateClmmAction;
|
||||
export default raydiumCreateClmmAction;
|
||||
|
||||
@@ -4,57 +4,57 @@ import { z } from "zod";
|
||||
import { getTokenDataByTicker } from "../tools";
|
||||
|
||||
const tokenDataByTickerAction: Action = {
|
||||
name: "solana_token_data_by_ticker",
|
||||
similes: [
|
||||
"token data by ticker",
|
||||
"fetch token info by ticker",
|
||||
"lookup token ticker info",
|
||||
"get token info by ticker",
|
||||
name: "solana_token_data_by_ticker",
|
||||
similes: [
|
||||
"token data by ticker",
|
||||
"fetch token info by ticker",
|
||||
"lookup token ticker info",
|
||||
"get token info by ticker",
|
||||
],
|
||||
description: "Get the token data for a given token ticker",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
ticker: "USDC",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
tokenData: {
|
||||
// Some placeholder example data
|
||||
symbol: "USDC",
|
||||
name: "USD Coin",
|
||||
decimals: 6,
|
||||
mintAddress: "FhRg...",
|
||||
},
|
||||
},
|
||||
explanation: "Fetches metadata for the USDC token by its ticker.",
|
||||
},
|
||||
],
|
||||
description: "Get the token data for a given token ticker",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
ticker: "USDC",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
tokenData: {
|
||||
// Some placeholder example data
|
||||
symbol: "USDC",
|
||||
name: "USD Coin",
|
||||
decimals: 6,
|
||||
mintAddress: "FhRg...",
|
||||
},
|
||||
},
|
||||
explanation: "Fetches metadata for the USDC token by its ticker.",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
ticker: z.string().min(1).describe("Ticker of the token, e.g. 'USDC'"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const ticker = input.ticker as string;
|
||||
],
|
||||
schema: z.object({
|
||||
ticker: z.string().min(1).describe("Ticker of the token, e.g. 'USDC'"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const ticker = input.ticker as string;
|
||||
|
||||
// Use agent’s method to get token data by ticker
|
||||
const tokenData = await getTokenDataByTicker(ticker);
|
||||
// Use agent’s method to get token data by ticker
|
||||
const tokenData = await getTokenDataByTicker(ticker);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
tokenData: tokenData,
|
||||
message: `Successfully fetched token data for ticker: ${ticker}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to fetch token data for ticker: ${input.ticker || ""}. ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
return {
|
||||
status: "success",
|
||||
tokenData: tokenData,
|
||||
message: `Successfully fetched token data for ticker: ${ticker}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to fetch token data for ticker: ${input.ticker || ""}. ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default tokenDataByTickerAction;
|
||||
export default tokenDataByTickerAction;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user