Overview
This guide covers critical considerations and best practices for integrating the Fibrous Router API into your application. Following these guidelines will ensure a robust, secure, and user-friendly integration.Critical Considerations
0. Integrator Features - API Key Requirement ⚠️
1. Understanding min_received Calculation ⚠️🔴
What is min_received?min_received is the minimum amount of output tokens the user will receive after accounting for:
- Integrator fees (if applicable)
- Slippage tolerance
Without Integrator Fee (Normal Swap)
amount_out= Expected output amount from routeslippage_amount=amount_out × (slippage / 100)
With Integrator Fee
amount_out= Expected output amount from routefee_amount=amount_out × (integratorFeePercentageBps / 10000)slippage_amount=amount_out_after_fee × (slippage / 100)
-
User Protection:
min_receivedensures users get at least this amount, protecting against:- Price movements (slippage)
- Integrator fees
- Both combined
-
Transaction Reversion: If the actual output is less than
min_received, the transaction will revert, protecting the user. -
Display to Users: Always show users the
min_receivedamount so they know the minimum they’ll receive. -
Fee Transparency: Users should see:
- Expected output amount
- Fee amount (if applicable)
- Amount after fee
- Minimum received (with slippage)
2. Slippage Management
Setting Appropriate Slippage:| Token Pair Type | Recommended Slippage | Notes |
|---|---|---|
| Stable pairs (USDC/USDT) | 0.1% - 0.5% | Low volatility, high liquidity |
| Major pairs (ETH/USDC) | 0.5% - 1% | Moderate volatility |
| Volatile pairs | 1% - 3% | Higher price movement risk |
| Low liquidity tokens | 3% - 5% | May need higher slippage |
- Never set slippage to 0% - transactions will likely fail
- Higher slippage increases success rate but may result in worse prices
- Monitor price impact in route responses
- Consider showing slippage warning to users for values > 1%
3. Error Handling
Always implement comprehensive error handling:- Token Same Error: User selected same token for input and output
- Rate Limit: Too many requests - implement exponential backoff
- Invalid Route: Route expired or invalid - fetch new route
- Network Error: Connection issues - retry with backoff
- Validation Error: Invalid parameters - show user-friendly message
4. Rate Limiting
Default Limits:- 200 requests per minute (shared across all endpoints)
- Rate limits reset every minute
- Request an API key for increased rate limits
- Contact [email protected] for enterprise limits
5. Token Approvals
Approval Flow:- Native tokens (ETH, MON) don’t require approval
- Check allowance before every swap
- Consider approving max amount for better UX
- Show clear approval UI to users
6. Gas Estimation
Always add gas buffer:- Use estimated gas from API response as baseline
- Add 10-20% buffer for safety
- Monitor gas prices and adjust accordingly
- Consider using
maxFeePerGasandmaxPriorityFeePerGasfor EIP-1559
7. Network-Specific Considerations
EVM Networks (Base, HyperEVM, Scroll, Monad):- Use standard EVM transaction format
- Native tokens:
0x0000000000000000000000000000000000000000or0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE - Gas estimation required
- Token approvals needed for ERC-20 tokens
- Different address format (Cairo)
- Different transaction structure
- See Starknet API documentation
9. Integrator Features and API Key Requirements
Two Swap Modes:Normal Swap (No API Key)
If you don’t have an API key or don’t want to use integrator features:Integrator Swap (With API Key)
If you have an API key and want to monetize your integration:- API Key Required: Integrator features only work with a valid API key
- Function Selection:
- Normal swap → Use
swap()function - Integrator swap → Use
swapIntegrator()function
- Normal swap → Use
- Integrator Data: When using integrator features, the calldata includes
integrator_datawhich must be passed toswapIntegrator()
10. V1 vs V2 API
When to use V1:- Existing integrations that work well
- Simple use cases without integrator features
- When you need backward compatibility
- New integrations
- Need integrator features (fee/surplus)
- Want enhanced metadata tracking
- Prefer clearer endpoint names
See V2 Migration Guide for detailed comparison and migration steps.
- V1
/calldata→ V2/routeAndCallData(GET) - V1
/execute→ V2/calldata(POST)
11. Security Best Practices
Input Validation:- ✅ Always validate user inputs
- ✅ Sanitize addresses (lowercase, checksum)
- ✅ Verify route freshness
- ✅ Check minimum received amounts
- ✅ Never trust client-side calculations
- ✅ Use HTTPS only
- ✅ Implement request signing for sensitive operations
- ✅ Rate limit user requests on your side
12. User Experience Considerations
Loading States:- Show clear loading states
- Display route information (output amount, price impact)
- Warn about high slippage
- Show transaction status
- Provide clear error messages
- Estimate gas costs
13. Testing Recommendations
Test Scenarios:-
Happy Path:
- Successful swap with fresh route
- Token approval flow
- Transaction confirmation
-
Error Cases:
- Same token addresses
- Invalid addresses
- Insufficient balance
- Rate limiting
- Network errors
-
Edge Cases:
- Very small amounts
- Very large amounts
- Low liquidity pairs
- High volatility tokens
-
Integration Tests:
- Test on testnets first
- Test with small amounts on mainnet
- Monitor transaction success rate
- Test error recovery
14. Monitoring and Analytics
Key Metrics to Track:- Route fetch success rate
- Transaction success rate
- Average route calculation time
- Average transaction gas cost
- Error rates by type
- User slippage preferences
- Most popular token pairs
Complete Integration Example
Here’s a complete, production-ready integration example:Checklist
Before going to production, ensure you’ve covered:- Route freshness validation
- Appropriate slippage settings
- Comprehensive error handling
- Rate limiting implementation
- Token approval flow
- Gas estimation with buffer
- Input validation
- Network-specific handling
- User feedback and loading states
- Testing on testnets
- Error monitoring
- Analytics tracking
- Integrator Features (if using):
- API key obtained from Fibrous Finance
-
swapIntegrator()function used instead ofswap() -
integrator_datapassed to contract function -
min_receivedcalculation verified (amount_out - fee - slippage) - Fee amounts displayed correctly to users
Additional Resources
- API Reference - Complete API documentation
- Error Codes - Error handling reference
- Rate Limits - Rate limiting details
- V2 Migration Guide - Migrating to V2 API
- SDK Documentation - Use our SDK for easier integration
Support
Need help with integration?- Discord: Join our Discord for community support
- Email: [email protected] for direct support
- Documentation: Check our FAQ for common questions