1
- // TODO: add unruggable
2
-
3
1
import {
4
2
ActionExample ,
5
3
elizaLogger ,
@@ -12,143 +10,153 @@ import {
12
10
} from "@ai16z/eliza" ;
13
11
import { composeContext } from "@ai16z/eliza" ;
14
12
import { generateObject } from "@ai16z/eliza" ;
15
- import {
16
- executeSwap as executeAvnuSwap ,
17
- fetchQuotes ,
18
- QuoteRequest ,
19
- } from "@avnu/avnu-sdk" ;
20
13
21
- import { getStarknetAccount , validateSettings } from "../utils/index.ts" ;
14
+ import {
15
+ getStarknetAccount ,
16
+ getStarknetProvider ,
17
+ validateSettings ,
18
+ } from "../utils/index.ts" ;
19
+ import { DeployData , Factory } from "@unruggable_starknet/core" ;
22
20
23
21
interface SwapContent {
24
22
sellTokenAddress : string ;
25
23
buyTokenAddress : string ;
26
24
sellAmount : string ;
27
25
}
28
26
29
- export function isSwapContent ( content : SwapContent ) : content is SwapContent {
27
+ export function isDeployTokenContent (
28
+ content : DeployData
29
+ ) : content is DeployData {
30
30
// Validate types
31
31
const validTypes =
32
- typeof content . sellTokenAddress === "string" &&
33
- typeof content . buyTokenAddress === "string" &&
34
- typeof content . sellAmount === "string" ;
32
+ typeof content . name === "string" &&
33
+ typeof content . symbol === "string" &&
34
+ typeof content . owner === "string" &&
35
+ typeof content . initialSupply === "string" ;
35
36
if ( ! validTypes ) {
36
37
return false ;
37
38
}
38
39
39
40
// Validate addresses (must be 32-bytes long with 0x prefix)
40
41
const validAddresses =
41
- content . sellTokenAddress . startsWith ( "0x" ) &&
42
- content . sellTokenAddress . length === 66 &&
43
- content . buyTokenAddress . startsWith ( "0x" ) &&
44
- content . buyTokenAddress . length === 66 ;
42
+ content . name . length > 2 &&
43
+ content . symbol . length > 2 &&
44
+ parseInt ( content . initialSupply ) > 0 &&
45
+ content . owner . startsWith ( "0x" ) &&
46
+ content . owner . length === 66 ;
45
47
46
48
return validAddresses ;
47
49
}
48
50
49
- const swapTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
50
-
51
- These are known addresses you will get asked to swap, use these addresses for sellTokenAddress and buyTokenAddress:
52
- - BROTHER/brother/$brother: 0x03b405a98c9e795d427fe82cdeeeed803f221b52471e3a757574a2b4180793ee
53
- - BTC/btc: 0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac
54
- - ETH/eth: 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
55
- - STRK/strk: 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d
56
- - LORDS/lords: 0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49
51
+ const deployTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
57
52
58
53
Example response:
59
54
\`\`\`json
60
55
{
61
- "sellTokenAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
62
- "buyTokenAddress": "0x124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49",
63
- "sellAmount": "1000000000000000000"
56
+ "name": "Brother",
57
+ "symbol": "BROTHER",
58
+ "owner": "0x0000000000000000000000000000000000000000000000000000000000000000",
59
+ "initialSupply": "1000000000000000000"
64
60
}
65
61
\`\`\`
66
62
67
63
{{recentMessages}}
68
64
69
- Extract the following information about the requested token swap:
70
- - Sell token address
71
- - Buy token address
72
- - Amount to sell (in wei)
65
+ Extract the following information about the requested token deployment:
66
+ - Token Name
67
+ - Token Symbol
68
+ - Token Owner
69
+ - Token initial supply
73
70
74
71
Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.` ;
75
72
76
73
export const deployToken : Action = {
77
- name : "EXECUTE_STARKNET_SWAP " ,
74
+ name : "DEPLOY_STARKNET_UNRUGGABLE_MEME_TOKEN " ,
78
75
similes : [
79
- "STARKNET_SWAP_TOKENS" ,
80
- "STARKNET_TOKEN_SWAP" ,
81
- "STARKNET_TRADE_TOKENS" ,
82
- "STARKNET_EXCHANGE_TOKENS" ,
76
+ "DEPLOY_STARKNET_UNRUGGABLE_TOKEN" ,
77
+ "STARKNET_DEPLOY_MEMECOIN" ,
78
+ "STARKNET_CREATE_MEMECOIN" ,
83
79
] ,
84
80
validate : async ( runtime : IAgentRuntime , message : Memory ) => {
85
81
return validateSettings ( runtime ) ;
86
82
} ,
87
83
description :
88
- "Perform a token swap on starknet . Use this action when a user asks you to swap tokens anything ." ,
84
+ "Deploy an Unruggable Memecoin on Starknet . Use this action when a user asks you to deploy a new token on Starknet ." ,
89
85
handler : async (
90
86
runtime : IAgentRuntime ,
91
87
message : Memory ,
92
88
state : State ,
93
89
_options : { [ key : string ] : unknown } ,
94
90
callback ?: HandlerCallback
95
91
) : Promise < boolean > => {
96
- elizaLogger . log ( "Starting EXECUTE_STARKNET_SWAP handler..." ) ;
92
+ elizaLogger . log (
93
+ "Starting DEPLOY_STARKNET_UNRUGGABLE_MEME_TOKEN handler..."
94
+ ) ;
97
95
if ( ! state ) {
98
96
state = ( await runtime . composeState ( message ) ) as State ;
99
97
} else {
100
98
state = await runtime . updateRecentMessageState ( state ) ;
101
99
}
102
100
103
- const swapContext = composeContext ( {
101
+ const deployContext = composeContext ( {
104
102
state,
105
- template : swapTemplate ,
103
+ template : deployTemplate ,
106
104
} ) ;
107
105
108
106
const response = await generateObject ( {
109
107
runtime,
110
- context : swapContext ,
108
+ context : deployContext ,
111
109
modelClass : ModelClass . MEDIUM ,
112
110
} ) ;
111
+ elizaLogger . log ( "init supply." + response . initialSupply ) ;
112
+ elizaLogger . log ( response ) ;
113
113
114
- if ( ! isSwapContent ( response ) ) {
115
- callback ?.( { text : "Invalid swap content, please try again." } ) ;
114
+ if ( ! isDeployTokenContent ( response ) ) {
115
+ callback ?.( {
116
+ text : "Invalid deployment content, please try again." ,
117
+ } ) ;
116
118
return false ;
117
119
}
118
120
119
121
try {
120
- // Get quote
121
- const quoteParams : QuoteRequest = {
122
- sellTokenAddress : response . sellTokenAddress ,
123
- buyTokenAddress : response . buyTokenAddress ,
124
- sellAmount : BigInt ( response . sellAmount ) ,
125
- } ;
126
-
127
- const quote = await fetchQuotes ( quoteParams ) ;
128
-
129
- // Execute swap
130
- const swapResult = await executeAvnuSwap (
131
- getStarknetAccount ( runtime ) ,
132
- quote [ 0 ] ,
133
- {
134
- slippage : 0.05 , // 5% slippage
135
- executeApprove : true ,
136
- }
137
- ) ;
122
+ const provider = getStarknetProvider ( runtime ) ;
123
+ const account = getStarknetAccount ( runtime ) ;
124
+
125
+ const factory = new Factory ( {
126
+ provider,
127
+ chainId : await provider . getChainId ( ) ,
128
+ } ) ;
129
+
130
+ const { tokenAddress, calls } = factory . getDeployCalldata ( {
131
+ name : response . name ,
132
+ symbol : response . symbol ,
133
+ owner : response . owner ,
134
+ initialSupply : response . initialSupply ,
135
+ } ) ;
138
136
139
137
elizaLogger . log (
140
- "Swap completed successfully!" + swapResult . transactionHash
138
+ "Deployment has been initiated for coin: " +
139
+ response . name +
140
+ " at address: " +
141
+ tokenAddress
141
142
) ;
143
+ const tx = await account . execute ( calls ) ;
144
+
142
145
callback ?.( {
143
146
text :
144
- "Swap completed successfully! tx: " +
145
- swapResult . transactionHash ,
147
+ "Token Deployment completed successfully!" +
148
+ response . symbol +
149
+ " deployed in tx: " +
150
+ tx . transaction_hash ,
146
151
} ) ;
147
152
148
153
return true ;
149
154
} catch ( error ) {
150
- elizaLogger . error ( "Error during token swap:" , error ) ;
151
- callback ?.( { text : `Error during swap:` } ) ;
155
+ elizaLogger . error ( "Error during token deployment:" , error ) ;
156
+ callback ?.( {
157
+ text : `Error during deployment: ${ error . message } ` ,
158
+ content : { error : error . message } ,
159
+ } ) ;
152
160
return false ;
153
161
}
154
162
} ,
@@ -157,41 +165,41 @@ export const deployToken: Action = {
157
165
{
158
166
user : "{{user1}}" ,
159
167
content : {
160
- text : "Swap 10 ETH for LORDS" ,
168
+ text : "Deploy a new token called Lords with the symbol LORDS, owned by 0x024BA6a4023fB90962bDfc2314F3B94372aa382D155291635fc3E6b777657A5B and initial supply of 1000000000000000000 on Starknet " ,
161
169
} ,
162
170
} ,
163
171
{
164
172
user : "{{agent}}" ,
165
173
content : {
166
- text : "Ok, I'll swap 10 ETH for LORDS " ,
174
+ text : "Ok, I'll deploy the Lords token to Starknet " ,
167
175
} ,
168
176
} ,
169
177
] ,
170
178
[
171
179
{
172
180
user : "{{user1}}" ,
173
181
content : {
174
- text : "Swap 100 $lords on starknet " ,
182
+ text : "Deploy the SLINK coin to Starknet " ,
175
183
} ,
176
184
} ,
177
185
{
178
186
user : "{{agent}}" ,
179
187
content : {
180
- text : "Ok, I'll swap 100 $lords on starknet " ,
188
+ text : "Ok, I'll deploy your coin on Starknet " ,
181
189
} ,
182
190
} ,
183
191
] ,
184
192
[
185
193
{
186
194
user : "{{user1}}" ,
187
195
content : {
188
- text : "Swap 0.5 BTC for LORDS " ,
196
+ text : "Create a new coin on Starknet " ,
189
197
} ,
190
198
} ,
191
199
{
192
200
user : "{{agent}}" ,
193
201
content : {
194
- text : "Ok, I'll swap 0.5 BTC for LORDS " ,
202
+ text : "Ok, I'll create a new coin for you on Starknet " ,
195
203
} ,
196
204
} ,
197
205
] ,
0 commit comments