completed gas inefficiency detector example#213
Open
buggythanos wants to merge 1 commit intobnb-chain:mainfrom
Open
completed gas inefficiency detector example#213buggythanos wants to merge 1 commit intobnb-chain:mainfrom
buggythanos wants to merge 1 commit intobnb-chain:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
Adds a Gas Inefficiency Detector for BNB Smart Chain (BSC) that analyzes smart contract transactions to find gas optimization opportunities. It inspects transaction patterns, gas usage, and common inefficiency signals and returns structured findings and recommendations.
The tool fetches transaction receipts and details via BSC RPC, runs several heuristics, and produces an efficiency score (0–100), severity‑classified inefficiencies, and estimated gas savings where possible. It supports both single‑tx and batch analysis.
Features:
analyzeMultipleTransactionswith aggregate stats (total/average gas, average score, most common issues).POST /api/analyze(single tx),POST /api/analyze-multiple(batch).Tech stack: TypeScript, ethers.js v6, Express, Jest.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
The project includes a Jest test suite that targets:
getBSCProviderBSC_RPC_URLis unset.BSC_RPC_URLwhen set.analyzeTransactiontxHash,blockNumber,from,to,gasUsed,inefficiencies, andefficiencyScorein [0, 100].analyzeMultipleTransactionsanalysesplusaggregate(e.g.totalGasUsed,averageGasUsed,averageEfficiencyScore,mostCommonIssues).Efficiency score (via
analyzeTransaction)Tests use a custom
__mocks__/ethers.tsthat replacesJsonRpcProviderwith a shared mock provider; all RPC calls are mocked.How to run:
npm testManual checks:
npm start serverornpm run dev server, then openhttp://localhost:3000.POST /api/analyzewith{ "txHash": "0x..." }andPOST /api/analyze-multiplewith{ "txHashes": ["0x...", "0x..."] }.Note: The suite currently fails with TypeScript errors (see terminal output): mutating read‑only properties on
mockReceipt/mockTransaction(e.g.gasUsed,contractAddress,logs,status,maxFeePerGas) and mock objects not matchingTransactionReceipt(e.g.#private). Fixing these (e.g. by creating new mock objects per test instead of mutating, and usingas anyor minimal mock types) is required fornpm testto pass. The PR description above assumes that work is done before submission.Checklist: