UNPKG

@agentix/plugin-solana-solutiofi

Version:
464 lines (455 loc) 14 kB
"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_agentix2 = require("agentix"); // src/actions/burnTokens.ts var import_zod = require("zod"); // src/tools/solutiofi.ts var import_sdk = __toESM(require("@solutiofi/sdk"), 1); var import_agentix = require("agentix"); var solutiofiClient = null; async function initClient(agent) { if (!agent.config?.SOLUTIOFI_API_KEY) { throw new Error("SolutioFi API key not found in config"); } if (!solutiofiClient) { solutiofiClient = new import_sdk.default({ apiKey: agent.config?.SOLUTIOFI_API_KEY }); await solutiofiClient.authenticate(); } return solutiofiClient; } async function closeAccounts(agent, mints) { try { const client = await initClient(agent); const signaturesOrTxs = []; const versionedTxns = await client.close( agent.wallet.getAddress(), mints ); for (const transaction of versionedTxns) { try { const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash(); transaction.message.recentBlockhash = blockhash; const signatureOrTx = await (0, import_agentix.signOrSendTX)(agent, transaction); signaturesOrTxs.push(signatureOrTx); } catch (_error) { continue; } } return signaturesOrTxs; } catch (e) { throw new Error(`Failed to close accounts: ${e}`); } } async function burnTokens(agent, mints) { try { const client = await initClient(agent); const signaturesOrTxs = []; const versionedTxns = await client.burn( agent.wallet.getAddress(), mints ); for (const transaction of versionedTxns) { try { const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash(); transaction.message.recentBlockhash = blockhash; const signatureOrTx = await (0, import_agentix.signOrSendTX)(agent, transaction); signaturesOrTxs.push(signatureOrTx); } catch (_error) { continue; } } return signaturesOrTxs; } catch (e) { throw new Error(`Failed to burn tokens: ${e}`); } } async function mergeTokens(agent, inputAssets, outputMint, priorityFee) { try { const client = await initClient(agent); const signaturesOrTxs = []; const swapData = await client.merge( agent.wallet.getAddress(), inputAssets, outputMint, priorityFee ); for (const txn of swapData.transactions) { try { const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash(); txn.transaction.message.recentBlockhash = blockhash; const signatureOrTx = await (0, import_agentix.signOrSendTX)(agent, txn.transaction); signaturesOrTxs.push(signatureOrTx); } catch (_error) { continue; } } return signaturesOrTxs; } catch (e) { throw new Error(`Failed to merge tokens: ${e}`); } } async function spreadToken(agent, inputAsset, targetTokens, priorityFee) { try { const client = await initClient(agent); const signaturesOrTxs = []; const swapData = await client.spread( agent.wallet.getAddress(), inputAsset, targetTokens, priorityFee ); for (const txn of swapData.transactions) { try { const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash(); txn.transaction.message.recentBlockhash = blockhash; const signatureOrTx = await (0, import_agentix.signOrSendTX)(agent, txn.transaction); signaturesOrTxs.push(signatureOrTx); } catch (_error) { continue; } } return signaturesOrTxs; } catch (e) { throw new Error(`Failed to spread token: ${e}`); } } // src/actions/burnTokens.ts var burnTokensAction = { name: "SOLUTIOFI_BURN_TOKENS", description: "Burn tokens using SolutioFi", similes: [ "burn tokens", "burn spl tokens", "burn spl-token", "destroy tokens", "burn assets", "burn nfts", "burn an nft", "permanently delete an nft or a token", "remove tokens from circulation", "delete my tokens", "permanently remove my tokens", "burn tokens with solutiofi", "burn nfts with solutiofi" ], examples: [ [ { input: { mints: ["tokenMint123", "tokenMint456"] }, output: { status: "success", message: "Successfully burnt tokens", transactions: ["tx_signature"] }, explanation: "Burn specified tokens" } ] ], schema: import_zod.z.object({ mints: import_zod.z.array(import_zod.z.string()).describe("Array of mint addresses to burn") }), handler: async (agent, input) => { try { const { mints } = input; const transactions = await burnTokens(agent, mints); return { status: "success", transactions, message: "Successfully burned tokens" }; } catch (error) { return { status: "error", message: `Failed to burn tokens: ${error.message}`, code: error.code || "BURN_TOKENS_ERROR" }; } } }; var burnTokens_default = burnTokensAction; // src/actions/closeAccounts.ts var import_zod2 = require("zod"); var closeAccountsAction = { name: "SOLUTIOFI_CLOSE_ACCOUNTS", description: "Close specific token accounts using SolutioFi", similes: [ "close token accounts", "close accounts with solutiofi", "close specific token accounts", "close specific spl token account", "remove empty accounts", "clean up token accounts", "close SPL token accounts", "delete my empty token accounts", "remove unused accounts", "disable token accounts", "deactivate empty token accounts", "clear empty token accounts", "reclaim SOL by closing accounts", "reclaim rent by closing empty accounts", "purge my wallet of empty accounts", "I want to close some accounts", "help me remove empty token accounts", "delete unnecessary accounts", "get rid of my empty accounts", "close down specific Solana token accounts", "remove all zero-balance tokens from my wallet", "I want to remove some token accounts" ], examples: [ [ { input: { mints: ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"] }, output: { status: "success", message: "Successfully closed accounts", transactions: ["tx_signature"] }, explanation: "Close specified token accounts" } ] ], schema: import_zod2.z.object({ mints: import_zod2.z.array(import_zod2.z.string()).describe("Array of mint addresses to close") }), handler: async (agent, input) => { try { const { mints } = input; const transactions = await closeAccounts(agent, mints); return { status: "success", transactions, message: `Successfully closed ${mints.length} accounts` }; } catch (error) { return { status: "error", message: `Failed to close accounts: ${error.message}`, code: error.code || "CLOSE_ACCOUNTS_ERROR" }; } } }; var closeAccounts_default = closeAccountsAction; // src/actions/mergeTokens.ts var import_zod3 = require("zod"); var mergeTokensAction = { name: "SOLUTIOFI_MERGE_TOKENS", description: "Merge multiple tokens into one using SolutioFi", similes: [ "merge tokens", "combine tokens", "swap tokens", "merge tokens with solutiofi", "swap multiple tokens for one", "convert tokens into a single asset", "merge SPL tokens", "swap tokens into one", "combine assets into one token", "convert multiple tokens into one", "swap multiple assets into a single token", "combine token holdings", "exchange tokens for a unified asset", "aggregate tokens into one" ], examples: [ [ { input: { inputAssets: [ { mint: "mint1", amount: "100" }, { mint: "mint2", amount: "200" } ], outputMint: "outputMint123", priorityFee: "fast" }, output: { status: "success", message: "Successfully merged tokens", result: { transaction: "tx_signature" } }, explanation: "Merge multiple tokens into one output token" } ] ], schema: import_zod3.z.object({ inputAssets: import_zod3.z.array( import_zod3.z.object({ mint: import_zod3.z.string(), amount: import_zod3.z.string() }) ).describe("Array of input assets to merge"), outputMint: import_zod3.z.string().describe("Output token mint address"), priorityFee: import_zod3.z.enum(["fast", "turbo", "ultra"]).describe("Transaction priority level") }), handler: async (agent, input) => { try { const { inputAssets, outputMint, priorityFee } = input; const transactions = await mergeTokens( agent, inputAssets, outputMint, priorityFee ); return { status: "success", transactions, message: "Successfully merged tokens" }; } catch (error) { return { status: "error", message: `Failed to merge tokens: ${error.message}`, code: error.code || "MERGE_TOKENS_ERROR" }; } } }; var mergeTokens_default = mergeTokensAction; // src/actions/spreadToken.ts var import_zod4 = require("zod"); var spreadTokenAction = { name: "SOLUTIOFI_SPREAD_TOKEN", description: "Split a token into multiple tokens using SolutioFi", similes: [ "spread token", "split token", "swap token", "spread tokens with solutiofi", "swap one token for multiple", "buy multiple tokens at once", "break token into parts", "split token into multiple assets", "convert one token into many", "swap token into different tokens", "allocate token to multiple assets", "spread token balance across multiple tokens", "swap and distribute token", "convert token into smaller portions", "exchange one token for multiple", "redistribute token into other tokens", "convert and spread token balance", "swap one asset for multiple tokens" ], examples: [ [ { input: { inputAsset: { mint: "inputMint", amount: "1000" }, targetTokens: [ { mint: "targetMint1", percentage: 60 }, { mint: "targetMint2", percentage: 40 } ], priorityFee: "fast" }, output: { status: "success", message: "Successfully spread token", result: { transaction: "tx_signature" } }, explanation: "Split one token into multiple target tokens" } ] ], schema: import_zod4.z.object({ inputAsset: import_zod4.z.object({ mint: import_zod4.z.string(), amount: import_zod4.z.string() }).describe("Input asset to spread"), targetTokens: import_zod4.z.array( import_zod4.z.object({ mint: import_zod4.z.string(), percentage: import_zod4.z.number() }) ).describe("Target tokens with allocation percentages"), priorityFee: import_zod4.z.enum(["fast", "turbo", "ultra"]).describe("Transaction priority level") }), handler: async (agent, input) => { try { const { inputAsset, targetTokens, priorityFee } = input; const result = await spreadToken( agent, inputAsset, targetTokens, priorityFee ); return { status: "success", transactions: result, message: "Successfully spread token" }; } catch (error) { return { status: "error", message: `Failed to spread token: ${error.message}`, code: error.code || "SPREAD_TOKEN_ERROR" }; } } }; var spreadToken_default = spreadTokenAction; // src/index.ts var SolutiofiPlugin = class extends import_agentix2.PluginBase { constructor() { const methods = { burnTokens, closeAccounts, mergeTokens, spreadToken }; const actions = [ burnTokens_default, closeAccounts_default, mergeTokens_default, spreadToken_default ]; const supportedChains = [ { type: "solana" } ]; super("solutiofi", methods, actions, supportedChains); } supportsWallet(wallet) { return wallet instanceof import_agentix2.SolanaWalletBase; } }; var index_default = SolutiofiPlugin;