mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-14 15:10:20 +00:00
fix: Update tests for Meteora
This commit is contained in:
14294
pnpm-lock.yaml
generated
14294
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -63,6 +63,8 @@ import {
|
||||
fetchPythPriceFeedID,
|
||||
flashOpenTrade,
|
||||
flashCloseTrade,
|
||||
createMeteoraDynamicAMMPool,
|
||||
createMeteoraDlmmPool,
|
||||
} from "../tools";
|
||||
import {
|
||||
CollectionDeployment,
|
||||
@@ -339,6 +341,57 @@ export class SolanaAgentKit {
|
||||
);
|
||||
}
|
||||
|
||||
async meteoraCreateDynamicPool(
|
||||
tokenAMint: PublicKey,
|
||||
tokenBMint: PublicKey,
|
||||
tokenAAmount: BN,
|
||||
tokenBAmount: BN,
|
||||
tradeFeeNumerator: number,
|
||||
activationPoint: BN | null,
|
||||
hasAlphaVault: boolean,
|
||||
activationType: number,
|
||||
): Promise<string> {
|
||||
return createMeteoraDynamicAMMPool(
|
||||
this,
|
||||
tokenAMint,
|
||||
tokenBMint,
|
||||
tokenAAmount,
|
||||
tokenBAmount,
|
||||
{
|
||||
tradeFeeNumerator,
|
||||
activationPoint,
|
||||
hasAlphaVault,
|
||||
activationType,
|
||||
padding: new Array(90).fill(0),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async meteoraCreateDlmmPool(
|
||||
binStep: number,
|
||||
tokenAMint: PublicKey,
|
||||
tokenBMint: PublicKey,
|
||||
initialPrice: number,
|
||||
priceRoundingUp: boolean,
|
||||
feeBps: number,
|
||||
activationType: number,
|
||||
hasAlphaVault: boolean,
|
||||
activationPoint: BN | undefined,
|
||||
): Promise<string> {
|
||||
return createMeteoraDlmmPool(
|
||||
this,
|
||||
binStep,
|
||||
tokenAMint,
|
||||
tokenBMint,
|
||||
initialPrice,
|
||||
priceRoundingUp,
|
||||
feeBps,
|
||||
activationType,
|
||||
hasAlphaVault,
|
||||
activationPoint,
|
||||
);
|
||||
}
|
||||
|
||||
async orcaClosePosition(positionMintAddress: PublicKey) {
|
||||
return orcaClosePosition(this, positionMintAddress);
|
||||
}
|
||||
|
||||
@@ -34,4 +34,9 @@ export const JUP_API = "https://quote-api.jup.ag/v6";
|
||||
export const JUP_REFERRAL_ADDRESS =
|
||||
"REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3";
|
||||
|
||||
export const METEORA_DYNAMIC_AMM_PROGRAM_ID = new PublicKey("Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB");
|
||||
export const METEORA_DYNAMIC_AMM_PROGRAM_ID = new PublicKey(
|
||||
"Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB",
|
||||
);
|
||||
export const METEORA_DLMM_PROGRAM_ID = new PublicKey(
|
||||
"LbVRzDTvBDEcrthxfZ4RL6yiq3uZw8bS6MwtdY6UhFQ",
|
||||
);
|
||||
|
||||
@@ -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