Update agent and langchain

This commit is contained in:
calintje
2024-12-19 00:50:54 +01:00
parent 2c3fb17e41
commit f82f83f8ad
4 changed files with 84 additions and 2 deletions

View File

@@ -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
)
}
}

View File

@@ -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<string> {
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),

View File

@@ -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,

View File

@@ -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";
export * from "./fetch_price";
export * from "./create_orca_single_sided_whirlpool";