1
1
import {
2
2
ActionExample ,
3
+ composeContext ,
3
4
Content ,
4
5
elizaLogger ,
6
+ generateObjectDeprecated ,
5
7
HandlerCallback ,
6
8
IAgentRuntime ,
7
9
Memory ,
@@ -10,6 +12,8 @@ import {
10
12
type Action ,
11
13
} from "@elizaos/core" ;
12
14
15
+ import { SolanaAgentKit } from "solana-agent-kit" ;
16
+
13
17
export interface CreateTokenContent extends Content {
14
18
name : string ;
15
19
uri : string ;
@@ -32,6 +36,30 @@ function isCreateTokenContent(
32
36
) ;
33
37
}
34
38
39
+ const createTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
40
+
41
+ Example response:
42
+ \`\`\`json
43
+ {
44
+ "name": "Example Token",
45
+ "symbol": "EXMPL",
46
+ "uri": "https://raw.githubusercontent.com/solana-developers/opos-asset/main/assets/CompressedCoil/image.png",
47
+ "decimals": 18,
48
+ "initialSupply": 1000000,
49
+ }
50
+ \`\`\`
51
+
52
+ {{recentMessages}}
53
+
54
+ Given the recent messages, extract the following information about the requested token transfer:
55
+ - Token name
56
+ - Token symbol
57
+ - Token uri
58
+ - Token decimals
59
+ - Token initialSupply
60
+
61
+ Respond with a JSON markdown block containing only the extracted values.` ;
62
+
35
63
export default {
36
64
name : "CREATE_TOKEN" ,
37
65
similes : [ "DEPLOY_TOKEN" ] ,
@@ -45,7 +73,75 @@ export default {
45
73
callback ?: HandlerCallback
46
74
) : Promise < boolean > => {
47
75
elizaLogger . log ( "Starting CREATE_TOKEN handler..." ) ;
48
- return true ;
76
+ // Initialize or update state
77
+ if ( ! state ) {
78
+ state = ( await runtime . composeState ( message ) ) as State ;
79
+ } else {
80
+ state = await runtime . updateRecentMessageState ( state ) ;
81
+ }
82
+
83
+ // Compose transfer context
84
+ const transferContext = composeContext ( {
85
+ state,
86
+ template : createTemplate ,
87
+ } ) ;
88
+
89
+ // Generate transfer content
90
+ const content = await generateObjectDeprecated ( {
91
+ runtime,
92
+ context : transferContext ,
93
+ modelClass : ModelClass . LARGE ,
94
+ } ) ;
95
+
96
+ // Validate transfer content
97
+ if ( ! isCreateTokenContent ( runtime , content ) ) {
98
+ elizaLogger . error ( "Invalid content for CREATE_TOKEN action." ) ;
99
+ if ( callback ) {
100
+ callback ( {
101
+ text : "Unable to process create token request. Invalid content provided." ,
102
+ content : { error : "Invalid creat token content" } ,
103
+ } ) ;
104
+ }
105
+ return false ;
106
+ }
107
+
108
+ elizaLogger . log ( "Init solana agent kit..." ) ;
109
+ const solanaPrivatekey = runtime . getSetting ( "SOLANA_PRIVATE_KEY" ) ;
110
+ const rpc = runtime . getSetting ( "RPC_URL" ) ;
111
+ const openAIKey = runtime . getSetting ( "OPENAI_API_KEY" ) ;
112
+ const solanaAgentKit = new SolanaAgentKit (
113
+ solanaPrivatekey ,
114
+ rpc ,
115
+ openAIKey
116
+ ) ;
117
+ try {
118
+ const deployedAddress = solanaAgentKit . deployToken (
119
+ content . name ,
120
+ content . uri ,
121
+ content . symbol ,
122
+ content . decimals ,
123
+ content . initialSupply
124
+ ) ;
125
+ elizaLogger . log ( "Create successful: " , deployedAddress ) ;
126
+ if ( callback ) {
127
+ callback ( {
128
+ text : `Successfully create token ${ content . name } ` ,
129
+ content : {
130
+ success : true ,
131
+ } ,
132
+ } ) ;
133
+ }
134
+ return true ;
135
+ } catch ( error ) {
136
+ if ( callback ) {
137
+ elizaLogger . error ( "Error during create token: " , error ) ;
138
+ callback ( {
139
+ text : `Error creating token: ${ error . message } ` ,
140
+ content : { error : error . message } ,
141
+ } ) ;
142
+ }
143
+ return false ;
144
+ }
49
145
} ,
50
146
examples : [
51
147
[
0 commit comments