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

170 lines (169 loc) 5 kB
import { Web3SubscriptionSkill } from './Web3SubscriptionSkill'; import { Web3SubscriptionConfig, Subscription, BillingPeriod, RevenueStats } from './types'; export interface EnhancedWeb3SubscriptionConfig extends Web3SubscriptionConfig { chains?: { [chainId: number]: { name: string; rpcUrl: string; explorer: string; nativeToken: string; gasLimit?: number; gasPrice?: string; }; }; tokens?: { [tokenAddress: string]: { name: string; symbol: string; decimals: number; chainId: number; logo?: string; priceFeed?: string; }; }; enhancedAnalytics?: { trackRevenue: boolean; trackUsage: boolean; exportData: boolean; realTimeMetrics: boolean; customEvents?: string[]; }; webhooks?: { subscriptionCreated?: string; subscriptionCancelled?: string; paymentProcessed?: string; refundIssued?: string; subscriptionUpgraded?: string; subscriptionDowngraded?: string; trialStarted?: string; trialEnded?: string; }; refunds?: { enabled: boolean; gracePeriod: number; autoRefund: boolean; refundPolicy: 'full' | 'prorated' | 'none'; requireApproval: boolean; }; subscriptionManagement?: { allowUpgrades: boolean; allowDowngrades: boolean; prorationEnabled: boolean; trialPeriod: number; gracePeriod: number; autoRenewal: boolean; }; platformFee?: { percentage: number; safeAddress: string; autoTransfer: boolean; }; } export interface PaymentMethod { type: 'token' | 'native'; address: string; symbol: string; decimals: number; chainId: number; balance: number; priceUSD?: number; } export interface EnhancedSubscription extends Subscription { paymentMethod: PaymentMethod; chainId: number; transactionHash?: string; refundHistory?: RefundRecord[]; upgradeHistory?: UpgradeRecord[]; analytics?: SubscriptionAnalytics; } export interface RefundRecord { id: string; amount: number; reason: string; status: 'pending' | 'approved' | 'rejected' | 'processed'; timestamp: Date; transactionHash?: string; } export interface UpgradeRecord { id: string; fromPlan: string; toPlan: string; fromPeriod: BillingPeriod; toPeriod: BillingPeriod; proratedAmount: number; timestamp: Date; transactionHash?: string; } export interface SubscriptionAnalytics { totalPayments: number; totalRevenue: number; averageSessionDuration: number; featureUsage: { [feature: string]: number; }; churnRate: number; lifetimeValue: number; } export interface WebhookPayload { event: string; subscriptionId: string; userAddress: string; data: any; timestamp: Date; signature?: string; } export interface EnhancedRevenueStats extends RevenueStats { byChain: { [chainId: number]: number; }; byToken: { [tokenAddress: string]: number; }; byPeriod: { [period: string]: number; }; churnRate: number; averageLifetimeValue: number; refundRate: number; upgradeRate: number; } export declare class EnhancedWeb3SubscriptionSkill extends Web3SubscriptionSkill { private enhancedConfig; private webhookQueue; private analyticsCache; constructor(config: EnhancedWeb3SubscriptionConfig); /** * Get available payment methods for a user across all chains */ getPaymentMethods(userAddress: string): Promise<PaymentMethod[]>; /** * Create subscription with enhanced features */ createEnhancedSubscription(userAddress: string, planId: string, billingPeriod: BillingPeriod, paymentMethod: PaymentMethod): Promise<EnhancedSubscription>; /** * Upgrade subscription to a higher plan */ upgradeSubscription(userAddress: string, newPlanId: string, newPeriod?: BillingPeriod): Promise<EnhancedSubscription>; /** * Downgrade subscription to a lower plan */ downgradeSubscription(userAddress: string, newPlanId: string, newPeriod?: BillingPeriod): Promise<EnhancedSubscription>; /** * Process refund for a subscription */ processRefund(userAddress: string, amount: number, reason: string): Promise<RefundRecord>; /** * Get enhanced analytics for a subscription */ getEnhancedAnalytics(userAddress: string): Promise<SubscriptionAnalytics>; /** * Get enhanced revenue statistics */ getEnhancedRevenueStats(): Promise<EnhancedRevenueStats>; private sendWebhook; private trackAnalytics; private getDefaultPaymentMethod; private calculateProratedUpgrade; private calculateDowngradeCredit; private calculateEnhancedMonthlyPrice; }