Skip to content

feat: tiered pricing engine with validation, bill breakdown, and comprehensive tests#62

Open
Th3Slack3r wants to merge 1 commit into
Nexussyn:mainfrom
Th3Slack3r:agent/hermes/issue-1
Open

feat: tiered pricing engine with validation, bill breakdown, and comprehensive tests#62
Th3Slack3r wants to merge 1 commit into
Nexussyn:mainfrom
Th3Slack3r:agent/hermes/issue-1

Conversation

@Th3Slack3r

Copy link
Copy Markdown

Summary

Implements the Tiered Pricing Engine for issue #1 — a 4-tier pricing system for x402 API calls designed to increase revenue by ~30%.

Changes

src/pricing/tier-engine.ts — Core pricing logic:

  • getTierPrice(callCount, priorityFlag) — returns price per call based on tier
  • calculateBatchCost(startCount, numCalls, priority) — batch cost calculation with tier boundary crossing
  • calculateBill(startCount, numCalls, priority) — full bill with per-tier breakdown
  • Input validation: all functions reject NaN, Infinity, negative, fractional, and unsafe integers
  • All 4 tiers: free ($0.00), standard ($0.01), premium ($0.03), priority ($0.10)

tests/pricing.test.ts — 29 unit tests covering:

  • ✓ All 4 tiers with price and callsInTier verification
  • ✓ Boundary crossings: free→standard, standard→premium, free→standard→premium
  • ✓ Priority flag override on all tiers
  • calculateBill with per-tier breakdowns
  • ✓ Input validation: zero, negative, fractional, NaN, Infinity, unsafe integers
  • ✓ Empty batch (zero calls) returns $0

migrations/add_tiered_pricing.sql — Idempotent SQL migration (unchanged):

  • Adds tier, price_per_call, priority_flag columns to x402_calls
  • Creates pricing_tiers lookup table with upsert semantics

Acceptance Criteria

  • SQL migration adds tier column to relevant payment table
  • Logic function get_tier_price(call_count, priority_flag) returns correct price
  • Unit tests covering all 4 tiers
  • No existing tests broken (29/29 pass)
  • Migration is idempotent (uses IF NOT EXISTS / ON CONFLICT)

Validation

deno test tests/pricing.test.ts
ok | 29 passed | 0 failed (38ms)

Closes #1

Wallet: 0x09239d9722910bf0f6d685fb5f1af38ba660cb1d

…, and comprehensive tests

Implements Tiered Pricing Engine for issue Nexussyn#1:
- Migration: add_tiered_pricing.sql (already present, idempotent)
- Logic: getTierPrice, calculateBatchCost, calculateBill in tier-engine.ts
  with safe-integer validation on all inputs
- Tests: 29 unit tests covering all 4 tiers, boundary crossings,
  batch cost, bill breakdown, and input validation

Closes Nexussyn#1
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.

[AGENT-TASK] Implement tiered pricing engine — +30% revenue expected

1 participant