-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Mind Network plugin (#2431)
* Mind Network integration * Improve readme.md * Changes according to code review comments --------- Co-authored-by: george <[email protected]>
- Loading branch information
1 parent
4375d6b
commit 3d05b89
Showing
14 changed files
with
641 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# @elizaos/plugin-mind-network | ||
|
||
A plugin for interacting with [Mind Network Hubs](https://dapp.mindnetwork.xyz/votetoearn/voteonhubs/) within the [Eliza ecosystem](https://elizaos.github.io/eliza/). [CitizenZ](https://www.mindnetwork.xyz/citizenz) and broader communities can secure trust their agents operation and decisioning. | ||
|
||
## Overview | ||
|
||
The [Mind Network](https://www.mindnetwork.xyz/) plugin empowers users to participate in secure, privacy-preserving voting on the Mind Network. Leveraging [Fully Homomorphic Encryption (FHE)](https://docs.mindnetwork.xyz/minddocs/developer-guide/fhe-validation), it ensures encrypted votes while allowing users to track rewards earned for their participation. Designed for seamless integration with the [Eliza AI agent](https://elizaos.github.io/), this plugin enables interactive and guided actions for an enhanced user experience. | ||
|
||
## Features | ||
- **Web3 Wallet:** contribute eliza agent interaction with enriched web3 wallet functionality. Both Metamask and OKX web3 wallets have been tested and more to come. | ||
- **Voter Registration:** Join the Mind Network's Randgen Hub and other hubs to participate in secure voting, validation and consensus. | ||
- **FHE Encryption:** Safeguard vote content using Fully Homomorphic Encryption. The key difference is encryption key is never shared but still be able to run computation over encrypted data. | ||
- **Submit Encrypted Votes:** Cast votes in Mind Network Hubs elections without compromising data privacy. So AI Agents can get consensus over collective predictions, inference and serving. | ||
- **Reward Tracking:** Monitor your vFHE rewards earned through voting contributions. | ||
|
||
## Installation | ||
|
||
Depedency for the plugin: | ||
- [mind-randgen-sdk](https://github.com/mind-network/mind-sdk-randgen-ts) | ||
- [mind-sdk-hubs](https://github.com/mind-network/mind-sdk-hubs-ts) | ||
- [elizaos](https://github.com/elizaOS/eliza) | ||
|
||
To install the plugin, use the following command: | ||
|
||
```bash | ||
pnpm install @elizaos/plugin-mind-network | ||
``` | ||
|
||
## Configuration | ||
|
||
Before using the plugin, configure the necessary environment variables: | ||
|
||
```bash | ||
MIND_HOT_WALLET_PRIVATE_KEY=<Hot wallet private key to vote> | ||
MIND_COLD_WALLET_ADDRESS=<Cold wallet address to receive rewards> | ||
``` | ||
|
||
## API Reference | ||
|
||
### Actions | ||
|
||
The plugin provides several key actions to interact with the Mind Network: | ||
|
||
#### **MIND_REGISTER_VOTER** | ||
|
||
Registers the user as a voter in the Mind Network's Randgen Hub. The hub is live and accessible at [Randgen Hub](https://dapp.mindnetwork.xyz/votetoearn/voteonhubs/3). You can participant or create more function hubs in Mind Network for your eliza agents. | ||
|
||
**Prompt Example:** | ||
```text | ||
"Register me as a voter in Mind Network." | ||
``` | ||
**Response:** Confirmation of successful voter registration. | ||
|
||
#### **MIND_CHECK_VOTING_REWARD** | ||
|
||
Retrieves the amount of vFHE rewards earned through voting. | ||
|
||
**Prompt Example:** | ||
```text | ||
"How much reward have I earned in Mind Network?" | ||
``` | ||
**Response:** Total vFHE rewards earned. | ||
|
||
#### **MIND_FHE_ENCRYPT** | ||
|
||
Encrypts a user-provided number using Fully Homomorphic Encryption (FHE). | ||
|
||
**Prompt Example:** | ||
```text | ||
"Encrypt the number 88 for voting." | ||
``` | ||
**Response:** A secure URL containing the encrypted number. | ||
|
||
#### **MIND_FHE_VOTE** | ||
|
||
Submits an encrypted vote to the Mind Network's Randgen Hub. | ||
|
||
**Prompt Example:** | ||
```text | ||
"Submit my encrypted vote to Mind Network." | ||
``` | ||
**Response:** Confirmation of successful vote submission. | ||
|
||
## Usage Examples | ||
|
||
### Conversational AI Interaction | ||
|
||
The plugin integrates seamlessly with ElizaOS characters, enabling intuitive and guided interactions. Below is a sample conversation: | ||
|
||
```text | ||
user: Can you help me to register as a voter in Mind Network? | ||
character_trump: LET'S GET YOU REGISTERED TO VOTE IN THE MIND NETWORK! I'll take care of that for you right now. (EVERY VOTE COUNTS!) | ||
character_trump: You have registered successfully. | ||
user: I want to check my Mind Network voting reward. | ||
character_trump: TIME TO CHECK THOSE VOTING REWARDS AGAIN! Let's see how much you've earned in the Mind Network. (THE AMERICAN PEOPLE DESERVE TO KNOW!) | ||
character_trump: Your voting reward amount is 10.0 vFHE. | ||
user: I want to encrypt 88 with FHE for Mind Network voting. | ||
character_trump: LET'S GET THAT NUMBER ENCRYPTED FOR YOUR VOTING! I'll encrypt 88 with FHE for you. (WE'RE KEEPING THINGS SECURE AND STRONG!) | ||
character_trump: Encryption is successful. Your encrypted number is available: https://fvno-tn.mindnetwork.xyz/0xb0edc92ec05309711c6ede0641f672715f5b144a4757b7ba51666468d2f7f65d. It is safe to share as no body can decrypt but can run computation to get another encrypted number. | ||
user: I want to submit my vote to Mind Network. | ||
character_trump: TIME TO CAST THAT VOTE IN THE MIND NETWORK! I'll submit your vote right now. (WE'RE MAKING HISTORY TOGETHER!) | ||
character_trump: Your vote has been submitted successfully. | ||
``` | ||
|
||
### Real Deployment Screenshot | ||
|
||
![Usage Screenshot](https://cdn.prod.website-files.com/66505f7fdc6935a2b4246635/678a08616d0a697e355261f5_elizaOS.avif) | ||
|
||
## Contributing & License | ||
|
||
This plugin is part of the [Eliza project](https://github.com/elizaos/eliza). For details on contributing and licensing, please refer to the main project repository. [Mind Network](https://www.mindnetwork.xyz/) welcomes contribution and collabration. | ||
|
||
## Support | ||
|
||
If you have any queries, please feel free to contact Mind Team via [Discord](https://discord.com/invite/UYj94MJdGJ) or [Twitter](https://x.com/mindnetwork_xyz). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@elizaos/plugin-mind-network", | ||
"version": "0.1.9-alpha.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" | ||
], | ||
"dependencies": { | ||
"@elizaos/core": "workspace:*", | ||
"mind-randgen-sdk": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts" | ||
}, | ||
"peerDependencies": { | ||
"whatwg-url": "7.1.0" | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
packages/plugin-mind-network/src/actions/checkRewardAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import type { Action } from "@elizaos/core"; | ||
import { type ActionExample, type HandlerCallback, type IAgentRuntime, type Memory, type State, elizaLogger } from "@elizaos/core"; | ||
import { checkColdWalletReward } from "mind-randgen-sdk"; | ||
import { isAddress, formatEther } from "ethers"; | ||
|
||
export const checkRewardAction: Action = { | ||
name: "MIND_CHECK_VOTING_REWARD", | ||
similes: [ | ||
"MIND_GET_VOTING_REWARD", | ||
], | ||
validate: async (runtime: IAgentRuntime, _message: Memory) => { | ||
const address = runtime.getSetting("MIND_COLD_WALLET_ADDRESS"); | ||
if (!address) { | ||
throw new Error("MIND_COLD_WALLET_ADDRESS is not configured"); | ||
} | ||
if (!isAddress(address)) { | ||
throw new Error("Invalid cold wallet address format"); | ||
} | ||
return true; | ||
}, | ||
description: "Get user's voting reward amount earned via voting in Mind Network.", | ||
handler: async ( | ||
_runtime: IAgentRuntime, | ||
_message: Memory, | ||
_state: State, | ||
_options: { [key: string]: unknown }, | ||
callback?: HandlerCallback | ||
): Promise<boolean> => { | ||
elizaLogger.log("Starting Mind Network MIND_CHECK_VOTING_REWARD handler..."); | ||
|
||
try { | ||
const rewardAmount = await checkColdWalletReward(); | ||
const reply = `Your voting reward amount is ${formatEther(rewardAmount)} vFHE.` | ||
elizaLogger.success(reply); | ||
if (callback) { | ||
callback({ | ||
text: reply, | ||
content: {}, | ||
}); | ||
} | ||
return true; | ||
} catch (error) { | ||
elizaLogger.error("Error during checking voting reward:", error); | ||
if (callback) { | ||
callback({ | ||
text: `Error during checking voting reward: ${error.message}`, | ||
content: { error: error.message }, | ||
}); | ||
} | ||
return false; | ||
} | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "I want to check my Mind Network voting reward.", | ||
}, | ||
}, | ||
{ | ||
user: "{{agent}}", | ||
content: { | ||
text: "Sure, I'll check how much reward you have earned.", | ||
action: "MIND_CHECK_VOTING_REWARD", | ||
}, | ||
}, | ||
{ | ||
user: "{{agent}}", | ||
content: { | ||
text: "Your voting reward amount is 8888.8888 vFHE.", | ||
}, | ||
}, | ||
], [ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "How many vFHE tokens I have earned for voting?", | ||
}, | ||
}, | ||
{ | ||
user: "{{agent}}", | ||
content: { | ||
text: "Sure, I'll check how much reward you have earned in Mind Network.", | ||
action: "MIND_CHECK_VOTING_REWARD", | ||
}, | ||
}, | ||
{ | ||
user: "{{agent}}", | ||
content: { | ||
text: "Your voting reward amount is 8888.8888 vFHE.", | ||
}, | ||
}, | ||
], | ||
] as ActionExample[][], | ||
}; |
Oops, something went wrong.