feat(pricing): add CoinPaprika pricing implementation#413
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds a CoinPaprika pricing provider with HTTP price fetching, caching, rate limiting, USD-only conversion rules, config validation, registry wiring, and tests. The solver-pricing library now exports and registers the provider. ChangesCoinPaprika Pricing Provider
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant CoinPaprikaPricing
participant Cache
participant CoinPaprikaAPI
Caller->>CoinPaprikaPricing: get_pair_price(base, quote)
CoinPaprikaPricing->>Cache: get_cached_price_if_fresh(key)
alt cache hit
Cache-->>CoinPaprikaPricing: cached price
else cache miss
CoinPaprikaPricing->>CoinPaprikaPricing: apply_rate_limit()
CoinPaprikaPricing->>CoinPaprikaAPI: fetch ticker (with timeout)
CoinPaprikaAPI-->>CoinPaprikaPricing: price or error
CoinPaprikaPricing->>Cache: write success/failure result
end
CoinPaprikaPricing-->>Caller: price or PriceNotAvailable
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
nahimterrazas
left a comment
There was a problem hiding this comment.
Thanks for your contributions @donbagger!
Approving it.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@donbagger, Commits must have verified signatures to merge the PR. Please rebase your commits so we can merge it. Thanks! |
Add a CoinPaprika-backed PricingInterface implementation alongside the existing CoinGecko and DefiLlama sources. CoinPaprika's ticker API is free with no API key required, which makes it a practical primary or fallback feed for permissionless solvers. The implementation mirrors the CoinGecko source one-to-one: TTL price cache plus short negative cache, in-flight fetch deduplication, schedule-based rate limiting with a bounded sleep cap, request timeouts, custom price overrides, and a token id map override. USD-only parity with the existing sources is kept. An optional api_key switches the base URL to the api-pro tier. Registered as "coinpaprika" in get_all_implementations, with a 30-test offline suite (wiremock) matching the conventions of the existing implementations.
fa46864 to
ea26106
Compare
|
Done! Rebased onto latest main as a single signed commit (ea26106, signature shows verified). The tree is byte-identical to the previously green CI state, so it should go clean. Thanks for the review! |
Summary
Adds a CoinPaprika-backed
PricingInterfaceimplementation alongside the existing CoinGecko and DefiLlama sources, registered as"coinpaprika".Why CoinPaprika: the ticker API is free with no API key and no sign-up, which makes it a practical primary or fallback feed for permissionless solver operators - one more independent source to chain in
PricingServicefallbacks. An optionalapi_keyswitches to the api-pro tier (higher limits) automatically.Design notes:
coingecko.rsone-to-one so the shape is familiar: TTL price cache + short negative cache, in-flight fetch deduplication, schedule-based rate limiter with a bounded sleep cap, request timeout,custom_prices, and atoken_id_mapoverride.{symbol}-{name}shaped, so the source carries its ownCOINPAPRIKA_TOKEN_MAPPINGS(ETH ->eth-ethereum, USDC ->usdc-usd-coin, including a real WETH id) instead of reusing the CoinGecko-shapedDEFAULT_TOKEN_MAPPINGS.PriceNotAvailable, same as CoinGecko).GET /v1/tickers/{coin_id}?quotes=USD), which matches howget_pricealready fetches - one id per call.defillama.rsdoes the same). Happy to extract shared plumbing in a follow-up if you'd prefer.I work on developer relations for CoinPaprika, so flagging that interest openly. The implementation only touches the pricing crate and adds no default behavior change - nothing selects it unless configured.
Testing Process
cargo fmt --check,cargo clippy -p solver-pricing --all-targets -- -D warnings,cargo build -p solver-pricingall cleancargo test -p solver-pricing: 122 passed, 0 failed (30 new tests, all offline via wiremock local servers - same-asset conversion, unsupported pairs, custom base_url retrieval, non-USD rejection, unknown token, invalid amounts, cache TTL and negative cache, in-flight dedup, rate-limit sleep cap, timeout bounds, api-pro key routing)convert_asset("ETH","USD","1.0")-> 1642.13,wei_to_currency("1000000000000000000","USD")-> 1642.13,currency_to_wei("3000","USD")-> 1826895156733445020, and ETH/SOL correctly rejected as non-USDChecklist
Summary by CodeRabbit