Skip to content

Commit

Permalink
feat: Add Cronos Evm (elizaOS#2585)
Browse files Browse the repository at this point in the history
* 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 <hi@sayo.wtf>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and 0xrubusdata committed Jan 21, 2025
1 parent 3511479 commit 705cf09
Show file tree
Hide file tree
Showing 11 changed files with 1,005 additions and 0 deletions.
257 changes: 257 additions & 0 deletions packages/plugin-cronos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
# @elizaos/plugin-cronos

Cronos plugin for Eliza, extending the EVM plugin functionality.

## Supported Networks

### Mainnet
- Cronos Mainnet (Chain ID: 25)
- RPC Endpoint: https://evm.cronos.org/
- Explorer: https://explorer.cronos.org/
- Native Token: CRO

### Testnet
- Cronos Testnet 3 (Chain ID: 338)
- RPC Endpoint: https://evm-t3.cronos.org/
- Explorer: https://cronos.org/explorer/testnet3
- Native Token: TCRO

## Installation

```bash
pnpm add @elizaos/plugin-cronos
```

## Usage

### Basic Setup
```typescript
import { cronosPlugin } from "@elizaos/plugin-cronos";

// Use the plugin in your Eliza configuration
const config = {
plugins: [cronosPlugin],
// ... rest of your config
};
```

### Character Configuration Guide

Create a `your-character.character.json` file with the following structure:

```json
{
"name": "YourCharacterName",
"plugins": ["@elizaos/plugin-cronos"],
"clients": ["telegram"],
"modelProvider": "openai",
"settings": {
"secrets": {},
"chains": {
"evm": ["cronos", "cronosTestnet"]
}
},
"system": "Primary function is to execute token transfers and check balances on Cronos chain.",
"actions": {
"SEND_TOKEN": {
"enabled": true,
"priority": 1,
"force": true,
"schema": {
"type": "object",
"properties": {
"fromChain": {
"type": "string",
"description": "The chain to execute the transfer on",
"enum": ["cronos", "cronosTestnet"]
},
"toAddress": {
"type": "string",
"description": "The recipient's wallet address",
"pattern": "^0x[a-fA-F0-9]{40}$"
},
"amount": {
"type": "string",
"description": "The amount of tokens to transfer",
"pattern": "^[0-9]*(\\.[0-9]+)?$"
}
},
"required": ["fromChain", "toAddress", "amount"]
},
"triggers": [
"send * CRO to *",
"transfer * CRO to *"
],
"examples": [
{
"input": "Send 0.1 CRO to 0x...",
"output": {
"fromChain": "cronos",
"toAddress": "0x...",
"amount": "0.1"
}
}
]
},
"CHECK_BALANCE": {
"enabled": true,
"priority": 1,
"force": true,
"schema": {
"type": "object",
"properties": {
"chain": {
"type": "string",
"description": "The chain to check balance on",
"enum": ["cronos", "cronosTestnet"]
}
},
"required": ["chain"]
},
"triggers": [
"check balance",
"show balance",
"what's my balance",
"how much CRO do I have",
"check balance on *",
"show balance on *"
],
"examples": [
{
"input": "check balance",
"output": {
"chain": "cronos"
}
},
{
"input": "what's my balance on testnet",
"output": {
"chain": "cronosTestnet"
}
}
]
}
},
"messageExamples": [
[
{
"user": "{{user1}}",
"content": {
"text": "Send 100 CRO to 0x..."
}
},
{
"user": "YourCharacterName",
"content": {
"text": "Processing token transfer...",
"action": "SEND_TOKEN"
}
}
],
[
{
"user": "{{user1}}",
"content": {
"text": "What's my balance?"
}
},
{
"user": "YourCharacterName",
"content": {
"text": "Checking your balance...",
"action": "CHECK_BALANCE"
}
}
]
]
}
```

#### Key Configuration Fields:

1. **Basic Setup**
- `name`: Your character's name
- `plugins`: Include `@elizaos/plugin-cronos`
- `clients`: Supported client platforms

2. **Chain Settings**
- Configure both mainnet and testnet in `settings.chains.evm`
- Available options: `"cronos"` (mainnet) and `"cronosTestnet"`

3. **Action Configuration**
- `SEND_TOKEN`: Action for token transfers
- `CHECK_BALANCE`: Action for checking wallet balance
- `schema`: Defines the required parameters for each action
- `triggers`: Phrases that activate the actions
- `examples`: Sample inputs and outputs

4. **Message Examples**
- Provide example interactions
- Show how actions are triggered
- Demonstrate expected responses

### Action Examples
```
// Send tokens on mainnet
"Send 0.1 CRO to 0x..." use mainnet
// Send tokens on testnet
"Send 0.1 TCRO to 0x..." use testnet
// Check balance on mainnet
"check balance"
"what's my balance"
"how much CRO do I have"
// Check balance on testnet
"check balance on testnet"
"what's my balance on testnet"
```

## Features

- All standard EVM functionality inherited from @elizaos/plugin-evm
- Preconfigured for both Cronos Mainnet and Testnet
- Native CRO/TCRO token support
- Automated token transfer actions
- Balance checking functionality
- Built-in chain configuration

## Environment Variables

Required environment variable for transactions:

```env
# Wallet private key (Required, must start with 0x)
CRONOS_PRIVATE_KEY=0x...
```

### Security Warnings ⚠️

- **NEVER** commit private keys to version control
- **NEVER** share private keys with anyone
- **ALWAYS** use environment variables or secure key management
- Use separate keys for mainnet and testnet
- Monitor your wallet for unauthorized transactions

### Setup

1. Create `.env` file:
```env
CRONOS_PRIVATE_KEY=0x... # Mainnet
```

2. For testnet development, use `.env.local`:
```env
CRONOS_PRIVATE_KEY=0x... # Testnet only
```

3. Add to `.gitignore`:
```
.env
.env.*
```

## License

MIT
33 changes: 33 additions & 0 deletions packages/plugin-cronos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@elizaos/plugin-cronos",
"version": "0.0.1",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"@elizaos/source": "./src/index.ts",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"scripts": {
"build": "tsup --format esm --dts"
},
"dependencies": {
"@elizaos/core": "workspace:*",
"node-cache": "^5.1.2",
"viem": "^2.0.0"
},
"devDependencies": {
"tsup": "^8.0.1",
"typescript": "^5.3.3"
}
}
Loading

0 comments on commit 705cf09

Please sign in to comment.