fix(meteora): Exclude alpha vault due to package conflict

This commit is contained in:
quangkeu95
2024-12-21 09:14:10 +07:00
parent 0e5e1b276c
commit 25f301599e
4 changed files with 188 additions and 115 deletions

View File

@@ -33,3 +33,5 @@ export const DEFAULT_OPTIONS = {
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");

View File

@@ -1,121 +1,121 @@
import AlphaVault, { PoolType, WhitelistMode } from "@meteora-ag/alpha-vault";
import { SolanaAgentKit } from "../agent";
import { PublicKey, sendAndConfirmTransaction } from "@solana/web3.js";
import BN from "bn.js";
// import AlphaVault, { PoolType, WhitelistMode } from "@meteora-ag/alpha-vault";
// import { SolanaAgentKit } from "../agent";
// import { PublicKey, sendAndConfirmTransaction } from "@solana/web3.js";
// import BN from "bn.js";
/**
* Create Meteora FCFS alpha vault
* @param agent SolanaAgentKit instance
* @param tokenAMint Token A mint
* @param tokenBMint Token B mint
* @param poolAddress Pool mint
* @param poolType Either PoolType.DYNAMIC or PoolType.DLMM
* @param depositingPoint The point when the vault allows deposits
* @param startVestingPoint The point when the vault starts vesting
* @param endVestingPoint The point when the vault ends vesting
* @param maxDepositingCap Maximum number of deposit amount for vault
* @param individualDepositingCap Maximum number of deposit amount for individual
* @param escrowFee Fee to create stake escrow account
* @param whitelistMode Alpha vault whitelist mode
* @returns
*/
export async function createMeteoraFcfsAlphaVault(
agent: SolanaAgentKit,
tokenAMint: PublicKey,
tokenBMint: PublicKey,
poolAddress: PublicKey,
poolType: PoolType,
depositingPoint: BN,
startVestingPoint: BN,
endVestingPoint: BN,
maxDepositingCap: BN,
individualDepositingCap: BN,
escrowFee: BN,
whitelistMode: WhitelistMode
): Promise<string> {
const createAlphaVaultTx = await AlphaVault.createCustomizableFcfsVault(
agent.connection,
{
baseMint: tokenAMint,
quoteMint: tokenBMint,
poolAddress,
poolType,
depositingPoint,
startVestingPoint,
endVestingPoint,
maxDepositingCap,
individualDepositingCap,
escrowFee,
whitelistMode
},
agent.wallet_address
);
// /**
// * Create Meteora FCFS alpha vault
// * @param agent SolanaAgentKit instance
// * @param tokenAMint Token A mint
// * @param tokenBMint Token B mint
// * @param poolAddress Pool mint
// * @param poolType Either PoolType.DYNAMIC or PoolType.DLMM
// * @param depositingPoint The point when the vault allows deposits
// * @param startVestingPoint The point when the vault starts vesting
// * @param endVestingPoint The point when the vault ends vesting
// * @param maxDepositingCap Maximum number of deposit amount for vault
// * @param individualDepositingCap Maximum number of deposit amount for individual
// * @param escrowFee Fee to create stake escrow account
// * @param whitelistMode Alpha vault whitelist mode
// * @returns
// */
// export async function createMeteoraFcfsAlphaVault(
// agent: SolanaAgentKit,
// tokenAMint: PublicKey,
// tokenBMint: PublicKey,
// poolAddress: PublicKey,
// poolType: PoolType,
// depositingPoint: BN,
// startVestingPoint: BN,
// endVestingPoint: BN,
// maxDepositingCap: BN,
// individualDepositingCap: BN,
// escrowFee: BN,
// whitelistMode: WhitelistMode
// ): Promise<string> {
// const createAlphaVaultTx = await AlphaVault.createCustomizableFcfsVault(
// agent.connection,
// {
// baseMint: tokenAMint,
// quoteMint: tokenBMint,
// poolAddress,
// poolType,
// depositingPoint,
// startVestingPoint,
// endVestingPoint,
// maxDepositingCap,
// individualDepositingCap,
// escrowFee,
// whitelistMode
// },
// agent.wallet_address
// );
const createAlphaVaultTxHash = await sendAndConfirmTransaction(
agent.connection,
createAlphaVaultTx,
[agent.wallet],
).catch((err) => {
console.error(err);
throw err;
});
// const createAlphaVaultTxHash = await sendAndConfirmTransaction(
// agent.connection,
// createAlphaVaultTx,
// [agent.wallet],
// ).catch((err) => {
// console.error(err);
// throw err;
// });
return createAlphaVaultTxHash;
}
// return createAlphaVaultTxHash;
// }
/**
* Create Meteora Prorata alpha vault
* @param agent SolanaAgentKit instance
* @param tokenAMint Token A mint
* @param tokenBMint Token B mint
* @param poolAddress Pool mint
* @param poolType Either PoolType.DYNAMIC or PoolType.DLMM
* @param depositingPoint The point when the vault allows deposits
* @param startVestingPoint The point when the vault starts vesting
* @param endVestingPoint The point when the vault ends vesting
* @param maxBuyingCap Maximum buying amount
* @param escrowFee Fee to create stake escrow account
* @param whitelistMode Alpha vault whitelist mode
* @returns
*/
export async function createMeteoraProrataAlphaVault(
agent: SolanaAgentKit,
tokenAMint: PublicKey,
tokenBMint: PublicKey,
poolAddress: PublicKey,
poolType: PoolType,
depositingPoint: BN,
startVestingPoint: BN,
endVestingPoint: BN,
maxBuyingCap: BN,
escrowFee: BN,
whitelistMode: WhitelistMode
): Promise<string> {
const createAlphaVaultTx = await AlphaVault.createCustomizableProrataVault(
agent.connection,
{
baseMint: tokenAMint,
quoteMint: tokenBMint,
poolAddress,
poolType,
depositingPoint,
startVestingPoint,
endVestingPoint,
maxBuyingCap,
escrowFee,
whitelistMode
},
agent.wallet_address
);
// /**
// * Create Meteora Prorata alpha vault
// * @param agent SolanaAgentKit instance
// * @param tokenAMint Token A mint
// * @param tokenBMint Token B mint
// * @param poolAddress Pool mint
// * @param poolType Either PoolType.DYNAMIC or PoolType.DLMM
// * @param depositingPoint The point when the vault allows deposits
// * @param startVestingPoint The point when the vault starts vesting
// * @param endVestingPoint The point when the vault ends vesting
// * @param maxBuyingCap Maximum buying amount
// * @param escrowFee Fee to create stake escrow account
// * @param whitelistMode Alpha vault whitelist mode
// * @returns
// */
// export async function createMeteoraProrataAlphaVault(
// agent: SolanaAgentKit,
// tokenAMint: PublicKey,
// tokenBMint: PublicKey,
// poolAddress: PublicKey,
// poolType: PoolType,
// depositingPoint: BN,
// startVestingPoint: BN,
// endVestingPoint: BN,
// maxBuyingCap: BN,
// escrowFee: BN,
// whitelistMode: WhitelistMode
// ): Promise<string> {
// const createAlphaVaultTx = await AlphaVault.createCustomizableProrataVault(
// agent.connection,
// {
// baseMint: tokenAMint,
// quoteMint: tokenBMint,
// poolAddress,
// poolType,
// depositingPoint,
// startVestingPoint,
// endVestingPoint,
// maxBuyingCap,
// escrowFee,
// whitelistMode
// },
// agent.wallet_address
// );
const createAlphaVaultTxHash = await sendAndConfirmTransaction(
agent.connection,
createAlphaVaultTx,
[agent.wallet],
).catch((err) => {
console.error(err);
throw err;
});
// const createAlphaVaultTxHash = await sendAndConfirmTransaction(
// agent.connection,
// createAlphaVaultTx,
// [agent.wallet],
// ).catch((err) => {
// console.error(err);
// throw err;
// });
return createAlphaVaultTxHash;
}
// return createAlphaVaultTxHash;
// }

View File

@@ -0,0 +1,42 @@
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");
}

29
test/tools.ts Normal file
View File

@@ -0,0 +1,29 @@
import * as dotenv from "dotenv";
import { test_deploy_token } from "./deployToken";
import { test_deploy_collection } from "./deployCollection";
import { test_mint_nft } from "./mintNft";
dotenv.config();
async function main() {
try {
console.log("Starting Agent...");
// Test Tools
await test_deploy_token();
await test_deploy_collection();
await test_mint_nft();
} 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);
});
}