Skip to content

feat: Gas Optimization & Fee Analysis#93

Open
pugsley76 wants to merge 1 commit into
Lumina-eX:mainfrom
pugsley76:feat/gas-optimization-fee-analysis
Open

feat: Gas Optimization & Fee Analysis#93
pugsley76 wants to merge 1 commit into
Lumina-eX:mainfrom
pugsley76:feat/gas-optimization-fee-analysis

Conversation

@pugsley76
Copy link
Copy Markdown

closes #84

Summary

Implements gas cost measurement, storage optimization, and transaction fee analysis for Soroban escrow contracts on the Stellar network.

Changes

Database

  • Migration 003: adds transaction_fees, fee_estimates, and fee_analytics_snapshots tables with indexes for fast analytics queries

Core Engine

  • lib/soroban/feeEstimator.ts — pre-submission simulation via Soroban RPC, resource footprint analysis (CPU, memory, ledger I/O, tx size), optimization hint generation, and actual fee extraction from confirmed transactions
  • lib/gas/analyzer.ts — per-operation cost breakdown, storage usage analysis, efficiency scoring (0–100), daily trend aggregation, and prioritized recommendations

API Routes

  • POST /api/contracts/fee-estimate — returns min/recommended/max fee estimate before deployment
  • GET /api/gas/analytics — full efficiency report (admin) or user fee summary

Worker

  • scripts/worker.ts — captures fee_charged from every Horizon payment event and persists it for analytics

Deployment

  • lib/soroban/deploy.ts — upgraded from stub to fee-optimized real deployment; stub path preserved when SOROBAN_RPC_URL is unset

UI

  • components/dashboard/fee-analysis.tsx — efficiency score gauge, cost breakdown table, daily trend chart, storage usage chart, and recommendation cards
  • FeeEstimatePreview inline widget for the contract creation form

Acceptance Criteria

  • Measure contract execution cost across functions
  • Optimize storage usage to lower gas consumption
  • Reduce transaction footprint for efficiency

- Add transaction_fees, fee_estimates, fee_analytics_snapshots tables (migration 003)
- Implement Soroban fee estimator with pre-submission simulation, resource
  footprint analysis, and optimization hint generation (feeEstimator.ts)
- Add gas analytics engine with per-operation cost breakdown, storage usage
  analysis, efficiency scoring, and recommendations (lib/gas/analyzer.ts)
- Upgrade deploy.ts from stub to fee-optimized real Soroban deployment;
  stub path preserved when SOROBAN_RPC_URL is unset
- Add POST /api/contracts/fee-estimate for pre-deployment cost preview
- Add GET /api/gas/analytics for platform-wide fee efficiency report
- Capture actual fees in worker for every escrow deposit/release/refund
- Add FeeAnalysis dashboard component and FeeEstimatePreview inline widget
- Document new env vars in env.example

Closes: Gas Optimization and Fee Analysis issue
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@pugsley76 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

@SudiptaPaul-31
Copy link
Copy Markdown
Collaborator

@pugsley76 resolve the merge conflicts properly

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.

[Feature]: Gas Optimization & Fee Analysis

2 participants