Skip to content

Implement subscription smart contract oracle integration for price feeds#462

Merged
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
Itodo-S:issue-370-oracle-integration
May 27, 2026
Merged

Implement subscription smart contract oracle integration for price feeds#462
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
Itodo-S:issue-370-oracle-integration

Conversation

@Itodo-S
Copy link
Copy Markdown
Contributor

@Itodo-S Itodo-S commented May 27, 2026

Description

Integrate on-chain price oracles for subscription pricing in stablecoins or volatile tokens, ensuring fair market-rate conversions at billing time.

Changes

Oracle Price Feed Integration

  • Added OracleContract storage key for registering the oracle contract address
  • Added TokenSymbol mapping to resolve token addresses to oracle symbols
  • Added set_oracle_contract, clear_oracle_contract, get_oracle_contract admin functions
  • Added set_token_symbol, remove_token_symbol, get_token_symbol for token-to-symbol mapping

Price Lookup at Billing Execution Time

  • Modified charge_subscription to consult oracle pricing via resolve_charge_price helper
  • Uses cached oracle reads (get_price_with_cache with 600s TTL) for gas efficiency
  • Gracefully falls back to stored plan price when oracle is unavailable

Slippage Protection

  • Added PriceBounds struct with min_price_bps and max_price_bps for per-plan bounds
  • Added set_price_bounds, clear_price_bounds, get_price_bounds admin functions
  • Charge price is capped within bounds to prevent price manipulation at billing boundary

Oracle Health Monitoring

  • Added OracleMonitorService backend service with periodic health checks
  • Tracks feed staleness, circuit breaker state, and consecutive faults
  • Generates alerts for stale prices, open circuits, and missing price data

Fiat Equivalent Display

  • Added fiatPrice, fiatCurrency, fiatPriceUpdatedAt, oraclePriceDeviationBps to Subscription type
  • Added OraclePriceService frontend service for enriching subscriptions with fiat prices
  • Added totalFiatMonthlySpend and fiatCurrency to SubscriptionStats

Files Changed

  • contracts/types/src/lib.rs - Added OracleContract, PriceBounds, TokenSymbol storage keys and PriceBounds struct
  • contracts/subscription/Cargo.toml - Added subtrackr-oracle dependency
  • contracts/subscription/src/lib.rs - Oracle integration in charge_subscription with slippage protection
  • backend/services/oracleMonitorService.ts - Oracle health monitoring service
  • backend/services/index.ts - Service export
  • src/services/oraclePriceService.ts - Frontend fiat price enrichment service
  • src/types/subscription.ts - Fiat price display fields

Closes #370

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@Itodo-S Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Smartdevs17 Smartdevs17 merged commit a4a7062 into Smartdevs17:main May 27, 2026
5 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement subscription smart contract oracle integration for price feeds

2 participants