From 40193b75e8b53ec742e7a7c659783cf6d04146aa Mon Sep 17 00:00:00 2001 From: shivaji43 Date: Sun, 12 Jan 2025 16:25:31 +0530 Subject: [PATCH] fix:deleted unncessary files --- src/tools/get_assets_by_owner.ts | 57 ------- src/tools/helius_transaction_parsing.ts | 44 ----- src/tools/helius_webhook.ts | 132 --------------- src/tools/send_transaction_with_priority.ts | 175 -------------------- 4 files changed, 408 deletions(-) delete mode 100644 src/tools/get_assets_by_owner.ts delete mode 100644 src/tools/helius_transaction_parsing.ts delete mode 100644 src/tools/helius_webhook.ts delete mode 100644 src/tools/send_transaction_with_priority.ts diff --git a/src/tools/get_assets_by_owner.ts b/src/tools/get_assets_by_owner.ts deleted file mode 100644 index 45f3dbe..0000000 --- a/src/tools/get_assets_by_owner.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { SolanaAgentKit } from "../index"; -import { PublicKey } from "@solana/web3.js"; - -/** - * Fetch assets by owner using the Helius Digital Asset Standard (DAS) API - * @param agent SolanaAgentKit instance - * @param ownerPublicKey Owner's Solana wallet PublicKey - * @param limit Number of assets to retrieve per request - * @returns Assets owned by the specified address - */ -export async function getAssetsByOwner( - agent: SolanaAgentKit, - ownerPublicKey: PublicKey, - limit: number, -): Promise { - try { - const apiKey = agent.config.HELIUS_API_KEY; - if (!apiKey) { - throw new Error("HELIUS_API_KEY not found in environment variables"); - } - - const url = `https://mainnet.helius-rpc.com/?api-key=${apiKey}`; - - const response = await fetch(url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - jsonrpc: "2.0", - id: "get-assets", - method: "getAssetsByOwner", - params: { - ownerAddress: ownerPublicKey.toString(), - page: 3, - limit: limit, - displayOptions: { - showFungible: true, - }, - }, - }), - }); - - if (!response.ok) { - throw new Error( - `Failed to fetch: ${response.status} - ${response.statusText}`, - ); - } - - const data = await response.json(); - - return data.result.items; - } catch (error: any) { - console.error("Error retrieving assets: ", error.message); - throw new Error(`Assets retrieval failed: ${error.message}`); - } -} diff --git a/src/tools/helius_transaction_parsing.ts b/src/tools/helius_transaction_parsing.ts deleted file mode 100644 index 1f24ee3..0000000 --- a/src/tools/helius_transaction_parsing.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { SolanaAgentKit } from "../index"; - -/** - * Parse a Solana transaction using the Helius Enhanced Transactions API - * @param agent SolanaAgentKit instance - * @param transactionId The transaction ID to parse - * @returns Parsed transaction data - */ -export async function parseTransaction( - agent: SolanaAgentKit, - transactionId: string, -): Promise { - try { - const apiKey = agent.config.HELIUS_API_KEY; - if (!apiKey) { - throw new Error("HELIUS_API_KEY not found in environment variables"); - } - - const url = `https://api.helius.xyz/v0/transactions/?api-key=${apiKey}`; - - const response = await fetch(url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - transactions: [transactionId], - }), - }); - - if (!response.ok) { - throw new Error( - `Failed to fetch: ${response.status} - ${response.statusText}`, - ); - } - - const data = await response.json(); - - return data; - } catch (error: any) { - console.error("Error parsing transaction: ", error.message); - throw new Error(`Transaction parsing failed: ${error.message}`); - } -} diff --git a/src/tools/helius_webhook.ts b/src/tools/helius_webhook.ts deleted file mode 100644 index 98b083f..0000000 --- a/src/tools/helius_webhook.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { SolanaAgentKit } from "../index"; -import { HeliusWebhookResponse, HeliusWebhookIdResponse } from "../index"; - -export async function create_HeliusWebhook( - agent: SolanaAgentKit, - accountAddresses: string[], - webhookURL: string, -): Promise { - try { - const response = await fetch( - `https://api.helius.xyz/v0/webhooks?api-key=${agent.config.HELIUS_API_KEY}`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - webhookURL, - transactionTypes: ["Any"], - accountAddresses, - webhookType: "enhanced", - txnStatus: "all", - }), - }, - ); - - const data = await response.json(); - return { - webhookURL: data.webhookURL, - webhookID: data.webhookID, - }; - } catch (error: any) { - throw new Error(`Failed to create Webhook: ${error.message}`); - } -} - -/** - * Retrieves a Helius Webhook by ID, returning only the specified fields. - * - * @param agent - An instance of SolanaAgentKit (with .config.HELIUS_API_KEY) - * @param webhookID - The unique ID of the webhook to retrieve - * - * @returns A HeliusWebhook object containing { wallet, webhookURL, transactionTypes, accountAddresses, webhookType } - */ -export async function getHeliusWebhook( - agent: SolanaAgentKit, - webhookID: string, -): Promise { - try { - const apiKey = agent.config.HELIUS_API_KEY; - if (!apiKey) { - throw new Error("HELIUS_API_KEY is missing in agent.config"); - } - - const response = await fetch( - `https://api.helius.xyz/v0/webhooks/${webhookID}?api-key=${apiKey}`, - { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - }, - ); - - if (!response.ok) { - throw new Error( - `Failed to fetch webhook with ID ${webhookID}. ` + - `Status Code: ${response.status}`, - ); - } - - const data = await response.json(); - - return { - wallet: data.wallet, - webhookURL: data.webhookURL, - transactionTypes: data.transactionTypes, - accountAddresses: data.accountAddresses, - webhookType: data.webhookType, - }; - } catch (error: any) { - throw new Error(`Failed to get webhook by ID: ${error.message}`); - } -} - -/** - * Deletes a Helius Webhook by its ID. - * - * @param agent - An instance of SolanaAgentKit (with .config.HELIUS_API_KEY) - * @param webhookID - The unique ID of the webhook to delete - * - * @returns The response body from the Helius API (which may contain status or other info) - */ -export async function deleteHeliusWebhook( - agent: SolanaAgentKit, - webhookID: string, -): Promise { - try { - const apiKey = agent.config.HELIUS_API_KEY; - if (!apiKey) { - throw new Error("Missing Helius API key in agent.config.HELIUS_API_KEY"); - } - - const url = `https://api.helius.xyz/v0/webhooks/${webhookID}?api-key=${apiKey}`; - const response = await fetch(url, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - }, - }); - - if (!response.ok) { - throw new Error( - `Failed to delete webhook: ${response.status} ${response.statusText}`, - ); - } - if (response.status === 204) { - return { message: "Webhook deleted successfully (no content returned)" }; - } - const contentLength = response.headers.get("Content-Length"); - if (contentLength === "0" || !contentLength) { - return { message: "Webhook deleted successfully (empty body)" }; - } - - // Otherwise, parse as JSON - const data = await response.json(); - return data; - } catch (error: any) { - console.error("Error deleting Helius Webhook:", error.message); - throw new Error(`Failed to delete Helius Webhook: ${error.message}`); - } -} diff --git a/src/tools/send_transaction_with_priority.ts b/src/tools/send_transaction_with_priority.ts deleted file mode 100644 index 136f333..0000000 --- a/src/tools/send_transaction_with_priority.ts +++ /dev/null @@ -1,175 +0,0 @@ -import { SolanaAgentKit } from "../agent"; -import { - SystemProgram, - Transaction, - sendAndConfirmTransaction, - ComputeBudgetProgram, - PublicKey, - LAMPORTS_PER_SOL, -} from "@solana/web3.js"; -import { - getAssociatedTokenAddress, - createTransferInstruction, - getMint, - createAssociatedTokenAccountInstruction, -} from "@solana/spl-token"; -import bs58 from "bs58"; -import { PriorityFeeResponse } from "../types"; - -/** - * Sends a transaction with an estimated priority fee using the provided SolanaAgentKit. - * - * @param agent An instance of SolanaAgentKit containing connection, wallet, etc. - * @param priorityLevel The priority level (e.g., "Min", "Low", "Medium", "High", "VeryHigh", or "UnsafeMax"). - * @param amount The amount of SOL to send (in SOL, not lamports). - * @param to The recipient's PublicKey. - * @returns The transaction signature (string) once confirmed along with the fee used. - */ -export async function sendTransactionWithPriorityFee( - agent: SolanaAgentKit, - priorityLevel: string, - amount: number, - to: PublicKey, - splmintAddress?: PublicKey, -): Promise<{ transactionId: string; fee: number }> { - try { - if (!splmintAddress) { - const transaction = new Transaction(); - const { blockhash, lastValidBlockHeight } = - await agent.connection.getLatestBlockhash(); - transaction.recentBlockhash = blockhash; - transaction.lastValidBlockHeight = lastValidBlockHeight; - transaction.feePayer = agent.wallet_address; - - const transferIx = SystemProgram.transfer({ - fromPubkey: agent.wallet_address, - toPubkey: to, - lamports: amount * LAMPORTS_PER_SOL, - }); - - transaction.add(transferIx); - transaction.sign(agent.wallet); - - const response = await fetch( - `https://mainnet.helius-rpc.com/?api-key=${agent.config.HELIUS_API_KEY}`, - { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - jsonrpc: "2.0", - id: "1", - method: "getPriorityFeeEstimate", - params: [ - { - transaction: bs58.encode(transaction.serialize()), - options: { priorityLevel: priorityLevel }, - }, - ], - } as PriorityFeeResponse), - }, - ); - - const data = await response.json(); - if (data.error) { - throw new Error("Error fetching priority fee:"); - } - const feeEstimate: number = data.result.priorityFeeEstimate; - - // Set the priority fee if applicable - const computePriceIx = ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: feeEstimate, - }); - transaction.add(computePriceIx); - - // Send the transaction and confirm - const txSignature = await sendAndConfirmTransaction( - agent.connection, - transaction, - [agent.wallet], - ); - - return { - transactionId: txSignature, - fee: feeEstimate, - }; - } else { - const fromAta = await getAssociatedTokenAddress( - splmintAddress, - agent.wallet_address, - ); - const toAta = await getAssociatedTokenAddress(splmintAddress, to); - - const mintInfo = await getMint(agent.connection, splmintAddress); - const adjustedAmount = amount * Math.pow(10, mintInfo.decimals); - - const transaction = new Transaction(); - const { blockhash, lastValidBlockHeight } = - await agent.connection.getLatestBlockhash(); - transaction.recentBlockhash = blockhash; - transaction.lastValidBlockHeight = lastValidBlockHeight; - transaction.feePayer = agent.wallet_address; - - const response = await fetch( - `https://mainnet.helius-rpc.com/?api-key=${agent.config.HELIUS_API_KEY}`, - { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - jsonrpc: "2.0", - id: "1", - method: "getPriorityFeeEstimate", - params: [ - { - transaction: bs58.encode(transaction.serialize()), - options: { priorityLevel: priorityLevel }, - }, - ], - } as PriorityFeeResponse), - }, - ); - - const data = await response.json(); - if (data.error) { - throw new Error("Error fetching priority fee:"); - } - const feeEstimate: number = data.result.priorityFeeEstimate; - - transaction.add( - ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: feeEstimate, - }), - ); - - transaction.add( - createAssociatedTokenAccountInstruction( - agent.wallet_address, - toAta, - to, - splmintAddress, - ), - ); - - transaction.add( - createTransferInstruction( - fromAta, - toAta, - agent.wallet_address, - adjustedAmount, - ), - ); - - const txSignature = await sendAndConfirmTransaction( - agent.connection, - transaction, - [agent.wallet], - ); - - return { - transactionId: txSignature, - fee: feeEstimate, - }; - } - } catch (error: any) { - throw new Error(`Failed to process transaction: ${error.message}`); - } -}