Feature and its Use Cases
Problem
Critical event parameters are not indexed, making off-chain filtering inefficient for frontends, indexers, and analytics tools.
Current (inefficient):
// Factory.sol
event TNTCreated(address indexed owner, address tntAddress); // ❌ tntAddress not indexed
// TNT.sol
event TokenIssued(address indexed issuer, address indexed user, uint256 tokenId); // ❌ tokenId not indexed
event TokenRevoked(address indexed revoker, uint256 tokenId); // ❌ tokenId not indexed
Without indexing, clients must fetch ALL events and filter client-side:
// ❌ Inefficient: Download all events, filter locally
const all = await factory.queryFilter(factory.filters.TNTCreated());
const filtered = all.filter(e => e.args.tntAddress === myAddress);
Solution
Add indexed to 3 parameters across 2 files:
// Factory.sol (Line ~15)
event TNTCreated(address indexed owner, address indexed tntAddress); // ✅
// TNT.sol (Lines ~38-39)
event TokenIssued(address indexed issuer, address indexed user, uint256 indexed tokenId); // ✅
event TokenRevoked(address indexed revoker, uint256 indexed tokenId); // ✅
After (efficient):
// ✅ Filter at RPC/node level
const filtered = await factory.queryFilter(
factory.filters.TNTCreated(null, specificTNTAddress)
);
Benefits
- Efficient Filtering - Query specific TNT addresses/token IDs at node level
- Improved Indexing - The Graph and similar tools can create DB indexes
- Reduced RPC Load - No need to download all events for client-side filtering
- Better Analytics - Track specific contracts/tokens without full scans
Gas Cost: +375 gas per indexed parameter (~1,125 gas total increase per TNT creation)
Testing
Create test/EventIndexing.test.js:
- Verify
TNTCreated has 3 topics (signature + 2 indexed params)
- Verify
TokenIssued has 4 topics (signature + 3 indexed params)
- Verify
TokenRevoked has 3 topics (signature + 2 indexed params)
- Test filtering by indexed parameters
- Measure gas cost increase
Technical Details
Files to modify:
contracts/src/Factory.sol - TNTCreated event
contracts/src/TNT.sol - TokenIssued, TokenRevoked events
Additional Context
No response
Code of Conduct
Feature and its Use Cases
Problem
Critical event parameters are not indexed, making off-chain filtering inefficient for frontends, indexers, and analytics tools.
Current (inefficient):
Without indexing, clients must fetch ALL events and filter client-side:
Solution
Add
indexedto 3 parameters across 2 files:After (efficient):
Benefits
Gas Cost: +375 gas per indexed parameter (~1,125 gas total increase per TNT creation)
Testing
Create
test/EventIndexing.test.js:TNTCreatedhas 3 topics (signature + 2 indexed params)TokenIssuedhas 4 topics (signature + 3 indexed params)TokenRevokedhas 3 topics (signature + 2 indexed params)Technical Details
Files to modify:
contracts/src/Factory.sol- TNTCreated eventcontracts/src/TNT.sol- TokenIssued, TokenRevoked eventsAdditional Context
No response
Code of Conduct