@agentix/plugin-solana-meteora
Version:
324 lines (316 loc) • 12.3 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
default: () => index_default
});
module.exports = __toCommonJS(index_exports);
var import_agentix3 = require("agentix");
// src/actions/createMeteoraDLMMPool.ts
var import_web33 = require("@solana/web3.js");
var import_bn2 = __toESM(require("bn.js"), 1);
var import_zod = require("zod");
// src/tools/create_meteora_dlmm_pool.ts
var import_dlmm = __toESM(require("@meteora-ag/dlmm"), 1);
var import_spl_token = require("@solana/spl-token");
var import_web3 = require("@solana/web3.js");
var import_bn = __toESM(require("bn.js"), 1);
var import_agentix = require("agentix");
async function createMeteoraDlmmPool(agent, binStep, tokenAMint, tokenBMint, initialPrice, priceRoundingUp, feeBps, activationType, hasAlphaVault, activationPoint) {
const tokenAMintInfo = await (0, import_spl_token.getMint)(agent.wallet.getConnection(), tokenAMint);
const tokenBMintInfo = await (0, import_spl_token.getMint)(agent.wallet.getConnection(), tokenBMint);
const initPrice = import_dlmm.default.getPricePerLamport(
tokenAMintInfo.decimals,
tokenBMintInfo.decimals,
initialPrice
);
const activateBinId = import_dlmm.default.getBinIdFromPrice(
initPrice,
binStep,
!priceRoundingUp
);
const initPoolTx = await import_dlmm.default.createCustomizablePermissionlessLbPair(
agent.wallet.getConnection(),
new import_bn.default(binStep),
tokenAMint,
tokenBMint,
new import_bn.default(activateBinId.toString()),
new import_bn.default(feeBps),
activationType,
hasAlphaVault,
new import_web3.PublicKey(agent.wallet.getAddress()),
activationPoint,
{
cluster: "mainnet-beta"
}
);
const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash();
initPoolTx.recentBlockhash = blockhash;
return (0, import_agentix.signOrSendTX)(agent, initPoolTx, void 0, "max");
}
// src/tools/create_meteora_dynamic_amm_pool.ts
var import_dynamic_amm_sdk = __toESM(require("@mercurial-finance/dynamic-amm-sdk"), 1);
var import_web32 = require("@solana/web3.js");
var import_agentix2 = require("agentix");
async function createMeteoraDynamicAMMPool(agent, tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, customizableParams) {
const initPoolTx = await import_dynamic_amm_sdk.default.createCustomizablePermissionlessConstantProductPool(
agent.wallet.getConnection(),
new import_web32.PublicKey(agent.wallet.getAddress()),
tokenAMint,
tokenBMint,
tokenAAmount,
tokenBAmount,
customizableParams
);
const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash();
initPoolTx.recentBlockhash = blockhash;
return await (0, import_agentix2.signOrSendTX)(agent, initPoolTx, void 0, "max");
}
// src/actions/createMeteoraDLMMPool.ts
var createMeteoraDLMMPoolAction = {
name: "CREATE_METEORA_DLMM_POOL",
description: "Create a new Meteora DLMM pool",
similes: [
"create Meteora DLMM pool",
"setup Meteora DLMM pool",
"new Meteora DLMM pool",
"create DLMM pool",
"setup Meteora DLMM pool",
"new DLMM pool"
],
examples: [
[
{
input: {
binStep: 100,
tokenAMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
tokenBMint: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
initialPrice: 1,
priceRoundingUp: false,
feeBps: 1e3,
activationType: "Timestamp",
hasAlphaVault: false,
activationPoint: 0
},
output: {
status: "success",
transaction: "78fj2...",
message: "Successfully created Meteora DLMM pool"
},
explanation: "Create a new Meteora DLMM pool for USDC/JUP"
}
]
],
schema: import_zod.z.object({
binStep: import_zod.z.number().positive().describe("DLMM pool bin step"),
tokenAMint: import_zod.z.string().min(1).describe("The token A mint address"),
tokenBMint: import_zod.z.string().min(1).describe("The token B mint address"),
initialPrice: import_zod.z.number().positive().describe("Initial pool price in ratio tokenA / tokenB"),
priceRoundingUp: import_zod.z.boolean().describe("Whether to rounding up the initial pool price").optional(),
feeBps: import_zod.z.number().positive().describe("Pool trading fee in BPS"),
activationType: import_zod.z.enum(["Timestamp", "Slot"]).describe("Pool activation type").optional(),
hasAlphaVault: import_zod.z.boolean().describe("Whether the pool has Meteora alpha vault or not").optional().default(false),
activationPoint: import_zod.z.number().describe(
"Activation point depending on activation type, or null if pool doesn't have an activation point"
).optional()
}),
handler: async (agent, input) => {
try {
const tokenAMint = new import_web33.PublicKey(input.tokenAMint);
const tokenBMint = new import_web33.PublicKey(input.tokenBMint);
const binStep = input.binStep;
const initialPrice = input.initialPrice;
const feeBps = input.feeBps;
const priceRoundingUp = input.priceRoundingUp ?? true;
const activationType = input.activationType ?? 1;
const activationPoint = input.activationPoint ? new import_bn2.default(input.activationPoint) : void 0;
const hasAlphaVault = input.hasAlphaVault ?? false;
const transaction = await createMeteoraDlmmPool(
agent,
binStep,
tokenAMint,
tokenBMint,
initialPrice,
priceRoundingUp,
feeBps,
activationType,
hasAlphaVault,
activationPoint
);
return {
status: "success",
message: "Meteora DLMM pool created successfully.",
transaction
};
} catch (error) {
return {
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR"
};
}
}
};
var createMeteoraDLMMPool_default = createMeteoraDLMMPoolAction;
// src/actions/createMeteoraDynamicAMMPool.ts
var import_spl_token2 = require("@solana/spl-token");
var import_web34 = require("@solana/web3.js");
var import_bn3 = __toESM(require("bn.js"), 1);
var import_decimal = __toESM(require("decimal.js"), 1);
var import_zod2 = require("zod");
var createMeteoraDynamicAMMPoolAction = {
name: "CREATE_METEORA_DYNAMIC_AMM_POOL",
description: "Create a new dynamic AMM pool on Meteora",
similes: [
"create dynamic AMM pool",
"setup AMM pool",
"new dynamic AMM pool",
"create AMM pool",
"setup liquidity pool",
"new AMM pool"
],
examples: [
[
{
input: {
tokenAAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
tokenBAddress: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
tokenAAmount: 100,
tokenBAmount: 100,
tradeFeeNumerator: 1e3,
activationType: "Timestamp",
activationPoint: 0,
hasAlphaVault: false
},
output: {
status: "success",
transaction: "78fj2...",
message: "Successfully created Meteora dynamic AMM pool"
},
explanation: "Create a new dynamic AMM pool on Meteora for USDC/JUP"
}
]
],
schema: import_zod2.z.object({
tokenAAddress: import_zod2.z.string().min(1).describe("The token A mint address"),
tokenBAddress: import_zod2.z.string().min(1).describe("The token B mint address"),
tokenAAmount: import_zod2.z.number().positive().describe("The token A amount in lamport units"),
tokenBAmount: import_zod2.z.number().positive().describe("The token B amount in lamport units"),
tradeFeeNumerator: import_zod2.z.number().positive().describe("Trade fee numerator"),
activationType: import_zod2.z.enum(["Timestamp", "Slot"]).describe("Activation type").optional(),
activationPoint: import_zod2.z.number().describe("Activation point").optional(),
hasAlphaVault: import_zod2.z.boolean().describe("Whether the pool has Meteora alpha vault or not").default(false)
}),
handler: async (agent, input) => {
try {
const tokenAMint = new import_web34.PublicKey(input.tokenAMint);
const tokenBMint = new import_web34.PublicKey(input.tokenBMint);
const tokenAMintInfo = await agent.wallet.getConnection().getAccountInfo(tokenAMint);
const tokenBMintInfo = await agent.wallet.getConnection().getAccountInfo(tokenBMint);
if (!tokenAMintInfo) {
return {
status: "error",
message: "failed to fetch tokenAMint info",
code: "UNKNOWN_ERROR"
};
}
if (!tokenBMintInfo) {
return {
status: "error",
message: "failed to fetch tokenBMint info",
code: "UNKNOWN_ERROR"
};
}
const tokenADecimals = import_spl_token2.MintLayout.decode(tokenAMintInfo.data).decimals;
const tokenBDecimals = import_spl_token2.MintLayout.decode(tokenBMintInfo.data).decimals;
const tokenAAmount = new import_bn3.default(
new import_decimal.default(input.tokenAAmount).mul(10 ** tokenADecimals).toString()
);
const tokenBAmount = new import_bn3.default(
new import_decimal.default(input.tokenBAmount).mul(10 ** tokenBDecimals).toString()
);
const tradeFeeNumerator = new import_bn3.default(
input.tradeFeeNumerator.toString()
).toNumber();
const activationType = input.activationType ?? 1;
const activationPoint = input.activationPoint ? new import_bn3.default(input.activationPoint) : null;
const hasAlphaVault = input.hasAlphaVault ?? false;
const transaction = await createMeteoraDynamicAMMPool(
agent,
tokenAMint,
tokenBMint,
tokenAAmount,
tokenBAmount,
{
activationPoint,
activationType,
hasAlphaVault,
tradeFeeNumerator,
padding: Array(90).fill(0)
}
);
return {
status: "success",
message: "Meteora Dynamic pool created successfully.",
transaction
};
} catch (error) {
return {
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR"
};
}
}
};
var createMeteoraDynamicAMMPool_default = createMeteoraDynamicAMMPoolAction;
// src/index.ts
var MeteoraPlugin = class extends import_agentix3.PluginBase {
constructor() {
const methods = {
createMeteoraDlmmPool,
createMeteoraDynamicAMMPool
};
const actions = [
createMeteoraDLMMPool_default,
createMeteoraDynamicAMMPool_default
];
const supportedChains = [
{
type: "solana"
}
];
super("meteora", methods, actions, supportedChains);
}
supportsWallet(wallet) {
return wallet instanceof import_agentix3.SolanaWalletBase;
}
};
var index_default = MeteoraPlugin;