-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Type: Feature
Priority: P1 (High)
Labels: feature, backend, billing, blockchain
Epic: #XXX (Epic: Complete Remaining Features)
Estimated Effort: 3-4 weeks
Description
Implement AdaptivePricingService for adaptive cost calculation per service and BridgeCreditVerificationService for cross-chain credit verification via bridge.
Current State:
- ✅ RollingCreditsService fully implemented
- ✅ CreditBalance and CreditTransaction models with credit types exist
- ✅ CreditToken.sol contract exists
- ❌ AdaptivePricingService missing (mentioned in rules but service doesn't exist)
- ❌ BridgeCreditVerificationService missing
Target State:
- Adaptive cost calculation per service
- Server-set fees for server transactions
- Adaptive fees for client-side calls
- Bridge-based credit verification
- Credit conversion via bridge
Related Plan
dev/ROLLING_CREDITS_SUBSCRIPTION_PLAN.md - Complete implementation plan (Projects 3 & 4)
Sub-Tasks
Backend Services
-
Create AdaptivePricingService (
app/services/adaptive_pricing_service.py)-
calculate_adaptive_cost()- Calculate adaptive cost for workflow -
_get_pricing_factors()- Get pricing factors (complexity, volume, tier, time of day, organization) -
get_server_fee()- Get server-set fee for server transaction/call -
get_client_call_fee()- Get adaptive fee for client-side call - Base costs per workflow type
- Server fees configuration
- Pricing factor calculations
-
-
Create BridgeCreditVerificationService (
app/services/bridge_credit_verification_service.py)-
verify_credit_usage()- Verify credit usage on organization blockchain via bridge -
convert_credits_via_bridge()- Convert credits from one type to another via bridge -
_update_credits_via_bridge()- Update credits on organization blockchain via bridge -
_get_blockchain_credit_balance()- Get credit balance from blockchain -
_sync_balance_from_blockchain()- Sync credit balance from blockchain to database
-
Integration
-
Integrate AdaptivePricingService with RollingCreditsService
- Use adaptive pricing when spending credits
- Record base_cost and adaptive_cost in CreditTransaction
- Record pricing_factors in CreditTransaction
-
Integrate BridgeCreditVerificationService with RollingCreditsService
- Verify credit usage after spending
- Sync balances if mismatch detected
- Support credit conversion
API Endpoints
-
Create Adaptive Pricing API (
app/api/pricing_routes.py)-
GET /api/pricing/calculate- Calculate adaptive cost for workflow -
GET /api/pricing/server-fee- Get server fee for service -
GET /api/pricing/client-fee- Get client call fee
-
-
Create Bridge Verification API (
app/api/bridge_verification_routes.py)-
POST /api/bridge-verification/verify- Verify credit usage -
POST /api/bridge-verification/convert- Convert credits via bridge -
POST /api/bridge-verification/sync- Sync balance from blockchain
-
Acceptance Criteria
- ✅ Adaptive cost calculation works for all workflow types
- ✅ Pricing factors (complexity, volume, tier, time, organization) applied correctly
- ✅ Server fees set and retrieved correctly
- ✅ Client call fees calculated adaptively
- ✅ Credit usage verified on organization blockchain via bridge
- ✅ Credit conversion via bridge works
- ✅ Balance synchronization from blockchain works
- ✅ Integration with RollingCreditsService complete
Dependencies
- RollingCreditsService (✅ Already implemented)
- CreditBalance/CreditTransaction models (✅ Already implemented)
- CreditToken.sol contract (✅ Already implemented)
- CrossChainService (
⚠️ May need to be created - see Organization plan) - BlockchainRouterService (
⚠️ May need to be created - see Organization plan)
Testing
- Test adaptive cost calculation
- Test pricing factors
- Test server fee setting
- Test client call fee calculation
- Test credit usage verification
- Test credit conversion
- Test balance synchronization
Created: 2026-01-26
Status: Open
Metadata
Metadata
Assignees
Labels
Type
Projects
Status