The Cost Estimator service predicts and tracks the monthly operating costs of the Tikka oracle based on expected raffle volume. It helps operators budget for oracle operations and alerts when actual costs significantly exceed estimates.
- Monthly Cost Estimation: Calculate expected costs based on raffle volume
- VRF vs PRNG Cost Differentiation: Factor in computational overhead
- Actual Cost Tracking: Record and analyze real operating costs
- Cost Alerts: Automatic alerts when costs exceed thresholds
- Cost Per Reveal Metric: Real-time monitoring metric for dashboards
- Base Fee: 100 stroops (Stellar minimum)
- Priority Fee: Dynamic based on network congestion (p95 percentile)
- Fee Caps:
- Low-stakes raffles (< 500 XLM): Capped at 1 XLM
- High-stakes raffles (≥ 500 XLM): Capped at 10 XLM
- PRNG: ~0 stroops (instant, no overhead)
- VRF: ~50,000 stroops (~0.005 XLM) for Ed25519 VRF computation
Total Cost = Gas Fee + Computational Cost
import { CostEstimatorService } from './submitter/cost-estimator.service';
// Estimate for 1000 reveals/month, 70% low-stakes
const estimate = await costEstimator.estimateMonthlyCost(1000, 70);
console.log(`Monthly cost: ${estimate.totalMonthlyCostXLM} XLM`);
console.log(`Avg per reveal: ${estimate.avgCostPerReveal / 10_000_000} XLM`);
console.log(`Low-stakes: ${estimate.breakdown.lowStakes.count} reveals`);
console.log(`High-stakes: ${estimate.breakdown.highStakes.count} reveals`);// Record each reveal cost
costEstimator.recordRevealCost(
raffleId,
'VRF', // or 'PRNG'
gasFeeStroops,
);
// Get actual metrics for a period
const metrics = costEstimator.getActualCosts(
startDate,
endDate,
);
console.log(`Total reveals: ${metrics.totalReveals}`);
console.log(`Total cost: ${metrics.totalCostXLM} XLM`);
console.log(`Avg per reveal: ${metrics.avgCostPerReveal / 10_000_000} XLM`);The oracle now exports real-time cost metrics in Prometheus format. These can be scraped by a Prometheus server and visualized in Grafana.
Metrics Endpoint: /metrics
Exported Metrics:
tikka_oracle_estimated_fee_stroops: Current estimated fee for the next submission.tikka_oracle_actual_fee_total_stroops: Cumulative actual fees paid for successful submissions.tikka_oracle_submission_outcome_total: Counter for submission outcomes (success,failure,retry).tikka_oracle_memory_usage_bytes: Current memory usage of the oracle process.
Labels:
network: The network passphrase (e.g.,testnet,public).method: The submission method (VRForPRNG).outcome: For outcome metrics (success,failure,retry).
Example Grafana Query:
# Average cost per VRF reveal over the last hour
rate(tikka_oracle_actual_fee_total_stroops{method="VRF"}[1h])
/
rate(tikka_oracle_submission_outcome_total{method="VRF", outcome="success"}[1h])
The CostEstimatorService automatically generates alerts for abnormal costs or failed submissions.
Alert Types:
COST_EXCEEDED: Actual average cost > 150% of estimate.HIGH_FEE_DETECTED: Single reveal fee > 0.5 XLM.BUDGET_WARNING: Projected monthly cost > 90% of budget.SUBMISSION_FAILED: A transaction submission failed after all retries.
Severity Levels:
LOW: Informational.MEDIUM: Requires attention (e.g., fee spike).HIGH: Critical issue (e.g., submission failure or extreme fee).
Alerts are currently logged to the console with appropriate severity levels and emojis. In production, these should be integrated with a monitoring system (e.g., Slack webhooks, PagerDuty).
// Example of a HIGH severity alert in logs
🚨 [SUBMISSION_FAILED] Submission failed for raffle 123: tx_insufficient_fee
CRITICAL COST ALERT: {"error":"tx_insufficient_fee"}Triggered when actual average cost per reveal exceeds estimate by >50%.
Severity: MEDIUM (>50% over) or HIGH (>200% over)
Example:
Actual costs exceed estimate by 175.3%
Estimated: 250 stroops, Actual: 688 stroops
Triggered when a single reveal costs more than 0.5 XLM (5M stroops).
Severity: MEDIUM
Example:
High gas fee detected: 0.75 XLM
Threshold: 0.5 XLM
Triggered when projected monthly cost will exceed budget by >90%.
Severity: MEDIUM (>90%) or HIGH (>120%)
Example:
Projected to use 135.2% of monthly budget
Estimated: 100 XLM, Projected: 135.2 XLM
Assumptions:
- 80% low-stakes (PRNG)
- 20% high-stakes (VRF)
- Average gas fee: 200 stroops (p95)
Calculation:
Low-stakes: 800 reveals × (200 + 0) = 160,000 stroops
High-stakes: 200 reveals × (300 + 50,000) = 10,060,000 stroops
Total: 10,220,000 stroops = 1.022 XLM/month
Assumptions:
- 70% low-stakes (PRNG)
- 30% high-stakes (VRF)
- Average gas fee: 250 stroops (p95)
Calculation:
Low-stakes: 3,500 reveals × (250 + 0) = 875,000 stroops
High-stakes: 1,500 reveals × (350 + 50,000) = 75,525,000 stroops
Total: 76,400,000 stroops = 7.64 XLM/month
Assumptions:
- 60% low-stakes (PRNG)
- 40% high-stakes (VRF)
- Average gas fee: 300 stroops (p95)
Calculation:
Low-stakes: 6,000 reveals × (300 + 0) = 1,800,000 stroops
High-stakes: 4,000 reveals × (400 + 50,000) = 201,600,000 stroops
Total: 203,400,000 stroops = 20.34 XLM/month
Environment variables:
# Maximum fee cap (default: 10 XLM)
ORACLE_MAX_FEE_STROOPS=100000000
# Low stakes threshold (default: 500 XLM)
LOW_STAKES_THRESHOLD_XLM=500
# Soroban RPC endpoint
SOROBAN_RPC_URL=https://soroban-testnet.stellar.org// Export cost per reveal metric
const costPerReveal = costEstimator.getCostPerRevealMetric();
prometheusRegistry.gauge('oracle_cost_per_reveal_stroops', costPerReveal);
// Export total monthly cost
const metrics = costEstimator.getActualCosts(monthStart, monthEnd);
prometheusRegistry.gauge('oracle_monthly_cost_xlm', metrics.totalCostXLM);Recommended panels:
- Cost Per Reveal (gauge) - Current average cost
- Monthly Cost Trend (line chart) - Cost over time
- Method Distribution (pie chart) - PRNG vs VRF usage
- Cost Alerts (table) - Recent alerts
- Budget Usage (gauge) - Percentage of estimated budget used
// Send high-severity alerts to Slack
const alerts = await costEstimator.checkCostThresholds(estimate, metrics);
for (const alert of alerts) {
if (alert.severity === 'HIGH') {
await slackClient.postMessage({
channel: '#oracle-alerts',
text: `🚨 ${alert.type}: ${alert.message}`,
attachments: [{
color: 'danger',
fields: [
{ title: 'Estimated', value: `${alert.details.estimated} stroops`, short: true },
{ title: 'Actual', value: `${alert.details.actual} stroops`, short: true },
],
}],
});
}
}Run cost estimator tests:
pnpm test cost-estimator.service.spec.tsRun example:
npx ts-node src/submitter/cost-estimator.example.tsAlways run cost estimates before deploying to production to understand budget requirements.
Set up dashboards to track actual costs vs estimates in real-time.
Configure alerts at appropriate levels (e.g., 120% of estimate) to catch cost overruns early.
Conduct monthly reviews to adjust estimates based on actual usage patterns.
During high network activity, costs can spike. Budget for 2-3x normal costs as a buffer.
Ensure the VRF/PRNG threshold (500 XLM) is appropriate for your use case to minimize VRF overhead.
If most raffles are high-value, consider raising the VRF threshold to reduce VRF computational costs.
If possible, batch multiple reveals in a single transaction to amortize gas costs.
Process reveals during off-peak hours when network fees are lower.
Adjust fee caps based on actual network conditions to avoid overpaying.
For low-stakes raffles, ensure PRNG is used to avoid unnecessary VRF costs.
Symptom: Actual costs significantly exceed estimates
Possible Causes:
- Network congestion causing high gas fees
- More high-stakes raffles than expected (more VRF usage)
- Fee caps set too high
Solutions:
- Review fee cap configuration
- Analyze raffle distribution (low vs high stakes)
- Check network fee trends
- Consider adjusting VRF threshold
Symptom: No alerts despite high costs
Possible Causes:
- Alert thresholds set too high
- Cost tracking not recording properly
- Estimate too high (masking actual overruns)
Solutions:
- Lower alert threshold percentage
- Verify
recordRevealCost()is being called - Re-run estimates with realistic parameters
- Predictive Cost Modeling: ML model to predict costs based on time-of-day patterns
- Multi-Currency Support: Track costs in USD/EUR for budgeting
- Cost Attribution: Break down costs by raffle creator or category
- Automated Budget Adjustments: Dynamically adjust fee caps based on budget constraints
- Historical Cost Analysis: Long-term trend analysis and forecasting