An example indexer for Flap Protocol that indexes token information and provides a REST API for querying tokens and getting quotes.
- Indexes token creation events and updates from the Flap Portal Contract
- Tracks token bonding curve parameters, circulating supply, and DEX listing status
- Provides REST API endpoints for token information and buy/sell quotes
- Supports data remediation for tokens created before the indexer start block
- Uses SQLite database for persistent storage
- Install dependencies:
npm install- Create a
.envfile based on.env.example:
cp .env.example .env-
Update the
.envfile with your configuration:PORTAL_CONTRACT_ADDRESS: The address of the Flap Portal ContractRPC_URL: RPC endpoint for the blockchainDEFAULT_START_BLOCK: Block number to start indexing from- Other configuration options as needed
-
Build the project:
npm run build- Start the indexer:
npm startFor development, you can run directly with ts-node:
npm run devGET /token/:address&try_remediation=<true|false>
And optionally with query parameter:
try_remediation(optional): Boolean flag. Iftrue, the API will attempt to fetch token data from the blockchain if the token is not found in the database. Note: The call may revert if the token doesn't exist on-chain.
Returns comprehensive token information including:
- Basic token details (name, symbol, creator, etc.)
- Bonding curve parameters (r, h, k)
- Current circulating supply and price
- DEX listing status and progress
GET /quote?token=<address>&side=<buy|sell>&input_amount=<amount>&try_remediation=<true|false>
Parameters:
token: Token addressside: Either "buy" or "sell"input_amount: Amount to buy with (for buy) or amount to sell (for sell)try_remediation(optional): Boolean flag. Iftrue, the API will attempt to fetch token data from the blockchain if the token is not found in the database. Note: The call may revert if the token doesn't exist on-chain.
Returns the estimated output amount for the trade including the quote token address.
GET /health
Returns server status and timestamp.
The indexer is configured via environment variables in the .env file:
PORTAL_CONTRACT_ADDRESS: Portal contract address (required)CHAIN_NAME: Blockchain name (default: "morph")RPC_URL: RPC endpoint URLDEFAULT_START_BLOCK: Starting block number for indexingINDEX_BATCH_SIZE: Number of blocks to process per batch (default: 200)INDEX_INTERVAL: Milliseconds between batches (default: 200)BUY_FEE_RATE: Buy fee in basis points (default: 250 = 2.5%)SELL_FEE_RATE: Sell fee in basis points (default: 250 = 2.5%)PORT: API server port (default: 3000)DATABASE_FILE: SQLite database file (default: "tokens.db")
The indexer uses SQLite with two main tables:
Stores token information including bonding curve parameters, supply, and status.
Stores indexer metadata, primarily the last processed block number.