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

118 lines (117 loc) 3.35 kB
import { ethers } from 'ethers'; import { Web3SubscriptionConfig, SubscriptionStatus, BillingPeriod, Plan } from './types'; export interface TokenGatingConfig { subscription: Web3SubscriptionConfig; fundAgent: { chainId: number; network: string; rpcUrl: string; tokenAddress: string; tokenSymbol: string; tokenDecimals: number; safeFactoryAddress?: string; minDeposit: number; agentAddress: string; provider?: ethers.Provider; }; gating: { requireSafeWallet: boolean; autoCreateSafe: boolean; minTokenForAccess: number; gracePeriod: number; features: { [feature: string]: { requiredPlan: string; requiredTokens: number; requireSafeWallet: boolean; }; }; }; database?: { endpoint: string; apiKey?: string; }; } export interface UserAccess { hasAccess: boolean; subscription: SubscriptionStatus | null; safeWallet: string | null; adaoBalance: number; features: { [feature: string]: { accessible: boolean; reason?: string; }; }; nextBillingDate?: Date; gracePeriodDays?: number; } export interface SafeWalletInfo { address: string; owners: string[]; threshold: number; balance: string; isActive: boolean; createdAt: Date; } export declare class TokenGatingService { private config; private subscriptionSkill; private fundAgent; private provider; constructor(config: TokenGatingConfig); /** * Check user access to AgentDAO features */ checkUserAccess(userAddress: string): Promise<UserAccess>; /** * Create subscription and Safe wallet for new user */ onboardUser(userAddress: string, planId: string, billingPeriod: BillingPeriod, createSafeWallet?: boolean): Promise<{ subscription: any; safeWallet?: string; success: boolean; error?: string; }>; /** * Upgrade user subscription and potentially Safe wallet */ upgradeUser(userAddress: string, newPlanId: string, newBillingPeriod: BillingPeriod): Promise<{ success: boolean; subscription?: any; error?: string; }>; /** * Get user's Safe wallet information */ getUserSafeWallet(userAddress: string): Promise<SafeWalletInfo | null>; /** * Check if user can access a specific feature */ checkFeatureAccess(userAddress: string, adaoBalance: number, subscription: SubscriptionStatus, safeWallet: SafeWalletInfo | null): Promise<{ [feature: string]: { accessible: boolean; reason?: string; }; }>; /** * Get available plans for user based on their ADAO balance */ getAvailablePlansForUser(userAddress: string): Promise<Plan[]>; /** * Get user's ADAO balance */ getADaoBalance(userAddress: string): Promise<number>; /** * Determine overall access based on subscription, balance, and Safe wallet */ private determineAccess; /** * Calculate grace period days */ private calculateGracePeriod; /** * Set signer for transactions */ setSigner(signer: ethers.Signer): void; }