Skip to content

Commit

Permalink
wip: langchain
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyanag committed Dec 31, 2024
1 parent 2a08017 commit 42e8e47
Show file tree
Hide file tree
Showing 4 changed files with 601 additions and 458 deletions.
187 changes: 93 additions & 94 deletions src/actions/compressedAirdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
124 changes: 62 additions & 62 deletions src/actions/raydiumCreateClmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading

0 comments on commit 42e8e47

Please sign in to comment.