From e5fb59dd47b6042a0cb34d535556d38afabff34d Mon Sep 17 00:00:00 2001 From: quangkeu95 Date: Sat, 11 Jan 2025 08:59:49 +0700 Subject: [PATCH] fix: Update initPrice when creating DLMM pool --- src/tools/create_meteora_dlmm_pool.ts | 2 +- src/utils/keypair.ts | 18 ++++++--- test/tools/create_meteora_dlmm_pool.ts | 34 ++++++++++++++--- test/tools/create_meteora_dynamic_amm_pool.ts | 37 ++++++++++++++++--- 4 files changed, 74 insertions(+), 17 deletions(-) diff --git a/src/tools/create_meteora_dlmm_pool.ts b/src/tools/create_meteora_dlmm_pool.ts index 147f67f..5439281 100644 --- a/src/tools/create_meteora_dlmm_pool.ts +++ b/src/tools/create_meteora_dlmm_pool.ts @@ -40,7 +40,7 @@ export async function createMeteoraDlmmPool( ); const activateBinId = DLMM.getBinIdFromPrice( - initialPrice, + initPrice, binStep, !priceRoundingUp, ); diff --git a/src/utils/keypair.ts b/src/utils/keypair.ts index 25d1a0e..1b62f1f 100644 --- a/src/utils/keypair.ts +++ b/src/utils/keypair.ts @@ -1,4 +1,9 @@ -import { Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js"; +import { + Keypair, + PublicKey, + Transaction, + VersionedTransaction, +} from "@solana/web3.js"; import bs58 from "bs58"; export const keypair = Keypair.generate(); @@ -6,7 +11,6 @@ export const keypair = Keypair.generate(); console.log(keypair.publicKey.toString()); console.log(bs58.encode(keypair.secretKey)); - export class Wallet { private _signer: Keypair; @@ -14,7 +18,9 @@ export class Wallet { this._signer = signer; } - async signTransaction(tx: T): Promise { + async signTransaction( + tx: T, + ): Promise { if (tx instanceof Transaction) { tx.sign(this._signer); } else if (tx instanceof VersionedTransaction) { @@ -25,11 +31,13 @@ export class Wallet { return tx; } - async signAllTransactions(txs: T[]): Promise { + async signAllTransactions( + txs: T[], + ): Promise { return Promise.all(txs.map((tx) => this.signTransaction(tx))); } get publicKey(): PublicKey { return this._signer.publicKey; } -} \ No newline at end of file +} diff --git a/test/tools/create_meteora_dlmm_pool.ts b/test/tools/create_meteora_dlmm_pool.ts index 3596ac2..ceb554b 100644 --- a/test/tools/create_meteora_dlmm_pool.ts +++ b/test/tools/create_meteora_dlmm_pool.ts @@ -10,11 +10,25 @@ const agent = new SolanaAgentKit( async function main() { console.log("<<< Test Create Meteora DLMM pool"); - const { mint: tokenAMint } = await deploy_token(agent, "token_a_mint", "www.example.com", "TOKEN_A", 6, 100_000); - const { mint: tokenBMint } = await deploy_token(agent, "token_b_mint", "www.example.com", "TOKEN_B", 6, 100_000); + const { mint: tokenAMint } = await deploy_token( + agent, + "token_a_mint", + "www.example.com", + "TOKEN_A", + 6, + 100_000, + ); + const { mint: tokenBMint } = await deploy_token( + agent, + "token_b_mint", + "www.example.com", + "TOKEN_B", + 6, + 100_000, + ); // Delay for 5 seconds - await new Promise(resolve => setTimeout(resolve, 5000)); + await new Promise((resolve) => setTimeout(resolve, 5000)); const binStep = 20; const initialPrice = 0.25; @@ -24,7 +38,17 @@ async function main() { const hasAlphaVault = false; const activationPoint = undefined; - const txHash = await agent.meteoraCreateDlmmPool(binStep, tokenAMint, tokenBMint, initialPrice, priceRoundingUp, feeBps, activationType, hasAlphaVault, activationPoint); + const txHash = await agent.meteoraCreateDlmmPool( + binStep, + tokenAMint, + tokenBMint, + initialPrice, + priceRoundingUp, + feeBps, + activationType, + hasAlphaVault, + activationPoint, + ); console.log(`Tx successfully ${txHash.toString()}`); console.log(">>> Test Create Meteora DLMM Pool Passed"); @@ -32,4 +56,4 @@ async function main() { main(); -export { SolanaAgentKit, createSolanaTools }; \ No newline at end of file +export { SolanaAgentKit, createSolanaTools }; diff --git a/test/tools/create_meteora_dynamic_amm_pool.ts b/test/tools/create_meteora_dynamic_amm_pool.ts index e7a2c51..ed88a15 100644 --- a/test/tools/create_meteora_dynamic_amm_pool.ts +++ b/test/tools/create_meteora_dynamic_amm_pool.ts @@ -14,11 +14,25 @@ const agent = new SolanaAgentKit( async function main() { console.log("<<< Test Create Meteora Dynamic AMM pool"); - const { mint: tokenAMint } = await deploy_token(agent, "token_a_mint", "www.example.com", "TOKEN_A", 6, 100_000); - const { mint: tokenBMint } = await deploy_token(agent, "token_b_mint", "www.example.com", "TOKEN_B", 6, 100_000); + const { mint: tokenAMint } = await deploy_token( + agent, + "token_a_mint", + "www.example.com", + "TOKEN_A", + 6, + 100_000, + ); + const { mint: tokenBMint } = await deploy_token( + agent, + "token_b_mint", + "www.example.com", + "TOKEN_B", + 6, + 100_000, + ); // Delay for 5 seconds - await new Promise(resolve => setTimeout(resolve, 5000)); + await new Promise((resolve) => setTimeout(resolve, 5000)); const tokenAAmount = new BN(1000); const tokenBAmount = new BN(5); @@ -28,11 +42,22 @@ async function main() { hasAlphaVault: false, activationType: 0, }; - const txHash = await agent.meteoraCreateDynamicPool(tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, params.tradeFeeNumerator, params.activationPoint, params.hasAlphaVault, params.activationType); + const txHash = await agent.meteoraCreateDynamicPool( + tokenAMint, + tokenBMint, + tokenAAmount, + tokenBAmount, + params.tradeFeeNumerator, + params.activationPoint, + params.hasAlphaVault, + params.activationType, + ); console.log(`Tx successfully ${txHash.toString()}`); const poolKey = deriveCustomizablePermissionlessConstantProductPoolAddress( - tokenAMint, tokenBMint, METEORA_DYNAMIC_AMM_PROGRAM_ID + tokenAMint, + tokenBMint, + METEORA_DYNAMIC_AMM_PROGRAM_ID, ); const pool = await AmmImpl.create(agent.connection, poolKey); await pool.updateState(); @@ -42,4 +67,4 @@ async function main() { main(); -export { SolanaAgentKit, createSolanaTools }; \ No newline at end of file +export { SolanaAgentKit, createSolanaTools };