mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-19 15:10:36 +00:00
fix: Update tests for Meteora
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
import { fromWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
||||
import { SolanaAgentKit } from "../src";
|
||||
import { createMeteoraDynamicAMMPool, deploy_token } from "../src/tools";
|
||||
import BN from "bn.js";
|
||||
import AmmImpl from "@mercurial-finance/dynamic-amm-sdk";
|
||||
import { deriveCustomizablePermissionlessConstantProductPoolAddress } from "@mercurial-finance/dynamic-amm-sdk/dist/cjs/src/amm/utils";
|
||||
import { METEORA_DYNAMIC_AMM_PROGRAM_ID } from "../src/constants";
|
||||
|
||||
export async function test_create_meteora_dynamic_amm_pool() {
|
||||
console.log("<<< Test Create Meteora Dynamic AMM pool");
|
||||
const solanaKit = new SolanaAgentKit(
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL,
|
||||
process.env.OPENAI_API_KEY!
|
||||
);
|
||||
|
||||
const { mint: tokenAMint } = await deploy_token(solanaKit, "token_a_mint", "www.example.com", "TOKEN_A", 6, 100_000);
|
||||
const { mint: tokenBMint } = await deploy_token(solanaKit, "token_b_mint", "www.example.com", "TOKEN_B", 6, 100_000);
|
||||
|
||||
// Delay for 5 seconds
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
|
||||
const tokenAAmount = new BN(1000);
|
||||
const tokenBAmount = new BN(5);
|
||||
const params = {
|
||||
tradeFeeNumerator: 250,
|
||||
activationPoint: null,
|
||||
hasAlphaVault: false,
|
||||
activationType: 0,
|
||||
padding: Array(90).fill(0)
|
||||
};
|
||||
const txHash = await createMeteoraDynamicAMMPool(solanaKit, tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, params);
|
||||
console.log(`Tx successfully ${txHash.toString()}`);
|
||||
|
||||
const poolKey = deriveCustomizablePermissionlessConstantProductPoolAddress(
|
||||
tokenAMint, tokenBMint, METEORA_DYNAMIC_AMM_PROGRAM_ID
|
||||
);
|
||||
const pool = await AmmImpl.create(solanaKit.connection, poolKey);
|
||||
await pool.updateState();
|
||||
|
||||
console.log(">>> Test Create Meteora Dynamic AMM Pool Passed");
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import * as dotenv from "dotenv";
|
||||
import { test_create_meteora_dynamic_amm_pool } from "./create_meteora_dynamic_amm_pool";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.log("Starting Agent...");
|
||||
|
||||
// Test Tools
|
||||
await test_create_meteora_dynamic_amm_pool();
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.error("Error:", error.message);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main().catch(error => {
|
||||
console.error("Fatal error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
35
test/tools/create_meteora_dlmm_pool.ts
Normal file
35
test/tools/create_meteora_dlmm_pool.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { SolanaAgentKit, createSolanaTools } from "../../src";
|
||||
import { deploy_token } from "../../src/tools";
|
||||
|
||||
const agent = new SolanaAgentKit(
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL!,
|
||||
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY! },
|
||||
);
|
||||
|
||||
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);
|
||||
|
||||
// Delay for 5 seconds
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
|
||||
const binStep = 20;
|
||||
const initialPrice = 0.25;
|
||||
const priceRoundingUp = true;
|
||||
const feeBps = 20;
|
||||
const activationType = 1; // timestamp
|
||||
const hasAlphaVault = false;
|
||||
const activationPoint = undefined;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
export { SolanaAgentKit, createSolanaTools };
|
||||
@@ -1,21 +1,21 @@
|
||||
import { fromWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
||||
import { SolanaAgentKit } from "../../src";
|
||||
import { createMeteoraDynamicAMMPool, deploy_token } from "../../src/tools";
|
||||
import { SolanaAgentKit, createSolanaTools } from "../../src";
|
||||
import { deploy_token } from "../../src/tools";
|
||||
import BN from "bn.js";
|
||||
import AmmImpl from "@mercurial-finance/dynamic-amm-sdk";
|
||||
import { deriveCustomizablePermissionlessConstantProductPoolAddress } from "@mercurial-finance/dynamic-amm-sdk/dist/cjs/src/amm/utils";
|
||||
import { METEORA_DYNAMIC_AMM_PROGRAM_ID } from "../../src/constants";
|
||||
|
||||
export async function test_create_meteora_dynamic_amm_pool() {
|
||||
console.log("<<< Test Create Meteora Dynamic AMM pool");
|
||||
const solanaKit = new SolanaAgentKit(
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL,
|
||||
process.env.OPENAI_API_KEY!
|
||||
);
|
||||
const agent = new SolanaAgentKit(
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL!,
|
||||
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY! },
|
||||
);
|
||||
|
||||
const { mint: tokenAMint } = await deploy_token(solanaKit, "token_a_mint", "www.example.com", "TOKEN_A", 6, 100_000);
|
||||
const { mint: tokenBMint } = await deploy_token(solanaKit, "token_b_mint", "www.example.com", "TOKEN_B", 6, 100_000);
|
||||
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);
|
||||
|
||||
// Delay for 5 seconds
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
@@ -27,16 +27,19 @@ export async function test_create_meteora_dynamic_amm_pool() {
|
||||
activationPoint: null,
|
||||
hasAlphaVault: false,
|
||||
activationType: 0,
|
||||
padding: Array(90).fill(0)
|
||||
};
|
||||
const txHash = await createMeteoraDynamicAMMPool(solanaKit, tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, params);
|
||||
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
|
||||
);
|
||||
const pool = await AmmImpl.create(solanaKit.connection, poolKey);
|
||||
const pool = await AmmImpl.create(agent.connection, poolKey);
|
||||
await pool.updateState();
|
||||
|
||||
console.log(">>> Test Create Meteora Dynamic AMM Pool Passed");
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
export { SolanaAgentKit, createSolanaTools };
|
||||
Reference in New Issue
Block a user