UNPKG

@agentdao/core

Version:

Core functionality, skills, and ready-made UI components for AgentDAO - Web3 subscriptions, content generation, social media, help support, live chat, RSS fetching, web search, and agent pricing integration

345 lines (344 loc) 13.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.polygonConfig = exports.ethereumConfig = void 0; exports.createChainConfig = createChainConfig; exports.createChainAgnosticTokenGating = createChainAgnosticTokenGating; exports.demonstrateMultiChainTokenGating = demonstrateMultiChainTokenGating; const TokenGatingSkill_1 = require("../TokenGatingSkill"); // Example configurations for different chains exports.ethereumConfig = { subscription: { agentId: 'ethereum-agent', agentName: 'Ethereum Agent', domain: 'ethereum.example.com', adaoToken: { address: '0xA0b86a33E6441b8C4C8C8C8C8C8C8C8C8C8C8C8C', decimals: 6, network: 'base', logo: 'https://example.com/usdc-logo.png' }, plans: { basic: { name: 'Basic Plan', description: 'Basic features for Ethereum users', features: ['chat', 'help'], pricing: { monthly: { price: 10, discount: 0 }, quarterly: { price: 25, discount: 5 }, annually: { price: 90, discount: 20 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } }, pro: { name: 'Pro Plan', description: 'Pro features for Ethereum users', features: ['chat', 'help', 'content', 'social', 'analytics'], pricing: { monthly: { price: 50, discount: 0 }, quarterly: { price: 125, discount: 15 }, annually: { price: 450, discount: 30 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } } }, provider: { rpcUrl: 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY', chainId: 1, explorer: 'https://etherscan.io' }, payment: { autoApprove: false, requireConfirmation: true, refundPolicy: { enabled: true, gracePeriod: 7 }, billing: { allowTrial: true, trialDays: 7, gracePeriodDays: 3 } }, integration: { webhookUrl: 'https://your-api.com/webhooks', redirectUrl: 'https://your-app.com/success', successMessage: 'Subscription created successfully!', errorMessage: 'Failed to create subscription' }, analytics: { trackRevenue: true, trackUsage: true, exportData: true }, database: { endpoint: 'https://your-api.com/subscriptions', apiKey: 'your-api-key' } }, fundAgent: { chainId: 1, // Ethereum mainnet network: 'Ethereum', rpcUrl: 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY', // USDC token on Ethereum tokenAddress: '0xA0b86a33E6441b8C4C8C8C8C8C8C8C8C8C8C8C8C', tokenSymbol: 'USDC', tokenDecimals: 6, // Safe wallet configuration safeFactoryAddress: '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', minDeposit: 100, // 100 USDC agentAddress: '0x1234567890123456789012345678901234567890' }, gating: { requireSafeWallet: false, autoCreateSafe: false, minTokenForAccess: 10, // 10 USDC minimum gracePeriod: 7, features: { chat: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false }, help: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false }, content: { requiredPlan: 'pro', requiredTokens: 50, requireSafeWallet: false }, social: { requiredPlan: 'pro', requiredTokens: 50, requireSafeWallet: false }, analytics: { requiredPlan: 'pro', requiredTokens: 100, requireSafeWallet: false } } } }; exports.polygonConfig = { subscription: { agentId: 'polygon-agent', agentName: 'Polygon Agent', domain: 'polygon.example.com', adaoToken: { address: '0x0000000000000000000000000000000000001010', decimals: 18, network: 'base', logo: 'https://example.com/matic-logo.png' }, plans: { basic: { name: 'Basic Plan', description: 'Basic features for Polygon users', features: ['chat', 'help'], pricing: { monthly: { price: 5, discount: 0 }, quarterly: { price: 12, discount: 5 }, annually: { price: 45, discount: 20 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } }, pro: { name: 'Pro Plan', description: 'Pro features for Polygon users', features: ['chat', 'help', 'content', 'social', 'analytics'], pricing: { monthly: { price: 25, discount: 0 }, quarterly: { price: 60, discount: 15 }, annually: { price: 225, discount: 30 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } } }, provider: { rpcUrl: 'https://polygon-rpc.com', chainId: 137, explorer: 'https://polygonscan.com' }, payment: { autoApprove: false, requireConfirmation: true, refundPolicy: { enabled: true, gracePeriod: 7 }, billing: { allowTrial: true, trialDays: 7, gracePeriodDays: 3 } }, integration: { webhookUrl: 'https://your-api.com/webhooks', redirectUrl: 'https://your-app.com/success', successMessage: 'Subscription created successfully!', errorMessage: 'Failed to create subscription' }, analytics: { trackRevenue: true, trackUsage: true, exportData: true }, database: { endpoint: 'https://your-api.com/subscriptions', apiKey: 'your-api-key' } }, fundAgent: { chainId: 137, // Polygon network: 'Polygon', rpcUrl: 'https://polygon-rpc.com', // MATIC token on Polygon tokenAddress: '0x0000000000000000000000000000000000001010', tokenSymbol: 'MATIC', tokenDecimals: 18, // Safe wallet configuration safeFactoryAddress: '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', minDeposit: 50, // 50 MATIC agentAddress: '0x1234567890123456789012345678901234567890' }, gating: { requireSafeWallet: false, autoCreateSafe: false, minTokenForAccess: 5, // 5 MATIC minimum gracePeriod: 7, features: { chat: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false }, help: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false }, content: { requiredPlan: 'pro', requiredTokens: 25, requireSafeWallet: false }, social: { requiredPlan: 'pro', requiredTokens: 25, requireSafeWallet: false }, analytics: { requiredPlan: 'pro', requiredTokens: 50, requireSafeWallet: false } } } }; // Helper function to create config for any chain function createChainConfig(chainId, network, rpcUrl, tokenAddress, tokenSymbol, tokenDecimals, minDeposit, agentAddress, safeFactoryAddress, explorer) { return { subscription: { agentId: `${network.toLowerCase()}-agent`, agentName: `${network} Agent`, domain: `${network.toLowerCase()}.example.com`, adaoToken: { address: tokenAddress, decimals: tokenDecimals, network: 'base', logo: `https://example.com/${tokenSymbol.toLowerCase()}-logo.png` }, plans: { basic: { name: 'Basic Plan', description: `Basic features for ${network} users`, features: ['chat', 'help'], pricing: { monthly: { price: minDeposit * 0.1, discount: 0 }, quarterly: { price: minDeposit * 0.25, discount: 5 }, annually: { price: minDeposit * 0.9, discount: 20 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } }, pro: { name: 'Pro Plan', description: `Pro features for ${network} users`, features: ['chat', 'help', 'content', 'social', 'analytics'], pricing: { monthly: { price: minDeposit * 0.5, discount: 0 }, quarterly: { price: minDeposit * 1.2, discount: 15 }, annually: { price: minDeposit * 4.5, discount: 30 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } } }, provider: { rpcUrl, chainId, explorer: explorer || `https://${network.toLowerCase()}.example.com` }, payment: { autoApprove: false, requireConfirmation: true, refundPolicy: { enabled: true, gracePeriod: 7 }, billing: { allowTrial: true, trialDays: 7, gracePeriodDays: 3 } }, integration: { webhookUrl: 'https://your-api.com/webhooks', redirectUrl: 'https://your-app.com/success', successMessage: 'Subscription created successfully!', errorMessage: 'Failed to create subscription' }, analytics: { trackRevenue: true, trackUsage: true, exportData: true }, database: { endpoint: 'https://your-api.com/subscriptions', apiKey: 'your-api-key' } }, fundAgent: { chainId, network, rpcUrl, tokenAddress, tokenSymbol, tokenDecimals, safeFactoryAddress, minDeposit, agentAddress }, gating: { requireSafeWallet: false, autoCreateSafe: false, minTokenForAccess: minDeposit * 0.1, gracePeriod: 7, features: { chat: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false }, help: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false }, content: { requiredPlan: 'pro', requiredTokens: minDeposit * 0.5, requireSafeWallet: false }, social: { requiredPlan: 'pro', requiredTokens: minDeposit * 0.5, requireSafeWallet: false }, analytics: { requiredPlan: 'pro', requiredTokens: minDeposit, requireSafeWallet: false } } } }; } // Example usage function async function createChainAgnosticTokenGating(chainConfig) { const tokenGating = new TokenGatingSkill_1.TokenGatingSkill(chainConfig); // Example: Check user access const userAddress = '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6'; const access = await tokenGating.checkUserAccess(userAddress); console.log(`User access on ${chainConfig.fundAgent.network}:`, { hasAccess: access.hasAccess, tokenBalance: access.adaoBalance, tokenSymbol: chainConfig.fundAgent.tokenSymbol, features: access.features }); return tokenGating; } // Example: Create token gating for different chains async function demonstrateMultiChainTokenGating() { console.log('=== Multi-Chain Token Gating Demo ===\n'); // Ethereum with USDC const ethereumTokenGating = await createChainAgnosticTokenGating(exports.ethereumConfig); // Polygon with MATIC const polygonTokenGating = await createChainAgnosticTokenGating(exports.polygonConfig); console.log('\nAll chains configured with different tokens and requirements!'); }