-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ambero
committed
Feb 10, 2025
1 parent
81a3528
commit b585af4
Showing
20 changed files
with
4,695 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# `@elizaos/plugin-d.a.t.a` | ||
|
||
The **`@elizaos/plugin-d.a.t.a`** (Data Authentication, Trust, and Attestation framework) plugin is a plugin from CARV. It enhances the Eliza Agent Framework with powerful data processing capabilities, enabling agents to analyze, transform, and derive insights from various data sources. | ||
|
||
- **Comprehensive Data Processing:** Transform raw data into actionable insights through advanced analysis techniques. | ||
- **Flexible Data Handling:** Support for multiple data formats and sources, from CSV to JSON and APIs. | ||
- **Intelligent Analysis:** Leverage statistical methods and machine learning techniques for deeper understanding. | ||
|
||
Integrate **`@elizaos/plugin-d.a.t.a`** to empower your AI agents with sophisticated data analysis capabilities. | ||
|
||
## Use Cases | ||
|
||
- On-chain stats fetching. | ||
- Token info. | ||
- On-chain address tracking (CARV ID required). | ||
|
||
## Example | ||
|
||
**Q**: Can you tell me about the AAVE | ||
|
||
**A**: Searching the results from d.a.t.a, please wait a moment... Analyzing Aave (AAVE) token data. Aave is a decentralized lending and borrowing protocol operating on multiple blockchains, including Ethereum, Polygon, Avalanche, and others. The AAVE token is primarily used for governance, allowing holders to vote on protocol upgrades and changes. It also serves as a safety mechanism, where staked AAVE can be used to cover shortfalls in the protocol. Aave is categorized under 'Decentralized Finance (DeFi)', 'Lending/Borrowing Protocols', and multiple ecosystem integrations, indicating its broad utility and adoption across various blockchain environments. The token is deployed on 12 different platforms, showcasing its cross-chain capabilities. Would you like a deeper analysis of its technical features, market trends, or specific use cases? | ||
|
||
Logs: | ||
``` | ||
◎ LOGS | ||
%%%% D.A.T.A. Querying token info for ticker: | ||
AAVE | ||
["◎ Querying token info for ticker: AAVE"] | ||
["◎ Successfully retrieved token info for AAVE"] | ||
◎ LOGS | ||
%%%% D.A.T.A. queryResult: | ||
{ | ||
"success": true, | ||
"data": { | ||
"ticker": "aave", | ||
"symbol": "aave", | ||
"name": "Aave", | ||
"platform": "ethereum", | ||
"categories": [ | ||
"Decentralized Finance (DeFi)", | ||
"Governance", | ||
"Yield Farming", | ||
"BNB Chain Ecosystem", | ||
"Lending/Borrowing Protocols", | ||
"Avalanche Ecosystem", | ||
"Polygon Ecosystem", | ||
"Near Protocol Ecosystem", | ||
"Fantom Ecosystem", | ||
"Harmony Ecosystem", | ||
"Arbitrum Ecosystem", | ||
"Ethereum Ecosystem", | ||
"Optimism Ecosystem", | ||
"Index Coop Defi Index", | ||
"Energi Ecosystem", | ||
"Sora Ecosystem", | ||
"Huobi ECO Chain Ecosystem", | ||
"GMCI DeFi Index", | ||
"Blockchain Capital Portfolio", | ||
"Index Coop Index", | ||
"GMCI Index", | ||
"World Liberty Financial Portfolio" | ||
], | ||
"contract_infos": [ | ||
{ | ||
"platform": "near-protocol", | ||
"address": "7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9.factory.bridge.near" | ||
}, | ||
{ | ||
"platform": "huobi-token", | ||
"address": "0x202b4936fe1a82a4965220860ae46d7d3939bb25" | ||
}, | ||
{ | ||
"platform": "fantom", | ||
"address": "0x6a07a792ab2965c72a5b8088d3a069a7ac3a993b" | ||
}, | ||
{ | ||
"platform": "energi", | ||
"address": "0xa7f2f790355e0c32cab03f92f6eb7f488e6f049a" | ||
}, | ||
{ | ||
"platform": "binance-smart-chain", | ||
"address": "0xfb6115445bff7b52feb98650c87f44907e58f802" | ||
}, | ||
{ | ||
"platform": "ethereum", | ||
"address": "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9" | ||
}, | ||
{ | ||
"platform": "optimistic-ethereum", | ||
"address": "0x76fb31fb4af56892a25e32cfc43de717950c9278" | ||
}, | ||
{ | ||
"platform": "polygon-pos", | ||
"address": "0xd6df932a45c0f255f85145f286ea0b292b21c90b" | ||
}, | ||
{ | ||
"platform": "harmony-shard-0", | ||
"address": "0xcf323aad9e522b93f11c352caa519ad0e14eb40f" | ||
}, | ||
{ | ||
"platform": "arbitrum-one", | ||
"address": "0xba5ddd1f9d7f570dc94a51479a000e3bce967196" | ||
}, | ||
{ | ||
"platform": "avalanche", | ||
"address": "0x63a72806098bd3d9520cc43356dd78afe5d386d9" | ||
}, | ||
{ | ||
"platform": "sora", | ||
"address": "0x0091bd8d8295b25cab5a7b8b0e44498e678cfc15d872ede3215f7d4c7635ba36" | ||
} | ||
], | ||
"price": 0 | ||
}, | ||
"metadata": { | ||
"queryTime": "2025-01-24T15:02:01.461Z", | ||
"queryType": "token", | ||
"executionTime": 1362, | ||
"cached": false, | ||
"queryDetails": { | ||
"params": { | ||
"ticker": "AAVE", | ||
"platform": "ethereum" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Start leveraging the power of data analysis in your AI applications with **`@elizaos/plugin-d.a.t.a`** and unlock new possibilities for your Eliza agents. |
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,39 @@ | ||
{ | ||
"name": "@elizaos/plugin-d.a.t.a", | ||
"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" | ||
], | ||
"dependencies": { | ||
"@elizaos/core": "workspace:*", | ||
"@elizaos/plugin-tee": "workspace:*", | ||
"@lifi/data-types": "5.15.5", | ||
"@lifi/sdk": "3.4.1", | ||
"@lifi/types": "16.3.0", | ||
"tsup": "8.3.5", | ||
"zod": "3.23.8" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts", | ||
"dev": "tsup --format esm --dts --watch", | ||
"test": "vitest run", | ||
"lint": "eslint --fix --cache ." | ||
}, | ||
"peerDependencies": { | ||
"whatwg-url": "7.1.0" | ||
} | ||
} |
201 changes: 201 additions & 0 deletions
201
packages/plugin-d.a.t.a/src/actions/carv/twitterBalance.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,201 @@ | ||
import { | ||
Action, | ||
HandlerCallback, | ||
IAgentRuntime, | ||
Memory, | ||
State, | ||
elizaLogger, | ||
} from "@elizaos/core"; | ||
import { | ||
TwitterBalanceProvider, | ||
TwitterBalanceParams, | ||
TwitterBalanceQueryResult, | ||
createTwitterBalanceProvider, | ||
} from "../../providers/carv/twitterBalance"; | ||
|
||
export class TwitterBalanceAction { | ||
constructor(private provider: TwitterBalanceProvider) {} | ||
|
||
/** | ||
* Validate query parameters | ||
*/ | ||
private validateParams(params: TwitterBalanceParams): string[] { | ||
const validationMessages: string[] = []; | ||
|
||
if (!params.twitter_user_id) { | ||
validationMessages.push("Twitter handle is required"); | ||
} | ||
|
||
if (!params.chain_name) { | ||
validationMessages.push("Chain name is required"); | ||
} else { | ||
params.chain_name = params.chain_name.toLowerCase(); | ||
} | ||
|
||
if (!params.token_ticker) { | ||
validationMessages.push("Token ticker is required"); | ||
} else { | ||
params.token_ticker = params.token_ticker.toUpperCase(); | ||
} | ||
|
||
return validationMessages; | ||
} | ||
|
||
/** | ||
* Format response for display | ||
*/ | ||
private formatResponse(result: TwitterBalanceQueryResult): string { | ||
if (result.success && result.data) { | ||
const params = result.metadata.queryDetails.params; | ||
return `🔍 Balance Information: | ||
• Twitter User: @${params.twitter_user_id} | ||
• Chain: ${params.chain_name} | ||
• Token: ${params.token_ticker} | ||
• Balance: ${result.data.balance} ${params.token_ticker}`; | ||
} else { | ||
const errorMsg = result.error?.message || "Unknown error occurred"; | ||
switch (errorMsg) { | ||
case "received rsp err twitter handle not found": | ||
return "❌ Error: Twitter handle not found. Please check if the Twitter handle is correct."; | ||
case "no token found in this chain": | ||
return "❌ Error: Token not found on this chain. Please verify the token ticker and chain name."; | ||
case "unsupported chain name": | ||
return "❌ Error: Unsupported blockchain. Please check the chain name."; | ||
default: | ||
return `❌ Error: ${errorMsg}`; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get Twitter user's token balance | ||
*/ | ||
public async getTwitterBalance( | ||
message: Memory, | ||
runtime: IAgentRuntime, | ||
state: State | ||
): Promise<{ | ||
success: boolean; | ||
response: string; | ||
data?: TwitterBalanceQueryResult; | ||
}> { | ||
try { | ||
const result = await this.provider.processD_A_T_AQuery( | ||
runtime, | ||
message, | ||
state | ||
); | ||
|
||
if (!result) { | ||
return { | ||
success: false, | ||
response: | ||
"❌ Error: Failed to process query. Please make sure to provide Twitter handle, chain name, and token ticker.", | ||
}; | ||
} | ||
|
||
const { queryResult } = result; | ||
return { | ||
success: queryResult.success, | ||
response: this.formatResponse(queryResult), | ||
data: queryResult, | ||
}; | ||
} catch (error) { | ||
elizaLogger.error("Error in getTwitterBalance:", error); | ||
return { | ||
success: false, | ||
response: `❌ Error: ${error.message}`, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
export const twitterBalanceAction: Action = { | ||
name: "TWITTER_BALANCE", | ||
description: "Check token balance of a Twitter user on specific blockchain", | ||
handler: async ( | ||
runtime: IAgentRuntime, | ||
message: Memory, | ||
state: State, | ||
_options: any, | ||
callback?: HandlerCallback | ||
) => { | ||
try { | ||
const provider = createTwitterBalanceProvider(runtime); | ||
const action = new TwitterBalanceAction(provider); | ||
const result = await action.getTwitterBalance( | ||
message, | ||
runtime, | ||
state | ||
); | ||
|
||
if (callback) { | ||
callback({ | ||
text: result.response, | ||
content: { | ||
success: result.success, | ||
data: result.data, | ||
}, | ||
}); | ||
} | ||
|
||
return result.success; | ||
} catch (error) { | ||
elizaLogger.error("Error in twitter balance action:", error); | ||
if (callback) { | ||
callback({ | ||
text: `Error checking balance: ${error.message}`, | ||
content: { error: error.message }, | ||
}); | ||
} | ||
return false; | ||
} | ||
}, | ||
validate: async (runtime: IAgentRuntime) => { | ||
const apiKey = runtime.getSetting("DATA_API_KEY"); | ||
return !!apiKey; | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "user", | ||
content: { | ||
text: "Check CARV balance for Twitter user @gatsbyter on Arbitrum", | ||
action: "TWITTER_BALANCE", | ||
twitter_user_id: "gatsbyter", | ||
chain_name: "arbitrum-one", | ||
token_ticker: "carv", | ||
}, | ||
}, | ||
], | ||
[ | ||
{ | ||
user: "user", | ||
content: { | ||
text: "Show me how many AAVE tokens @vitalik has on Ethereum", | ||
action: "TWITTER_BALANCE", | ||
twitter_user_id: "vitalik", | ||
chain_name: "ethereum", | ||
token_ticker: "aave", | ||
}, | ||
}, | ||
], | ||
], | ||
similes: [ | ||
"check balance", | ||
"get token balance", | ||
"show token amount", | ||
"view balance", | ||
"check token holdings", | ||
"show wallet balance", | ||
"display token balance", | ||
"get holdings", | ||
"check account balance", | ||
"view token amount", | ||
"show crypto balance", | ||
"check token value", | ||
"get wallet holdings", | ||
"display account balance", | ||
"view holdings", | ||
], | ||
}; |
Oops, something went wrong.