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.
Implement per-pair route counters and cumulative volume
Description
The router keeps only a single global
DataKey::TotalRoutesAllTimecounter insrc/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 everyrouteevent off-chain. This issue adds on-chain per-pair route counts and cumulative routed volume.Requirements and context
DataKey::PairRouteCount(Symbol, Symbol)(u64) andDataKey::PairVolume(Symbol, Symbol)(i128); increment both insidecompute_route_feeusingsaturating_add.get_pair_route_countandget_pair_volume(both default 0 when absent).PairInfois out of scope — keep these as standalone getters so the existing struct shape stays stable.Suggested execution
git checkout -b feature/contracts-32-per-pair-metricssrc/lib.rs— the two newDataKeyvariants, the increments incompute_route_fee, and the getters.src/lib.rs#[cfg(test)] mod test— assert count and volume increment per route, stay isolated per pair, and default to 0.README.md.///) on the new entrypoints.Test and commit
cargo fmt --all -- --check,cargo build, andcargo test.cargo testoutput 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 trackingGuidelines
Community & contribution rewards