diff --git a/packages/plugin-near/src/actions/swap.ts b/packages/plugin-near/src/actions/swap.ts index f11f6b134f..5d1ebbe3db 100644 --- a/packages/plugin-near/src/actions/swap.ts +++ b/packages/plugin-near/src/actions/swap.ts @@ -1,6 +1,7 @@ import { ActionExample, HandlerCallback, + elizaLogger, IAgentRuntime, Memory, ModelClass, @@ -34,7 +35,7 @@ async function checkStorageBalance( }); return balance !== null && balance.total !== "0"; } catch (error) { - console.log(`Error checking storage balance: ${error}`); + elizaLogger.log(`Error checking storage balance: ${error}`); return false; } } @@ -142,7 +143,7 @@ async function swapToken( return transactions; } catch (error) { - console.error("Error in swapToken:", error); + elizaLogger.error("Error in swapToken:", error); throw error; } } @@ -186,8 +187,8 @@ export const executeSwap: Action = { "TRADE_TOKENS_NEAR", "EXCHANGE_TOKENS_NEAR", ], - validate: async (runtime: IAgentRuntime, message: Memory) => { - console.log("Message:", message); + validate: async (_runtime: IAgentRuntime, message: Memory) => { + elizaLogger.log("Message:", message); return true; }, description: "Perform a token swap using Ref Finance.", @@ -221,14 +222,14 @@ export const executeSwap: Action = { modelClass: ModelClass.LARGE, }); - console.log("Response:", response); + elizaLogger.log("Response:", response); if ( !response.inputTokenId || !response.outputTokenId || !response.amount ) { - console.log("Missing required parameters, skipping swap"); + elizaLogger.log("Missing required parameters, skipping swap"); const responseMsg = { text: "I need the input token ID, output token ID, and amount to perform the swap", }; @@ -290,7 +291,7 @@ export const executeSwap: Action = { } } - console.log("Swap completed successfully!"); + elizaLogger.log("Swap completed successfully!"); const txHashes = results.map((r) => r.transaction.hash).join(", "); const responseMsg = { @@ -300,7 +301,7 @@ export const executeSwap: Action = { callback?.(responseMsg); return true; } catch (error) { - console.error("Error during token swap:", error); + elizaLogger.error("Error during token swap:", error); const responseMsg = { text: `Error during swap: ${error instanceof Error ? error.message : String(error)}`, }; diff --git a/packages/plugin-near/src/actions/transfer.ts b/packages/plugin-near/src/actions/transfer.ts index f0a2d53b77..ab37f5030e 100644 --- a/packages/plugin-near/src/actions/transfer.ts +++ b/packages/plugin-near/src/actions/transfer.ts @@ -6,6 +6,7 @@ import { Memory, ModelClass, State, + elizaLogger, type Action, composeContext, generateObject, @@ -132,7 +133,7 @@ export const executeTransfer: Action = { // Validate transfer content if (!isTransferContent(runtime, content)) { - console.error("Invalid content for TRANSFER_NEAR action."); + elizaLogger.error("Invalid content for TRANSFER_NEAR action."); if (callback) { callback({ text: "Unable to process transfer request. Invalid content provided.", @@ -163,7 +164,7 @@ export const executeTransfer: Action = { return true; } catch (error) { - console.error("Error during NEAR transfer:", error); + elizaLogger.error("Error during NEAR transfer:", error); if (callback) { callback({ text: `Error transferring NEAR: ${error}`, diff --git a/packages/plugin-near/src/providers/wallet.ts b/packages/plugin-near/src/providers/wallet.ts index 218398d397..a35a082148 100644 --- a/packages/plugin-near/src/providers/wallet.ts +++ b/packages/plugin-near/src/providers/wallet.ts @@ -1,4 +1,10 @@ -import { IAgentRuntime, Memory, Provider, State } from "@elizaos/core"; +import { + IAgentRuntime, + Memory, + Provider, + State, + elizaLogger, +} from "@elizaos/core"; import { KeyPair, keyStores, connect, Account, utils } from "near-api-js"; import BigNumber from "bignumber.js"; import { KeyPairString } from "near-api-js/lib/utils"; @@ -51,7 +57,7 @@ export class WalletProvider implements Provider { try { return await this.getFormattedPortfolio(runtime); } catch (error) { - console.error("Error in wallet provider:", error); + elizaLogger.error("Error in wallet provider:", error); return null; } } @@ -102,7 +108,7 @@ export class WalletProvider implements Provider { } return await response.json(); } catch (error) { - console.error(`Attempt ${i + 1} failed:`, error); + elizaLogger.error(`Attempt ${i + 1} failed:`, error); lastError = error as Error; if (i < PROVIDER_CONFIG.MAX_RETRIES - 1) { await new Promise((resolve) => @@ -125,7 +131,7 @@ export class WalletProvider implements Provider { const cachedValue = this.cache.get(cacheKey); if (cachedValue) { - console.log("Cache hit for fetchPortfolioValue"); + elizaLogger.log("Cache hit for fetchPortfolioValue"); return cachedValue; } @@ -160,7 +166,7 @@ export class WalletProvider implements Provider { this.cache.set(cacheKey, portfolio); return portfolio; } catch (error) { - console.error("Error fetching portfolio:", error); + elizaLogger.error("Error fetching portfolio:", error); throw error; } } @@ -181,7 +187,7 @@ export class WalletProvider implements Provider { this.cache.set(cacheKey, price); return price; } catch (error) { - console.error("Error fetching NEAR price:", error); + elizaLogger.error("Error fetching NEAR price:", error); return 0; } } @@ -214,7 +220,7 @@ export class WalletProvider implements Provider { const portfolio = await this.fetchPortfolioValue(runtime); return this.formatPortfolio(runtime, portfolio); } catch (error) { - console.error("Error generating portfolio report:", error); + elizaLogger.error("Error generating portfolio report:", error); return "Unable to fetch wallet information. Please try again later."; } } @@ -234,7 +240,7 @@ const walletProvider: Provider = { const provider = new WalletProvider(accountId); return await provider.getFormattedPortfolio(runtime); } catch (error) { - console.error("Error in wallet provider:", error); + elizaLogger.error("Error in wallet provider:", error); return null; } },