A lightweight API that indexes Mars Protocol tokenomics data hourly and serves it through low-latency endpoints. Built for deployment on Vercel with automatic hourly data updates via cron jobs.
- Hourly Data Updates: Automatically fetches and updates tokenomics data every hour
- Multiple Data Sources: Integrates with Mars Protocol status endpoints, Neutron blockchain, CoinGecko, and Astroport
- Robust Error Handling: Implements fallback mechanisms and data validation
- Low Latency: Serves pre-processed data with appropriate caching headers
- Comprehensive Testing: Full test coverage with validation logic
- TypeScript: Fully typed for better development experience
The API collects data from the following sources:
- Burned Supply: Neutron blockchain wallet balance of burn address (normalized)
- Treasury Supply: Neutron blockchain wallet balance of treasury address (normalized)
- Price: CoinGecko API for MARS token price
- On-Chain Liquidity: Astroport pools containing MARS tokens
Note: Total and circulating supply data are available through other Mars Protocol services and are not included in this API to maintain reliability.
Base URL: https://tokenomics.marsprotocol.io
Returns Mars Protocol tokenomics data.
Query Parameters:
days
(optional): Number of days of data to return30
(default): Last 30 days90
: Last 90 days180
: Last 180 daysall
: All available data
Example:
curl "https://tokenomics.marsprotocol.io/api/tokenomics?days=30"
Response Format:
{
"data": {
"burned_supply": [
{
"date": "2025-09-12",
"amount": "50000000",
"value_usd": 7500000.0
}
],
"treasury_supply": [
{
"date": "2025-09-12",
"amount": "150000000",
"value_usd": 22500000.0
}
],
"price_usd": [
{
"date": "2025-09-12",
"value_usd": 0.15
}
],
"on_chain_liquidity_usd": [
{
"date": "2025-09-12",
"value_usd": 100000.0
}
]
},
"meta": {
"token": {
"symbol": "MARS",
"denom": "factory/neutron1ndu2wvkrxtane8se2tr48gv7nsm46y5gcqjhux/MARS",
"decimals": 6
},
"last_updated": "2025-09-12",
"total_records": 30,
"days_requested": 30
}
}
Internal endpoint for daily data indexing (triggered by Vercel cron).
-
Clone the repository
git clone <repository-url> cd mars-tokenomics-api
-
Install dependencies
npm install
-
Set up environment variables
cp env.example .env.local
Add your Vercel Blob storage token:
BLOB_READ_WRITE_TOKEN=your_vercel_blob_token
-
Run development server
npm run dev
-
Run tests
npm test
-
Connect to Vercel
vercel
-
Set environment variables in Vercel dashboard
BLOB_READ_WRITE_TOKEN
: Your Vercel Blob storage token
-
Deploy
vercel --prod
The cron job will automatically start running hourly once deployed.
The API is configured for the MARS token on Neutron:
{
symbol: 'MARS',
denom: 'factory/neutron1ndu2wvkrxtane8se2tr48gv7nsm46y5gcqjhux/MARS',
decimals: 6
}
Data validation includes checks for:
- Price range: $0.0001 - $1000
- Supply range: 1M - 100B tokens
- Maximum daily change: 50%
- USD value calculation consistency
- Burn Address:
neutron1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhufaa6
- Treasury Address:
neutron1yv9veqnaxt3xwafnfdtr9r995m50ad6039lduux5huay6nhnef8sapq3zp
The API uses Vercel Blob storage for data persistence:
- Each day's data is stored as a separate JSON file
- Files are named with the pattern:
daily-data-YYYY-MM-DD.json
- Data is publicly accessible for fast retrieval
- Storage grows incrementally with each day's data
The API implements comprehensive error handling:
- Retry Logic: Failed API calls are retried up to 3 times with exponential backoff
- Data Validation: All fetched data is validated against reasonable thresholds
- Fallback Mechanism: If data fetching fails, the system uses the previous day's data
- Graceful Degradation: Partial failures are handled by mixing fresh and fallback data
Run the test suite:
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run with coverage
npm test -- --coverage
Tests cover:
- Data fetching from all external APIs
- Data validation logic
- Storage operations
- API endpoint responses
- Error handling scenarios
The API provides detailed logging for monitoring:
- Daily indexing results
- Data validation warnings and errors
- API response times
- Fallback usage
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions, please create an issue in the repository.