@@ -4,7 +4,7 @@ import { getCacheKey, getRequiredFieldsForAction, isFieldComplete, formatAddress
4
4
import { performTradeValidations } from "../utils/validation" ;
5
5
import { SecurityManager } from "../utils/securityManager" ;
6
6
import { MongoDBManager } from "../utils/mongoConfig" ;
7
- import { TransactionService } from "../utils/transactionService" ;
7
+ import { TransactionService , WalletProvider } from "../utils/transactionService" ;
8
8
9
9
export const balanceAction : Action = {
10
10
name : "CHECK_BALANCE" ,
@@ -59,7 +59,7 @@ export const balanceAction: Action = {
59
59
60
60
return validationResult . isValid ;
61
61
} catch ( error ) {
62
- elizaLogger . error ( `[balanceAction] Error validating: ${ error . message } ` ) ;
62
+ elizaLogger . error ( `[balanceAction] Error validating: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
63
63
return false ;
64
64
}
65
65
} ,
@@ -70,7 +70,7 @@ export const balanceAction: Action = {
70
70
options : { [ key : string ] : unknown ; } ,
71
71
callback : HandlerCallback
72
72
) => {
73
- elizaLogger . info ( `[balanceAction] Processing balance request for user ${ message . userId } ` ) ;
73
+ elizaLogger . info ( `[balanceAction] Processing balance request for user ${ message . userId } ${ state . senderName } ` ) ;
74
74
75
75
// Initialize MongoDB
76
76
const mongodb = new MongoDBManager ( runtime ) ;
@@ -112,7 +112,7 @@ export const balanceAction: Action = {
112
112
// Get user wallet
113
113
const userWallet = await transactionService . getOrCreateUserWallet (
114
114
message . userId ,
115
- platform as 'twitter' | 'farcaster' | 'discord'
115
+ platform as string
116
116
) ;
117
117
118
118
if ( ! userWallet || ! userWallet . wallets || userWallet . wallets . length === 0 ) {
@@ -124,6 +124,9 @@ export const balanceAction: Action = {
124
124
return false ;
125
125
}
126
126
127
+ // Log the wallet provider being used
128
+ elizaLogger . info ( `[balanceAction] Using wallet provider: ${ userWallet . provider || 'Privy' } ` ) ;
129
+
127
130
// Get the wallet address for the specified chain
128
131
const wallet = transactionService . getWalletForChain ( userWallet , tradeDetails . sourceChain ! ) ;
129
132
if ( ! wallet ) {
@@ -136,7 +139,7 @@ export const balanceAction: Action = {
136
139
}
137
140
138
141
// Fetch balances - in a production environment, you would call blockchain APIs
139
- // For this example, we're simulating the response
142
+ // This fetchTokenBalances function would need to be adapted for different providers
140
143
const balances = await fetchTokenBalances ( wallet . address , tradeDetails . sourceChain ! ) ;
141
144
142
145
// Save balance results to MongoDB for user history
@@ -149,7 +152,8 @@ export const balanceAction: Action = {
149
152
wallet : wallet . address ,
150
153
balances,
151
154
timestamp : Date . now ( ) ,
152
- operation : 'balance'
155
+ operation : 'balance' ,
156
+ provider : userWallet . provider || 'privy' // Track which provider was used
153
157
} ) ;
154
158
}
155
159
@@ -169,8 +173,8 @@ export const balanceAction: Action = {
169
173
walletAddress : formatAddress ( wallet . address ) ,
170
174
balances : balances ,
171
175
totalValue : totalValue . toFixed ( 2 ) ,
172
- specificToken : tradeDetails . tokenSymbol // If a specific token was requested
173
- ,
176
+ specificToken : tradeDetails . tokenSymbol , // If a specific token was requested
177
+ provider : userWallet . provider || 'privy' ,
174
178
bio : "" ,
175
179
lore : "" ,
176
180
messageDirections : "" ,
@@ -181,7 +185,7 @@ export const balanceAction: Action = {
181
185
recentMessagesData : [ ]
182
186
} ,
183
187
template : `
184
- You are a cryptocurrency trading assistant.
188
+ You are a cryptocurrency trading assistant named Swapr .
185
189
Create a friendly, concise message showing the user's token balances on {{chain}}.
186
190
187
191
Wallet: {{walletAddress}}
@@ -199,8 +203,10 @@ export const balanceAction: Action = {
199
203
200
204
{{#if specificToken}}Focus on providing details about {{specificToken}} specifically.{{/if}}
201
205
202
- Keep your response under 280 characters but make sure to include the most valuable tokens.
203
- Use crypto-related emojis (💰, 🪙, 💎, 📈) and format numbers nicely.
206
+ Present the information in a clean, organized way using emoji indicators (💰, 🪙, 💎, 📈) for easy reading.
207
+
208
+ If balances are being retrieved using Para, mention that this is using the multi-chain secure wallet infrastructure.
209
+ If using Privy, don't mention the wallet provider.
204
210
` ,
205
211
templatingEngine : "handlebars"
206
212
} ) ;
@@ -219,7 +225,8 @@ export const balanceAction: Action = {
219
225
chain : tradeDetails . sourceChain ,
220
226
walletAddress : wallet . address ,
221
227
balances : balances ,
222
- totalValue : totalValue
228
+ totalValue : totalValue ,
229
+ provider : userWallet . provider
223
230
}
224
231
} ) ;
225
232
@@ -245,7 +252,7 @@ export const balanceAction: Action = {
245
252
}
246
253
} ,
247
254
{
248
- user : "TradingAgent " ,
255
+ user : "Swapr " ,
249
256
content : {
250
257
text : "I'll check your token balances on Base." ,
251
258
action : "CHECK_BALANCE"
@@ -260,12 +267,27 @@ export const balanceAction: Action = {
260
267
}
261
268
} ,
262
269
{
263
- user : "TradingAgent " ,
270
+ user : "Swapr " ,
264
271
content : {
265
272
text : "💰 Your Arbitrum balance:\n- ETH: 0.423 ($1,269)\n- USDC: 150.00 ($150)\n- ARB: 75.5 ($56.63)\n\nTotal Value: $1,475.63" ,
266
273
action : "BALANCE_SUCCESS"
267
274
}
268
275
}
276
+ ] ,
277
+ [
278
+ {
279
+ user : "{{user1}}" ,
280
+ content : {
281
+ text : "Can I check my Solana wallet balance?"
282
+ }
283
+ } ,
284
+ {
285
+ user : "Swapr" ,
286
+ content : {
287
+ text : "🪙 Here's your Solana wallet:\n- SOL: 5.32 ($956.76)\n- USDC: 125.45 ($125.45)\n\nTotal Value: $1,082.21" ,
288
+ action : "BALANCE_SUCCESS"
289
+ }
290
+ }
269
291
]
270
292
]
271
293
} ;
@@ -325,8 +347,10 @@ async function fetchTokenBalances(address: string, chain: string): Promise<Array
325
347
{ symbol : 'USDC' , address : '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E' , decimals : 6 , minAmount : 50 , maxAmount : 500 , usdPrice : 1 }
326
348
] ,
327
349
'solana' : [
328
- { symbol : 'SOL' , address : 'So11111111111111111111111111111111111111112' , decimals : 9 , minAmount : 1 , maxAmount : 20 , usdPrice : 100 } ,
329
- { symbol : 'USDC' , address : 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' , decimals : 6 , minAmount : 50 , maxAmount : 500 , usdPrice : 1 }
350
+ { symbol : 'SOL' , address : 'So11111111111111111111111111111111111111112' , decimals : 9 , minAmount : 1 , maxAmount : 20 , usdPrice : 180 } ,
351
+ { symbol : 'USDC' , address : 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' , decimals : 6 , minAmount : 50 , maxAmount : 500 , usdPrice : 1 } ,
352
+ { symbol : 'BONK' , address : 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263' , decimals : 5 , minAmount : 1000000 , maxAmount : 10000000 , usdPrice : 0.00003 } ,
353
+ { symbol : 'JUP' , address : 'JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN' , decimals : 6 , minAmount : 100 , maxAmount : 1000 , usdPrice : 0.80 }
330
354
]
331
355
} ;
332
356
0 commit comments