Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fluxbeam #145

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/actions/fluxbeamCreatePool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { PublicKey } from "@solana/web3.js";
import { Action } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { createPoolFluxBeam } from "../tools";

export const fluxbeamCreatePoolAction: Action = {
name: "FLUXBEAM_CREATE_POOL",
similes: [
"create liquidity pool on fluxbeam",
"add new pool to fluxbeam",
"initialize fluxbeam pool",
"setup trading pair on fluxbeam",
"create token pair pool",
],
description: `This tool allows you to create a new liquidity pool on FluxBeam DEX with two tokens.`,
examples: [
[
{
input: {
token_a: "So11111111111111111111111111111111111111112",
token_a_amount: 1,
token_b: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
token_b_amount: 1000,
},
output: {
status: "success",
message: "Pool created successfully on FluxBeam",
transaction:
"4KvgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
token_a: "SOL",
token_a_amount: 1,
token_b: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
token_b_amount: 1000,
},
explanation: "Create a new SOL-USDC pool with 1 SOL and 1000 USDC",
},
],
[
{
input: {
token_a: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
token_a_amount: 1000,
token_b: "7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx",
token_b_amount: 1000,
},
output: {
status: "success",
message: "Pool created successfully on FluxBeam",
transaction:
"5UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
token_a: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
token_a_amount: 1000,
token_b: "7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx",
token_b_amount: 1000,
},
explanation: "Create a new USDC-USDT pool with 1000 USDC and 1000 USDT",
},
],
],
schema: z.object({
token_a: z.string().min(32, "Invalid token_a mint address"),
token_a_amount: z.number().positive("Token A amount must be positive"),
token_b: z.string().min(32, "Invalid token_b mint address"),
token_b_amount: z.number().positive("Token B amount must be positive"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const tx = await createPoolFluxBeam(
agent,
new PublicKey(input.token_a),
input.token_a_amount,
new PublicKey(input.token_b),
input.token_b_amount,
);

return {
status: "success",
message: "Pool created successfully on FluxBeam",
transaction: tx,
token_a: input.token_a,
token_a_amount: input.token_a_amount,
token_b: input.token_b,
token_b_amount: input.token_b_amount,
};
} catch (error: any) {
return {
status: "error",
message: `FluxBeam pool creation failed: ${error.message}`,
error: error.message,
};
}
},
};
89 changes: 89 additions & 0 deletions src/actions/swapWithFluxBeam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { PublicKey } from "@solana/web3.js";
import { Action } from "../types/action";
import { SolanaAgentKit } from "../agent";
import { z } from "zod";
import { swapFluxBeam } from "../tools";

export const fluxbeamSwapAction: Action = {
name: "FLUXBEAM_SWAP",
similes: [
"swap tokens on fluxbeam",
"exchange tokens using fluxbeam",
"trade on fluxbeam",
"convert tokens via fluxbeam",
"use fluxbeam dex",
],
description: `This tool allows you to swap tokens using the FluxBeam DEX on Solana.`,
examples: [
[
{
input: {
outputMint: "So11111111111111111111111111111111111111112",
inputAmount: 100,
inputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
},
output: {
status: "success",
message: "Swap executed successfully on FluxBeam",
transaction:
"3KvgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
inputAmount: 100,
inputToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
outputToken: "So11111111111111111111111111111111111111112",
},
explanation: "Swap 100 USDC for SOL using FluxBeam DEX",
},
],
[
{
input: {
outputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
inputAmount: 1,
slippageBps: 100,
},
output: {
status: "success",
message: "Swap executed successfully on FluxBeam",
transaction:
"2UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
inputAmount: 1,
inputToken: "SOL",
outputToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
},
explanation: "Swap 1 SOL for USDC with 1% slippage on FluxBeam",
},
],
],
schema: z.object({
outputMint: z.string().min(32, "Invalid output mint address"),
inputAmount: z.number().positive("Input amount must be positive"),
inputMint: z.string().min(32, "Invalid input mint address").optional(),
slippageBps: z.number().min(0).max(10000).optional(),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const tx = await swapFluxBeam(
agent,
new PublicKey(input.outputMint),
input.inputAmount,
input.inputMint ? new PublicKey(input.inputMint) : undefined,
input.slippageBps,
);

return {
status: "success",
message: "Swap executed successfully on FluxBeam",
transaction: tx,
inputAmount: input.inputAmount,
inputToken: input.inputMint || "SOL",
outputToken: input.outputMint,
};
} catch (error: any) {
return {
status: "error",
message: `FluxBeam swap failed: ${error.message}`,
error: error.message,
};
}
},
};
25 changes: 25 additions & 0 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import {
fetchTokenDetailedReport,
fetchPythPrice,
fetchPythPriceFeedID,
swapFluxBeam,
createPoolFluxBeam,
} from "../tools";
import {
CollectionDeployment,
Expand Down Expand Up @@ -541,4 +543,27 @@ export class SolanaAgentKit {
async fetchTokenDetailedReport(mint: string): Promise<TokenCheck> {
return fetchTokenDetailedReport(mint);
}
async swapFluxBeam(
outputMint: PublicKey,
inputAmount: number,
inputMint?: PublicKey,
slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS,
): Promise<string> {
return swapFluxBeam(this, outputMint, inputAmount, inputMint, slippageBps);
}

async createPoolFluxBeam(
token_a: PublicKey,
token_a_amount: number,
token_b: PublicKey,
token_b_amount: number,
): Promise<string> {
return createPoolFluxBeam(
this,
token_a,
token_a_amount,
token_b,
token_b_amount,
);
}
}
95 changes: 95 additions & 0 deletions src/langchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,99 @@ export class SolanaFetchTokenDetailedReportTool extends Tool {
}
}

export class SolanaSwapFluxBeamTool extends Tool {
name = "solana_swap_fluxbeam";
description = `This tool can be used to swap tokens using FluxBeam DEX.

Inputs ( input is a JSON string ):
outputMint: string, eg "So11111111111111111111111111111111111111112" (required)
inputAmount: number, eg 1 or 0.01 (required)
inputMint?: string, eg "USDC" or "So11111111111111111111111111111111111111112" (optional)
slippageBps?: number, eg 300 for 3% (optional)`;

constructor(private solanaKit: SolanaAgentKit) {
super();
}

protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);

const signature = await this.solanaKit.swapFluxBeam(
new PublicKey(parsedInput.outputMint),
parsedInput.inputAmount,
parsedInput.inputMint
? new PublicKey(parsedInput.inputMint)
: new PublicKey("So11111111111111111111111111111111111111112"),
parsedInput.slippageBps,
);

return JSON.stringify({
status: "success",
message: "Swap executed successfully",
transaction: signature,
inputAmount: parsedInput.inputAmount,
inputToken: parsedInput.inputMint || "USDC",
outputToken: parsedInput.outputMint,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}

export class SolanaCreatePoolFluxBeamTool extends Tool {
name = "solana_create_pool_fluxbeam";
description = `This tool can be used to create a new liquidity pool using FluxBeam.

Inputs ( input is a JSON string ):
tokenA: string, eg "So11111111111111111111111111111111111111112" (required)
tokenAAmount: number, eg 100 (required)
tokenB: string, eg "SENDdRQtYMWaQrBroBrJ2Q53fgVuq95CV9UPGEvpCxa" (required)
tokenBAmount: number, eg 200 (required)`;

constructor(private solanaKit: SolanaAgentKit) {
super();
}

protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
const tokenA = new PublicKey(parsedInput.tokenA);
const tokenAAmount = parsedInput.tokenAAmount;
const tokenB = new PublicKey(parsedInput.tokenB);
const tokenBAmount = parsedInput.tokenBAmount;

const signature = await this.solanaKit.createPoolFluxBeam(
tokenA,
tokenAAmount,
tokenB,
tokenBAmount,
);

return JSON.stringify({
status: "success",
message: "Pool created successfully",
transaction: signature,
tokenA: parsedInput.tokenA,
tokenAAmount: parsedInput.tokenAAmount,
tokenB: parsedInput.tokenB,
tokenBAmount: parsedInput.tokenBAmount,
});
} 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),
Expand Down Expand Up @@ -2179,5 +2272,7 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaFetchTokenDetailedReportTool(solanaKit),
new SolanaPerpOpenTradeTool(solanaKit),
new SolanaPerpCloseTradeTool(solanaKit),
new SolanaSwapFluxBeamTool(solanaKit),
new SolanaCreatePoolFluxBeamTool(solanaKit),
];
}
Loading