forked from sendaifun/solana-agent-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sendaifun#3 from quangkeu95/feat/meteora
feat: Create Meteora pools
- Loading branch information
Showing
14 changed files
with
5,111 additions
and
5,188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./meteora_dlmm_pool"; | ||
export * from "./meteora_dynamic_pool"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { Tool } from "langchain/tools"; | ||
import { SolanaAgentKit } from "../../agent"; | ||
import { BN } from "bn.js"; | ||
|
||
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, e.g., 20 (required). | ||
- initialPrice: number, pool initial price, e.g., 0.25 (required). | ||
- feeBps: number, trade fee in percentage, e.g. 20 for 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). | ||
- computeUnitMicroLamports: number, the priority fee in micro-lamports unit, default is 100000 (optional). | ||
`; | ||
|
||
constructor(private solanaKit: SolanaAgentKit) { | ||
super(); | ||
} | ||
|
||
async _call(input: string): Promise<string> { | ||
try { | ||
interface CreateMeteoraDlmmPoolInput { | ||
tokenAMint: string; | ||
tokenBMint: string; | ||
binStep: number; | ||
initialPrice: number; | ||
feeBps: number; | ||
priceRoundingUp?: boolean; | ||
activationType?: number; | ||
activationPoint?: number; | ||
hasAlphaVault?: boolean; | ||
computeUnitMicroLamports?: number; | ||
} | ||
const inputFormat: CreateMeteoraDlmmPoolInput = JSON.parse(input); | ||
|
||
const tokenAMint = new PublicKey(inputFormat.tokenAMint); | ||
const tokenBMint = new PublicKey(inputFormat.tokenBMint); | ||
const binStep = inputFormat.binStep; | ||
const initialPrice = inputFormat.initialPrice; | ||
const feeBps = inputFormat.feeBps; | ||
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 computeUnitMicroLamports = | ||
inputFormat.computeUnitMicroLamports ?? 100000; | ||
|
||
const txId = await this.solanaKit.meteoraCreateDlmmPool( | ||
tokenAMint, | ||
tokenBMint, | ||
binStep, | ||
initialPrice, | ||
priceRoundingUp, | ||
feeBps, | ||
activationType, | ||
hasAlphaVault, | ||
activationPoint, | ||
computeUnitMicroLamports, | ||
); | ||
|
||
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", | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { Tool } from "langchain/tools"; | ||
import { SolanaAgentKit } from "../../agent"; | ||
import { BN } from "bn.js"; | ||
|
||
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 including decimals, e.g., 1000000000 (required). | ||
- tokenBAmount: number, token B amount including decimals, e.g., 1000000000 (required). | ||
- tradeFeeNumerator: number, trade fee numerator, e.g., 2500 for 2.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). | ||
- computeUnitMicroLamports: number, the priority fee in micro-lamports unit, default is 100000 (optional). | ||
`; | ||
|
||
constructor(private solanaKit: SolanaAgentKit) { | ||
super(); | ||
} | ||
|
||
async _call(input: string): Promise<string> { | ||
try { | ||
interface CreateMeteoraDynamicAmmPoolInput { | ||
tokenAMint: string; | ||
tokenBMint: string; | ||
tokenAAmount: number; | ||
tokenBAmount: number; | ||
tradeFeeNumerator: number; | ||
activationType?: number; | ||
activationPoint?: number; | ||
hasAlphaVault?: boolean; | ||
computeUnitMicroLamports?: number; | ||
} | ||
const inputFormat: CreateMeteoraDynamicAmmPoolInput = JSON.parse(input); | ||
|
||
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.tradeFeeNumerator.toString(), | ||
).toNumber(); | ||
const activationType = inputFormat.activationType ?? 1; | ||
const activationPoint = inputFormat.activationPoint | ||
? new BN(inputFormat.activationPoint) | ||
: null; | ||
const hasAlphaVault = inputFormat.hasAlphaVault ?? false; | ||
const computeUnitMicroLamports = | ||
inputFormat.computeUnitMicroLamports ?? 100000; | ||
|
||
const txId = await this.solanaKit.meteoraCreateDynamicPool( | ||
tokenAMint, | ||
tokenBMint, | ||
tokenAAmount, | ||
tokenBAmount, | ||
tradeFeeNumerator, | ||
activationPoint, | ||
hasAlphaVault, | ||
activationType, | ||
computeUnitMicroLamports, | ||
); | ||
|
||
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", | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.