From e31fed549bff68b6c80cb4fc28a21c26c2594565 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Mon, 16 Dec 2024 11:21:49 +0900 Subject: [PATCH 1/5] Adding plugin for Cronos ZKEVM --- .env.example | 4 + agent/package.json | 1 + agent/src/index.ts | 2 + packages/plugin-cronoszkevm/package.json | 20 ++ .../src/actions/transfer.ts | 230 ++++++++++++++++++ packages/plugin-cronoszkevm/src/enviroment.ts | 36 +++ packages/plugin-cronoszkevm/src/index.ts | 13 + packages/plugin-cronoszkevm/tsconfig.json | 8 + packages/plugin-cronoszkevm/tsup.config.ts | 20 ++ 9 files changed, 334 insertions(+) create mode 100644 packages/plugin-cronoszkevm/package.json create mode 100644 packages/plugin-cronoszkevm/src/actions/transfer.ts create mode 100644 packages/plugin-cronoszkevm/src/enviroment.ts create mode 100644 packages/plugin-cronoszkevm/src/index.ts create mode 100644 packages/plugin-cronoszkevm/tsconfig.json create mode 100644 packages/plugin-cronoszkevm/tsup.config.ts diff --git a/.env.example b/.env.example index feb720cd5f..015fa93fa7 100644 --- a/.env.example +++ b/.env.example @@ -319,3 +319,7 @@ STORY_PRIVATE_KEY= # Story private key STORY_API_BASE_URL= # Story API base URL STORY_API_KEY= # Story API key PINATA_JWT= # Pinata JWT for uploading files to IPFS + +# Cronos zkEVM +CRONOSZKEVM_ADDRESS= +CRONOSZKEVM_PRIVATE_KEY= diff --git a/agent/package.json b/agent/package.json index a0d291f934..84926cf4c1 100644 --- a/agent/package.json +++ b/agent/package.json @@ -50,6 +50,7 @@ "@ai16z/plugin-multiversx": "workspace:*", "@ai16z/plugin-near": "workspace:*", "@ai16z/plugin-zksync-era": "workspace:*", + "@ai16z/plugin-crozksy noszkevm": "workspace:*", "readline": "1.3.0", "ws": "8.18.0", "yargs": "17.7.2" diff --git a/agent/src/index.ts b/agent/src/index.ts index 3b9a63a463..123bffd26e 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -53,6 +53,7 @@ import { suiPlugin } from "@ai16z/plugin-sui"; import { TEEMode, teePlugin } from "@ai16z/plugin-tee"; import { tonPlugin } from "@ai16z/plugin-ton"; import { zksyncEraPlugin } from "@ai16z/plugin-zksync-era"; +import { cronosZkEVMPlugin } from "@ai16z/plugin-cronoszkEVM"; import Database from "better-sqlite3"; import fs from "fs"; import path from "path"; @@ -541,6 +542,7 @@ export async function createAgent( getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null, getSecret(character, "MVX_PRIVATE_KEY") ? multiversxPlugin : null, getSecret(character, "ZKSYNC_PRIVATE_KEY") ? zksyncEraPlugin : null, + getSecret(character, "CRONOSZKEVM_PRIVATE_KEY") ? zksyncEraPlugin : null, getSecret(character, "TON_PRIVATE_KEY") ? tonPlugin : null, getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null, getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null, diff --git a/packages/plugin-cronoszkevm/package.json b/packages/plugin-cronoszkevm/package.json new file mode 100644 index 0000000000..5098b11193 --- /dev/null +++ b/packages/plugin-cronoszkevm/package.json @@ -0,0 +1,20 @@ +{ + "name": "@ai16z/plugin-cronoszkevm", + "version": "0.1.4-alpha.3", + "main": "dist/index.js", + "type": "module", + "types": "dist/index.d.ts", + "dependencies": { + "@ai16z/eliza": "workspace:*", + "@ai16z/plugin-trustdb": "workspace:*", + "tsup": "^8.3.5", + "web3": "^4.15.0", + "web3-plugin-zksync": "^1.0.8" + }, + "scripts": { + "build": "tsup --format esm --dts" + }, + "peerDependencies": { + "whatwg-url": "7.1.0" + } +} diff --git a/packages/plugin-cronoszkevm/src/actions/transfer.ts b/packages/plugin-cronoszkevm/src/actions/transfer.ts new file mode 100644 index 0000000000..38932c8d63 --- /dev/null +++ b/packages/plugin-cronoszkevm/src/actions/transfer.ts @@ -0,0 +1,230 @@ +import { + ActionExample, + Content, + HandlerCallback, + IAgentRuntime, + Memory, + ModelClass, + State, + type Action, + elizaLogger, + composeContext, + generateObject +} from "@ai16z/eliza"; +import { validateCronosZkevmConfig } from "../enviroment"; + +import {Web3} from "web3"; +import { + ZKsyncPlugin, + ZKsyncWallet, + types, + Web3ZKsyncL2 +} from "web3-plugin-zksync"; + +export interface TransferContent extends Content { + tokenAddress: string; + recipient: string; + amount: string | number; +} + +export function isTransferContent( + content: TransferContent + ): content is TransferContent { + + // Validate types + const validTypes = + typeof content.tokenAddress === "string" && + typeof content.recipient === "string" && + (typeof content.amount === "string" || + typeof content.amount === "number"); + if (!validTypes) { + return false; + } + + // Validate addresses + const validAddresses = + content.tokenAddress.startsWith("0x") && + content.tokenAddress.length === 42 && + content.recipient.startsWith("0x") && + content.recipient.length === 42; + + return validAddresses; +} + + +const transferTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined. + +Here are several frequently used addresses. Use these for the corresponding tokens: +- ZKCRO/zkCRO: 0x000000000000000000000000000000000000800A +- USDC/usdc: 0xaa5b845f8c9c047779bedf64829601d8b264076c +- ETH/eth: 0x898b3560affd6d955b1574d87ee09e46669c60ea + +Example response: +\`\`\`json +{ + "tokenAddress": "0xaa5b845f8c9c047779bedf64829601d8b264076c", + "recipient": "0xCCa8009f5e09F8C5dB63cb0031052F9CB635Af62", + "amount": "1000" +} +\`\`\` + +{{recentMessages}} + +Given the recent messages, extract the following information about the requested token transfer: +- Token contract address +- Recipient wallet address +- Amount to transfer + +Respond with a JSON markdown block containing only the extracted values.`; + +export default { + name: "SEND_TOKEN", + similes: [ + "TRANSFER_TOKEN_ON_CRONOSZKEVM", + "TRANSFER_TOKENS_ON_CRONOSZK", + "SEND_TOKENS_ON_CRONOSZKEVM", + "SEND_TOKENS_ON_CRONOSZK", + "SEND_ETH_ON_CRONOSZKEVM", + "SEND_ETH_ON_CRONOSZK", + "PAY_ON_CRONOSZKEVM", + "PAY_ON_CRONOSZK", + ], + validate: async (runtime: IAgentRuntime, message: Memory) => { + await validateCronosZkevmConfig(runtime); + return true; + }, + description: "Transfer tokens from the agent's wallet to another address", + handler: async ( + runtime: IAgentRuntime, + message: Memory, + state: State, + _options: { [key: string]: unknown }, + callback?: HandlerCallback + ): Promise => { + elizaLogger.log("Starting SEND_TOKEN handler..."); + + // Initialize or update state + if (!state) { + state = (await runtime.composeState(message)) as State; + } else { + state = await runtime.updateRecentMessageState(state); + } + + // Compose transfer context + const transferContext = composeContext({ + state, + template: transferTemplate, + }); + + // Generate transfer content + const content = await generateObject({ + runtime, + context: transferContext, + modelClass: ModelClass.SMALL, + }); + + // Validate transfer content + if (!isTransferContent(content)) { + console.error("Invalid content for TRANSFER_TOKEN action."); + if (callback) { + callback({ + text: "Unable to process transfer request. Invalid content provided.", + content: { error: "Invalid transfer content" }, + }); + } + return false; + } + + try { + const PRIVATE_KEY = runtime.getSetting("CRONOSZKEVM_PRIVATE_KEY")!; + const PUBLIC_KEY = runtime.getSetting("CRONOSZKEVM_ADDRESS")!; + + const web3: Web3 = new Web3(/* optional L1 provider */); + + web3.registerPlugin( + new ZKsyncPlugin( + Web3ZKsyncL2.initWithDefaultProvider(types.Network.Mainnet), + ), + ); + + const smartAccount = new web3.ZKsync.SmartAccount({ address: PUBLIC_KEY, secret: "0x" + PRIVATE_KEY }) + + const transferTx = await smartAccount.transfer({ + to: content.recipient, + token: content.tokenAddress, + amount: web3.utils.toWei(content.amount,'ether'), + }); + + const receipt = await transferTx.wait(); + + elizaLogger.success( + "Transfer completed successfully! tx: " + receipt.transactionHash + ); + if (callback) { + callback({ + text: + "Transfer completed successfully! tx: " + + receipt.transactionHash, + content: {}, + }); + } + + return true; + } catch (error) { + elizaLogger.error("Error during token transfer:", error); + if (callback) { + callback({ + text: `Error transferring tokens: ${error.message}`, + content: { error: error.message }, + }); + } + return false; + } + }, + + examples: [ + [ + { + user: "{{user1}}", + content: { + text: "Send 100 USDC to 0xCCa8009f5e09F8C5dB63cb0031052F9CB635Af62", + }, + }, + { + user: "{{agent}}", + content: { + text: "Sure, I'll send 100 USDC to that address now.", + action: "SEND_TOKEN", + }, + }, + { + user: "{{agent}}", + content: { + text: "Successfully sent 100 USDC to 0xCCa8009f5e09F8C5dB63cb0031052F9CB635Af62\nTransaction: 0x4fed598033f0added272c3ddefd4d83a521634a738474400b27378db462a76ec", + }, + }, + ], + [ + { + user: "{{user1}}", + content: { + text: "Please send 100 ZKCRO tokens to 0xbD8679cf79137042214fA4239b02F4022208EE82", + }, + }, + { + user: "{{agent}}", + content: { + text: "Of course. Sending 100 ZKCRO to that address now.", + action: "SEND_TOKEN", + }, + }, + { + user: "{{agent}}", + content: { + text: "Successfully sent 100 ZKCRO to 0xbD8679cf79137042214fA4239b02F4022208EE82\nTransaction: 0x0b9f23e69ea91ba98926744472717960cc7018d35bc3165bdba6ae41670da0f0", + }, + }, + ] + ] as ActionExample[][], +} as Action; + diff --git a/packages/plugin-cronoszkevm/src/enviroment.ts b/packages/plugin-cronoszkevm/src/enviroment.ts new file mode 100644 index 0000000000..0fc02e3ac7 --- /dev/null +++ b/packages/plugin-cronoszkevm/src/enviroment.ts @@ -0,0 +1,36 @@ +import { IAgentRuntime } from "@ai16z/eliza"; +import { z } from "zod"; + +export const CronosZkEVMEnvSchema = z.object({ + CRONOSZKEVM_ADDRESS: z.string().min(1, "Cronos zkEVM address is required"), + CRONOSZKEVM_PRIVATE_KEY: z.string().min(1, "Cronos zkEVM private key is required"), +}); + +export type CronoszkEVMConfig = z.infer; + +export async function validateCronosZkevmConfig( + runtime: IAgentRuntime +): Promise { + try { + const config = { + CRONOSZKEVM_ADDRESS: + runtime.getSetting("CRONOSZKEVM_ADDRESS") || + process.env.CRONOSZKEVM_ADDRESS, + CRONOSZKEVM_PRIVATE_KEY: + runtime.getSetting("CRONOSZKEVM_PRIVATE_KEY") || + process.env.CRONOSZKEVM_PRIVATE_KEY + }; + + return CronosZkEVMEnvSchema.parse(config); + } catch (error) { + if (error instanceof z.ZodError) { + const errorMessages = error.errors + .map((err) => `${err.path.join(".")}: ${err.message}`) + .join("\n"); + throw new Error( + `CronosZkEVM configuration validation failed:\n${errorMessages}` + ); + } + throw error; + } +} diff --git a/packages/plugin-cronoszkevm/src/index.ts b/packages/plugin-cronoszkevm/src/index.ts new file mode 100644 index 0000000000..5c6ccf8f9b --- /dev/null +++ b/packages/plugin-cronoszkevm/src/index.ts @@ -0,0 +1,13 @@ +import { Plugin } from "@ai16z/eliza"; + +import transfer from "./actions/transfer"; + +export const cronosZkEVMPlugin: Plugin = { + name: "cronoszkevm", + description: "Cronos zkEVM plugin for Eliza", + actions: [transfer], + evaluators: [], + providers: [], +}; + +export default cronosZkEVMPlugin; diff --git a/packages/plugin-cronoszkevm/tsconfig.json b/packages/plugin-cronoszkevm/tsconfig.json new file mode 100644 index 0000000000..005fbac9d3 --- /dev/null +++ b/packages/plugin-cronoszkevm/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../core/tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src/**/*.ts"] +} diff --git a/packages/plugin-cronoszkevm/tsup.config.ts b/packages/plugin-cronoszkevm/tsup.config.ts new file mode 100644 index 0000000000..121caa999a --- /dev/null +++ b/packages/plugin-cronoszkevm/tsup.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["src/index.ts"], + outDir: "dist", + sourcemap: true, + clean: true, + format: ["esm"], // Ensure you're targeting CommonJS + external: [ + "dotenv", // Externalize dotenv to prevent bundling + "fs", // Externalize fs to use Node.js built-in module + "path", // Externalize other built-ins if necessary + "@reflink/reflink", + "@node-llama-cpp", + "https", + "http", + "agentkeepalive" + // Add other modules you want to externalize + ], +}); From df8512da7ac00097c98bb7706356e0201af43f48 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Mon, 16 Dec 2024 11:38:53 +0900 Subject: [PATCH 2/5] fix import --- agent/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/package.json b/agent/package.json index 84926cf4c1..4d65a427bd 100644 --- a/agent/package.json +++ b/agent/package.json @@ -50,7 +50,7 @@ "@ai16z/plugin-multiversx": "workspace:*", "@ai16z/plugin-near": "workspace:*", "@ai16z/plugin-zksync-era": "workspace:*", - "@ai16z/plugin-crozksy noszkevm": "workspace:*", + "@ai16z/plugin-cronoszkevm": "workspace:*", "readline": "1.3.0", "ws": "8.18.0", "yargs": "17.7.2" From fb9378723c6e70f1cbadaf734e9906d94f4591f1 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Mon, 16 Dec 2024 13:43:22 +0900 Subject: [PATCH 3/5] fix rpc url --- packages/plugin-cronoszkevm/src/actions/transfer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-cronoszkevm/src/actions/transfer.ts b/packages/plugin-cronoszkevm/src/actions/transfer.ts index 38932c8d63..772a0bd3e2 100644 --- a/packages/plugin-cronoszkevm/src/actions/transfer.ts +++ b/packages/plugin-cronoszkevm/src/actions/transfer.ts @@ -143,7 +143,7 @@ export default { web3.registerPlugin( new ZKsyncPlugin( - Web3ZKsyncL2.initWithDefaultProvider(types.Network.Mainnet), + new Web3ZKsyncL2('https://mainnet.zkevm.cronos.org'), ), ); From cb78a26ec6a9911e3a5b57b046a9fd5868aaf8df Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Mon, 16 Dec 2024 13:45:47 +0900 Subject: [PATCH 4/5] fix plugin --- agent/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/src/index.ts b/agent/src/index.ts index 123bffd26e..6a6ddd3c92 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -542,7 +542,7 @@ export async function createAgent( getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null, getSecret(character, "MVX_PRIVATE_KEY") ? multiversxPlugin : null, getSecret(character, "ZKSYNC_PRIVATE_KEY") ? zksyncEraPlugin : null, - getSecret(character, "CRONOSZKEVM_PRIVATE_KEY") ? zksyncEraPlugin : null, + getSecret(character, "CRONOSZKEVM_PRIVATE_KEY") ? cronosZkEVMPlugin : null, getSecret(character, "TON_PRIVATE_KEY") ? tonPlugin : null, getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null, getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null, From 15d9375e0b579dabef415c7d422d759882ece77c Mon Sep 17 00:00:00 2001 From: samarth30 Date: Thu, 26 Dec 2024 16:05:21 +0530 Subject: [PATCH 5/5] fix: did few fixes renaming from ai16z to elizaos and resolved build issues --- agent/package.json | 122 +++++++++--------- agent/src/index.ts | 6 +- packages/plugin-cronoszkevm/package.json | 6 +- .../src/actions/transfer.ts | 31 ++--- packages/plugin-cronoszkevm/src/enviroment.ts | 8 +- packages/plugin-cronoszkevm/src/index.ts | 2 +- pnpm-lock.yaml | 66 +++++++--- 7 files changed, 135 insertions(+), 106 deletions(-) diff --git a/agent/package.json b/agent/package.json index 78b4d8a4ad..bb7b6fabd5 100644 --- a/agent/package.json +++ b/agent/package.json @@ -1,63 +1,63 @@ { - "name": "@elizaos/agent", - "version": "0.1.7-alpha.1", - "main": "src/index.ts", - "type": "module", - "scripts": { - "start": "node --loader ts-node/esm src/index.ts", - "dev": "node --loader ts-node/esm src/index.ts", - "check-types": "tsc --noEmit" - }, - "nodemonConfig": { - "watch": [ - "src", - "../core/dist" - ], - "ext": "ts,json", - "exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" - }, - "dependencies": { - "@elizaos/adapter-postgres": "workspace:*", - "@elizaos/adapter-redis": "workspace:*", - "@elizaos/adapter-sqlite": "workspace:*", - "@elizaos/client-auto": "workspace:*", - "@elizaos/client-direct": "workspace:*", - "@elizaos/client-discord": "workspace:*", - "@elizaos/client-farcaster": "workspace:*", - "@elizaos/client-lens": "workspace:*", - "@elizaos/client-telegram": "workspace:*", - "@elizaos/client-twitter": "workspace:*", - "@elizaos/client-slack": "workspace:*", - "@elizaos/core": "workspace:*", - "@elizaos/plugin-0g": "workspace:*", - "@elizaos/plugin-aptos": "workspace:*", - "@elizaos/plugin-bootstrap": "workspace:*", - "@elizaos/plugin-intiface": "workspace:*", - "@elizaos/plugin-coinbase": "workspace:*", - "@elizaos/plugin-conflux": "workspace:*", - "@elizaos/plugin-evm": "workspace:*", - "@elizaos/plugin-flow": "workspace:*", - "@elizaos/plugin-story": "workspace:*", - "@elizaos/plugin-goat": "workspace:*", - "@elizaos/plugin-icp": "workspace:*", - "@elizaos/plugin-image-generation": "workspace:*", - "@elizaos/plugin-nft-generation": "workspace:*", - "@elizaos/plugin-node": "workspace:*", - "@elizaos/plugin-solana": "workspace:*", - "@elizaos/plugin-starknet": "workspace:*", - "@elizaos/plugin-ton": "workspace:*", - "@elizaos/plugin-sui": "workspace:*", - "@elizaos/plugin-tee": "workspace:*", - "@elizaos/plugin-multiversx": "workspace:*", - "@elizaos/plugin-near": "workspace:*", - "@elizaos/plugin-zksync-era": "workspace:*", - "@ai16z/plugin-cronoszkevm": "workspace:*", - "readline": "1.3.0", - "ws": "8.18.0", - "yargs": "17.7.2" - }, - "devDependencies": { - "ts-node": "10.9.2", - "tsup": "8.3.5" - } + "name": "@elizaos/agent", + "version": "0.1.7-alpha.1", + "main": "src/index.ts", + "type": "module", + "scripts": { + "start": "node --loader ts-node/esm src/index.ts", + "dev": "node --loader ts-node/esm src/index.ts", + "check-types": "tsc --noEmit" + }, + "nodemonConfig": { + "watch": [ + "src", + "../core/dist" + ], + "ext": "ts,json", + "exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" + }, + "dependencies": { + "@elizaos/adapter-postgres": "workspace:*", + "@elizaos/adapter-redis": "workspace:*", + "@elizaos/adapter-sqlite": "workspace:*", + "@elizaos/client-auto": "workspace:*", + "@elizaos/client-direct": "workspace:*", + "@elizaos/client-discord": "workspace:*", + "@elizaos/client-farcaster": "workspace:*", + "@elizaos/client-lens": "workspace:*", + "@elizaos/client-telegram": "workspace:*", + "@elizaos/client-twitter": "workspace:*", + "@elizaos/client-slack": "workspace:*", + "@elizaos/core": "workspace:*", + "@elizaos/plugin-0g": "workspace:*", + "@elizaos/plugin-aptos": "workspace:*", + "@elizaos/plugin-bootstrap": "workspace:*", + "@elizaos/plugin-intiface": "workspace:*", + "@elizaos/plugin-coinbase": "workspace:*", + "@elizaos/plugin-conflux": "workspace:*", + "@elizaos/plugin-evm": "workspace:*", + "@elizaos/plugin-flow": "workspace:*", + "@elizaos/plugin-story": "workspace:*", + "@elizaos/plugin-goat": "workspace:*", + "@elizaos/plugin-icp": "workspace:*", + "@elizaos/plugin-image-generation": "workspace:*", + "@elizaos/plugin-nft-generation": "workspace:*", + "@elizaos/plugin-node": "workspace:*", + "@elizaos/plugin-solana": "workspace:*", + "@elizaos/plugin-starknet": "workspace:*", + "@elizaos/plugin-ton": "workspace:*", + "@elizaos/plugin-sui": "workspace:*", + "@elizaos/plugin-tee": "workspace:*", + "@elizaos/plugin-multiversx": "workspace:*", + "@elizaos/plugin-near": "workspace:*", + "@elizaos/plugin-zksync-era": "workspace:*", + "@elizaos/plugin-cronoszkevm": "workspace:*", + "readline": "1.3.0", + "ws": "8.18.0", + "yargs": "17.7.2" + }, + "devDependencies": { + "ts-node": "10.9.2", + "tsup": "8.3.5" + } } diff --git a/agent/src/index.ts b/agent/src/index.ts index 038324e8b1..d6aa31497f 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -55,7 +55,7 @@ import { suiPlugin } from "@elizaos/plugin-sui"; import { TEEMode, teePlugin } from "@elizaos/plugin-tee"; import { tonPlugin } from "@elizaos/plugin-ton"; import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era"; -import { cronosZkEVMPlugin } from "@ai16z/plugin-cronoszkEVM"; +import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkEVM"; import Database from "better-sqlite3"; import fs from "fs"; import path from "path"; @@ -569,7 +569,9 @@ export async function createAgent( getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null, getSecret(character, "MVX_PRIVATE_KEY") ? multiversxPlugin : null, getSecret(character, "ZKSYNC_PRIVATE_KEY") ? zksyncEraPlugin : null, - getSecret(character, "CRONOSZKEVM_PRIVATE_KEY") ? cronosZkEVMPlugin : null, + getSecret(character, "CRONOSZKEVM_PRIVATE_KEY") + ? cronosZkEVMPlugin + : null, getSecret(character, "TON_PRIVATE_KEY") ? tonPlugin : null, getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null, getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null, diff --git a/packages/plugin-cronoszkevm/package.json b/packages/plugin-cronoszkevm/package.json index 5098b11193..b6b971288c 100644 --- a/packages/plugin-cronoszkevm/package.json +++ b/packages/plugin-cronoszkevm/package.json @@ -1,12 +1,12 @@ { - "name": "@ai16z/plugin-cronoszkevm", + "name": "@elizaos/plugin-cronoszkevm", "version": "0.1.4-alpha.3", "main": "dist/index.js", "type": "module", "types": "dist/index.d.ts", "dependencies": { - "@ai16z/eliza": "workspace:*", - "@ai16z/plugin-trustdb": "workspace:*", + "@elizaos/core": "workspace:*", + "@elizaos/plugin-trustdb": "workspace:*", "tsup": "^8.3.5", "web3": "^4.15.0", "web3-plugin-zksync": "^1.0.8" diff --git a/packages/plugin-cronoszkevm/src/actions/transfer.ts b/packages/plugin-cronoszkevm/src/actions/transfer.ts index 772a0bd3e2..f91dcea880 100644 --- a/packages/plugin-cronoszkevm/src/actions/transfer.ts +++ b/packages/plugin-cronoszkevm/src/actions/transfer.ts @@ -9,16 +9,16 @@ import { type Action, elizaLogger, composeContext, - generateObject -} from "@ai16z/eliza"; + generateObject, +} from "@elizaos/core"; import { validateCronosZkevmConfig } from "../enviroment"; -import {Web3} from "web3"; +import { Web3 } from "web3"; import { ZKsyncPlugin, ZKsyncWallet, types, - Web3ZKsyncL2 + Web3ZKsyncL2, } from "web3-plugin-zksync"; export interface TransferContent extends Content { @@ -29,8 +29,7 @@ export interface TransferContent extends Content { export function isTransferContent( content: TransferContent - ): content is TransferContent { - +): content is TransferContent { // Validate types const validTypes = typeof content.tokenAddress === "string" && @@ -51,7 +50,6 @@ export function isTransferContent( return validAddresses; } - const transferTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined. Here are several frequently used addresses. Use these for the corresponding tokens: @@ -142,23 +140,27 @@ export default { const web3: Web3 = new Web3(/* optional L1 provider */); web3.registerPlugin( - new ZKsyncPlugin( - new Web3ZKsyncL2('https://mainnet.zkevm.cronos.org'), - ), + new ZKsyncPlugin( + new Web3ZKsyncL2("https://mainnet.zkevm.cronos.org") + ) ); - const smartAccount = new web3.ZKsync.SmartAccount({ address: PUBLIC_KEY, secret: "0x" + PRIVATE_KEY }) + const smartAccount = new web3.ZKsync.SmartAccount({ + address: PUBLIC_KEY, + secret: "0x" + PRIVATE_KEY, + }); const transferTx = await smartAccount.transfer({ to: content.recipient, token: content.tokenAddress, - amount: web3.utils.toWei(content.amount,'ether'), + amount: web3.utils.toWei(content.amount, "ether"), }); const receipt = await transferTx.wait(); elizaLogger.success( - "Transfer completed successfully! tx: " + receipt.transactionHash + "Transfer completed successfully! tx: " + + receipt.transactionHash ); if (callback) { callback({ @@ -224,7 +226,6 @@ export default { text: "Successfully sent 100 ZKCRO to 0xbD8679cf79137042214fA4239b02F4022208EE82\nTransaction: 0x0b9f23e69ea91ba98926744472717960cc7018d35bc3165bdba6ae41670da0f0", }, }, - ] + ], ] as ActionExample[][], } as Action; - diff --git a/packages/plugin-cronoszkevm/src/enviroment.ts b/packages/plugin-cronoszkevm/src/enviroment.ts index 0fc02e3ac7..ba1e9a3356 100644 --- a/packages/plugin-cronoszkevm/src/enviroment.ts +++ b/packages/plugin-cronoszkevm/src/enviroment.ts @@ -1,9 +1,11 @@ -import { IAgentRuntime } from "@ai16z/eliza"; +import { IAgentRuntime } from "@elizaos/eliza"; import { z } from "zod"; export const CronosZkEVMEnvSchema = z.object({ CRONOSZKEVM_ADDRESS: z.string().min(1, "Cronos zkEVM address is required"), - CRONOSZKEVM_PRIVATE_KEY: z.string().min(1, "Cronos zkEVM private key is required"), + CRONOSZKEVM_PRIVATE_KEY: z + .string() + .min(1, "Cronos zkEVM private key is required"), }); export type CronoszkEVMConfig = z.infer; @@ -18,7 +20,7 @@ export async function validateCronosZkevmConfig( process.env.CRONOSZKEVM_ADDRESS, CRONOSZKEVM_PRIVATE_KEY: runtime.getSetting("CRONOSZKEVM_PRIVATE_KEY") || - process.env.CRONOSZKEVM_PRIVATE_KEY + process.env.CRONOSZKEVM_PRIVATE_KEY, }; return CronosZkEVMEnvSchema.parse(config); diff --git a/packages/plugin-cronoszkevm/src/index.ts b/packages/plugin-cronoszkevm/src/index.ts index 5c6ccf8f9b..1d14aacbcd 100644 --- a/packages/plugin-cronoszkevm/src/index.ts +++ b/packages/plugin-cronoszkevm/src/index.ts @@ -1,4 +1,4 @@ -import { Plugin } from "@ai16z/eliza"; +import { Plugin } from "@elizaos/core"; import transfer from "./actions/transfer"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f0e904aa4..7026282af2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -150,6 +150,9 @@ importers: '@elizaos/plugin-conflux': specifier: workspace:* version: link:../packages/plugin-conflux + '@elizaos/plugin-cronoszkevm': + specifier: workspace:* + version: link:../packages/plugin-cronoszkevm '@elizaos/plugin-evm': specifier: workspace:* version: link:../packages/plugin-evm @@ -541,12 +544,6 @@ importers: packages/client-discord: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core - '@elizaos/plugin-node': - specifier: workspace:* - version: link:../plugin-node '@discordjs/opus': specifier: github:discordjs/opus version: https://codeload.github.com/discordjs/opus/tar.gz/31da49d8d2cc6c5a2ab1bfd332033ff7d5f9fb02(encoding@0.1.13) @@ -556,6 +553,12 @@ importers: '@discordjs/voice': specifier: 0.17.0 version: 0.17.0(@discordjs/opus@https://codeload.github.com/discordjs/opus/tar.gz/31da49d8d2cc6c5a2ab1bfd332033ff7d5f9fb02(encoding@0.1.13))(bufferutil@4.0.8)(ffmpeg-static@5.2.0)(utf-8-validate@5.0.10) + '@elizaos/core': + specifier: workspace:* + version: link:../core + '@elizaos/plugin-node': + specifier: workspace:* + version: link:../plugin-node discord.js: specifier: 14.16.3 version: 14.16.3(bufferutil@4.0.8)(utf-8-validate@5.0.10) @@ -943,12 +946,12 @@ importers: packages/plugin-aptos: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core '@aptos-labs/ts-sdk': specifier: ^1.26.0 version: 1.33.1 + '@elizaos/core': + specifier: workspace:* + version: link:../core bignumber: specifier: 1.1.0 version: 1.1.0 @@ -1020,6 +1023,27 @@ importers: specifier: 0.7.1 version: 0.7.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10) + packages/plugin-cronoszkevm: + dependencies: + '@elizaos/core': + specifier: workspace:* + version: link:../core + '@elizaos/plugin-trustdb': + specifier: workspace:* + version: link:../plugin-trustdb + tsup: + specifier: ^8.3.5 + version: 8.3.5(@swc/core@1.10.1(@swc/helpers@0.5.15))(jiti@2.4.2)(postcss@8.4.49)(typescript@5.6.3)(yaml@2.6.1) + web3: + specifier: ^4.15.0 + version: 4.16.0(bufferutil@4.0.8)(encoding@0.1.13)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8) + web3-plugin-zksync: + specifier: ^1.0.8 + version: 1.0.8(bufferutil@4.0.8)(ts-node@10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.10.2)(typescript@5.6.3))(typescript@5.6.3)(utf-8-validate@5.0.10)(web3@4.16.0(bufferutil@4.0.8)(encoding@0.1.13)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)) + whatwg-url: + specifier: 7.1.0 + version: 7.1.0 + packages/plugin-echochambers: dependencies: '@elizaos/core': @@ -1134,9 +1158,6 @@ importers: packages/plugin-icp: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core '@dfinity/agent': specifier: 2.1.3 version: 2.1.3(@dfinity/candid@2.1.3(@dfinity/principal@2.1.3))(@dfinity/principal@2.1.3) @@ -1149,6 +1170,9 @@ importers: '@dfinity/principal': specifier: 2.1.3 version: 2.1.3 + '@elizaos/core': + specifier: workspace:* + version: link:../core devDependencies: '@types/jest': specifier: 29.5.14 @@ -1297,9 +1321,6 @@ importers: packages/plugin-node: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core '@aws-sdk/client-s3': specifier: ^3.705.0 version: 3.713.0 @@ -1318,6 +1339,9 @@ importers: '@echogarden/speex-resampler-wasm': specifier: 0.2.1 version: 0.2.1 + '@elizaos/core': + specifier: workspace:* + version: link:../core '@huggingface/transformers': specifier: 3.0.2 version: 3.0.2 @@ -1475,6 +1499,9 @@ importers: packages/plugin-solana: dependencies: + '@coral-xyz/anchor': + specifier: 0.30.1 + version: 0.30.1(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.10) '@elizaos/core': specifier: workspace:* version: link:../core @@ -1484,9 +1511,6 @@ importers: '@elizaos/plugin-trustdb': specifier: workspace:* version: link:../plugin-trustdb - '@coral-xyz/anchor': - specifier: 0.30.1 - version: 0.30.1(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.10) '@solana/spl-token': specifier: 0.4.9 version: 0.4.9(@solana/web3.js@1.95.8(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(encoding@0.1.13)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.6.3)(utf-8-validate@5.0.10) @@ -1526,15 +1550,15 @@ importers: packages/plugin-starknet: dependencies: + '@avnu/avnu-sdk': + specifier: 2.1.1 + version: 2.1.1(ethers@6.13.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(qs@6.13.1)(starknet@6.18.0(encoding@0.1.13)) '@elizaos/core': specifier: workspace:* version: link:../core '@elizaos/plugin-trustdb': specifier: workspace:* version: link:../plugin-trustdb - '@avnu/avnu-sdk': - specifier: 2.1.1 - version: 2.1.1(ethers@6.13.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(qs@6.13.1)(starknet@6.18.0(encoding@0.1.13)) '@uniswap/sdk-core': specifier: 6.0.0 version: 6.0.0