eliza icon indicating copy to clipboard operation
eliza copied to clipboard

Refactor: Separate Data Providers into Plugins

Open daizhengxue opened this issue 1 month ago • 1 comments

Description:

Currently, the wallet provider contains multiple hardcoded data sources (BirdEye, Codex) which makes the code: Hard to maintain Difficult to test It is not flexible for users who want to use different data sources

Proposed Solution:

Create a plugin system for data providers:

// Example structure:
interface TokenDataProvider {
    getTokenPrices(tokens: string[]): Promise<Prices>;
    getWalletTokens(wallet: string): Promise<WalletData>;
}

class BirdEyeProvider implements TokenDataProvider {
    // BirdEye specific implementation
}

class CodexProvider implements TokenDataProvider {
    // Codex specific implementation
}

Benefits: Easy to add new data providers Users can choose their preferred data source 3. Better testing isolation Cleaner code organization

export class WalletProvider {
    constructor(
        private connection: Connection,
        private walletPublicKey: PublicKey,
        private dataProvider: TokenDataProvider // 👈 Inject provider
    ) {
        this.cache = new NodeCache({ stdTTL: 300 });
    }

    async fetchPortfolioValue(runtime): Promise<WalletPortfolio> {
        // Use injected provider instead of hardcoded API calls
        const data = await this.dataProvider.getWalletTokens(
            this.walletPublicKey.toBase58()
        );
        // ... rest of the logic
    }
}

daizhengxue avatar Jan 10 '25 18:01 daizhengxue