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: Add Cronos Evm #2585

Merged
merged 4 commits into from
Jan 21, 2025
Merged

feat: Add Cronos Evm #2585

merged 4 commits into from
Jan 21, 2025

Conversation

leejw51crypto
Copy link
Contributor

@leejw51crypto leejw51crypto commented Jan 21, 2025

  • Created @elizaos/plugin-cronos with:

    • Support for Cronos Mainnet and Testnet
    • Token transfer functionality
    • Balance checking capability
    • Wallet provider implementation
  • README.md: Documentation and setup guide

  • Action handlers for transfers and balance checks

  • Chain configurations and wallet provider

  • TypeScript configurations and types

  • CRO/TCRO token support

  • Environment variable setup for private keys

  • Security guidelines for key management

  • Comprehensive API documentation

feat: Enhance balance and transfer actions with validation and schema

  • Updated BalanceAction and TransferAction to include Zod validation schemas for parameters.
  • Replaced deprecated generateObjectDeprecated with generateObject for better type safety.
  • Improved error handling and logging for balance and transfer operations.
  • Added address validation to ensure proper Ethereum address format.
  • Updated templates to reflect new parameter requirements for balance checks.
  • Refactored wallet provider methods to support fetching balance by address.

Relates to

Risks

Background

What does this PR do?

What kind of change is this?

Documentation changes needed?

Testing

Where should a reviewer start?

Detailed testing steps

Summary by CodeRabbit

Release Notes for @elizaos/plugin-cronos v0.0.1

  • New Features

    • Added Cronos blockchain plugin supporting mainnet and testnet
    • Implemented token transfer functionality for CRO tokens
    • Added balance checking for CRO tokens
    • Introduced wallet provider for Cronos blockchain interactions
  • Documentation

    • Created comprehensive README with installation and usage instructions
    • Added configuration guidelines for Cronos plugin
  • Infrastructure

    • Established TypeScript configuration and build setup
    • Configured package metadata and dependencies

- Created `@elizaos/plugin-cronos` with:
  - Support for Cronos Mainnet and Testnet
  - Token transfer functionality
  - Balance checking capability
  - Wallet provider implementation

- `README.md`: Documentation and setup guide
- Action handlers for transfers and balance checks
- Chain configurations and wallet provider
- TypeScript configurations and types

- CRO/TCRO token support
- Environment variable setup for private keys
- Security guidelines for key management
- Comprehensive API documentation

feat: Enhance balance and transfer actions with validation and schema

- Updated `BalanceAction` and `TransferAction` to include Zod validation schemas for parameters.
- Replaced deprecated `generateObjectDeprecated` with `generateObject` for better type safety.
- Improved error handling and logging for balance and transfer operations.
- Added address validation to ensure proper Ethereum address format.
- Updated templates to reflect new parameter requirements for balance checks.
- Refactored wallet provider methods to support fetching balance by address.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @leejw51crypto! Welcome to the elizaOS community. Thanks for submitting your first pull request; your efforts are helping us accelerate towards AGI. We'll review it shortly. You are now an elizaOS contributor!

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/plugin-cronos/src/actions/balance.ts

Oops! Something went wrong! :(

ESLint: 9.18.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

📝 Walkthrough

Walkthrough

The pull request introduces the @elizaos/plugin-cronos, a new plugin for the Eliza framework that enables interactions with the Cronos blockchain. It provides functionality for token transfers and balance checks on both Cronos Mainnet and Testnet. The plugin includes comprehensive documentation, type definitions, action handlers, and a wallet provider to facilitate blockchain operations.

Changes

File Change Summary
README.md New documentation for Cronos plugin, including installation, usage, and configuration instructions
package.json New package declaration with dependencies, build scripts, and module configuration
src/actions/balance.ts Added balance checking functionality with input validation
src/actions/transfer.ts Implemented token transfer actions with transaction handling
src/constants/chains.ts Defined Cronos Mainnet and Testnet chain configurations
src/index.ts Created plugin entry point with exports and plugin configuration
src/providers/wallet.ts Developed wallet provider for Cronos blockchain interactions
src/templates/index.ts Added templates for transfer and balance actions
src/types/index.ts Introduced type definitions and interfaces
tsconfig.json, tsup.config.ts Added build and TypeScript configuration files

Possibly related PRs

Suggested Labels

Needs Testing, Plugin_new

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (11)
packages/plugin-cronos/src/constants/chains.ts (1)

11-18: Consider adding fallback RPC URLs

Using the same URL for both default and public configurations creates a single point of failure. Consider adding alternative RPC endpoints for redundancy.

     rpcUrls: {
         default: {
-            http: ["https://evm.cronos.org/"],
+            http: [
+                "https://evm.cronos.org/",
+                "https://cronos-evm.publicnode.com",
+            ],
         },
         public: {
-            http: ["https://evm.cronos.org/"],
+            http: [
+                "https://evm.cronos.org/",
+                "https://cronos-evm.publicnode.com",
+            ],
         },
     },

Also applies to: 36-43

packages/plugin-cronos/src/templates/index.ts (1)

1-31: Add important transaction details to transfer template

The template should guide users about:

  • Expected gas fees
  • Transaction confirmation times
  • What to do if transaction fails
 Remember:
 - The chain name must be exactly "cronos" or "cronosTestnet"
 - The amount should be a string representing the number without any currency symbol
 - The recipient address must be a valid Ethereum address starting with "0x"
+- Transaction requires gas fees in CRO
+- Typical confirmation time is 5-6 seconds
+- If transaction fails, check gas price and balance
packages/plugin-cronos/package.json (2)

2-7: Consider adding package metadata.

Add description, keywords, repository, and license fields to improve package discoverability and provide essential metadata.

 {
     "name": "@elizaos/plugin-cronos",
     "version": "0.0.1",
     "type": "module",
+    "description": "Cronos blockchain plugin for Eliza framework",
+    "keywords": ["cronos", "blockchain", "eliza", "evm"],
+    "repository": {
+        "type": "git",
+        "url": "https://github.com/elizaOS/eliza.git"
+    },
+    "license": "MIT",
     "main": "dist/index.js",

22-22: Enhance build configuration.

The current build setup is minimal. Consider adding clean, watch, and type-check scripts.

     "scripts": {
-        "build": "tsup --format esm --dts"
+        "clean": "rm -rf dist",
+        "build": "tsup --format esm --dts",
+        "build:watch": "tsup --format esm --dts --watch",
+        "type-check": "tsc --noEmit"
     },
packages/plugin-cronos/README.md (3)

9-10: Use markdown links for URLs.

Replace bare URLs with proper markdown links for better readability.

-  - RPC Endpoint: https://evm.cronos.org/
-  - Explorer: https://explorer.cronos.org/
+  - RPC Endpoint: [https://evm.cronos.org/](https://evm.cronos.org/)
+  - Explorer: [https://explorer.cronos.org/](https://explorer.cronos.org/)

Also applies to: 15-16

🧰 Tools
🪛 Markdownlint (0.37.0)

9-9: null
Bare URL used

(MD034, no-bare-urls)


10-10: null
Bare URL used

(MD034, no-bare-urls)


192-207: Add language identifier to code block.

Specify the language for the code block to enable syntax highlighting.

-```
+```text
 // Send tokens on mainnet
 "Send 0.1 CRO to 0x..." use mainnet
🧰 Tools
🪛 Markdownlint (0.37.0)

192-192: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


223-224: Add validation hint for private key.

Include the expected length of the private key in the environment variable description.

-# Wallet private key (Required, must start with 0x)
-CRONOS_PRIVATE_KEY=0x...
+# Wallet private key (Required, must start with 0x and be 64 characters long)
+CRONOS_PRIVATE_KEY=0x<64_hex_characters>
packages/plugin-cronos/src/actions/transfer.ts (2)

72-74: Sanitize error messages before throwing exceptions

When catching errors, avoid directly including error.message in thrown errors. Provide user-friendly messages to prevent potential leakage of sensitive information.


140-148: Provide generic error messages to callbacks

Returning raw error messages to users can expose sensitive details. Consider replacing error.message with a generic error description.

packages/plugin-cronos/src/providers/wallet.ts (2)

105-107: Use consistent logging mechanism

Replace console.error with elizaLogger.error for error logging to maintain consistency across the codebase.


192-195: Standardize error logging

Consider using elizaLogger.error instead of console.error to ensure uniform logging practices.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a00f723 and 2895f7b.

📒 Files selected for processing (11)
  • packages/plugin-cronos/README.md (1 hunks)
  • packages/plugin-cronos/package.json (1 hunks)
  • packages/plugin-cronos/src/actions/balance.ts (1 hunks)
  • packages/plugin-cronos/src/actions/transfer.ts (1 hunks)
  • packages/plugin-cronos/src/constants/chains.ts (1 hunks)
  • packages/plugin-cronos/src/index.ts (1 hunks)
  • packages/plugin-cronos/src/providers/wallet.ts (1 hunks)
  • packages/plugin-cronos/src/templates/index.ts (1 hunks)
  • packages/plugin-cronos/src/types/index.ts (1 hunks)
  • packages/plugin-cronos/tsconfig.json (1 hunks)
  • packages/plugin-cronos/tsup.config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/plugin-cronos/tsconfig.json
  • packages/plugin-cronos/tsup.config.ts
🧰 Additional context used
🪛 Markdownlint (0.37.0)
packages/plugin-cronos/README.md

168-168: Punctuation: ':'
Trailing punctuation in heading

(MD026, no-trailing-punctuation)


9-9: null
Bare URL used

(MD034, no-bare-urls)


10-10: null
Bare URL used

(MD034, no-bare-urls)


15-15: null
Bare URL used

(MD034, no-bare-urls)


16-16: null
Bare URL used

(MD034, no-bare-urls)


192-192: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


248-248: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (7)
packages/plugin-cronos/src/index.ts (1)

1-20: Clean and well-structured plugin implementation!

The plugin follows the standard pattern and includes all necessary components.

packages/plugin-cronos/src/types/index.ts (1)

6-13: Well-defined transaction interface!

Good use of Hex type from viem for type-safe blockchain interactions.

packages/plugin-cronos/package.json (1)

24-28: Verify viem version compatibility.

The plugin uses viem v2.0.0 which was recently released. Ensure compatibility with the core framework.

✅ Verification successful

✅ viem v2.0.0 usage is compatible with core framework

The core package only uses basic client creation features from viem which remain stable across versions. The v2 breaking changes don't affect this minimal usage pattern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if core framework has viem as a dependency and its version
jq -r '.dependencies.viem // empty' packages/core/package.json

# Check for potential breaking changes in viem v2
gh api repos/wagmi-dev/viem/releases/tags/[email protected] --jq '.body'

Length of output: 586


Script:

#!/bin/bash
# Search for viem imports in core package
rg "from ['|\"]viem['\"]|require\(['|\"]viem['\"]" packages/core -n

# Search for any file containing "viem" to catch other usage patterns
rg "viem" packages/core -n

Length of output: 272

packages/plugin-cronos/src/actions/balance.ts (2)

28-41: BalanceAction class is well-implemented

The BalanceAction class effectively retrieves balances with proper error handling.


68-113: Handler function manages balance checks efficiently

The handler correctly orchestrates the balance retrieval process and handles success and error scenarios appropriately.

packages/plugin-cronos/src/actions/transfer.ts (1)

37-75: TransferAction class handles token transfers effectively

The TransferAction class correctly manages CRO token transfers with appropriate validation and error handling.

packages/plugin-cronos/src/providers/wallet.ts (1)

83-108: Efficient balance retrieval with caching

The getAddressBalance method effectively retrieves and caches balance information, enhancing performance.

packages/plugin-cronos/src/types/index.ts Show resolved Hide resolved
packages/plugin-cronos/README.md Outdated Show resolved Hide resolved
wtfsayo and others added 2 commits January 21, 2025 16:15
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@wtfsayo wtfsayo enabled auto-merge (squash) January 21, 2025 10:46
@wtfsayo wtfsayo self-requested a review January 21, 2025 11:09
Copy link
Member

@wtfsayo wtfsayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leejw51crypto need to initialize plugin in agent/src/index and agent/package.json
and add your env requirements to .env.example

@wtfsayo wtfsayo merged commit 306f16c into elizaOS:develop Jan 21, 2025
3 checks passed
0xrubusdata pushed a commit to 0xrubusdata/eliza that referenced this pull request Jan 21, 2025
* feat: Add Cronos Evm

- Created `@elizaos/plugin-cronos` with:
  - Support for Cronos Mainnet and Testnet
  - Token transfer functionality
  - Balance checking capability
  - Wallet provider implementation

- `README.md`: Documentation and setup guide
- Action handlers for transfers and balance checks
- Chain configurations and wallet provider
- TypeScript configurations and types

- CRO/TCRO token support
- Environment variable setup for private keys
- Security guidelines for key management
- Comprehensive API documentation

feat: Enhance balance and transfer actions with validation and schema

- Updated `BalanceAction` and `TransferAction` to include Zod validation schemas for parameters.
- Replaced deprecated `generateObjectDeprecated` with `generateObject` for better type safety.
- Improved error handling and logging for balance and transfer operations.
- Added address validation to ensure proper Ethereum address format.
- Updated templates to reflect new parameter requirements for balance checks.
- Refactored wallet provider methods to support fetching balance by address.

* Update packages/plugin-cronos/README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Sayo <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants