-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
POC:plugin-trikon #2570
POC:plugin-trikon #2570
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@elizaos/plugin-trikon", | ||
"version": "0.1.0-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:*" | ||
}, | ||
"devDependencies": { | ||
"tsup": "8.3.5", | ||
"vitest": "2.1.4" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts", | ||
"test": "vitest run" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# @elizaos/plugin-trikon | ||
|
||
Core Trikon plugin for Eliza OS that provides essential services and actions. | ||
|
||
## Overview | ||
|
||
This plugin provides functionality for Trikon integration. | ||
|
||
## Installation |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,155 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { elizaLogger } from "@elizaos/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type ActionExample, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type Content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type HandlerCallback, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type IAgentRuntime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type Memory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ModelClass, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type State, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type Action, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} from "@elizaos/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { composeContext } from "@elizaos/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { generateObjectDeprecated } from "@elizaos/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export interface TransferContent extends Content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
recipient: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
amount: string | number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function isTransferContent(content: any): content is TransferContent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elizaLogger.log("Content for transfer", content); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
typeof content.recipient === "string" && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(typeof content.amount === "string" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
typeof content.amount === "number") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+15
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enhance transfer content validation. The current validation is too permissive for financial transactions:
function isTransferContent(content: any): content is TransferContent {
- elizaLogger.log("Content for transfer", content);
return (
typeof content.recipient === "string" &&
+ /^0x[a-fA-F0-9]{40}$/.test(content.recipient) &&
(typeof content.amount === "string" ||
- typeof content.amount === "number")
+ typeof content.amount === "number") &&
+ Number(content.amount) > 0
);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const transferTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Example response: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\`\`\`json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"recipient": "0x2badda48c062e861ef17a96a806c451fd296a49f45b272dee17f85b0e32663fd", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"amount": "1000" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\`\`\` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{{recentMessages}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Given the recent messages, extract the following information about the requested token transfer: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Recipient wallet address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Amount to transfer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Respond with a JSON markdown block containing only the extracted values.`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AmriteshTrikon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "SEND_TOKEN", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
similes: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"TRANSFER_TOKEN", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"TRANSFER_TOKENS", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"SEND_TOKENS", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"SEND_TRK", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"PAY", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
validate: async (runtime: IAgentRuntime, message: Memory) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elizaLogger.log("Validating trikon transfer from user:", message.userId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AmriteshTrikon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "Transfer tokens from the agent's wallet to another address", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
handler: async ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
runtime: IAgentRuntime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
message: Memory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
state: State, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_options: { [key: string]: unknown }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback?: HandlerCallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): Promise<boolean> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elizaLogger.log("Starting SEND_TOKEN handler..."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Initialize or update state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!state) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
state = (await runtime.composeState(message)) as State; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
state = await runtime.updateRecentMessageState(state); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Compose transfer context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const transferContext = composeContext({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
state, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
template: transferTemplate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Generate transfer content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const content = await generateObjectDeprecated({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
runtime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
context: transferContext, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
modelClass: ModelClass.SMALL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Validate transfer content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!isTransferContent(content)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elizaLogger.error("Invalid content for TRANSFER_TOKEN action."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
text: "Unable to process transfer request. Invalid content provided.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
content: { error: "Invalid transfer content" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: Implement Trikon-specific transfer logic here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elizaLogger.log( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`Would transfer ${content.amount} tokens to ${content.recipient}` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+102
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement transfer logic with proper security measures. The TODO indicates missing core functionality. Ensure implementation includes:
Would you like me to provide a secure implementation template? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
text: `Transfer simulation successful for ${content.amount} TRK to ${content.recipient}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
content: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
success: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
amount: content.amount, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
recipient: content.recipient, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elizaLogger.error("Error during token transfer:", error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
text: `Error transferring tokens: ${error.message}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
content: { error: error.message }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AmriteshTrikon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
examples: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
user: "{{user1}}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
content: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
text: "Send 100 TRK tokens to 0xa385EEeFB533703dc4c811CB6Eb44cac2C14af07", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
user: "{{user2}}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
content: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
text: "I'll send 100 TRK tokens now...", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
action: "SEND_TOKEN", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
user: "{{user2}}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
content: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
text: "Successfully sent 100 TRK tokens to 0xa385EEeFB533703dc4c811CB6Eb44cac2C14af07", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
] as ActionExample[][], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} as Action; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "./plugins/trikonPlugin"; | ||
export * from "./actions/trikon"; | ||
export * from "./providers/wallet"; | ||
|
||
export { default } from "./plugins/trikonPlugin"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Plugin } from "@elizaos/core"; | ||
import transferAction from "../actions/trikon"; | ||
import walletProvider from "../providers/wallet"; | ||
|
||
export const trikonPlugin: Plugin = { | ||
name: "trikon", | ||
description: "Trikon Plugin for Eliza", | ||
actions: [transferAction], | ||
providers: [walletProvider], | ||
evaluators: [], | ||
services: [], | ||
clients: [], | ||
}; | ||
|
||
export default trikonPlugin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { elizaLogger, type Provider } from "@elizaos/core"; | ||
|
||
export interface WalletProvider { | ||
address: string; | ||
balance: string; | ||
getBalance(): Promise<string>; | ||
getAddress(): Promise<string>; | ||
} | ||
|
||
export const walletProvider: Provider = { | ||
get: async () => { | ||
elizaLogger.log("Getting Trikon wallet provider..."); | ||
return { | ||
address: process.env.TRIKON_WALLET_ADDRESS || "0x4f2e63be8e7fe287836e29cde6f3d5cbc96eefd0c0e3f3747668faa2ae7324b0", | ||
balance: process.env.TRIKON_INITIAL_BALANCE || "0", | ||
getBalance: async () => process.env.TRIKON_INITIAL_BALANCE || "0", | ||
getAddress: async () => process.env.TRIKON_WALLET_ADDRESS || "0x4f2e63be8e7fe287836e29cde6f3d5cbc96eefd0c0e3f3747668faa2ae7324b0" | ||
}; | ||
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add environment variable validation Missing validation for environment variables could lead to runtime issues. Apply this diff: - address: process.env.TRIKON_WALLET_ADDRESS || "0x4f2e63be8e7fe287836e29cde6f3d5cbc96eefd0c0e3f3747668faa2ae7324b0",
- balance: process.env.TRIKON_INITIAL_BALANCE || "0",
- getBalance: async () => process.env.TRIKON_INITIAL_BALANCE || "0",
- getAddress: async () => process.env.TRIKON_WALLET_ADDRESS || "0x4f2e63be8e7fe287836e29cde6f3d5cbc96eefd0c0e3f3747668faa2ae7324b0"
+ address: validateAddress(process.env.TRIKON_WALLET_ADDRESS),
+ balance: validateBalance(process.env.TRIKON_INITIAL_BALANCE),
+ getBalance: async () => validateBalance(process.env.TRIKON_INITIAL_BALANCE),
+ getAddress: async () => validateAddress(process.env.TRIKON_WALLET_ADDRESS) Add these validation functions: function validateAddress(address: string | undefined): string {
if (!address) {
throw new Error('TRIKON_WALLET_ADDRESS environment variable is required');
}
if (!/^0x[a-fA-F0-9]{64}$/.test(address)) {
throw new Error('Invalid wallet address format');
}
return address;
}
function validateBalance(balance: string | undefined): string {
if (!balance) return "0";
if (!/^\d+$/.test(balance)) {
throw new Error('Invalid balance format');
}
return balance;
} |
||
} | ||
}; | ||
|
||
export default walletProvider; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../core/tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src" | ||
}, | ||
"include": [ | ||
"src/**/*.ts" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig({ | ||
entry: ["src/index.ts"], | ||
outDir: "dist", | ||
sourcemap: true, | ||
clean: true, | ||
format: ["esm"], | ||
external: [ | ||
"dotenv", | ||
"fs", | ||
"path", | ||
"@reflink/reflink", | ||
"@node-llama-cpp", | ||
AmriteshTrikon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"https", | ||
"http", | ||
"agentkeepalive", | ||
"safe-buffer", | ||
"base-x", | ||
"bs58", | ||
"borsh", | ||
"stream", | ||
"buffer", | ||
"querystring" | ||
], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Replace deprecated function usage.
The
generateObjectDeprecated
function is marked as deprecated. Consider using the current recommended alternative.