From b966069de51657ddb9031568f1a8c6313ff7d089 Mon Sep 17 00:00:00 2001 From: quangkeu95 Date: Sat, 11 Jan 2025 11:26:02 +0700 Subject: [PATCH] feat: Add Meteora to langchain index --- src/agent/index.ts | 2 +- src/langchain/index.ts | 84 ++++++++++++++++++++++++++ test/tools/create_meteora_dlmm_pool.ts | 2 +- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/agent/index.ts b/src/agent/index.ts index dc1b08c..7bd2691 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -368,9 +368,9 @@ export class SolanaAgentKit { } async meteoraCreateDlmmPool( - binStep: number, tokenAMint: PublicKey, tokenBMint: PublicKey, + binStep: number, initialPrice: number, priceRoundingUp: boolean, feeBps: number, diff --git a/src/langchain/index.ts b/src/langchain/index.ts index e442206..330a117 100644 --- a/src/langchain/index.ts +++ b/src/langchain/index.ts @@ -1310,6 +1310,88 @@ export class SolanaClosePosition extends Tool { } } +export class SolanaMeteoraCreateDynamicPool extends Tool { + name = "meteora_create_dynamic_pool"; + description = `Create a Meteora Dynamic Pool. This function adds liquidity with a constant-product formula. + + Inputs (JSON string): + - tokenAMint: string, token A mint (required). + - tokenBMint: string, token B mint (required). + - tokenAAmount: number, token A amount (required). + - tokenBAmount: number, token B amount (required). + - tradeFee: number, trade fee in percentage (required). + - activationType: number, pool start trading time indicator. 0 is slot and 1 is timestamp, default is timestamp (optional). + - activationPoint: number, pool start trading slot / timestamp, default is null means pool can start trading immediately (optional). + - hasAlphaVault: boolean, whether the pool supports alpha vault, default is false (optional). + `; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const inputFormat = JSON.parse(input); + console.log(inputFormat); + + const txId = ""; + + return JSON.stringify({ + status: "success", + message: "Meteora Dynamic pool created successfully.", + transaction: txId, + }); + } catch (error: any) { + return JSON.stringify({ + status: "error", + message: error.message, + code: error.code || "UNKNOWN_ERROR", + }); + } + } +} + +export class SolanaMeteoraCreateDlmmPool extends Tool { + name = "meteora_create_dlmm_pool"; + description = `Create a Meteora DLMM Pool. This function doesn't add liquidity. + + Inputs (JSON string): + - tokenAMint: string, token A mint (required). + - tokenBMint: string, token B mint (required). + - binStep: number, pool bin step (required). + - initialPrice: number, pool initial price (required). + - fee: number, trade fee in percentage (required). + - activationType: number, pool start trading time indicator. 0 is slot and 1 is timestamp, default is timestamp (optional). + - activationPoint: number, pool start trading slot / timestamp, default is null means pool can start trading immediately (optional). + - hasAlphaVault: boolean, whether the pool supports alpha vault, default is false (optional). + `; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const inputFormat = JSON.parse(input); + console.log(inputFormat); + + const txId = ""; + + return JSON.stringify({ + status: "success", + message: "Meteora DLMM pool created successfully.", + transaction: txId, + }); + } catch (error: any) { + return JSON.stringify({ + status: "error", + message: error.message, + code: error.code || "UNKNOWN_ERROR", + }); + } + } +} + export class SolanaOrcaCreateCLMM extends Tool { name = "orca_create_clmm"; description = `Create a Concentrated Liquidity Market Maker (CLMM) pool on Orca, the most efficient and capital-optimized CLMM on Solana. This function initializes a CLMM pool but does not add liquidity. You can add liquidity later using a centered position or a single-sided position. @@ -2720,6 +2802,8 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) { new SolanaBatchOrderTool(solanaKit), new SolanaCancelAllOrdersTool(solanaKit), new SolanaWithdrawAllTool(solanaKit), + new SolanaMeteoraCreateDynamicPool(solanaKit), + new SolanaMeteoraCreateDlmmPool(solanaKit), new SolanaClosePosition(solanaKit), new SolanaOrcaCreateCLMM(solanaKit), new SolanaOrcaCreateSingleSideLiquidityPool(solanaKit), diff --git a/test/tools/create_meteora_dlmm_pool.ts b/test/tools/create_meteora_dlmm_pool.ts index ceb554b..59b52ef 100644 --- a/test/tools/create_meteora_dlmm_pool.ts +++ b/test/tools/create_meteora_dlmm_pool.ts @@ -39,9 +39,9 @@ async function main() { const activationPoint = undefined; const txHash = await agent.meteoraCreateDlmmPool( - binStep, tokenAMint, tokenBMint, + binStep, initialPrice, priceRoundingUp, feeBps,