Documentation Index
Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
Use this file to discover all available pages before exploring further.
System architecture
The Bridge Hub is a microservices-based system that monitors, indexes, exposes, and automatically claims cross-chain bridge transactions. It consists of four packages that work together around a shared MongoDB database.| Package | Layer | Responsibility |
|---|---|---|
| Commons | Foundation | Shared TypeScript types, interfaces, and schemas used by all other packages |
| Consumer | Data ingestion | Polls AggKit Bridge Service APIs to index bridge transactions into MongoDB |
| API | Service | Exposes indexed transaction data and proxies claim proofs over a REST interface |
| Auto-Claim | Automation | Polls the API for claimable transactions and submits claim transactions on-chain |
Consumer internals
The Consumer package runs as a single Node.js process per network. It contains two components that together run four cron jobs.BridgeAPIConsumer
This component runs three cron jobs that fetch data from the AggKit Bridge Service:-
bridgesCron: Polls AggKit for new bridge deposit transactions. Each new deposit is inserted into the
transactionscollection with a status ofBRIDGED. The cron tracks its progress by updatinglastIndexedBridgeDepositCountin the metadata collection. -
claimsCron: Polls AggKit for claim events that have occurred on-chain. When a claim is detected, the corresponding transaction is updated to
CLAIMEDand theclaimTransactionHashand timestamp are recorded. Progress is tracked vialastIndexedClaimBlockNumber. -
mappingsCron: Polls AggKit for token mapping events. New or updated mappings are upserted into the
mappingscollection. Progress is tracked vialastIndexedMappingBlockNumber.
ClaimReadinessConsumer
This component runs a single cron job:- readyToClaimCron: Checks the L1 info tree data from AggKit and compares it against transactions that are currently in
BRIDGEDstatus. When a transaction becomes claimable, the cron updates it toREADY_TO_CLAIMand sets theleafIndexForProoffield needed for merkle proof generation.
Consumer data flow
Multi-network deployment
In production, the Bridge Hub runs one consumer instance per source network being indexed. Each network connected to the AggLayer has a unique network ID (for example, 0 for Ethereum, 1 for Polygon zkEVM). A single shared API service reads from the database and serves all networks, while one auto-claim instance runs per destination network.The consumer does not directly monitor the blockchain. It polls the AggKit Bridge Service APIs to fetch already-indexed data. Each chain’s AggKit Bridge Service is maintained by the chain operators and is external to the Bridge Hub deployment.
- Consumer instances: One per source network being indexed (
netId_0,netId_1, and so on). - Shared database: All consumers write to the same MongoDB instance.
- Single API: One API service reads from the database and serves all networks.
- Auto-Claim deployment: One instance per destination network you want to auto-claim for.
Database design
Bridge Hub uses a single shared MongoDB instance. Collections are organized by environment using the naming conventionbridge_hub_api_[type]_[environment], where the environment suffix is omitted for mainnet, _testnet for testnet, and _devnet for development.
Collections
The database contains three collection types:-
transactions: Stores all bridge transactions across all networks. Modified by
bridgesCron(upserts),claimsCron(status updates), andreadyToClaimCron(status updates). Transactions move through the statusesBRIDGED,LEAF_INCLUDED,READY_TO_CLAIM, andCLAIMED. -
mappings: Stores token address mappings between AggLayer networks. Modified by
mappingsCron. Each record maps an origin token address on one network to its wrapped token address on another. - metadata: Tracks indexing progress per network. Each cron job updates its own checkpoint field in this collection. One document exists per network ID being indexed.
Transaction document schema
Indexes
Metadata and resume capability
The metadata collection is critical for operational resilience. When a consumer instance restarts after a crash, planned maintenance, or redeployment, it reads its metadata document to find the last indexed position for each cron job. Without this checkpoint data, the consumer would need to re-index from the beginning, duplicating hours or days of work. Each metadata document tracks three resume points:lastIndexedBridgeDepositCount: wherebridgesCronshould resumelastIndexedClaimBlockNumber: whereclaimsCronshould resumelastIndexedMappingBlockNumber: wheremappingsCronshould resume
Data synchronization
The system maintains eventual consistency through three distinct data paths:- Write path (Consumer to MongoDB): Consumers poll AggKit APIs and write new or updated records into MongoDB. All writes use upsert operations, making them idempotent. Duplicate events from AggKit are handled gracefully.
- Read path (API from MongoDB): The API service reads directly from MongoDB and serves the data over REST endpoints. Because the API is stateless and read-only, it can be scaled horizontally behind a load balancer.
- Claim path (Auto-Claim to Blockchain): The Auto-Claim service polls the API for transactions in
READY_TO_CLAIMstatus, fetches merkle proofs through the API’s/claim-proofendpoint, and submits claim transactions on-chain. Claims are processed sequentially to avoid nonce conflicts.
Consistency guarantees
- Transactions are immutable once created; only status fields are updated.
- Status updates are atomic at the document level.
- Duplicate events are handled via upsert, so re-processing the same data is safe.
- No distributed transactions are needed because all state lives in a single MongoDB instance.
- There is a small window of delay between an on-chain event occurring and the consumer indexing it. During this window, the API may serve slightly stale data. This is acceptable for the bridge use case, where transactions take time to become claimable regardless.