mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-21 23:26:45 +00:00
feat: Add functions to create Meteora pools + alpha vault
This commit is contained in:
121
src/tools/create_meteora_alpha_vault.ts
Normal file
121
src/tools/create_meteora_alpha_vault.ts
Normal file
@@ -0,0 +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";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
});
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
const createAlphaVaultTxHash = await sendAndConfirmTransaction(
|
||||
agent.connection,
|
||||
createAlphaVaultTx,
|
||||
[agent.wallet],
|
||||
).catch((err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
});
|
||||
|
||||
return createAlphaVaultTxHash;
|
||||
}
|
||||
71
src/tools/create_meteora_dlmm_pool.ts
Normal file
71
src/tools/create_meteora_dlmm_pool.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { BN } from "bn.js";
|
||||
import { PublicKey, sendAndConfirmTransaction } from "@solana/web3.js";
|
||||
import DLMM, { ActivationType } from "@meteora-ag/dlmm";
|
||||
import { getMint } from "@solana/spl-token";
|
||||
|
||||
/**
|
||||
* Create Meteora DLMM pool
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param binStep DLMM pool bin step
|
||||
* @param tokenAMint Token A mint
|
||||
* @param tokenBMint Token B mint
|
||||
* @param initialPrice Initial pool price in ratio tokenA / tokenB
|
||||
* @param priceRoundingUp Whether to rounding up the initial pool price
|
||||
* @param feeBps Pool trading fee in BPS
|
||||
* @param activationType Pool activation type (ActivationType.Timestamp or ActivationType.Slot)
|
||||
* @param hasAlphaVault Whether the pool has Meteora alpha vault or not
|
||||
* @param activationPoint Activation point depending on activation type, or null if pool doesn't have an activation point
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function createMeteoraDlmmPool(
|
||||
agent: SolanaAgentKit,
|
||||
binStep: number,
|
||||
tokenAMint: PublicKey,
|
||||
tokenBMint: PublicKey,
|
||||
initialPrice: number,
|
||||
priceRoundingUp: boolean,
|
||||
feeBps: number,
|
||||
activationType: ActivationType,
|
||||
hasAlphaVault: boolean,
|
||||
activationPoint: BN | null
|
||||
): Promise<string> {
|
||||
const tokenAMintInfo = await getMint(agent.connection, tokenAMint);
|
||||
const tokenBMintInfo = await getMint(agent.connection, tokenBMint);
|
||||
|
||||
const initPrice = DLMM.getPricePerLamport(
|
||||
tokenAMintInfo.decimals,
|
||||
tokenBMintInfo.decimals,
|
||||
initialPrice,
|
||||
);
|
||||
|
||||
const activateBinId = DLMM.getBinIdFromPrice(
|
||||
initialPrice,
|
||||
binStep,
|
||||
!priceRoundingUp,
|
||||
);
|
||||
|
||||
const initPoolTx = await DLMM.createCustomizablePermissionlessLbPair(
|
||||
agent.connection,
|
||||
new BN(binStep),
|
||||
tokenAMint,
|
||||
tokenBMint,
|
||||
new BN(activateBinId.toString()),
|
||||
new BN(feeBps),
|
||||
activationType,
|
||||
hasAlphaVault,
|
||||
agent.wallet_address,
|
||||
activationPoint
|
||||
)
|
||||
|
||||
const initPoolTxHash = await sendAndConfirmTransaction(
|
||||
agent.connection,
|
||||
initPoolTx,
|
||||
[agent.wallet],
|
||||
).catch((err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
});
|
||||
|
||||
return initPoolTxHash;
|
||||
}
|
||||
44
src/tools/create_meteora_dynamic_amm_pool.ts
Normal file
44
src/tools/create_meteora_dynamic_amm_pool.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import AmmImpl from "@mercurial-finance/dynamic-amm-sdk";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { BN } from "bn.js";
|
||||
import { PublicKey, sendAndConfirmTransaction } from "@solana/web3.js";
|
||||
import { CustomizableParams } from "@mercurial-finance/dynamic-amm-sdk/dist/cjs/src/amm/types";
|
||||
|
||||
/**
|
||||
* Create Meteora Dynamic AMM pool
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param tokenAMint Token A mint
|
||||
* @param tokenBMint Token B mint
|
||||
* @param tokenAAmount Token A amount in lamport units
|
||||
* @param tokenBAmount Token B amount in lamport units
|
||||
* @param customizableParams Parameters to create Dynamic AMM pool
|
||||
* tradeFeeNumerator (number): Trade fee numerator, with default denominator is 100000
|
||||
* activationType (enum): Should be ActivationType.Timestamp or ActivationType.Slot
|
||||
* activationPoint (BN | null): Activation point depending on activation type, or null if pool doesn't have an activation point
|
||||
* hasAlphaVault (boolean): Whether the pool has Meteora alpha vault or not
|
||||
* padding (Array<number>): Should be set to value Array(90).fill(0)
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function createMeteoraDynamicAMMPool(
|
||||
agent: SolanaAgentKit,
|
||||
tokenAMint: PublicKey,
|
||||
tokenBMint: PublicKey,
|
||||
tokenAAmount: BN,
|
||||
tokenBAmount: BN,
|
||||
customizableParams: CustomizableParams
|
||||
): Promise<string> {
|
||||
const initPoolTx = await AmmImpl.createCustomizablePermissionlessConstantProductPool(
|
||||
agent.connection, agent.wallet_address, tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, customizableParams
|
||||
)
|
||||
|
||||
const initPoolTxHash = await sendAndConfirmTransaction(
|
||||
agent.connection,
|
||||
initPoolTx,
|
||||
[agent.wallet],
|
||||
).catch((err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
});
|
||||
|
||||
return initPoolTxHash;
|
||||
}
|
||||
@@ -50,3 +50,5 @@ export * from "./flash_open_trade";
|
||||
export * from "./flash_close_trade";
|
||||
|
||||
export * from "./create_3land_collectible";
|
||||
export * from "./create_meteora_dynamic_amm_pool";
|
||||
export * from "./create_meteora_dlmm_pool";
|
||||
|
||||
Reference in New Issue
Block a user