API Authentication
The APY Calculator API currently operates as an open API without authentication requirements. This design choice prioritizes accessibility and ease of integration for developers while maintaining service reliability through other protective mechanismsCORS Policy
The API implements comprehensive Cross-Origin Resource Sharing (CORS) settings to maximize compatibility across different client environments:- While permissive, the API relies on input validation and rate limiting for protection
- No sensitive authentication data is exposed due to the open access model
- All requests are logged with unique identifiers for monitoring
Request Identification
While authentication is not required, each request receives a unique identifier for tracking and debugging purposes:Rate Limits and Usage Constraints
The API implements intelligent constraints designed to balance performance, reliability, and fair resource allocation across all usersInput Amount Validation
Diluted APY Calculations:- Constraint: Input amounts must be non-negative integers (≥ 0)
- Rationale: Negative amounts would produce meaningless yield calculations
- Validation: Performed at the endpoint level before processing
- Error Response: Returns
422
status withvalidation_error
type
Batch Processing Limits
Maximum Multicall Size: 30 calls per batch request Technical Reasoning:- Timeout Prevention: Larger batches risk exceeding response time limits
- Memory Management: Prevents excessive memory allocation per request
- Fair Resource Distribution: Ensures no single request monopolizes system resources
- Group related calculations (same protocol/chain) for better caching efficiency
- Split large datasets into multiple sequential batch requests
- Implement client side batching logic for datasets exceeding 30 items
Blockchain Support
The API provides comprehensive coverage across major EVM-compatible networks, with standardized naming conventions and aliases for developer convenience- Ethereum (
ethereum
) - Base (
base
) - Arbitrum (
arbitrum
) - BNB Chain (
bnb
,binance smart chain
,bsc
) - Avalanche (
avalanche
) - Gnosis (
gnosis
) - Polygon (
polygon
) - Optimism (
optimism
) - Mantle (
mantle
) - Linea (
linea
) - Scroll (
scroll
) - Taiko (
taiko
) - Blast (
blast
) - Sonic (
sonic
) - Berachain (
berachain
) - Unichain (
unichain
) - HyperEVM (
hyperevm
)
Timeout Configurations
The API implements environment-aware timeout settings optimized for different deployment contextsOperation Type | Production Timeout | Local Timeout |
---|---|---|
Liquidity States | 1s | 20s |
Dependent States | 1s | 20s |
- Production: Aggressive timeouts ensure responsive user experience
- Development: Extended timeouts accommodate debugging and testing
- Automatic Failover: Requests failing due to timeouts trigger retry mechanisms where applicable
Cache Configuration
The API employs multi-tiered caching for optimal performance and resource utilization- Cache Size: 10,000 entries maximum
- Cache TTL: 300 seconds (5 minutes)
- APY Cache: 3,600 seconds (1 hour)
System Resource Limits
The API implements dynamic resource monitoring with automatic request rejection when system constraints are exceeded- CPU Usage: Above 95%
- Memory Usage: Above 95%
- Error Rate: Above 75% (when total requests > 10)
Error Handling
The API provides comprehensive error handling with structured responses designed for both human debugging and programmatic error recoveryError Format
All API errors follow a consistent, machine-readable JSON structure that provides multiple levels of diagnostic information:- success: Always
false
for error responses (enables quick programmatic checks) - error: Human readable message suitable for logging and debugging
- error_type: Standardized category for programmatic error handling
- step: Specific operation stage where failure occurred
- request_id: Unique identifier for support and debugging correlation
Error Types
Validation Errors
HTTP Status Code: 422 Unprocessable Entity Error Type:validation_error
These errors occur during input parameter validation before any processing begins. They indicate client-side issues that require request modification
- Invalid Ethereum addresses (must be 42 characters with 0x prefix)
- Unsupported blockchain networks
- Missing required parameters (
pool_address
orlp_token_address
) - Invalid input amounts (negative values)
- Input token same as LP token
Calculation Errors
HTTP Status Code: 404 Not Found Error Type:calculation_failed
These errors occur when the API successfully validates inputs but cannot complete the requested calculation due to missing data or computational issues
- Pool not found in database
- Incomplete pool states
- Missing protocol modules
- Network timeout during state calls
Internal Server Errors
HTTP Status Code: 500 Internal Server Error Error Type:internal_error
System level errors:
Service Unavailable
HTTP Status Code: 503 Service Unavailable Error Type:startup_error
or resource_exhaustion
Service initialization failures:
Database Errors
Database connectivity issues are handled gracefully:Network and Timeout Errors
Blockchain network calls may timeout:Error Step Mapping
Common Steps
input_validation
: Parameter validation failedpool_data_retrieval
: Cannot fetch pool data from databaseprotocol_id_validation
: Missing or invalid protocol identifiermodule_import_failed
: Cannot load required blockchain modulesinitialization_failed
: Pool initialization error
APY Calculation Steps
input_token_validation
: Invalid input token addresslp_token_validation
: Input token conflicts with LP tokenapy_calculation_error
: Mathematical calculation failedstates_incomplete
: Required blockchain states not available
TVL Calculation Steps
tvl_calculation_error
: TVL computation failedpool_creation_failed
: Cannot instantiate pool object
Health Monitoring
The API provides comprehensive health monitoring capabilities designed for both operational oversight and integration into larger monitoring ecosystemsHealth Check Endpoint
Endpoint:GET /health-check
Purpose: Comprehensive system validation suitable for load balancer health checks and monitoring systems
- Router initialization status
- Database connectivity
- Error rate analysis (must be < 75%)
- System resource usage (CPU and memory < 95%)
Metrics Monitoring
Endpoint:GET /metrics
Purpose: Detailed performance and operational metrics for observability and optimization
Response Format:
Best Practices
Error Handling in Client Applications
- Always check the
success
field before processing response data - Use
error_type
for programmatic error handling rather than parsing error messages - Include
request_id
in support requests for faster debugging - Implement retry logic for timeout and network errors
- Cache successful responses to reduce API load
Request Optimization
- Use caching: Identical requests within 5 minutes return cached results
- Validate addresses client-side: Ensure Ethereum addresses are properly formatted
- Handle both lookup methods: Support both
pool_address
andlp_token_address
parameters - Specify input tokens: Avoid auto-selection overhead when possible
Error Recovery
For transient errors (timeouts, network issues):- Use different endpoints if available (
pool_address
vslp_token_address
)
- Validate input data
- Check supported chains and protocols via
/active-protocols