Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-near): replace console.log to eliza logger #1745

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/plugin-near/src/actions/swap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ActionExample,
HandlerCallback,
elizaLogger,
IAgentRuntime,
Memory,
ModelClass,
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
};
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)}`,
};
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-near/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Memory,
ModelClass,
State,
elizaLogger,
type Action,
composeContext,
generateObject,
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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}`,
Expand Down
22 changes: 14 additions & 8 deletions packages/plugin-near/src/providers/wallet.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) =>
Expand All @@ -125,7 +131,7 @@ export class WalletProvider implements Provider {
const cachedValue = this.cache.get<WalletPortfolio>(cacheKey);

if (cachedValue) {
console.log("Cache hit for fetchPortfolioValue");
elizaLogger.log("Cache hit for fetchPortfolioValue");
return cachedValue;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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.";
}
}
Expand All @@ -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;
}
},
Expand Down
Loading