From 7a1cf93342ab4c5ccf1c0036203888b533691cfc Mon Sep 17 00:00:00 2001 From: bendanzhentan <455462586@qq.com> Date: Tue, 31 Dec 2024 17:28:20 +0800 Subject: [PATCH 1/3] refactor(plugin-conflux): output detailed invalid content --- .../plugin-conflux/src/actions/confiPump.ts | 9 ++++++--- packages/plugin-conflux/src/types.ts | 18 +++--------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/plugin-conflux/src/actions/confiPump.ts b/packages/plugin-conflux/src/actions/confiPump.ts index c5d143787d..bd23f71a45 100644 --- a/packages/plugin-conflux/src/actions/confiPump.ts +++ b/packages/plugin-conflux/src/actions/confiPump.ts @@ -213,7 +213,8 @@ export const confiPump: Action = { switch (contentObject.action) { case "CREATE_TOKEN": if (!isPumpCreateContent(contentObject)) { - throw new Error("Invalid content"); + console.error("Invalid PumpCreateContent: ", contentObject); + throw new Error("Invalid PumpCreateContent"); } console.log( "creating: ", @@ -235,7 +236,8 @@ export const confiPump: Action = { case "BUY_TOKEN": if (!isPumpBuyContent(contentObject)) { - throw new Error("Invalid content"); + console.error("Invalid PumpBuyContent: ", contentObject); + throw new Error("Invalid PumpBuyContent"); } value = parseUnits( contentObject.params.value.toString(), @@ -260,7 +262,8 @@ export const confiPump: Action = { case "SELL_TOKEN": if (!isPumpSellContent(contentObject)) { - throw new Error("Invalid content"); + console.error("Invalid PumpSellContent: ", contentObject); + throw new Error("Invalid PumpSellContent"); } const tokenAddress = getAddress( contentObject.params.tokenAddress as `0x${string}` diff --git a/packages/plugin-conflux/src/types.ts b/packages/plugin-conflux/src/types.ts index a605b5a714..9764386437 100644 --- a/packages/plugin-conflux/src/types.ts +++ b/packages/plugin-conflux/src/types.ts @@ -64,25 +64,13 @@ export function isPumpContent(object: any): object is PumpContent { } export function isPumpCreateContent(object: any): object is PumpCreateContent { - if (PumpCreateSchema.safeParse(object).success) { - return true; - } - console.error("Invalid content: ", object); - return false; + return PumpCreateSchema.safeParse(object).success; } export function isPumpBuyContent(object: any): object is PumpBuyContent { - if (PumpBuySchema.safeParse(object).success) { - return true; - } - console.error("Invalid content: ", object); - return false; + return PumpBuySchema.safeParse(object).success; } export function isPumpSellContent(object: any): object is PumpSellContent { - if (PumpSellSchema.safeParse(object).success) { - return true; - } - console.error("Invalid content: ", object); - return false; + return PumpSellSchema.safeParse(object).success; } From 1afd727537081f2f0e85e395926dec0d43051d00 Mon Sep 17 00:00:00 2001 From: Shakker Nerd Date: Tue, 31 Dec 2024 09:43:39 +0000 Subject: [PATCH 2/3] chore: console -> elizaLogger --- .../plugin-conflux/src/actions/confiPump.ts | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/plugin-conflux/src/actions/confiPump.ts b/packages/plugin-conflux/src/actions/confiPump.ts index bd23f71a45..ada3c50f8c 100644 --- a/packages/plugin-conflux/src/actions/confiPump.ts +++ b/packages/plugin-conflux/src/actions/confiPump.ts @@ -4,6 +4,7 @@ import { Memory, State, HandlerCallback, + elizaLogger, } from "@elizaos/core"; import { generateObject, composeContext, ModelClass } from "@elizaos/core"; import { @@ -38,7 +39,7 @@ async function ensureAllowance( memeAddress: `0x${string}`, amount: bigint ) { - console.log( + elizaLogger.log( `Checking allowance: token: ${tokenAddress} meme: ${memeAddress} amount: ${amount}` ); @@ -54,10 +55,10 @@ async function ensureAllowance( args: [account.address, memeAddress], }); - console.log("allowance:", allowance); + elizaLogger.log("allowance:", allowance); if (allowance < amount) { - console.log( + elizaLogger.log( `allowance(${allowance}) is less than amount(${amount}), approving...` ); @@ -73,11 +74,11 @@ async function ensureAllowance( kzg: null, }); - console.log(`Approving hash: ${hash}`); + elizaLogger.log(`Approving hash: ${hash}`); await publicClient.waitForTransactionReceipt({ hash }); - console.log(`Approving success: ${hash}`); + elizaLogger.log(`Approving success: ${hash}`); } else { - console.log(`No need to approve`); + elizaLogger.log(`No need to approve`); } } @@ -213,10 +214,13 @@ export const confiPump: Action = { switch (contentObject.action) { case "CREATE_TOKEN": if (!isPumpCreateContent(contentObject)) { - console.error("Invalid PumpCreateContent: ", contentObject); + elizaLogger.error( + "Invalid PumpCreateContent: ", + contentObject + ); throw new Error("Invalid PumpCreateContent"); } - console.log( + elizaLogger.log( "creating: ", contentObject.params.name, contentObject.params.symbol, @@ -236,14 +240,17 @@ export const confiPump: Action = { case "BUY_TOKEN": if (!isPumpBuyContent(contentObject)) { - console.error("Invalid PumpBuyContent: ", contentObject); + elizaLogger.error( + "Invalid PumpBuyContent: ", + contentObject + ); throw new Error("Invalid PumpBuyContent"); } value = parseUnits( contentObject.params.value.toString(), 18 ); - console.log( + elizaLogger.log( "buying: ", contentObject.params.tokenAddress, value @@ -262,13 +269,16 @@ export const confiPump: Action = { case "SELL_TOKEN": if (!isPumpSellContent(contentObject)) { - console.error("Invalid PumpSellContent: ", contentObject); + elizaLogger.error( + "Invalid PumpSellContent: ", + contentObject + ); throw new Error("Invalid PumpSellContent"); } const tokenAddress = getAddress( contentObject.params.tokenAddress as `0x${string}` ); - console.log( + elizaLogger.log( "selling: ", tokenAddress, account.address, @@ -315,7 +325,7 @@ export const confiPump: Action = { value, account, }); - console.log("simulate: ", simulate); + elizaLogger.log("simulate: ", simulate); const hash = await walletClient.sendTransaction({ account, @@ -335,7 +345,7 @@ export const confiPump: Action = { }); } } catch (error) { - console.error(`Error performing the action: ${error}`); + elizaLogger.error(`Error performing the action: ${error}`); if (callback) { callback({ text: `Failed to perform the action: ${content.object.action}: ${error}`, From e59c807979208c24ed51e28f4155966fe56353b4 Mon Sep 17 00:00:00 2001 From: Shakker Nerd Date: Tue, 31 Dec 2024 10:19:22 +0000 Subject: [PATCH 3/3] chore: pnpm lock file --- pnpm-lock.yaml | 73 +++----------------------------------------------- 1 file changed, 4 insertions(+), 69 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 24a75803b8..d21bab63e0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1923,10 +1923,10 @@ importers: version: 8.16.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.6.3) jest: specifier: 29.7.0 - version: 29.7.0(@types/node@20.17.9) + version: 29.7.0(@types/node@20.17.9)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)) ts-jest: specifier: 29.2.5 - version: 29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(jest@29.7.0(@types/node@20.17.9))(typescript@5.6.3) + version: 29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(esbuild@0.24.2)(jest@29.7.0(@types/node@20.17.9)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)))(typescript@5.6.3) typescript: specifier: 5.6.3 version: 5.6.3 @@ -31422,21 +31422,6 @@ snapshots: - supports-color - ts-node - create-jest@29.7.0(@types/node@20.17.9): - dependencies: - '@jest/types': 29.6.3 - chalk: 4.1.2 - exit: 0.1.2 - graceful-fs: 4.2.11 - jest-config: 29.7.0(@types/node@20.17.9)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.8.4)(typescript@5.6.3)) - jest-util: 29.7.0 - prompts: 2.4.2 - transitivePeerDependencies: - - '@types/node' - - babel-plugin-macros - - supports-color - - ts-node - create-jest@29.7.0(@types/node@20.17.9)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)): dependencies: '@jest/types': 29.6.3 @@ -35310,25 +35295,6 @@ snapshots: - supports-color - ts-node - jest-cli@29.7.0(@types/node@20.17.9): - dependencies: - '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.8.4)(typescript@5.6.3)) - '@jest/test-result': 29.7.0 - '@jest/types': 29.6.3 - chalk: 4.1.2 - create-jest: 29.7.0(@types/node@20.17.9) - exit: 0.1.2 - import-local: 3.2.0 - jest-config: 29.7.0(@types/node@20.17.9)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.8.4)(typescript@5.6.3)) - jest-util: 29.7.0 - jest-validate: 29.7.0 - yargs: 17.7.2 - transitivePeerDependencies: - - '@types/node' - - babel-plugin-macros - - supports-color - - ts-node - jest-cli@29.7.0(@types/node@20.17.9)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)): dependencies: '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)) @@ -35350,7 +35316,7 @@ snapshots: jest-cli@29.7.0(@types/node@22.10.2): dependencies: - '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.8.4)(typescript@5.6.3)) + '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)) '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 @@ -35804,18 +35770,6 @@ snapshots: - supports-color - ts-node - jest@29.7.0(@types/node@20.17.9): - dependencies: - '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.8.4)(typescript@5.6.3)) - '@jest/types': 29.6.3 - import-local: 3.2.0 - jest-cli: 29.7.0(@types/node@20.17.9) - transitivePeerDependencies: - - '@types/node' - - babel-plugin-macros - - supports-color - - ts-node - jest@29.7.0(@types/node@20.17.9)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)): dependencies: '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)) @@ -35830,7 +35784,7 @@ snapshots: jest@29.7.0(@types/node@22.10.2): dependencies: - '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.8.4)(typescript@5.6.3)) + '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@20.17.9)(typescript@5.6.3)) '@jest/types': 29.6.3 import-local: 3.2.0 jest-cli: 29.7.0(@types/node@22.10.2) @@ -41881,25 +41835,6 @@ snapshots: '@jest/types': 29.6.3 babel-jest: 29.7.0(@babel/core@7.26.0) - ts-jest@29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(jest@29.7.0(@types/node@20.17.9))(typescript@5.6.3): - dependencies: - bs-logger: 0.2.6 - ejs: 3.1.10 - fast-json-stable-stringify: 2.1.0 - jest: 29.7.0(@types/node@20.17.9) - jest-util: 29.7.0 - json5: 2.2.3 - lodash.memoize: 4.1.2 - make-error: 1.3.6 - semver: 7.6.3 - typescript: 5.6.3 - yargs-parser: 21.1.1 - optionalDependencies: - '@babel/core': 7.26.0 - '@jest/transform': 29.7.0 - '@jest/types': 29.6.3 - babel-jest: 29.7.0(@babel/core@7.26.0) - ts-jest@29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(jest@29.7.0(@types/node@22.8.4)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.8.4)(typescript@5.6.3)))(typescript@5.6.3): dependencies: bs-logger: 0.2.6