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 taiko plugin #3230

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ CRONOSZKEVM_PRIVATE_KEY=
# Fuel Ecosystem (FuelVM)
FUEL_WALLET_PRIVATE_KEY=

# Taiko Plugin Configuration
TAIKO_PRIVATE_KEY= # private key of the account to use
GOLDRUSH_API_KEY= # goldrush api key for contract analytics
TAIKO_PROVIDER_URL= # optional rpc url


# Tokenizer Settings
TOKENIZER_MODEL= # Specify the tokenizer model to be used.
TOKENIZER_TYPE= # Options: tiktoken (for OpenAI models) or auto (AutoTokenizer from Hugging Face for non-OpenAI models). Default: tiktoken.
Expand Down
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"@elizaos/plugin-near": "workspace:*",
"@elizaos/plugin-stargaze": "workspace:*",
"@elizaos/plugin-zksync-era": "workspace:*",
"@elizaos/plugin-taiko": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
108 changes: 108 additions & 0 deletions packages/plugin-taiko/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# `@elizaos/plugin-taiko`

## Description

The Taiko Plugin provides integration with the Taiko Layer 2 network and Taiko Hekla Testnet, offering essential tools for onchain interactions.

## Features

- Send native tokens and ERC20 tokens
- Onchain name resolution
- Monitor wallet balances in real-time
- Track on-chain analytics for any address
- Configure custom RPC endpoints

## Installation

```bash
pnpm install @elizaos/plugin-taiko
```

## Configuration

### Required Environment Variables

```env
# Required
TAIKO_PRIVATE_KEY= # Your Private Key
GOLDRUSH_API_KEY= # Request an API key from https://goldrush.dev/platform/

# Optional - Custom RPC URLs
TAIKO_PROVIDER_URL=https://your-custom-mainnet-rpc-url
```

### Chains Supported

By default, both **Taiko Alethia Mainnet** and **Taiko Hekla Testnet** are enabled.

## Actions

### 1. Transfer

Transfer native tokens and ERC20 tokens on Taiko L2:

> **Note:** This action supports domain name resolution for most name systems, including ENS and Unstoppable Domains. Check out the [Web3 Name SDK](https://goldrush.dev/platform/) for more information about name resolution.

```typescript
Transfer 1 ETH to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e
```

```typescript
Send 1 TAIKO to vitalik.eth on Taiko Hekla
```

### 2. Balance Retrieval

Fetch balances of ETH and ERC20 tokens:

> **Note:** This action supports domain name resolution for most name systems, including ENS and Unstoppable Domains. Check out the [Web3 Name SDK](https://goldrush.dev/platform/) for more information about name resolution.

```typescript
Can you tell me how much USDC does vitalik.eth have on Taiko?
```

```typescript
How much ETH does 0x123abc have on Taiko Hekla?
```

### 3. Onchain Analytics

Track detailed on-chain metrics for any address on Taiko L2, including:

- Total gas spent
- Transaction count
- Top interacted addresses
- Unique address interactions

Available time frames: 1 day, 7 days, and 30

> **Tip:** This action is useful to understand the performance of a given smart contract on Taiko

```typescript
Show me the onchain analytics for 0x1231223 on Taiko Hekla.
```

## Development

1. Clone the repository
2. Install dependencies:

```bash
pnpm install
```

3. Build the plugin:

```bash
pnpm run build
```

4. Run tests:

```bash
pnpm test
```

## License

This plugin is part of the Eliza project. See the main project repository for license information.
40 changes: 40 additions & 0 deletions packages/plugin-taiko/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@elizaos/plugin-taiko",
"version": "0.1.9",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"dependencies": {
"@elizaos/core": "workspace:*",
"@lifi/sdk": "3.4.1",
"@web3-name-sdk/core": "^0.3.2",
"tsup": "8.3.5",
"viem": "2.21.58",
"zod": "^3.22.4"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache .",
"test": "vitest run"
},
"peerDependencies": {
"whatwg-url": "7.1.0"
},
"devDependencies": {
"@types/node": "^20.0.0"
}
}
128 changes: 128 additions & 0 deletions packages/plugin-taiko/src/actions/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import {
composeContext,
elizaLogger,
generateObjectDeprecated,
type HandlerCallback,
ModelClass,
type IAgentRuntime,
type Memory,
type State,
} from "@elizaos/core";

import { taikoWalletProvider, initWalletProvider } from "../providers/wallet";
import { getBalanceTemplate, transferTemplate } from "../templates";
import type { GetBalanceParams } from "../types";

import { BalanceAction } from "../services/balance";

export const balanceAction = {
name: "balance",
description: "retrieve balance of a token for a given address.",
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State,
_options: Record<string, unknown>,
callback?: HandlerCallback
) => {
elizaLogger.log("Starting transfer action...");

// Initialize or update state
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
currentState = await runtime.updateRecentMessageState(currentState);
}
state.walletInfo = await taikoWalletProvider.get(
runtime,
message,
currentState
);

const balanceContext = composeContext({
state: currentState,
template: getBalanceTemplate,
});
const content = await generateObjectDeprecated({
runtime,
context: balanceContext,
modelClass: ModelClass.LARGE,
});

const walletProvider = initWalletProvider(runtime);
const action = new BalanceAction(walletProvider);
const paramOptions: GetBalanceParams = {
chain: content.chain,
token: content.token,
address: content.address,
};

try {
const resp = await action.balance(paramOptions);
callback?.({
text: `${resp.address} has ${resp.balance.amount} ${
resp.balance.token
} in ${resp.chain === "taikoHekla" ? "Taiko Hekla" : "Taiko"}.`,
content: { ...resp },
});

return true;
} catch (error) {
elizaLogger.error("Error during fetching balance:", error.message);
callback?.({
text: `Fetching failed: ${error.message}`,
content: { error: error.message },
});
return false;
}
},
template: transferTemplate,
validate: async (runtime: IAgentRuntime) => {
const privateKey = runtime.getSetting("TAIKO_PRIVATE_KEY");
return typeof privateKey === "string" && privateKey.startsWith("0x");
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "How much USDC does siddesh.eth have in Taiko?",
},
},
{
user: "{{agent}}",
content: {
text: "I'll find how much USDC does siddesh.eth have in Taiko",
action: "GET_BALANCE",
content: {
chain: "taiko",
token: "USDC",
address: "siddesh.eth",
},
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Tell how many ETH does 0x742d35Cc6634C0532925a3b844Bc454e4438f44e have in Taiko Hekla.",
},
},
{
user: "{{agent}}",
content: {
text: "Sure, Let me find the balance of ETH for 0x742d35Cc6634C0532925a3b844Bc454e4438f44e on Taiko Hekla",
action: "GET_BALANCE",
content: {
chain: "taikoHekla",
token: "ETH",
address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
},
},
},
],
],
similes: ["GET_BALANCE", "BALANCE"],
};
Loading
Loading