Skip to content

Add per-pair lifetime route counters and cumulative volume tracking #44

Description

@mikewheeleer

Implement per-pair route counters and cumulative volume

Description

The router keeps only a single global DataKey::TotalRoutesAllTime counter in src/lib.rs; there is no per-pair breakdown of how many routes a corridor has served or how much volume has flowed through it. Operators and dashboards cannot rank corridors, detect a hot pair, or reconcile per-corridor fee accrual without scraping every route event off-chain. This issue adds on-chain per-pair route counts and cumulative routed volume.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-contracts only.
  • Add DataKey::PairRouteCount(Symbol, Symbol) (u64) and DataKey::PairVolume(Symbol, Symbol) (i128); increment both inside compute_route_fee using saturating_add.
  • Add read entrypoints get_pair_route_count and get_pair_volume (both default 0 when absent).
  • Extend PairInfo is out of scope — keep these as standalone getters so the existing struct shape stays stable.
  • Do not change any existing error codes; bump TTL on the new slots when written.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b feature/contracts-32-per-pair-metrics
  • Implement changes
    • Write code in: src/lib.rs — the two new DataKey variants, the increments in compute_route_fee, and the getters.
    • Write comprehensive tests in: src/lib.rs #[cfg(test)] mod test — assert count and volume increment per route, stay isolated per pair, and default to 0.
    • Add documentation: document the per-pair metrics in README.md.
    • Include NatSpec-style doc comments (///) on the new entrypoints.
    • Validate security assumptions: saturating arithmetic cannot panic; counters are monotonic; pairs are independent.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases and failure paths: zero routes, multiple routes one pair, two pairs independent, volume near i128::MAX.
  • Include the full cargo test output and a short security notes section in the PR description (threat model + mitigations).

Example commit message

feat: add per-pair route counters and cumulative volume tracking

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions