Skip to content

Add multi-pool view contract for batched off-chain queries #35

Description

@prodbycorne

Overview

Querying user state across multiple farming pools requires one RPC call per pool. For a user staking in 5 pools, that is 5 sequential simulation calls. A read-only view contract that aggregates data across pools reduces this to a single call.

Design

MultiPoolViewer (deployed once, no admin, pure view functions)
  ├── user_summary(factory, user) -> Vec<UserPoolSummary>
  ├── pool_overview(factory, start_id, limit) -> Vec<PoolOverview>
  └── global_stats(factory) -> GlobalStats

UserPoolSummary

#[contracttype]
pub struct UserPoolSummary {
    pub pool_id: u32,
    pub pool_address: Address,
    pub staked_amount: i128,
    pub locked_amount: i128,
    pub total_credits: i128,
    pub has_boost: bool,
    pub boost_allocation_pct: u32,
    pub is_pool_paused: bool,
}

user_summary Implementation

pub fn user_summary(env: Env, factory: Address, user: Address) -> Vec<UserPoolSummary> {
    let factory_client = FactoryClient::new(&env, &factory);
    let count = factory_client.pool_count();
    let mut summaries = Vec::new(&env);

    for id in 0..count.min(50) {  // cap at 50 pools per call
        let record = factory_client.get_pool(&id);
        let pool = FarmingPoolClient::new(&env, &record.address);

        let stake = pool.get_stake(&user);
        let position = pool.get_user_position(&user);
        let credits = pool.get_credits(&user) + pool.calculate_credits(&user);
        let boost = pool.get_boost_config(&user);

        summaries.push_back(UserPoolSummary { ... });
    }
    summaries
}

Acceptance Criteria

  • contracts/multi-pool-viewer/ created with no Admin storage
  • user_summary returns correct aggregated data for each pool
  • pool_overview returns basic info for paginated pool list
  • Capped at 50 pools per call to stay within instruction budget
  • No state modifications (pure view — no bump_instance, no events)
  • Tests with 3 mock pools verify aggregation
  • Gas estimation documented in README

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignfeatureNew feature or capability

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions