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(new-plugin): A plugin for the Zilliqa blockchain #2455

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

rrw-zilliqa
Copy link

@rrw-zilliqa rrw-zilliqa commented Jan 17, 2025

Relates to

No issue yet; can file an issue if you'd like?

Risks

Additional functionality; may affect the workspace package list.

Background

What does this PR do?

This PR adds a plugin to support the Zilliqa blockchain and ecosystem so that developers on the Zilliqa ecosystem can use Eliza's features.

What kind of change is this?

Feature

Documentation changes needed?

My changes do not require a change to the project documentation.

Testing

Where should a reviewer start?

Define ENABLE_ZILLIQA, EVM_PROVIDER_URL and EVM_PRIVATE_KEY.
You should then be able to request the below.

Detailed testing steps

>  "What is your zilliqa wallet address?"
< My Zilliqa wallet address is 0x7bb3B0E8A59f3f61d9Bff038f4AEb42cAE2ECce8. Let me know if there's anything else I can assist you with!

> "Convert that to bech32"
< My Zilliqa wallet address in bech32 format is zil10wemp699nulkrkdl7qu0ft459jhzan8g6r5lh7. Let me know if there's anything else I can assist you with!

> "get me your zilliqa address balance"
<   The balance for the Zilliqa address `zil10wemp699nulkrkdl7qu0ft459jhzan8g6r5lh7` is 4376.542050665893 ZIL. 

> "transfer 3 ZIL from your zilliqa to your evm account"
<  I successfully transferred 3 ZIL from my Zilliqa address to my EVM account. The transaction ID is `0cb214ced3205a5c66a8a7a6db3761835329abc9b5982553ca862a65b04333d2`.


<!--
- As [anon/admin], go to [link]
  - [do action]
  - verify [result]
-->

<!-- If there is a UI change, please include before and after screenshots or videos. This will speed up PRs being merged. It is extra nice to annotate screenshots with arrows or boxes pointing out the differences. -->
<!--
## Screenshots
### Before
### After
-->

<!-- If there is anything about the deployment, please make a note. -->
<!--
# Deploy Notes
-->

<!--  Copy and paste command line output. -->
<!--
## Database changes
-->

<!--  Please specify deploy instructions if there is something more than the automated steps. -->
<!--
## Deployment instructions
-->

<!-- If you are on Discord, please join https://discord.gg/ai16z and state your Discord username here for the contributor role and join us in #development-feed -->
<!--
## Discord username

-->
_naranek


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **New Features**
	- Added Zilliqa blockchain plugin to support wallet and blockchain interactions
	- Introduced new on-chain actions for balance checking, converting, and transferring funds

- **Dependency Updates**
	- Updated `@goat-sdk/core` to version 0.4.6
	- Added new Zilliqa-related dependencies to support blockchain functionality

- **Documentation**
	- Created README for Zilliqa plugin, explaining installation and configuration

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

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 @rrw-zilliqa! 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!

@rrw-zilliqa rrw-zilliqa force-pushed the feat/add_zilliqa_plugin branch 5 times, most recently from eb58885 to 48ab933 Compare January 21, 2025 13:26
@rrw-zilliqa rrw-zilliqa marked this pull request as ready for review January 21, 2025 13:26
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request introduces the Zilliqa plugin to the ElizaOS agent ecosystem. The changes include adding a new package @elizaos/plugin-zilliqa with comprehensive functionality for blockchain interactions, specifically targeting Zilliqa and EVM wallet integrations. The plugin is conditionally initialized based on specific environment variables and provides on-chain actions like balance checking, converting, and transferring assets.

Changes

File Change Summary
agent/package.json Added @elizaos/plugin-zilliqa as workspace dependency
agent/src/index.ts Imported createZilliqaPlugin, conditionally initialized Zilliqa plugin
packages/plugin-goat/package.json Updated @goat-sdk/core from 0.4.0 to 0.4.6
packages/plugin-zilliqa/... New plugin package with README, package configuration, source files for wallet and action handling

Possibly related PRs


🪧 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: 5

🧹 Nitpick comments (8)
packages/plugin-zilliqa/src/wallet.ts (3)

33-52: Ensure consistent error handling in getZilliqaWalletClient

The function returns null when the privateKey is missing but throws an error when the provider is missing. This inconsistency can lead to confusion and potential runtime errors downstream. Consider throwing an error in both cases or handling both uniformly.

Option 1: Throw an error when privateKey is missing.

 export async function getZilliqaWalletClient(
     getSetting: (key: string) => string | undefined
 ): Promise<ZilliqaWalletClient | null> {
     const privateKey = getSetting("EVM_PRIVATE_KEY");
-    if (!privateKey) return null;
+    if (!privateKey) throw new Error("EVM_PRIVATE_KEY not configured");

     const provider = getSetting("EVM_PROVIDER_URL");
     if (!provider) throw new Error("EVM_PROVIDER_URL not configured");
     // ...
 }

Option 2: Return null when either is missing.

 export async function getZilliqaWalletClient(
     getSetting: (key: string) => string | undefined
 ): Promise<ZilliqaWalletClient | null> {
     const privateKey = getSetting("EVM_PRIVATE_KEY");
     if (!privateKey) return null;

     const provider = getSetting("EVM_PROVIDER_URL");
-    if (!provider) throw new Error("EVM_PROVIDER_URL not configured");
+    if (!provider) return null;
     // ...
 }

42-42: Add error handling for zilliqaChainId retrieval

The call to zilliqaChainId(provider) may fail due to network issues or invalid provider URLs. Consider wrapping this call in a try-catch block to handle potential exceptions gracefully.

Apply this diff:

 const provider = getSetting("EVM_PROVIDER_URL");
 if (!provider) throw new Error("EVM_PROVIDER_URL not configured");

-const chainId = await zilliqaChainId(provider);
+let chainId: number;
+try {
+    chainId = await zilliqaChainId(provider);
+} catch (error) {
+    throw new Error(`Failed to retrieve chain ID: ${error.message}`);
+}

54-84: Specify return types in getWalletProviders

The getWalletProviders function and its inner get methods lack explicit return types, which can affect readability and maintainability.

Add return types to the function and methods:

 export function getWalletProviders(
     walletClient: WalletClientBase,
     zilliqa: ZilliqaWalletClient
-)
+): { get(): Promise<string | null> }[] {
     return [
         {
             async get(): Promise<string | null> {
                 // ...
             },
         },
         {
             async get(): Promise<string | null> {
                 // ...
             },
         },
     ];
 }
packages/plugin-zilliqa/src/actions.ts (1)

155-218: Add type annotations for getActionHandler parameters and return type

Explicit type annotations enhance code readability and maintainability.

Add type annotations:

 function getActionHandler(
     actionName: string,
     actionDescription: string,
     tools: Record<string, unknown>
-)
+): HandlerCallback {
     return async (
         runtime: IAgentRuntime,
         message: Memory,
-        state: State | undefined,
+        state?: State,
         options?: Record<string, unknown>,
         callback?: HandlerCallback
-    ): Promise<boolean> => {
+    ) => {
         // ...
     };
 }

Ensure that HandlerCallback is correctly imported or defined.

packages/plugin-zilliqa/src/index.ts (1)

15-15: Ensure zilliqaWalletClient is not null before passing to providers

Passing a potentially null zilliqaWalletClient to getWalletProviders can lead to unexpected behavior.

Since you've added a null check above, this issue would be resolved. Ensure that any functions receiving zilliqaWalletClient handle it appropriately.

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

2-4: Consider starting with version 0.1.0-alpha.1.

Since this is a new package, it's recommended to start with version 0.1.0-alpha.1 instead of 0.1.7-alpha.2.

🧰 Tools
🪛 GitHub Actions: Integration Tests

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed

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

24-24: Align all GOAT SDK package versions.

Consider updating other GOAT SDK packages to match the latest versions used in plugin-zilliqa:

  • @goat-sdk/adapter-vercel-ai: 0.2.0 → 0.2.7
  • @goat-sdk/wallet-evm: 0.2.0 → 0.2.6
  • @goat-sdk/wallet-viem: 0.2.0 → 0.2.6
🧰 Tools
🪛 GitHub Actions: Integration Tests

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed

packages/plugin-zilliqa/README.md (1)

34-35: Improve text clarity and grammar.

Add missing commas and improve sentence structure:

-If you are using Trump as a character it might be tricky to get them to perform any action since the character is full of prompts that aim to change the topic of the conversation. To fix this try using a different character or create your own with prompts that are more suitable to what the agent is supposed to do.
+If you are using Trump as a character, it might be tricky to get them to perform any action since the character is full of prompts that aim to change the topic of the conversation. To fix this, try using a different character or create your own with prompts that are more suitable to what the agent is supposed to do.
🧰 Tools
🪛 LanguageTool

[style] ~34-~34: Consider using a different verb for a more formal wording.
Context: ... action. Removing the EVM Plugin should fix this issue. There is no need for you to...

(FIX_RESOLVE)


[uncategorized] ~35-~35: A comma might be missing here.
Context: ...time. - If you are using Trump as a character it might be tricky to get them to perfo...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)


[uncategorized] ~35-~35: A comma might be missing here.
Context: ...e the topic of the conversation. To fix this try using a different character or crea...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e80c2e6 and 48ab933.

📒 Files selected for processing (10)
  • agent/package.json (1 hunks)
  • agent/src/index.ts (3 hunks)
  • packages/plugin-goat/package.json (1 hunks)
  • packages/plugin-zilliqa/README.md (1 hunks)
  • packages/plugin-zilliqa/package.json (1 hunks)
  • packages/plugin-zilliqa/src/actions.ts (1 hunks)
  • packages/plugin-zilliqa/src/index.ts (1 hunks)
  • packages/plugin-zilliqa/src/wallet.ts (1 hunks)
  • packages/plugin-zilliqa/tsconfig.json (1 hunks)
  • packages/plugin-zilliqa/tsup.config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/plugin-zilliqa/tsconfig.json
  • packages/plugin-zilliqa/tsup.config.ts
🧰 Additional context used
🪛 GitHub Actions: Integration Tests
agent/package.json

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed

packages/plugin-goat/package.json

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed

packages/plugin-zilliqa/package.json

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed

🪛 LanguageTool
packages/plugin-zilliqa/README.md

[style] ~34-~34: Consider using a different verb for a more formal wording.
Context: ... action. Removing the EVM Plugin should fix this issue. There is no need for you to...

(FIX_RESOLVE)


[uncategorized] ~35-~35: A comma might be missing here.
Context: ...time. - If you are using Trump as a character it might be tricky to get them to perfo...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)


[uncategorized] ~35-~35: A comma might be missing here.
Context: ...e the topic of the conversation. To fix this try using a different character or crea...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

🔇 Additional comments (6)
packages/plugin-zilliqa/src/wallet.ts (2)

63-65: Verify the balance unit returned by walletClient.balanceOf

Ensure that walletClient.balanceOf(address) returns the balance in ZIL. Since this is an EVM wallet client, the balance might be in a different unit (e.g., ETH or wei).

Please confirm the unit of the balance and, if necessary, convert it to ZIL for accurate reporting.


75-76: Handle potential undefined defaultAccount in Zilliqa wallet

The expression zilliqa.getZilliqa().wallet.defaultAccount?.address may return undefined if defaultAccount is not set. Consider adding a check to handle this case.

Apply this diff to handle undefined address:

 const address = zilliqa.getZilliqa().wallet.defaultAccount?.address;
+if (!address) {
+    return null;
+}
 return `Zilliqa wallet address: ${address}\n`;
agent/src/index.ts (1)

48-48: LGTM! Plugin initialization follows established patterns.

The conditional initialization based on EVM_PRIVATE_KEY and secret retrieval is implemented correctly.

Also applies to: 842-847

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

8-17: Verify compatibility between GOAT SDK versions.

Ensure that the different GOAT SDK packages (@goat-sdk/*) at different versions (0.1.3, 0.2.6, 0.2.7, 0.4.6) are compatible with each other.

🧰 Tools
🪛 GitHub Actions: Integration Tests

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed

agent/package.json (2)

114-114: LGTM! Zilliqa plugin dependency added correctly.

The dependency follows the workspace pattern and maintains alphabetical ordering.

🧰 Tools
🪛 GitHub Actions: Integration Tests

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed


Line range hint 1-124: Verify peer dependency conflicts.

Pipeline shows warnings about peer dependencies. While not directly related to the Zilliqa plugin, these should be addressed:

  • @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0
  • typedoc requires typescript 4.6.x - 5.6.x
  • Missing vue >= 3.3.4

Let's check the dependency tree to identify the source packages:

🧰 Tools
🪛 GitHub Actions: Integration Tests

[warning] Peer dependency conflict: @react-spring/web requires react ^16.8.0 || ^17.0.0 || ^18.0.0 but found 19.0.0


[warning] Peer dependency conflict: typedoc requires typescript 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x but found 5.7.3


[warning] Missing peer dependency: vue@>=3.3.4 <4.0.0-0 is required but not installed

packages/plugin-zilliqa/src/wallet.ts Outdated Show resolved Hide resolved
packages/plugin-zilliqa/src/actions.ts Outdated Show resolved Hide resolved
packages/plugin-zilliqa/src/index.ts Outdated Show resolved Hide resolved
agent/src/index.ts Outdated Show resolved Hide resolved
packages/plugin-zilliqa/README.md Outdated Show resolved Hide resolved
@rrw-zilliqa rrw-zilliqa force-pushed the feat/add_zilliqa_plugin branch 4 times, most recently from 1f29398 to 961a810 Compare January 23, 2025 17:16
@rrw-zilliqa rrw-zilliqa force-pushed the feat/add_zilliqa_plugin branch from 961a810 to a7d3d7c Compare January 24, 2025 12:43
@wtfsayo
Copy link
Member

wtfsayo commented Jan 25, 2025

@rrw-zilliqa could you allow us to push to this branch!!!

@wtfsayo wtfsayo changed the title (feat) A plugin for the Zilliqa blockchain feat: A plugin for the Zilliqa blockchain Jan 25, 2025
@wtfsayo wtfsayo changed the title feat: A plugin for the Zilliqa blockchain feat(new-plugin): A plugin for the Zilliqa blockchain Jan 25, 2025
@wtfsayo
Copy link
Member

wtfsayo commented Jan 25, 2025

@rrw-zilliqa

  1. Please import your plugin to agent/src/index.ts
  2. Add it to agent/package.json
  3. Add required env variables to .env.example
  4. Resolve conflicts
  5. give us access to push to this branch

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