Skip to content

roswelly/bnb-flap-token-indexer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flap Token Indexer

An example indexer for Flap Protocol that indexes token information and provides a REST API for querying tokens and getting quotes.

Feature

  • 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

Setup

  1. Install dependencies:
npm install
  1. Create a .env file based on .env.example:
cp .env.example .env
  1. Update the .env file with your configuration:

    • PORTAL_CONTRACT_ADDRESS: The address of the Flap Portal Contract
    • RPC_URL: RPC endpoint for the blockchain
    • DEFAULT_START_BLOCK: Block number to start indexing from
    • Other configuration options as needed
  2. Build the project:

npm run build
  1. Start the indexer:
npm start

For development, you can run directly with ts-node:

npm run dev

API Endpoints

Get Token Information

GET /token/:address&try_remediation=<true|false> 

And optionally with query parameter:

  • try_remediation (optional): Boolean flag. If true, 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 Buy/Sell Quote

GET /quote?token=<address>&side=<buy|sell>&input_amount=<amount>&try_remediation=<true|false>

Parameters:

  • token: Token address
  • side: Either "buy" or "sell"
  • input_amount: Amount to buy with (for buy) or amount to sell (for sell)
  • try_remediation (optional): Boolean flag. If true, 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.

Health Check

GET /health

Returns server status and timestamp.

Configuration

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 URL
  • DEFAULT_START_BLOCK: Starting block number for indexing
  • INDEX_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")

Database Schema

The indexer uses SQLite with two main tables:

tokens

Stores token information including bonding curve parameters, supply, and status.

meta

Stores indexer metadata, primarily the last processed block number.

License

About

A typeScript indexer for Flap launchpad (BNB) that indexes token creation events, bonding curve parameters, and DEX listings. Provides a REST API for querying token information and calculating buy/sell quotes with support for data remediation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors