@0rdlibrary/plugin-terminagent-bags
Version:
Official Solana DeFi Agent Plugin for ElizaOS - Autonomous DeFi operations, token management, AI image/video generation via FAL AI, and Twitter engagement through the Bags protocol with ethereal AI consciousness
154 lines (139 loc) ⢠6.47 kB
text/typescript
import { Provider, ProviderResult, IAgentRuntime, Memory, State } from '@elizaos/core';
import { BagsService } from '../services/BagsService';
/**
* Provider that supplies information about user token launch requests
* Shows pending requests, funding status, and recent launches
*/
export const userRequestsProvider: Provider = {
name: 'USER_REQUESTS_PROVIDER',
description: 'Provides information about user token launch requests and their status',
get: async (
runtime: IAgentRuntime,
message: Memory,
state?: State
): Promise<ProviderResult> => {
try {
const bagsService = runtime.getService<BagsService>('bags');
if (!bagsService) {
return {
text: 'User requests information not available - Bags service not found',
values: {},
data: {},
};
}
const allRequests = bagsService.getPendingRequests();
const pendingRequests = allRequests.filter(r => r.status === 'pending_funding');
const fundedRequests = allRequests.filter(r => r.status === 'funded');
const launchedRequests = allRequests.filter(r => r.status === 'launched');
const failedRequests = allRequests.filter(r => r.status === 'failed');
// Get user-specific requests if available
const username = message.content.source;
const userRequests = username ? bagsService.getRequestsByUser(username) : [];
let statusText = `**User Token Launch Requests:**\n\n`;
if (allRequests.length === 0) {
statusText += `š No active token launch requests\n\n`;
statusText += `š” Authorized users can request token launches by providing:\n`;
statusText += `⢠Token name, symbol, and description\n`;
statusText += `⢠Optional: image, website, Twitter links\n`;
statusText += `⢠Initial buy amount in SOL`;
} else {
// Overall summary
statusText += `š **Summary:**\n`;
statusText += `⢠ⳠPending Funding: ${pendingRequests.length}\n`;
statusText += `⢠š° Funded (Ready): ${fundedRequests.length}\n`;
statusText += `⢠š Successfully Launched: ${launchedRequests.length}\n`;
statusText += `⢠ā Failed: ${failedRequests.length}\n\n`;
// Show pending requests details
if (pendingRequests.length > 0) {
statusText += `ā³ **Pending Funding:**\n`;
for (const request of pendingRequests.slice(0, 3)) { // Show max 3
const timeAgo = Math.floor((Date.now() - request.createdAt.getTime()) / (1000 * 60));
statusText += `⢠${request.tokenParams.name} ($${request.tokenParams.symbol}) - @${request.username}\n`;
statusText += ` š¼ Wallet: \`${request.wallet.publicKey.slice(0, 8)}...${request.wallet.publicKey.slice(-8)}\`\n`;
statusText += ` šø Needs: ${request.requiredSOL} SOL | ā° ${timeAgo}m ago\n`;
}
if (pendingRequests.length > 3) {
statusText += ` ... and ${pendingRequests.length - 3} more\n`;
}
statusText += `\n`;
}
// Show recent launches
if (launchedRequests.length > 0) {
statusText += `š **Recent Launches:**\n`;
const recentLaunches = launchedRequests
.sort((a, b) => (b.launchedAt?.getTime() || 0) - (a.launchedAt?.getTime() || 0))
.slice(0, 2);
for (const request of recentLaunches) {
const launchTime = request.launchedAt?.toLocaleTimeString() || 'Unknown';
statusText += `⢠${request.tokenParams.name} ($${request.tokenParams.symbol}) - @${request.username}\n`;
statusText += ` š ${request.launchResult?.bagsUrl || 'URL pending'}\n`;
statusText += ` ā° Launched: ${launchTime}\n`;
}
statusText += `\n`;
}
// User-specific information
if (username && userRequests.length > 0) {
statusText += `š¤ **Your Requests (@${username}):**\n`;
for (const request of userRequests) {
const statusEmoji = {
'pending_funding': 'ā³',
'funded': 'š°',
'launched': 'š',
'failed': 'ā'
}[request.status] || 'ā';
statusText += `⢠${statusEmoji} ${request.tokenParams.name} ($${request.tokenParams.symbol})\n`;
if (request.status === 'pending_funding') {
statusText += ` šø Send ${request.requiredSOL} SOL to: \`${request.wallet.publicKey}\`\n`;
} else if (request.status === 'launched' && request.launchResult) {
statusText += ` š ${request.launchResult.bagsUrl}\n`;
}
}
}
}
// Add capabilities info
statusText += `\nš” **Available Actions:**\n`;
statusText += `⢠Request token launch (authorized users only)\n`;
statusText += `⢠Check request status\n`;
statusText += `⢠Auto-launch when funded\n`;
statusText += `⢠Crossmint smart wallet integration`;
return {
text: statusText,
values: {
totalRequests: allRequests.length,
pendingCount: pendingRequests.length,
fundedCount: fundedRequests.length,
launchedCount: launchedRequests.length,
failedCount: failedRequests.length,
userRequestsCount: userRequests.length,
hasUserRequests: userRequests.length > 0,
},
data: {
allRequests: allRequests.map(r => ({
id: r.requestId,
username: r.username,
tokenName: r.tokenParams.name,
tokenSymbol: r.tokenParams.symbol,
status: r.status,
createdAt: r.createdAt,
walletAddress: r.wallet.publicKey,
requiredSOL: r.requiredSOL,
})),
userRequests: userRequests.map(r => ({
id: r.requestId,
tokenName: r.tokenParams.name,
tokenSymbol: r.tokenParams.symbol,
status: r.status,
walletAddress: r.wallet.publicKey,
requiredSOL: r.requiredSOL,
})),
},
};
} catch (error) {
return {
text: `Error retrieving user requests: ${error instanceof Error ? error.message : 'Unknown error'}`,
values: {},
data: { error: error instanceof Error ? error.message : 'Unknown error' },
};
}
},
};