Best Practices
Gas Optimization
Batch Operations
// ❌ Bad: Multiple transactions
await sdk.Pair.removeLiquidity(pair, { positionId, binIds: [1] });
await sdk.Pair.removeLiquidity(pair, { positionId, binIds: [2] });
await sdk.Pair.removeLiquidity(pair, { positionId, binIds: [3] });
// ✅ Good: Single transaction
await sdk.Pair.removeLiquidity(pair, {
positionId,
binIds: [1, 2, 3]
});Minimize Bin Count
// Gas scales with number of bins
const gasEfficient = {
// ❌ Excessive: 100 bins
wide: Array.from({length: 101}, (_, i) => i - 50),
// ✅ Efficient: Focused liquidity
focused: Array.from({length: 21}, (_, i) => i - 10)
};
// Consider gas cost vs capital efficiency
function optimizeBinCount(expectedVolatility: number): number {
if (expectedVolatility < 0.01) return 10; // Stable
if (expectedVolatility < 0.05) return 20; // Normal
return 30; // Volatile
}Efficient Data Fetching
Cache Pair Data
Batch RPC Calls
Selective Data Loading
Smart Contract Interactions
Reuse Transactions
Optimize Call Data
Error Handling Patterns
Retry with Backoff
Circuit Breaker
Memory Management
Clean Up Large Objects
Stream Large Results
Production Checklist
Pre-deployment
Performance Monitoring
Key Principles
Last updated