Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Separate Data Providers into Plugins #2126

Open
daizhengxue opened this issue Jan 10, 2025 · 1 comment
Open

Refactor: Separate Data Providers into Plugins #2126

daizhengxue opened this issue Jan 10, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@daizhengxue
Copy link
Contributor

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 daizhengxue added the enhancement New feature or request label Jan 10, 2025
Copy link
Contributor

Hello @daizhengxue! Welcome to the ai16z community. Thank you for opening your first issue; we appreciate your contribution. You are now a ai16z contributor!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant