From f82f83f8ad2c7097f2725fea2610270a4de0a17c Mon Sep 17 00:00:00 2001 From: calintje Date: Thu, 19 Dec 2024 00:50:54 +0100 Subject: [PATCH] Update agent and langchain --- src/agent/index.ts | 23 ++++++++ src/langchain/index.ts | 58 +++++++++++++++++++ .../create_orca_single_sided_whirlpool.ts | 2 +- src/tools/index.ts | 3 +- 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/agent/index.ts b/src/agent/index.ts index 23af3ad..d987b29 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -13,9 +13,13 @@ import { lendAsset, getTPS, stakeWithJup, + createOrcaSingleSidedWhirlpool, + FEE_TIERS } from "../tools"; import { CollectionOptions, PumpFunTokenOptions } from "../types"; import { DEFAULT_OPTIONS } from "../constants"; +import { BN } from "@coral-xyz/anchor"; +import Decimal from "decimal.js"; /** * Main class for interacting with Solana blockchain @@ -118,4 +122,23 @@ export class SolanaAgentKit { ) { return stakeWithJup(this, amount); } + + async createOrcaSingleSidedWhirlpool( + depositTokenAmount: BN, + depositTokenMint: PublicKey, + otherTokenMint: PublicKey, + initialPrice: Decimal, + maxPrice: Decimal, + feeTier: keyof typeof FEE_TIERS, + ) { + return createOrcaSingleSidedWhirlpool( + this, + depositTokenAmount, + depositTokenMint, + otherTokenMint, + initialPrice, + maxPrice, + feeTier + ) + } } diff --git a/src/langchain/index.ts b/src/langchain/index.ts index c4d506b..17ce444 100644 --- a/src/langchain/index.ts +++ b/src/langchain/index.ts @@ -4,6 +4,9 @@ import { PublicKey } from "@solana/web3.js"; import { toJSON } from "../utils/toJSON"; import { create_image } from "../tools/create_image"; import { fetchPrice } from "../tools/fetch_price"; +import { BN } from "@coral-xyz/anchor"; +import Decimal from "decimal.js"; +import { FEE_TIERS } from "../tools"; export class SolanaBalanceTool extends Tool { name = "solana_balance"; @@ -631,6 +634,61 @@ export class SolanaFetchPriceTool extends Tool { } } +export class SolanaCreateSingleSidedWhirlpoolTool extends Tool { + name = "create_orca_single_sided_whirlpool"; + description = `Create a single-sided Whirlpool with liquidity. + + Inputs (input is a JSON string): + - depositTokenAmount: number, eg: 1000000000 (required, in units of deposit token including decimals) + - depositTokenMint: string, eg: "DepositTokenMintAddress" (required, mint address of deposit token) + - otherTokenMint: string, eg: "OtherTokenMintAddress" (required, mint address of other token) + - initialPrice: number, eg: 0.001 (required, initial price of deposit token in terms of other token) + - maxPrice: number, eg: 5.0 (required, maximum price at which liquidity is added) + - feeTier: number, eg: 0.30 (required, fee tier for the pool)`; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const inputFormat = JSON.parse(input); + const depositTokenAmount = new BN(inputFormat.depositTokenAmount); + const depositTokenMint = new PublicKey(inputFormat.depositTokenMint); + const otherTokenMint = new PublicKey(inputFormat.otherTokenMint); + const initialPrice = new Decimal(inputFormat.initialPrice); + const maxPrice = new Decimal(inputFormat.maxPrice); + const feeTier = inputFormat.feeTier; + + if (!feeTier || !(feeTier in FEE_TIERS)) { + throw new Error(`Invalid feeTier. Available options: ${Object.keys(FEE_TIERS).join(", ")}`); + } + + const txId = await this.solanaKit.createOrcaSingleSidedWhirlpool( + depositTokenAmount, + depositTokenMint, + otherTokenMint, + initialPrice, + maxPrice, + feeTier, + ); + + return JSON.stringify({ + status: "success", + message: "Single-sided Whirlpool created successfully", + transaction: txId, + }); + } 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), diff --git a/src/tools/create_orca_single_sided_whirlpool.ts b/src/tools/create_orca_single_sided_whirlpool.ts index 0003b39..8f7835a 100644 --- a/src/tools/create_orca_single_sided_whirlpool.ts +++ b/src/tools/create_orca_single_sided_whirlpool.ts @@ -47,7 +47,7 @@ import { * @example * const tickSpacing = FEE_TIERS[0.30]; // Returns 64 */ -const FEE_TIERS = { +export const FEE_TIERS = { 0.01: 1, 0.02: 2, 0.04: 4, diff --git a/src/tools/index.ts b/src/tools/index.ts index dca3c04..66d0fb6 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -10,4 +10,5 @@ export * from "./launch_pumpfun_token"; export * from "./lend"; export * from "./get_tps"; export * from './stake_with_jup'; -export * from "./fetch_price"; \ No newline at end of file +export * from "./fetch_price"; +export * from "./create_orca_single_sided_whirlpool"; \ No newline at end of file