diff --git a/src/constants/index.ts b/src/constants/index.ts index 61c08af..de89664 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,4 +1,5 @@ import { PublicKey } from "@solana/web3.js"; +import { BN } from "bn.js"; /** * Common token addresses used across the toolkit @@ -27,6 +28,8 @@ export const DEFAULT_OPTIONS = { LEVERAGE_BPS: 50000, // 10000 = x1, 50000 = x5, 100000 = x10, 1000000 = x100 } as const; +export const METEORA_DYNAMIC_FEE_DENOMINATOR = new BN(100000); + /** * Jupiter API URL */ diff --git a/src/langchain/index.ts b/src/langchain/index.ts index 330a117..e4a1ac2 100644 --- a/src/langchain/index.ts +++ b/src/langchain/index.ts @@ -15,6 +15,7 @@ import { CreateSingleOptions, StoreInitOptions, } from "@3land/listings-sdk/dist/types/implementation/implementationTypes"; +import { METEORA_DYNAMIC_FEE_DENOMINATOR, TOKENS } from "../constants"; export class SolanaBalanceTool extends Tool { name = "solana_balance"; @@ -1317,10 +1318,10 @@ export class SolanaMeteoraCreateDynamicPool extends Tool { 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). + - tokenAAmount: number, token A amount including decimals, e.g., 1000000000 (required). + - tokenBAmount: number, token B amount including decimals, e.g., 1000000000 (required). + - tradeFee: number, trade fee in percentage, e.g., 0.5 (required). + - activationType: number, pool start trading time indicator, 0 is slot and 1 is timestamp, default is 1 for 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). `; @@ -1331,10 +1332,43 @@ export class SolanaMeteoraCreateDynamicPool extends Tool { async _call(input: string): Promise { try { - const inputFormat = JSON.parse(input); + interface CreateMeteoraDynamicAmmPoolInput { + tokenAMint: string; + tokenBMint: string; + tokenAAmount: number; + tokenBAmount: number; + tradeFee: number; + activationType?: number; + activationPoint?: number; + hasAlphaVault?: boolean; + } + const inputFormat: CreateMeteoraDynamicAmmPoolInput = JSON.parse(input); + console.log(inputFormat); - const txId = ""; + const tokenAMint = new PublicKey(inputFormat.tokenAMint); + const tokenBMint = new PublicKey(inputFormat.tokenBMint); + const tokenAAmount = new BN(inputFormat.tokenAAmount.toString()); + const tokenBAmount = new BN(inputFormat.tokenBAmount.toString()); + const tradeFeeNumerator = new BN(inputFormat.tradeFee.toString()) + .mul(METEORA_DYNAMIC_FEE_DENOMINATOR) + .toNumber(); + const activationType = inputFormat.activationType ?? 1; + const activationPoint = inputFormat.activationPoint + ? new BN(inputFormat.activationPoint) + : null; + const hasAlphaVault = inputFormat.hasAlphaVault ?? false; + + const txId = await this.solanaKit.meteoraCreateDynamicPool( + tokenAMint, + tokenBMint, + tokenAAmount, + tokenBAmount, + tradeFeeNumerator, + activationPoint, + hasAlphaVault, + activationType, + ); return JSON.stringify({ status: "success", @@ -1358,10 +1392,11 @@ export class SolanaMeteoraCreateDlmmPool extends Tool { 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). + - binStep: number, pool bin step, e.g., 20 (required). + - initialPrice: number, pool initial price, e.g., 0.25 (required). + - fee: number, trade fee in percentage, e.g. 0.2 (required). + - priceRoundingUp: boolean, whether the initial price should be rounded up or not, default is true (optional). + - activationType: number, pool start trading time indicator. 0 is slot and 1 is timestamp, default is 1 for 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). `; @@ -1372,10 +1407,44 @@ export class SolanaMeteoraCreateDlmmPool extends Tool { async _call(input: string): Promise { try { - const inputFormat = JSON.parse(input); + interface CreateMeteoraDlmmPoolInput { + tokenAMint: string; + tokenBMint: string; + binStep: number; + initialPrice: number; + fee: number; + priceRoundingUp?: boolean; + activationType?: number; + activationPoint?: number; + hasAlphaVault?: boolean; + } + const inputFormat: CreateMeteoraDlmmPoolInput = JSON.parse(input); + console.log(inputFormat); - const txId = ""; + const tokenAMint = new PublicKey(inputFormat.tokenAMint); + const tokenBMint = new PublicKey(inputFormat.tokenBMint); + const binStep = inputFormat.binStep; + const initialPrice = inputFormat.initialPrice; + const feeBps = inputFormat.fee * 10000; + const priceRoundingUp = inputFormat.priceRoundingUp ?? true; + const activationType = inputFormat.activationType ?? 1; + const activationPoint = inputFormat.activationPoint + ? new BN(inputFormat.activationPoint) + : undefined; + const hasAlphaVault = inputFormat.hasAlphaVault ?? false; + + const txId = await this.solanaKit.meteoraCreateDlmmPool( + tokenAMint, + tokenBMint, + binStep, + initialPrice, + priceRoundingUp, + feeBps, + activationType, + hasAlphaVault, + activationPoint, + ); return JSON.stringify({ status: "success",